Browse Source

feat: 对接obs数据

master
jiannibang 3 years ago
parent
commit
e712b88fa6
  1. 77
      src/js/helpers/data-helper.js

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

@ -2,11 +2,11 @@ import axios from "axios";
import icons from "./image-helper";
let mallInfos = new Map();
// dev
// export const code = "project-k5chc3vt0vkodjbmhl8rua";
// export const baseUrl = "https://iot-dev.123.1000my.com";
export const code = "project-k5chc3vt0vkodjbmhl8rua";
export const baseUrl = "https://iot-dev.123.1000my.com";
// test
export const code = "project-skcn0gk6yb2xutkcsmjtra";
export const baseUrl = "https://project-iot.test.1000my.com";
// export const code = "project-skcn0gk6yb2xutkcsmjtra";
// export const baseUrl = "https://project-iot.test.1000my.com";
export const post = async (url = "", data = {}) => {
const response = await fetch(baseUrl + url, {
method: "POST",
@ -36,10 +36,6 @@ const getMallInfo = async ({ memberID }) => {
offsetToNorth,
};
const floorMap = { 1: true };
const config = {
mapDataUrl: `${baseUrl}/api/guide/v1/web/getMallMapData/${code}/Aeditor`,
shopInfoUrl: `${baseUrl}/api/guide/v1/web/getMapInfo?projectCode=${code}`,
};
let cdnUrl;
try {
@ -51,27 +47,27 @@ const getMallInfo = async ({ memberID }) => {
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()}`,
// };
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失败");
// }
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 [
{ cityName, projectName },
mapDataJSON,
[buildingList, serverShopInfo],
serverShopInfo,
facs,
activities,
pois,
@ -95,7 +91,7 @@ const getMallInfo = async ({ memberID }) => {
try {
const {
data: {
data: { mapData: mapDataJSON },
data: [{ mapData: mapDataJSON }],
},
} = await axios.get(config.mapDataUrl);
return mapDataJSON;
@ -108,10 +104,10 @@ const getMallInfo = async ({ memberID }) => {
try {
const {
data: {
data: { buildingList, shopList: serverShopInfo },
data: [serverShopInfo],
},
} = await axios.get(config.shopInfoUrl);
return [buildingList, serverShopInfo];
return serverShopInfo;
} catch (error) {
console.error(error);
return {};
@ -194,29 +190,26 @@ const getMallInfo = async ({ memberID }) => {
}),
{}
);
mall.floors = buildingList[0].floorList.map(({ floor, floorOrder }) => ({
mall.floors = serverShopInfo.map(({ floor }, floorOrder) => ({
name: floor,
floorOrder,
url: floorMap[floorOrder] ? true : null,
}));
const shopInfo = serverShopInfo
.filter(({ buildingOrder }) => buildingOrder === 0)
.map((iot) => ({
const shopInfo = serverShopInfo.map(({ floorOrd: floorOrder, shopList }) => ({
floorOrder,
shopList: shopList.map((iot) => ({
...iot,
code: iot.shopCode,
name: iot.shopName,
houseNum: iot.houseNumber,
nameEn: iot.shopNameEn,
logoPath: cdnUrl + iot.logoUrl,
shopFormat: iot.industryFatherName,
intro: true,
}))
.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 }));
formatColor: iot.color,
floorOrder,
})),
}));
shopInfo.forEach(({ shopList }) =>
shopList.forEach((shop) => {
if (shopCouponMap[shop.code]) shop.hasCoupon = true;
@ -246,7 +239,7 @@ const getMallInfo = async ({ memberID }) => {
mapData.buildArr.forEach(({ mapData: { parkArea } }) => {
parkArea.forEach(({ parkNum }) => mall.lots.push(parkNum));
});
console.log(mapData);
console.log(mapData, shopInfo);
Object.assign(mall, {
floorData: mall.floors,
shopInfo,
@ -254,7 +247,7 @@ const getMallInfo = async ({ memberID }) => {
floors: mall.floors.reduce((acc, { name, floorOrder, url }) => {
acc[floorOrder] = [url, name];
return acc;
}, new Array()),
}, []),
poiMap,
menu,
});

Loading…
Cancel
Save