Browse Source

feat: 接口返回改为200

master
jiannibang 3 years ago
parent
commit
b68cb371bc
  1. 4
      package.json
  2. 123
      src/js/helpers/data-helper.js
  3. 13
      src/pages/Activities/Activities.js
  4. 2
      src/pages/Car/Car.js
  5. 4
      src/pages/Coupons/ApplyModal/ApplyModal.js
  6. 19
      src/pages/Coupons/CouponList/CouponList.js
  7. 4
      src/pages/Coupons/ShopManager/ShopManager.js
  8. 8
      src/pages/Coupons/WriteOffModal/WriteOffModal.js
  9. 6
      src/pages/Index/Index.js
  10. 15
      src/pages/ShopCoupons/ShopCoupons.js
  11. 23
      yarn.lock

4
package.json

@ -1,5 +1,5 @@
{
"name": "qmplaza",
"name": "iot-qmplaza",
"version": "0.1.0",
"private": true,
"homepage": "./",
@ -29,7 +29,7 @@
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build && coscmd config -a AKIDjS6at7fjTAVgggDNCrogRiZTSL304DPR -s FPPGCXr4xgZRLKDC8tZGp7HTZXlqx0gU -b lg-cjdqwkbo-1256266248 -r ap-shanghai && coscmd delete qmplaza -f && coscmd upload -r build qmplaza",
"build": "react-scripts build && coscmd config -a AKIDjS6at7fjTAVgggDNCrogRiZTSL304DPR -s FPPGCXr4xgZRLKDC8tZGp7HTZXlqx0gU -b lg-cjdqwkbo-1256266248 -r ap-shanghai && coscmd delete iot-qmplaza -f && coscmd upload -r build iot-qmplaza",
"test": "react-scripts test",
"eject": "react-scripts eject"
},

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

@ -1,79 +1,87 @@
import axios from "axios";
import icons from "./image-helper";
let mallInfos = new Map();
export const cdnUrl = "https://cdn.1000my.cn";
export const code = "b4a45cf0-85ce-4123-99f0-e4ddce2731de";
export const baseUrl = "https://test.ar.1000my.com";
export const code = "project-k5chc3vt0vkodjbmhl8rua";
export const baseUrl = "https://iot-dev.123.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 ({ memberID }) => {
const { name, city, groundFloorOrder, floors, scale, offsetToNorth } = {
name: "千目广场",
city: "南京",
const { name, groundFloorOrder, scale, offsetToNorth } = {
groundFloorOrder: 1,
scale: 0.15,
floors: [
{
name: "F1",
floorOrder: 0,
url: null,
},
{
name: "F2",
floorOrder: 1,
url: true,
},
],
offsetToNorth: 0,
};
document.title = name;
const mall = {
baseUrl,
name,
city,
code,
groundFloorIndex: groundFloorOrder,
needSpotLight: false,
scale,
floors,
isNew: true,
cloud: "1000my",
offsetToNorth,
};
const floorMap = { 1: true };
const config = {
mapDataUrl: `${cdnUrl}/test-projects/${code}/Aeditor/Aeditor.json?t=${new Date().getTime()}`,
shopInfoUrl: `${cdnUrl}/test-projects/${code}/QueryShopListForMap/QueryShopListForMap.json?t=${new Date().getTime()}`,
mapDataUrl: `${baseUrl}/api/guide/v1/web/getMallMapData/${code}/Aeditor`,
shopInfoUrl: `${baseUrl}/api/guide/v1/web/getMapInfo?projectCode=${code}`,
};
let cdnUrl;
try {
const {
data: { mapUrl, shopUrl },
} = await axios.get(
`${cdnUrl}/test-projects/${code}/config.json?t=${new Date().getTime()}`
);
if (mapUrl) config.mapDataUrl = mapUrl;
if (shopUrl) config.shopInfoUrl = shopUrl;
data: { data: uploadUrl },
} = await axios.get(`${baseUrl}/api/info/v1/web/getUploadUrl`);
cdnUrl = uploadUrl;
} catch (error) {
console.log("获取config失败");
console.error(error);
}
// try {
// const {
// data: { mapUrl, shopUrl },
// } = await axios.get(
// `${cdnUrl}/test-projects/${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,
serverShopInfo,
[buildingList, serverShopInfo],
facs,
activities,
pois,
menu,
shopCouponMap,
] = await Promise.all([
(async () => {
try {
const {
data: { data },
} = await axios.get(
`${baseUrl}/api/guide/v1/web/getMallData?projectCode=${code}`
);
return data;
} catch (error) {
console.error(error);
return {};
}
})(),
(async () => {
try {
const {
@ -90,9 +98,11 @@ const getMallInfo = async ({ memberID }) => {
(async () => {
try {
const {
data: { data: serverShopInfo },
data: {
data: { buildingList, shopList: serverShopInfo },
},
} = await axios.get(config.shopInfoUrl);
return serverShopInfo;
return [buildingList, serverShopInfo];
} catch (error) {
console.error(error);
return {};
@ -100,7 +110,11 @@ const getMallInfo = async ({ memberID }) => {
})(),
(async () => {
try {
const { data: facs } = await post(`/Api/Cdn/FacilityInfo`);
const {
data: { data: facs },
} = await axios.get(
`${baseUrl}/api/guide/v1/web/getProjectUsedIconList?projectCode=${code}`
);
return facs;
} catch (error) {
console.error(error);
@ -109,9 +123,12 @@ const getMallInfo = async ({ memberID }) => {
})(),
(async () => {
try {
const { data: activities } = await post(`/Api/Operation/MallActList`, {
memberID,
});
const { data: activities } = await post(
`/api/ar/v1/applet/MallActList`,
{
memberID,
}
);
return activities;
} catch (error) {
console.error(error);
@ -120,7 +137,7 @@ const getMallInfo = async ({ memberID }) => {
})(),
(async () => {
try {
const { data: pois } = await post(`/api/Operation/GetPoiList`);
const { data: pois } = await post(`/api/ar/v1/applet/GetPoiList`);
return pois;
} catch (error) {
console.error(error);
@ -129,7 +146,7 @@ const getMallInfo = async ({ memberID }) => {
})(),
(async () => {
try {
const { data: menu } = await post(`/Api/AppModule/MallAppModules`);
const { data: menu } = await post(`/api/ar/v1/applet/MallAppModules`);
return menu;
} catch (error) {
console.error(error);
@ -140,7 +157,7 @@ const getMallInfo = async ({ memberID }) => {
try {
const {
data: { shopDetailShowCoupon },
} = await post(`/Api/Operation/MiniproBasicData`, {
} = await post(`/api/ar/v1/applet/MiniproBasicData`, {
memberID,
});
const shopCouponMap = shopDetailShowCoupon.reduce(
@ -154,6 +171,9 @@ const getMallInfo = async ({ memberID }) => {
}
})(),
]);
mall.name = projectName;
document.title = projectName;
mall.city = cityName;
const mapData = JSON.parse(mapDataJSON)[0];
mall.activities = activities;
mall.pois = pois;
@ -165,7 +185,28 @@ const getMallInfo = async ({ memberID }) => {
}),
{}
);
const shopInfo = serverShopInfo;
mall.floors = buildingList[0].floorList.map(({ floor, floorOrder }) => ({
name: floor,
floorOrder,
url: floorMap[floorOrder] ? true : null,
}));
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,
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 }));
shopInfo.forEach(({ shopList }) =>
shopList.forEach((shop) => {
if (shopCouponMap[shop.code]) shop.hasCoupon = true;

13
src/pages/Activities/Activities.js

@ -35,14 +35,17 @@ const Activities = ({
const receive = async (activity) => {
setReceiving(true);
try {
const { code, data, msg } = await post("/Api/Coupon/CouponReceive", {
activityCode: activity.code,
memberID,
});
const { code, data, msg } = await post(
"/api/ar/v1/applet/CouponReceive",
{
activityCode: activity.code,
memberID,
}
);
window.weui.toast(msg, {
className: "toast",
});
if (code === "200") {
if (code === 200) {
activity.isReceived = true;
}
} catch (error) {

2
src/pages/Car/Car.js

@ -55,7 +55,7 @@ const Car = ({ lots, onLot = () => {}, plate, hasReverse }) => {
const {
data: { data, code, msg },
} = { data: { data: null, code: "201", msg: "123" } };
if (code !== "200")
if (code !== 200)
return window.weui.toast(msg, {
className: "toast",
});

4
src/pages/Coupons/ApplyModal/ApplyModal.js

@ -19,7 +19,7 @@ const ApplyModal = ({ onBack, memberID }) => {
if (!beginTime) return toast("请选择开始时间");
if (!endTime) return toast("请选择结束时间");
try {
const { code, msg } = await post("/api/coupon/ApplyCoupon", {
const { code, msg } = await post("/api/ar/v1/applet/ApplyCoupon", {
title,
totalCount,
beginTime,
@ -27,7 +27,7 @@ const ApplyModal = ({ onBack, memberID }) => {
memberID,
couponRules,
});
if (code === "200") {
if (code === 200) {
toast("已提交申请,审核中!");
onBack && onBack();
} else {

19
src/pages/Coupons/CouponList/CouponList.js

@ -30,14 +30,17 @@ const CouponList = ({ memberID }) => {
if (loading || nextPageIndex === null || !memberID) return;
setLoading(true);
try {
const { code, data, msg } = await post("/api/coupon/UserCouponList", {
paging: 1,
state,
pageIndex: nextPageIndex,
pageSize: 10,
memberID,
});
if (code === "200") {
const { code, data, msg } = await post(
"/api/ar/v1/applet/UserCouponList",
{
paging: 1,
state,
pageIndex: nextPageIndex,
pageSize: 10,
memberID,
}
);
if (code === 200) {
setList([...list, ...data.list]);
setNextPageIndex(
nextPageIndex + 1 > data.allPage ? null : nextPageIndex + 1

4
src/pages/Coupons/ShopManager/ShopManager.js

@ -30,13 +30,13 @@ const ShopManager = ({ memberID }) => {
if (loading || nextPageIndex === null) return;
setLoading(true);
try {
const { code, data, msg } = await post("/api/coupon/ApplyedList", {
const { code, data, msg } = await post("/api/ar/v1/applet/ApplyedList", {
paging: 1,
pageIndex: nextPageIndex,
pageSize: 10,
memberID,
});
if (code === "200") {
if (code === 200) {
setList([...list, ...data.list]);
setNextPageIndex(
nextPageIndex + 1 > data.allPage ? null : nextPageIndex + 1

8
src/pages/Coupons/WriteOffModal/WriteOffModal.js

@ -22,14 +22,14 @@ const WriteOffModal = ({ onBack, memberID }) => {
if (loading || nextPageIndex === null) return;
setLoading(true);
try {
const { code, data, msg } = await post("/api/Coupon/WriteOffHis", {
const { code, data, msg } = await post("/api/ar/v1/applet/WriteOffHis", {
paging: 1,
pageIndex: nextPageIndex,
pageSize: 10,
memberID,
month,
});
if (code === "200") {
if (code === 200) {
setList([...list, ...data.list]);
setNextPageIndex(
nextPageIndex + 1 > data.allPage ? null : nextPageIndex + 1
@ -61,11 +61,11 @@ const WriteOffModal = ({ onBack, memberID }) => {
});
const writeOff = async (orderNo) => {
try {
const { code, msg } = await post("/api/coupon/writeoffcoupon", {
const { code, msg } = await post("/api/ar/v1/applet/writeoffcoupon", {
orderNo,
memberID,
});
if (code === "200") {
if (code === 200) {
toast("核销成功");
return true;
} else {

6
src/pages/Index/Index.js

@ -84,7 +84,9 @@ const Index = () => {
const hasTab = mall && mall.menu.length > 1;
const setStatistics = mall
? ({ 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,
userId,
navType,
@ -647,7 +649,7 @@ const Index = () => {
<div
className="top-left"
onClick={async () => {
const { msg } = await post("/Api/Operation/GetUserAward", {
const { msg } = await post("/api/ar/v1/applet/GetUserAward", {
memberID,
poiCode: "97be8faa6ab34e08864bf2b1c231e6ab",
});

15
src/pages/ShopCoupons/ShopCoupons.js

@ -15,7 +15,7 @@ const ShopCoupons = ({ onBack, shop, memberID }) => {
shopCode: shop.code,
}
);
if (code !== "200")
if (code !== 200)
window.weui.toast(msg, {
className: "toast",
});
@ -30,14 +30,17 @@ const ShopCoupons = ({ onBack, shop, memberID }) => {
const receive = async (coupon) => {
setReceiving(true);
try {
const { code, data, msg } = await post("/Api/Coupon/ShopCouponReceive", {
couponCode: coupon.code,
memberID,
});
const { code, data, msg } = await post(
"/api/ar/v1/applet/ShopCouponReceive",
{
couponCode: coupon.code,
memberID,
}
);
window.weui.toast(msg, {
className: "toast",
});
if (code === "200") {
if (code === 200) {
getList();
}
} catch (error) {

23
yarn.lock

@ -5947,6 +5947,11 @@ html-webpack-plugin@4.5.0:
tapable "^1.1.3"
util.promisify "1.0.0"
html5-qrcode@^2.3.0:
version "2.3.7"
resolved "https://registry.npmmirror.com/html5-qrcode/-/html5-qrcode-2.3.7.tgz#09ed2ca7473a47bd551088c15fcfcb7cb409a5be"
integrity sha512-Jmlok9Ynm49hgVXkdupWryf8o430proIFoQsRl1LmTg4Rq461W72omylR9yw9tsEMtswMEw3wacUM5y0agOBQA==
htmlparser2@^3.10.1:
version "3.10.1"
resolved "https://registry.npm.taobao.org/htmlparser2/download/htmlparser2-3.10.1.tgz?cache=0&sync_timestamp=1607394274032&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fhtmlparser2%2Fdownload%2Fhtmlparser2-3.10.1.tgz#bd679dc3f59897b6a34bb10749c855bb53a9392f"
@ -7433,6 +7438,11 @@ lodash.templatesettings@^4.0.0:
dependencies:
lodash._reinterpolate "^3.0.0"
lodash.throttle@^4.1.1:
version "4.1.1"
resolved "https://registry.npmmirror.com/lodash.throttle/-/lodash.throttle-4.1.1.tgz#c23e91b710242ac70c37f1e1cda9274cc39bf2f4"
integrity sha512-wIkUCfVKpVsWo3JSZlc+8MB5it+2AN5W8J7YVMST30UrvcQNZ1Okbj+rbVniijTWE6FGYy4XJq/rHkas8qJMLQ==
lodash.uniq@^4.5.0:
version "4.5.0"
resolved "https://registry.npm.taobao.org/lodash.uniq/download/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
@ -9512,6 +9522,11 @@ q@^1.1.2:
resolved "https://registry.npm.taobao.org/q/download/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
integrity sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=
qrcodejs2@^0.0.2:
version "0.0.2"
resolved "https://registry.npmmirror.com/qrcodejs2/-/qrcodejs2-0.0.2.tgz#465afe5e39f19facecb932c11f7a186109146ae1"
integrity sha512-+Y4HA+cb6qUzdgvI3KML8GYpMFwB24dFwzMkS/yXq6hwtUGNUnZQdUnksrV1XGMc2mid5ROw5SAuY9XhI3ValA==
qs@6.7.0:
version "6.7.0"
resolved "https://registry.npm.taobao.org/qs/download/qs-6.7.0.tgz?cache=0&sync_timestamp=1610598174727&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fqs%2Fdownload%2Fqs-6.7.0.tgz#41dc1a015e3d581f1621776be31afb2876a9b1bc"
@ -9771,6 +9786,14 @@ react-is@^17.0.1:
resolved "https://registry.npm.taobao.org/react-is/download/react-is-17.0.1.tgz#5b3531bd76a645a4c9fb6e693ed36419e3301339"
integrity sha1-WzUxvXamRaTJ+25pPtNkGeMwEzk=
react-lazy-load-image-component@^1.5.1:
version "1.5.6"
resolved "https://registry.npmmirror.com/react-lazy-load-image-component/-/react-lazy-load-image-component-1.5.6.tgz#a4b84257be21b1825680b4e158d167c08aeda5ff"
integrity sha512-M0jeJtOlTHgThOfgYM9krSqYbR6ShxROy/KVankwbw9/amPKG1t5GSGN1sei6Cyu8+QJVuyAUvQ+LFtCVTTlKw==
dependencies:
lodash.debounce "^4.0.8"
lodash.throttle "^4.1.1"
react-lifecycles-compat@^3.0.0, react-lifecycles-compat@^3.0.4:
version "3.0.4"
resolved "https://registry.npm.taobao.org/react-lifecycles-compat/download/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"

Loading…
Cancel
Save