From 5823e880515fe2ebad216d5119990ca167aa467f Mon Sep 17 00:00:00 2001 From: jiannibang <271381693@qq.com> Date: Mon, 9 Jan 2023 17:23:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20mallCode=E4=BD=9C=E4=B8=BA=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=BC=A0=E9=80=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/js/helpers/data-helper.js | 178 ++++++++++++++++++---------------- src/pages/Index/Index.js | 7 +- 2 files changed, 96 insertions(+), 89 deletions(-) diff --git a/src/js/helpers/data-helper.js b/src/js/helpers/data-helper.js index b161fa3..e2451d5 100644 --- a/src/js/helpers/data-helper.js +++ b/src/js/helpers/data-helper.js @@ -2,31 +2,17 @@ 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, + +const getMallInfo = async (code) => { + const { groundFloorOrder, scale, offsetToNorth } = { + groundFloorOrder: 0, scale: 0.15, offsetToNorth: 0, }; - document.title = name; + const mall = { baseUrl, - name, - city, code, groundFloorIndex: groundFloorOrder, needSpotLight: false, @@ -40,72 +26,94 @@ const getMallInfo = async () => { shopInfoUrl: `${baseUrl}/api/guide/v1/web/getMapInfo?projectCode=${code}`, }; - const [cdnUrl, mapDataJSON, [buildingList, serverShopInfo], facs, theme] = - 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 []; - } - })(), - (async () => { - try { - const { - data: { data: theme }, - } = await axios.get( - `${baseUrl}/api/guide/v1/web/getProjectBindingTheme?projectCode=${code}` - ); - return theme; - } catch (error) { - console.error(error); - return {}; - } - })(), - ]); + const [ + cdnUrl, + mapDataJSON, + [buildingList, serverShopInfo], + facs, + theme, + { cityName, projectName }, + ] = 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 []; + } + })(), + (async () => { + try { + const { + data: { data: theme }, + } = await axios.get( + `${baseUrl}/api/guide/v1/web/getProjectBindingTheme?projectCode=${code}` + ); + return theme; + } catch (error) { + console.error(error); + return {}; + } + })(), + (async () => { + try { + const { + data: { data }, + } = await axios.get( + `${baseUrl}/api/guide/v1/web/getMallData?projectCode=${code}` + ); + return data; + } catch (error) { + console.error(error); + return {}; + } + })(), + ]); + mall.name = projectName; + document.title = projectName; + mall.city = cityName; const mapData = JSON.parse(mapDataJSON)[0]; mall.floors = buildingList[0].floorList.map(({ floor, floorOrder }) => ({ name: floor, diff --git a/src/pages/Index/Index.js b/src/pages/Index/Index.js index 4a48292..5e5af78 100644 --- a/src/pages/Index/Index.js +++ b/src/pages/Index/Index.js @@ -29,9 +29,9 @@ const Index = () => { const [map, setMap] = useState(null); const [sceneIndex, setSceneIndex] = useState(null); const params = new URLSearchParams(useLocation().search); - const [mallCode, setMallCode] = useState(null); const startParams = params.get("s"); let endId = params.get("e"); + const mallCode = params.get("code"); const [navigation, setNavigation] = useState(false); const [inAnimation, setInAnimation] = useState(false); const [showShops, setShowShops] = useState(false); @@ -318,9 +318,8 @@ const Index = () => { }; useEffect(() => { - if (!mallCode) { - getMallInfo().then((result) => { - if (!mallCode) setMallCode(result.mall.code); + if (mallCode) { + getMallInfo(mallCode).then((result) => { setMallInfo(result); }); }