diff --git a/src/js/helpers/data-helper.js b/src/js/helpers/data-helper.js index 526ed41..7ed3901 100644 --- a/src/js/helpers/data-helper.js +++ b/src/js/helpers/data-helper.js @@ -2,23 +2,21 @@ import axios from "axios"; import icons from "./image-helper"; let mallInfos = new Map(); +export const code = "project-1iijx369xueqhh5w8wyn0a"; +export const baseUrl = "https://iot.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 () => { - const { - baseUrl, - cdnUrl, - name, - city, - code, - groundFloorOrder, - floors, - scale, - offsetToNorth, - } = { - baseUrl: "https://ar.1000my.com", - cdnUrl: "https://cdn.1000my.cn", - name: "上海市东方医院", - city: "上海", - code: "5aae5c33-cb8e-4737-b243-ed735bce68e2", + const { groundFloorOrder, floors, scale, offsetToNorth } = { groundFloorOrder: 0, scale: 0.15, floors: [ @@ -47,9 +45,9 @@ const getMallInfo = async () => { }; const mall = { + city: "上海", + name: "上海市东方医院", baseUrl, - name, - city, code, groundFloorIndex: groundFloorOrder, needSpotLight: false, @@ -59,16 +57,27 @@ const getMallInfo = async () => { cloud: "1000my", offsetToNorth, }; + + 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}/projects/${code}/Aeditor/Aeditor.json?t=${new Date().getTime()}`, - shopInfoUrl: `${cdnUrl}/projects/${code}/QueryShopListForMap/QueryShopListForMap.json?t=${new Date().getTime()}`, + 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}/projects/${code}/config.json?t=${new Date().getTime()}` + `${cdnUrl}/ar/${code}/config.json?t=${new Date().getTime()}` ); if (mapUrl) config.mapDataUrl = mapUrl; if (shopUrl) config.shopInfoUrl = shopUrl; @@ -76,25 +85,49 @@ const getMallInfo = async () => { console.log("获取config失败"); } - const [ - { - data: { - data: { mapData: mapDataJSON }, - }, - }, - { - data: { data: serverShopInfo }, - }, - { - data: { data: facs }, - }, - ] = await Promise.all([ - axios.get(config.mapDataUrl), - axios.get(config.shopInfoUrl), - axios.post(`${baseUrl}/Api/Cdn/FacilityInfo`, { - mallCode: code, - }), + const [mapDataJSON, serverShopInfo, facs] = await Promise.all([ + (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: [serverShopInfo], + }, + } = await axios.get(config.shopInfoUrl); + return 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.facilityTypeMap = facs.reduce( (acc, nxt) => ({ ...acc, @@ -102,8 +135,37 @@ const getMallInfo = async () => { }), {} ); - const mapData = JSON.parse(mapDataJSON)[0]; - const shopInfo = serverShopInfo; + const shopCouponMap = {}; + const shopInfo = serverShopInfo.map(({ floorOrd: floorOrder, shopList }) => ({ + floorOrder, + shopList: shopList.map((iot) => ({ + ...iot, + code: iot.shopCode, + houseNum: iot.houseNumber, + logoPath: cdnUrl + iot.logoUrl, + shopFormat: iot.industryFatherName, + intro: true, + formatColor: iot.color, + floorOrder, + })), + })); + 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(""); + }) + ); + console.log(shopInfo); const images = facs.reduce( (acc, nxt) => ({ ...acc, [nxt.abbreviation]: nxt.filePath }), {} @@ -124,7 +186,7 @@ const getMallInfo = async () => { 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); diff --git a/src/pages/Index/Index.js b/src/pages/Index/Index.js index be1d258..2d738c4 100644 --- a/src/pages/Index/Index.js +++ b/src/pages/Index/Index.js @@ -71,7 +71,9 @@ const Index = () => { const setStatistics = mall ? ({ userId, navType, pointType, objectCode, objectName, floorName }) => - axios.post(mall.baseUrl + "/Api/Statistics/AddGuideRecord", { + userId && + userId !== "null" && + axios.post(mall.baseUrl + "/api/ar/v1/applet/AddGuideRecord", { mallCode: mall.code, userId, navType, @@ -363,7 +365,6 @@ const Index = () => { }, onAzimuthAngleChange: (angle) => setAzimuthAngle(Math.floor((angle / Math.PI) * 180)), - onClick: console.log, }); };