移动端千目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.
 
 
 

207 lines
5.1 KiB

import axios from "axios";
import icons from "./image-helper";
let mallInfos = new Map();
let baseUrl = "https://iot-dev.123.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,
};
try {
const {
data: { baseUrl: baseUrlFromConfig },
} = await axios.get(process.env.PUBLIC_URL + "/config.json");
baseUrl = baseUrlFromConfig;
} catch (error) {
console.log(error);
}
const config = {
mapDataUrl: `${baseUrl}/api/data/v1/web/getMallMapData/${code}/Aeditor`,
shopInfoUrl: `${baseUrl}/api/data/v1/web/getMapInfo?projectCode=${code}`,
};
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/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;
document.title = projectName;
mall.city = cityName;
const mapData = JSON.parse(mapDataJSON)[0];
mall.floors = buildingList[0].floorList.map(({ floor, floorOrder }) => ({
name: floor,
floorOrder,
url: true,
}));
mall.facilityTypeMap = facs.reduce(
(acc, nxt) => ({
...acc,
[nxt.node]: nxt.customFacilityName || nxt.name,
}),
{}
);
const shopInfo = serverShopInfo
.filter(({ buildingOrder }) => buildingOrder === 0)
.map((iot) => ({
...iot,
name: iot.shopName,
houseNum: iot.houseNumber,
nameEn: iot.shopNameEn,
logoPath: cdnUrl + iot.logoUrl,
shopFormat: iot.industryFatherName,
}))
.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) => {
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 };