Browse Source

feat: 东方医院迁移iot

dev
jiannibang 3 years ago
parent
commit
955bc32757
  1. 146
      src/js/helpers/data-helper.js
  2. 5
      src/pages/Index/Index.js

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

@ -2,23 +2,21 @@ 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-1iijx369xueqhh5w8wyn0a";
export const baseUrl = "https://iot.1000my.com";
export const post = async (url = "", data = {}) => {
const response = await fetch(baseUrl + url, {
method: "POST",
headers: {
"Content-Type": "application/json",
projectCode: code,
},
body: JSON.stringify({ ...data, mallCode: code }),
});
return response.json();
};
const getMallInfo = async () => { const getMallInfo = async () => {
const {
baseUrl,
cdnUrl,
name,
city,
code,
groundFloorOrder,
floors,
scale,
offsetToNorth,
} = {
baseUrl: "https://ar.1000my.com",
cdnUrl: "https://cdn.1000my.cn",
name: "上海市东方医院",
city: "上海",
code: "5aae5c33-cb8e-4737-b243-ed735bce68e2",
const { groundFloorOrder, floors, scale, offsetToNorth } = {
groundFloorOrder: 0, groundFloorOrder: 0,
scale: 0.15, scale: 0.15,
floors: [ floors: [
@ -47,9 +45,9 @@ const getMallInfo = async () => {
}; };
const mall = { const mall = {
city: "上海",
name: "上海市东方医院",
baseUrl, baseUrl,
name,
city,
code, code,
groundFloorIndex: groundFloorOrder, groundFloorIndex: groundFloorOrder,
needSpotLight: false, needSpotLight: false,
@ -59,16 +57,27 @@ const getMallInfo = async () => {
cloud: "1000my", cloud: "1000my",
offsetToNorth, 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 = { const config = {
mapDataUrl: `${cdnUrl}/projects/${code}/Aeditor/Aeditor.json?t=${new Date().getTime()}`,
shopInfoUrl: `${cdnUrl}/projects/${code}/QueryShopListForMap/QueryShopListForMap.json?t=${new Date().getTime()}`,
mapDataUrl: `${cdnUrl}/ar/${code}/Aeditor/Aeditor.json?t=${new Date().getTime()}`,
shopInfoUrl: `${cdnUrl}/ar/${code}/QueryShopListForMap/QueryShopListForMap.json?t=${new Date().getTime()}`,
}; };
try { try {
const { const {
data: { mapUrl, shopUrl }, data: { mapUrl, shopUrl },
} = await axios.get( } = await axios.get(
`${cdnUrl}/projects/${code}/config.json?t=${new Date().getTime()}`
`${cdnUrl}/ar/${code}/config.json?t=${new Date().getTime()}`
); );
if (mapUrl) config.mapDataUrl = mapUrl; if (mapUrl) config.mapDataUrl = mapUrl;
if (shopUrl) config.shopInfoUrl = shopUrl; if (shopUrl) config.shopInfoUrl = shopUrl;
@ -76,25 +85,49 @@ const getMallInfo = async () => {
console.log("获取config失败"); console.log("获取config失败");
} }
const [
{
data: {
data: { mapData: mapDataJSON },
},
},
{
data: { data: serverShopInfo },
},
{
data: { data: facs },
},
] = await Promise.all([
axios.get(config.mapDataUrl),
axios.get(config.shopInfoUrl),
axios.post(`${baseUrl}/Api/Cdn/FacilityInfo`, {
mallCode: code,
}),
const [mapDataJSON, serverShopInfo, facs] = await Promise.all([
(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: [serverShopInfo],
},
} = await axios.get(config.shopInfoUrl);
return 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 [];
}
})(),
]); ]);
const mapData = JSON.parse(mapDataJSON)[0];
mall.facilityTypeMap = facs.reduce( mall.facilityTypeMap = facs.reduce(
(acc, nxt) => ({ (acc, nxt) => ({
...acc, ...acc,
@ -102,8 +135,37 @@ const getMallInfo = async () => {
}), }),
{} {}
); );
const mapData = JSON.parse(mapDataJSON)[0];
const shopInfo = serverShopInfo;
const shopCouponMap = {};
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,
intro: true,
formatColor: iot.color,
floorOrder,
})),
}));
shopInfo.forEach(({ shopList }) =>
shopList.forEach((shop) => {
if (shopCouponMap[shop.code]) shop.hasCoupon = true;
else shop.hasCoupon = false;
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("");
})
);
console.log(shopInfo);
const images = facs.reduce( const images = facs.reduce(
(acc, nxt) => ({ ...acc, [nxt.abbreviation]: nxt.filePath }), (acc, nxt) => ({ ...acc, [nxt.abbreviation]: nxt.filePath }),
{} {}
@ -124,7 +186,7 @@ const getMallInfo = async () => {
floors: mall.floors.reduce((acc, { name, floorOrder, url }) => { floors: mall.floors.reduce((acc, { name, floorOrder, url }) => {
acc[floorOrder] = [url, name]; acc[floorOrder] = [url, name];
return acc; return acc;
}, new Array()),
}, []),
}); });
const mallInfo = { mall, shopInfo, images }; const mallInfo = { mall, shopInfo, images };
mallInfos.set(mall.code, mallInfo); mallInfos.set(mall.code, mallInfo);

5
src/pages/Index/Index.js

@ -71,7 +71,9 @@ const Index = () => {
const setStatistics = mall const setStatistics = mall
? ({ userId, navType, pointType, objectCode, objectName, floorName }) => ? ({ userId, navType, pointType, objectCode, objectName, floorName }) =>
axios.post(mall.baseUrl + "/Api/Statistics/AddGuideRecord", {
userId &&
userId !== "null" &&
axios.post(mall.baseUrl + "/api/ar/v1/applet/AddGuideRecord", {
mallCode: mall.code, mallCode: mall.code,
userId, userId,
navType, navType,
@ -363,7 +365,6 @@ const Index = () => {
}, },
onAzimuthAngleChange: (angle) => onAzimuthAngleChange: (angle) =>
setAzimuthAngle(Math.floor((angle / Math.PI) * 180)), setAzimuthAngle(Math.floor((angle / Math.PI) * 180)),
onClick: console.log,
}); });
}; };

Loading…
Cancel
Save