import axios from "axios"; import icons from "./image-helper"; let mallInfos = new Map(); // dev // export const code = "project-k5chc3vt0vkodjbmhl8rua"; // export const baseUrl = "https://iot-dev.123.1000my.com"; // test export const code = "project-skcn0gk6yb2xutkcsmjtra"; export const baseUrl = "https://project-iot.test.1000my.com"; export const post = async (url = "", data = {}) => { const response = await fetch(baseUrl + url, { method: "POST", headers: { "Content-Type": "application/json", projectCode: code, }, body: JSON.stringify({ ...data, mallCode: code }), }); return response.json(); }; const getMallInfo = async ({ memberID }) => { const { name, groundFloorOrder, scale, offsetToNorth } = { groundFloorOrder: 1, scale: 0.15, offsetToNorth: 0, }; document.title = name; const mall = { baseUrl, code, groundFloorIndex: groundFloorOrder, needSpotLight: false, scale, isNew: true, cloud: "1000my", offsetToNorth, }; const floorMap = { 1: true }; const config = { mapDataUrl: `${baseUrl}/api/guide/v1/web/getMallMapData/${code}/Aeditor`, shopInfoUrl: `${baseUrl}/api/guide/v1/web/getMapInfo?projectCode=${code}`, }; let cdnUrl; try { const { data: { data: uploadUrl }, } = await axios.get(`${baseUrl}/api/info/v1/web/getUploadUrl`); cdnUrl = uploadUrl; } catch (error) { console.error(error); } // const config = { // mapDataUrl: `${cdnUrl}/ar/${code}/Aeditor/Aeditor.json?t=${new Date().getTime()}`, // shopInfoUrl: `${cdnUrl}/ar/${code}/QueryShopListForMap/QueryShopListForMap.json?t=${new Date().getTime()}`, // }; // try { // const { // data: { mapUrl, shopUrl }, // } = await axios.get( // `${cdnUrl}/ar/${code}/config.json?t=${new Date().getTime()}` // ); // if (mapUrl) config.mapDataUrl = mapUrl; // if (shopUrl) config.shopInfoUrl = shopUrl; // } catch (error) { // console.log("获取config失败"); // } const [ { cityName, projectName }, mapDataJSON, [buildingList, serverShopInfo], facs, activities, pois, menu, shopCouponMap, ] = await Promise.all([ (async () => { try { const { data: { data }, } = await axios.get( `${baseUrl}/api/guide/v1/web/getMallData?projectCode=${code}` ); return data; } 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 []; } })(), (async () => { try { const { data: activities } = await post( `/api/ar/v1/applet/MallActList`, { memberID, } ); return activities; } catch (error) { console.error(error); return []; } })(), (async () => { try { const { data: pois } = await post(`/api/ar/v1/applet/GetPoiList`); return pois; } catch (error) { console.error(error); return []; } })(), (async () => { try { const { data: menu } = await post(`/api/ar/v1/applet/MallAppModules`); return menu; } catch (error) { console.error(error); return []; } })(), (async () => { try { const { data: { shopDetailShowCoupon }, } = await post(`/api/ar/v1/applet/MiniproBasicData`, { memberID, }); const shopCouponMap = shopDetailShowCoupon.reduce( (acc, nxt) => ({ ...acc, [nxt]: true }), {} ); return shopCouponMap; } catch (error) { console.error(error); return {}; } })(), ]); mall.name = projectName; document.title = projectName; mall.city = cityName; const mapData = JSON.parse(mapDataJSON)[0]; mall.activities = activities; mall.pois = pois; const poiMap = pois.reduce((acc, nxt) => ({ ...acc, [nxt.code]: nxt }), {}); mall.facilityTypeMap = facs.reduce( (acc, nxt) => ({ ...acc, [nxt.node]: nxt.customFacilityName || nxt.name, }), {} ); mall.floors = buildingList[0].floorList.map(({ floor, floorOrder }) => ({ name: floor, floorOrder, url: floorMap[floorOrder] ? true : null, })); const shopInfo = serverShopInfo .filter(({ buildingOrder }) => buildingOrder === 0) .map((iot) => ({ ...iot, code: iot.shopCode, name: iot.shopName, houseNum: iot.houseNumber, nameEn: iot.shopNameEn, logoPath: cdnUrl + iot.logoUrl, shopFormat: iot.industryFatherName, intro: true, })) .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 })); shopInfo.forEach(({ shopList }) => shopList.forEach((shop) => { if (shopCouponMap[shop.code]) shop.hasCoupon = true; else shop.hasCoupon = false; 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()), poiMap, menu, }); const mallInfo = { mall, shopInfo, images }; mallInfos.set(mall.code, mallInfo); return mallInfo; }; export { getMallInfo };