You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

113 lines
3.2 KiB

import { get, post } from "./pages/map2d/util";
import dataHelper from "./data-helper";
let mapDataAndShop = null;
export const mall = {
isNew: true,
name: "荟聚",
city: "无锡",
code: "ef2c0bd1-6751-41be-86b7-df4b9ef49bad",
mapFileUrl: `https://hjcdn.cdn.bcebos.com/livatwuxi/Aeditor/Aeditor.json?t=${new Date().getTime()}`,
mapDataUrl: "https://huiju.mapais.com/wxyj/api/CDN/GetMapInfo",
shopInfoUrl: `https://hjcdn.cdn.bcebos.com/livatwuxi/QueryShopListForMap/QueryShopListForMap.json?t=${new Date().getTime()}`,
groundFloorIndex: 0,
floors: [
[true, "L1"],
[true, "L2"],
[true, "L3"],
[true, "L4"],
[true, "L5"],
],
};
export const getMapData = async () => {
if (mapDataAndShop) return mapDataAndShop;
try {
const { mapUrl, shopUrl } = await get(
`https://hjcdn.cdn.bcebos.com/livatwuxi/config.json?t=${new Date().getTime()}`
);
if (mapUrl) mall.mapFileUrl = mapUrl;
if (shopUrl) mall.shopInfoUrl = shopUrl;
} catch (error) {
console.log("获取config失败");
}
let [mapData, serverShopInfo, ...rest] = await Promise.all([
get(mall.mapFileUrl),
get(mall.shopInfoUrl),
...mall.floors.map((_, i) =>
post(mall.mapDataUrl, {
mallCode: mall.code,
key: i,
})
),
]);
mapData = JSON.parse(mapData.data.mapData)[0];
const map2dData = rest.map(({ data: { mapData } }) => JSON.parse(mapData));
mall.floors.forEach((floor, i) => {
floor[2] = map2dData[i];
});
serverShopInfo = serverShopInfo.data;
const floors = mall.floors;
console.log(mall.floors);
let shopMap = {};
serverShopInfo.forEach(({ shopList }) => {
shopList.forEach((shop) => {
shop.floorName = floors[shop.floorOrder][1];
shopMap[shop.houseNum] = shop;
});
});
mapData.buildArr.forEach(({ mapData: { path } }, i) => {
if (i <= 2)
path.nodes.forEach((node) =>
node.list.forEach((adj) => {
adj.cost *= 3;
})
);
});
const dataHelperResponse = await dataHelper({
serverShopInfo,
mapData,
mall,
});
const pMap = mapData.buildArr
.map(({ mapData: { parkArea } }, i) => {
return Object.entries(
parkArea.reduce((acc, { parkNum, shopNav }) => {
const key = `${i}_${shopNav}`;
return {
...acc,
[key]: [...(acc[key] ? acc[key] : []), parkNum],
};
}, {})
).map(([key, parkNo]) => {
const [floorOrder, pathNo] = key.split("_");
return { floorOrder, pathNo, parkNo };
});
})
.reduce((acc, nxt) => [...acc, ...nxt], [])
.reduce((acc, { floorOrder, pathNo, parkNo }) => {
if (pathNo == -1 || !pathNo) return acc;
acc = { ...acc };
parkNo.forEach((name) => {
acc[name] = {
name,
navPoint: pathNo,
floorOrder,
floorName: floors[floorOrder][1],
xaxis: dataHelperResponse.points[floorOrder][pathNo]
? dataHelperResponse.points[floorOrder][pathNo].position
: null,
yaxis: pathNo,
};
});
return acc;
}, {});
mapDataAndShop = {
...dataHelperResponse,
serverShopInfo,
mapData,
mall,
shopMap,
pMap,
};
return mapDataAndShop;
};