import axios from "axios"; import icons from "./image-helper"; let mallInfos = new Map(); export const code = "project-200"; export const baseUrl = "https://project-iot.test.1000my.com"; export const get = async (url = "", data = {}) => { const response = await fetch(baseUrl + url, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ ...data, mallCode: code }), }); return response.json(); }; const getMallInfo = async () => { const { name, city, groundFloorOrder, scale, offsetToNorth } = { name: "桥北万象", city: "南京", groundFloorOrder: 2, scale: 0.15, offsetToNorth: 0, }; document.title = name; const mall = { baseUrl, name, city, code, groundFloorIndex: groundFloorOrder, needSpotLight: false, scale, isNew: true, cloud: "1000my", offsetToNorth, }; const config = { mapDataUrl: `${baseUrl}/api/guide/v1/web/getMallMapData/${code}/Aeditor`, shopInfoUrl: `${baseUrl}/api/guide/v1/web/getMapInfo?projectCode=${code}`, }; const [cdnUrl, mapDataJSON, [buildingList, serverShopInfo], facs] = await Promise.all([ (async () => { try { const { data: { data: cdnUrl }, } = await axios.get(`${baseUrl}/api/info/v1/web/getUploadUrl`); return cdnUrl; } catch (error) { console.error(error); return {}; } })(), (async () => { try { const { data: { data: { mapData: mapDataJSON }, }, } = await axios.get(config.mapDataUrl); return mapDataJSON; } catch (error) { console.error(error); return {}; } })(), (async () => { try { const { data: { data: { buildingList, shopList: serverShopInfo }, }, } = await axios.get(config.shopInfoUrl); return [buildingList, serverShopInfo]; } catch (error) { console.error(error); return {}; } })(), (async () => { try { const { data: { data: facs }, } = await axios.get( `${baseUrl}/api/guide/v1/web/getProjectUsedIconList?projectCode=${code}` ); return facs; } catch (error) { console.error(error); return []; } })(), ]); const mapData = JSON.parse(mapDataJSON)[0]; mall.floors = buildingList[0].floorList.map(({ floor, floorOrder }) => ({ name: floor, floorOrder, url: true, })); mall.facilityTypeMap = facs.reduce( (acc, nxt) => ({ ...acc, [nxt.node]: nxt.customFacilityName || nxt.name, }), {} ); const shopInfo = serverShopInfo .filter(({ buildingOrder }) => buildingOrder === 0) .map((iot) => ({ ...iot, name: iot.shopName, houseNum: iot.houseNumber, nameEn: iot.shopNameEn, logoPath: cdnUrl + iot.logoUrl, shopFormat: iot.industryFatherName, })) .reduce((acc, nxt) => { if (!acc[nxt.floorOrder]) acc[nxt.floorOrder] = [nxt]; else acc[nxt.floorOrder] = [...acc[nxt.floorOrder], nxt]; return acc; }, []) .map((shopList, floorOrder) => ({ floorOrder, shopList })); console.log(shopInfo); shopInfo.forEach(({ shopList }) => shopList.forEach((shop) => { shop.initialsCn = shop.name .split(" ") .filter((t) => t) .map((str) => str[0]) .join(""); shop.initialsEn = shop.nameEn .split(" ") .filter((t) => t) .map((str) => str[0]) .join(""); }) ); const images = facs.reduce( (acc, nxt) => ({ ...acc, [nxt.abbreviation]: nxt.filePath }), {} ); Object.assign(images, icons); mall.addtionalFacilityCodeMap = facs.reduce( (acc, nxt) => ({ ...acc, [nxt.abbreviation]: Number(nxt.node) }), {} ); mall.lots = []; mapData.buildArr.forEach(({ mapData: { parkArea } }) => { parkArea.forEach(({ parkNum }) => mall.lots.push(parkNum)); }); console.log(mapData); Object.assign(mall, { floorData: mall.floors, shopInfo, mapData, floors: mall.floors.reduce((acc, { name, floorOrder, url }) => { acc[floorOrder] = [url, name]; return acc; }, new Array()), }); const mallInfo = { mall, shopInfo, images }; mallInfos.set(mall.code, mallInfo); return mallInfo; }; export { getMallInfo };