Browse Source

feat: mallCode作为参数传递

pull/3/head
jiannibang 3 years ago
parent
commit
5823e88051
  1. 50
      src/js/helpers/data-helper.js
  2. 7
      src/pages/Index/Index.js

50
src/js/helpers/data-helper.js

@ -2,31 +2,17 @@ import axios from "axios";
import icons from "./image-helper"; import icons from "./image-helper";
let mallInfos = new Map(); let mallInfos = new Map();
export const code = "project-200";
export const baseUrl = "https://project-iot.test.1000my.com"; 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, scale: 0.15,
offsetToNorth: 0, offsetToNorth: 0,
}; };
document.title = name;
const mall = { const mall = {
baseUrl, baseUrl,
name,
city,
code, code,
groundFloorIndex: groundFloorOrder, groundFloorIndex: groundFloorOrder,
needSpotLight: false, needSpotLight: false,
@ -40,8 +26,14 @@ const getMallInfo = async () => {
shopInfoUrl: `${baseUrl}/api/guide/v1/web/getMapInfo?projectCode=${code}`, shopInfoUrl: `${baseUrl}/api/guide/v1/web/getMapInfo?projectCode=${code}`,
}; };
const [cdnUrl, mapDataJSON, [buildingList, serverShopInfo], facs, theme] =
await Promise.all([
const [
cdnUrl,
mapDataJSON,
[buildingList, serverShopInfo],
facs,
theme,
{ cityName, projectName },
] = await Promise.all([
(async () => { (async () => {
try { try {
const { const {
@ -105,7 +97,23 @@ const getMallInfo = async () => {
return {}; 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]; const mapData = JSON.parse(mapDataJSON)[0];
mall.floors = buildingList[0].floorList.map(({ floor, floorOrder }) => ({ mall.floors = buildingList[0].floorList.map(({ floor, floorOrder }) => ({
name: floor, name: floor,

7
src/pages/Index/Index.js

@ -29,9 +29,9 @@ const Index = () => {
const [map, setMap] = useState(null); const [map, setMap] = useState(null);
const [sceneIndex, setSceneIndex] = useState(null); const [sceneIndex, setSceneIndex] = useState(null);
const params = new URLSearchParams(useLocation().search); const params = new URLSearchParams(useLocation().search);
const [mallCode, setMallCode] = useState(null);
const startParams = params.get("s"); const startParams = params.get("s");
let endId = params.get("e"); let endId = params.get("e");
const mallCode = params.get("code");
const [navigation, setNavigation] = useState(false); const [navigation, setNavigation] = useState(false);
const [inAnimation, setInAnimation] = useState(false); const [inAnimation, setInAnimation] = useState(false);
const [showShops, setShowShops] = useState(false); const [showShops, setShowShops] = useState(false);
@ -318,9 +318,8 @@ const Index = () => {
}; };
useEffect(() => { useEffect(() => {
if (!mallCode) {
getMallInfo().then((result) => {
if (!mallCode) setMallCode(result.mall.code);
if (mallCode) {
getMallInfo(mallCode).then((result) => {
setMallInfo(result); setMallInfo(result);
}); });
} }

Loading…
Cancel
Save