移动端千目GO
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

204 lines
5.2 KiB

import axios from "axios";
import icons from "./image-helper";
let mallInfos = new Map();
const href = window.location.href;
let baseUrl =
href.includes("localhost") || href.includes("-dev") || href.includes("-test")
? "https://project-iot.test.1000my.com"
: "https://iot.1000my.com";
const getMallInfo = async (code) => {
const { groundFloorOrder, scale, offsetToNorth } = {
groundFloorOrder: 0,
scale: 0.15,
offsetToNorth: 0,
};
const mall = {
baseUrl,
code,
groundFloorIndex: groundFloorOrder,
needSpotLight: false,
scale,
isNew: true,
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}/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 [mapDataJSON, serverShopInfo, facs, theme, { cityName, projectName }] =
await Promise.all([
(async () => {
try {
const {
data: { data },
} = await axios.get(config.mapDataUrl);
return data[0].mapData;
} catch (error) {
console.error(error);
return {};
}
})(),
(async () => {
try {
const {
data: { data },
} = await axios.get(config.shopInfoUrl);
return data[0];
} catch (error) {
console.error(error);
return {};
}
})(),
(async () => {
try {
const {
data: { data: facs },
} = await axios.get(
`${baseUrl}/api/data/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/data/v1/web/getMallData?projectCode=${code}`
);
return data;
} catch (error) {
console.error(error);
return {};
}
})(),
]);
mall.name = projectName
.replace("导视", "")
.replace("信发", "")
.replace("项目", "")
.replace("/", "");
document.title = mall.name;
mall.city = cityName;
const mapData = JSON.parse(mapDataJSON)[0];
mall.floors = serverShopInfo.map(({ floor, floorOrd }) => ({
name: floor,
floorOrder: floorOrd,
url: true,
}));
mall.facilityTypeMap = facs.reduce(
(acc, nxt) => ({
...acc,
[nxt.node]: nxt.customFacilityName || nxt.name,
}),
{}
);
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,
shopFormatName: iot.industryFatherName,
intro: true,
formatColor: iot.color,
floorOrder,
})),
}));
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));
});
const r = document.querySelector(":root");
Object.entries(theme).forEach(([cat, obj]) => {
Object.entries(obj).forEach(([k, v]) => {
if (cat === "image") theme[cat][k] = cdnUrl + v;
else r.style.setProperty(`--${cat}-${k}`, v);
});
});
console.log(mapData, shopInfo, theme);
Object.assign(mall, {
floorData: mall.floors,
shopInfo,
mapData,
floors: mall.floors.reduce((acc, { name, floorOrder, url }) => {
acc[floorOrder] = [url, name];
return acc;
}, []),
theme,
});
const mallInfo = { mall, shopInfo, images };
mallInfos.set(mall.code, mallInfo);
return mallInfo;
};
export { getMallInfo };