mirror of
https://gitee.com/beijing_hongye_huicheng/lilishop-ui.git
synced 2026-11-09 02:18:55 +08:00
fix(buyer): 结算页异常兜底与白屏防御
- 1 处裸 await 包 try/catch,12 条 .then 链全部补 catch(原仅 2 条) - 结算数据加载失败给用户可见提示并保持页面可操作,不再白屏;错误提示与 request 层拦截器去重 - 约 20 处深链式访问加可选链/默认值(含模板渲染层) - 修复无效商品跳回购物车后缺少 return 导致的 TypeError
This commit is contained in:
@@ -137,14 +137,14 @@
|
|||||||
<div class="goods-list">
|
<div class="goods-list">
|
||||||
<div class="goods-item" v-for="(goods, goodsIndex) in shop.checkedSkuList" :key="goodsIndex">
|
<div class="goods-item" v-for="(goods, goodsIndex) in shop.checkedSkuList" :key="goodsIndex">
|
||||||
<span class="goods-main hover-color" @click="
|
<span class="goods-main hover-color" @click="
|
||||||
goGoodsDetail(goods.goodsSku.id, goods.goodsSku.goodsId)
|
goGoodsDetail(goods.goodsSku?.id, goods.goodsSku?.goodsId)
|
||||||
">
|
">
|
||||||
<img :src="goods.goodsSku.thumbnail" alt="" />
|
<img :src="goods.goodsSku?.thumbnail" alt="" />
|
||||||
<span class="goods-name">{{ goods.goodsSku.goodsName }}</span>
|
<span class="goods-name">{{ goods.goodsSku?.goodsName }}</span>
|
||||||
</span>
|
</span>
|
||||||
<span class="goods-price">{{ $filters.unitPrice(goods.purchasePrice, "¥") }}</span>
|
<span class="goods-price">{{ $filters.unitPrice(goods.purchasePrice, "¥") }}</span>
|
||||||
<span>{{ goods.num }}</span>
|
<span>{{ goods.num }}</span>
|
||||||
<span>{{ goods.goodsSku.quantity > 0 ? "有货" : "无货" }}</span>
|
<span>{{ goods.goodsSku?.quantity > 0 ? "有货" : "无货" }}</span>
|
||||||
<span class="goods-price">{{ $filters.unitPrice(goods.subTotal, "¥") }}</span>
|
<span class="goods-price">{{ $filters.unitPrice(goods.subTotal, "¥") }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -463,45 +463,54 @@ export default {
|
|||||||
// 获取收货地址列表
|
// 获取收货地址列表
|
||||||
memberAddress(this.searchForm).then((res) => {
|
memberAddress(this.searchForm).then((res) => {
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
this.addressList = res.result.records;
|
this.addressList = res.result?.records || [];
|
||||||
this.addressList.forEach((e, index) => {
|
this.addressList.forEach((e, index) => {
|
||||||
if (e.id === this.selectedAddress.id && index > 2) {
|
if (e.id === this.selectedAddress.id && index > 2) {
|
||||||
this.moreAddr = true;
|
this.moreAddr = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}).catch((err) => {
|
||||||
|
// 网络/登录异常已由 request 层统一提示,地址列表保持为空,可正常新增地址
|
||||||
|
console.warn("获取收货地址列表失败", err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// 获取配送方式列表
|
// 获取配送方式列表
|
||||||
async getDistribution() {
|
async getDistribution() {
|
||||||
let shopRes = await shippingMethodList({ way: this.$route.query.way });
|
try {
|
||||||
let shopList;
|
let shopRes = await shippingMethodList({ way: this.$route.query.way });
|
||||||
if (shopRes.success) {
|
let shopList;
|
||||||
shopList = shopRes.result;
|
if (shopRes.success) {
|
||||||
let way = [];
|
shopList = shopRes.result || [];
|
||||||
console.log(shopList)
|
let way = [];
|
||||||
this.shippingWay.forEach((item) => {
|
this.shippingWay.forEach((item) => {
|
||||||
shopList.forEach((child) => {
|
shopList.forEach((child) => {
|
||||||
if (item.value == child) {
|
if (item.value == child) {
|
||||||
way.push(item);
|
way.push(item);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
this.shippingMethod = way;
|
||||||
this.shippingMethod = way;
|
}
|
||||||
console.log(this.shippingMethod)
|
} catch (err) {
|
||||||
|
// 网络/登录异常已由 request 层统一提示,配送方式保持为空不影响页面其余模块
|
||||||
|
console.warn("获取配送方式列表失败", err);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async getStoreAddressList() {
|
async getStoreAddressList() {
|
||||||
getStoreAddress(this.storeId,this.searchForm).then(res => {
|
getStoreAddress(this.storeId,this.searchForm).then(res => {
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
this.storeAddressList = res.result.records
|
this.storeAddressList = res.result?.records || []
|
||||||
this.storeAddressList.forEach((e, index) => {
|
this.storeAddressList.forEach((e, index) => {
|
||||||
if (e.id === this.selectedAddress.id && index > 2) {
|
if (e.id === this.selectedAddress.id && index > 2) {
|
||||||
this.storeMoreAddr = true;
|
this.storeMoreAddr = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}).catch((err) => {
|
||||||
|
// 网络/登录异常已由 request 层统一提示,自提点列表保持为空
|
||||||
|
console.warn("获取自提点列表失败", err);
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
getGoodsDetail() {
|
getGoodsDetail() {
|
||||||
@@ -511,81 +520,85 @@ export default {
|
|||||||
.then((res) => {
|
.then((res) => {
|
||||||
Spin.hide();
|
Spin.hide();
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
|
const result = res.result || {};
|
||||||
if (
|
if (
|
||||||
!res.result.checkedSkuList ||
|
!result.checkedSkuList ||
|
||||||
res.result.checkedSkuList.length === 0
|
result.checkedSkuList.length === 0
|
||||||
) {
|
) {
|
||||||
if (res.result.skuList && res.result.skuList[0]) {
|
const firstSku = result.skuList?.[0];
|
||||||
|
if (firstSku) {
|
||||||
Modal.warning({
|
Modal.warning({
|
||||||
title: "购物车存在无效商品!",
|
title: "购物车存在无效商品!",
|
||||||
content:
|
content:
|
||||||
"[" +
|
"[" +
|
||||||
res.result.skuList[0].goodsSku.goodsName +
|
(firstSku.goodsSku?.goodsName || "") +
|
||||||
"]" +
|
"]" +
|
||||||
res.result.skuList[0].errorMessage,
|
(firstSku.errorMessage || ""),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.$router.push({
|
this.$router.push({
|
||||||
path: "/cart",
|
path: "/cart",
|
||||||
replace: true,
|
replace: true,
|
||||||
});
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
this.goodsList = res.result.cartList;
|
this.goodsList = result.cartList || [];
|
||||||
this.priceDetailDTO = res.result.priceDetailDTO;
|
this.priceDetailDTO = result.priceDetailDTO || {};
|
||||||
this.skuList = res.result.skuList;
|
this.skuList = result.skuList || [];
|
||||||
if (res.result.skuList[0] && res.result.skuList[0].goodsSku) {
|
if (this.skuList[0]?.goodsSku) {
|
||||||
this.goodsType = res.result.skuList[0].goodsSku.goodsType;
|
this.goodsType = this.skuList[0].goodsSku.goodsType;
|
||||||
}
|
}
|
||||||
this.storeId = this.goodsList[0].storeId
|
this.storeId = this.goodsList[0]?.storeId || ''
|
||||||
if (res.result.receiptVO) {
|
if (result.receiptVO) {
|
||||||
this.invoiceData = res.result.receiptVO;
|
this.invoiceData = result.receiptVO;
|
||||||
}
|
}
|
||||||
let notSupArea = res.result.notSupportFreight;
|
let notSupArea = result.notSupportFreight;
|
||||||
this.selectedCoupon = {};
|
this.selectedCoupon = {};
|
||||||
if (res.result.platformCoupon)
|
const platformCouponId = result.platformCoupon?.memberCoupon?.id;
|
||||||
this.selectedCoupon[res.result.platformCoupon.memberCoupon.id] =
|
if (platformCouponId)
|
||||||
res.result.platformCoupon;
|
this.selectedCoupon[platformCouponId] = result.platformCoupon;
|
||||||
if (
|
if (
|
||||||
res.result.storeCoupons &&
|
result.storeCoupons &&
|
||||||
Object.keys(res.result.storeCoupons)[0]
|
Object.keys(result.storeCoupons)[0]
|
||||||
) {
|
) {
|
||||||
let storeMemberCouponsId = Object.keys(
|
let storeMemberCouponsId = Object.keys(
|
||||||
res.result.storeCoupons
|
result.storeCoupons
|
||||||
)[0];
|
)[0];
|
||||||
let storeCouponId =
|
let storeCouponId =
|
||||||
res.result.storeCoupons[storeMemberCouponsId].memberCoupon.id;
|
result.storeCoupons[storeMemberCouponsId]?.memberCoupon?.id;
|
||||||
this.selectedCoupon[storeCouponId] =
|
if (storeCouponId)
|
||||||
res.result.storeCoupons[storeMemberCouponsId];
|
this.selectedCoupon[storeCouponId] =
|
||||||
|
result.storeCoupons[storeMemberCouponsId];
|
||||||
}
|
}
|
||||||
if (notSupArea) {
|
if (notSupArea) {
|
||||||
let content = [];
|
let content = [];
|
||||||
let title = "";
|
let title = "";
|
||||||
notSupArea.forEach((e) => {
|
notSupArea.forEach((e) => {
|
||||||
title = e.errorMessage;
|
title = e.errorMessage;
|
||||||
content.push(e.goodsSku.goodsName);
|
content.push(e.goodsSku?.goodsName || "");
|
||||||
});
|
});
|
||||||
Modal.warning({
|
Modal.warning({
|
||||||
title: "以下商品超出配送区域" || title,
|
title: "以下商品超出配送区域" || title,
|
||||||
content: content.toString(),
|
content: content.toString(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (res.result.memberAddress) {
|
if (result.memberAddress) {
|
||||||
this.selectedAddress = res.result.memberAddress;
|
this.selectedAddress = result.memberAddress;
|
||||||
}
|
}
|
||||||
this.getAddress();
|
this.getAddress();
|
||||||
this.getStoreAddressList();
|
this.getStoreAddressList();
|
||||||
this.totalNum = 0;
|
this.totalNum = 0;
|
||||||
for (let i = 0; i < this.skuList.length; i++) {
|
for (let i = 0; i < this.skuList.length; i++) {
|
||||||
this.totalNum += this.skuList[i].num;
|
this.totalNum += this.skuList[i].num || 0;
|
||||||
}
|
}
|
||||||
this.usedCouponId = [];
|
this.usedCouponId = [];
|
||||||
this.couponList = res.result.canUseCoupons;
|
this.couponList = result.canUseCoupons || [];
|
||||||
const couponKeys = Object.keys(this.selectedCoupon);
|
const couponKeys = Object.keys(this.selectedCoupon);
|
||||||
if (couponKeys.length) {
|
if (couponKeys.length) {
|
||||||
this.couponList.forEach((e) => {
|
this.couponList.forEach((e) => {
|
||||||
if (
|
if (
|
||||||
this.selectedCoupon[e.id] &&
|
this.selectedCoupon[e.id] &&
|
||||||
e.id === this.selectedCoupon[e.id].memberCoupon.id
|
e.id === this.selectedCoupon[e.id]?.memberCoupon?.id
|
||||||
) {
|
) {
|
||||||
this.usedCouponId.push(e.id);
|
this.usedCouponId.push(e.id);
|
||||||
}
|
}
|
||||||
@@ -594,19 +607,24 @@ export default {
|
|||||||
this.$forceUpdate();
|
this.$forceUpdate();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.giftCardDeductItems = Array.isArray(res.result.giftCardDeductItems)
|
this.giftCardDeductItems = Array.isArray(result.giftCardDeductItems)
|
||||||
? res.result.giftCardDeductItems
|
? result.giftCardDeductItems
|
||||||
: [];
|
: [];
|
||||||
this.tradeGiftCardDeductTotal =
|
this.tradeGiftCardDeductTotal =
|
||||||
res.result.giftCardDeductTotal != null && res.result.giftCardDeductTotal !== ""
|
result.giftCardDeductTotal != null && result.giftCardDeductTotal !== ""
|
||||||
? Number(res.result.giftCardDeductTotal)
|
? Number(result.giftCardDeductTotal)
|
||||||
: null;
|
: null;
|
||||||
this.giftCardList = Array.isArray(res.result.canUseGiftCards) ? res.result.canUseGiftCards : [];
|
this.giftCardList = Array.isArray(result.canUseGiftCards) ? result.canUseGiftCards : [];
|
||||||
this.syncGiftCardSelectionFromCart(res.result);
|
this.syncGiftCardSelectionFromCart(result);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch((err) => {
|
||||||
Spin.hide();
|
Spin.hide();
|
||||||
|
// 网络/登录异常已由 request 层统一提示;这里兜底 404 与返回数据结构异常
|
||||||
|
if (!err?.data || err?.data?.message) {
|
||||||
|
Message.error(err?.data?.message || "结算数据加载失败,请稍后重试");
|
||||||
|
}
|
||||||
|
console.warn("获取结算数据失败", err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
syncGiftCardSelectionFromCart(result) {
|
syncGiftCardSelectionFromCart(result) {
|
||||||
@@ -696,6 +714,9 @@ export default {
|
|||||||
if (res.success) {
|
if (res.success) {
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
}).catch((err) => {
|
||||||
|
// 网络/登录异常已由 request 层统一提示
|
||||||
|
console.warn("选择礼品卡失败", err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getCouponNum() {
|
getCouponNum() {
|
||||||
@@ -707,8 +728,8 @@ export default {
|
|||||||
let skuArr = [];
|
let skuArr = [];
|
||||||
this.goodsList.forEach((e) => {
|
this.goodsList.forEach((e) => {
|
||||||
storeArr.push(e.storeId);
|
storeArr.push(e.storeId);
|
||||||
e.skuList.forEach((i) => {
|
e.skuList?.forEach((i) => {
|
||||||
skuArr.push(i.goodsSku.id);
|
skuArr.push(i.goodsSku?.id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
let params = {
|
let params = {
|
||||||
@@ -721,12 +742,12 @@ export default {
|
|||||||
};
|
};
|
||||||
canUseCouponList(params).then((res) => {
|
canUseCouponList(params).then((res) => {
|
||||||
// 可用优惠券列表
|
// 可用优惠券列表
|
||||||
if (res.success) this.couponList = res.result.records;
|
if (res.success) this.couponList = res.result?.records || [];
|
||||||
const couponKeys = Object.keys(this.selectedCoupon);
|
const couponKeys = Object.keys(this.selectedCoupon);
|
||||||
this.usedCouponId = [];
|
this.usedCouponId = [];
|
||||||
if (couponKeys.length) {
|
if (couponKeys.length) {
|
||||||
this.couponList.forEach((e) => {
|
this.couponList.forEach((e) => {
|
||||||
if (e.id === this.selectedCoupon[couponKeys].memberCoupon.id) {
|
if (e.id === this.selectedCoupon[couponKeys]?.memberCoupon?.id) {
|
||||||
this.usedCouponId.push(e.id);
|
this.usedCouponId.push(e.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -734,8 +755,14 @@ export default {
|
|||||||
this.$forceUpdate();
|
this.$forceUpdate();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}).catch((err) => {
|
||||||
|
// 网络/登录异常已由 request 层统一提示
|
||||||
|
console.warn("获取可用优惠券列表失败", err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}).catch((err) => {
|
||||||
|
// 网络/登录异常已由 request 层统一提示
|
||||||
|
console.warn("获取可用优惠券数量失败", err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
remarkKey(shop) {
|
remarkKey(shop) {
|
||||||
@@ -775,11 +802,12 @@ export default {
|
|||||||
this.selectMethod = item;
|
this.selectMethod = item;
|
||||||
this.getGoodsDetail();
|
this.getGoodsDetail();
|
||||||
}
|
}
|
||||||
|
}).catch((err) => {
|
||||||
|
// 网络/登录异常已由 request 层统一提示
|
||||||
|
console.warn("选择收货地址失败", err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
selectStoreAddress(item) {
|
selectStoreAddress(item) {
|
||||||
console.log(item.id)
|
|
||||||
console.log(this.$route.query.way)
|
|
||||||
// 选择自提地址
|
// 选择自提地址
|
||||||
setStoreAddressId(item.id,this.$route.query.way).then((res) => {
|
setStoreAddressId(item.id,this.$route.query.way).then((res) => {
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
@@ -787,6 +815,9 @@ export default {
|
|||||||
this.selectedStoreAddress = item;
|
this.selectedStoreAddress = item;
|
||||||
this.getGoodsDetail();
|
this.getGoodsDetail();
|
||||||
}
|
}
|
||||||
|
}).catch((err) => {
|
||||||
|
// 网络/登录异常已由 request 层统一提示
|
||||||
|
console.warn("选择自提地址失败", err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
selectDeliverMethod(item) {
|
selectDeliverMethod(item) {
|
||||||
@@ -799,6 +830,9 @@ export default {
|
|||||||
this.selectedDeliverMethod = item.value;
|
this.selectedDeliverMethod = item.value;
|
||||||
this.getGoodsDetail();
|
this.getGoodsDetail();
|
||||||
}
|
}
|
||||||
|
}).catch((err) => {
|
||||||
|
// 网络/登录异常已由 request 层统一提示
|
||||||
|
console.warn("切换配送方式失败", err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
editAddress(id) {
|
editAddress(id) {
|
||||||
@@ -821,6 +855,9 @@ export default {
|
|||||||
Message.success("删除成功");
|
Message.success("删除成功");
|
||||||
this.getAddress();
|
this.getAddress();
|
||||||
}
|
}
|
||||||
|
}).catch((err) => {
|
||||||
|
// 网络/登录异常已由 request 层统一提示
|
||||||
|
console.warn("删除收货地址失败", err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onCancel: () => { },
|
onCancel: () => { },
|
||||||
@@ -850,6 +887,9 @@ export default {
|
|||||||
};
|
};
|
||||||
selectCoupon(params).then((res) => {
|
selectCoupon(params).then((res) => {
|
||||||
if (res.success) this.init();
|
if (res.success) this.init();
|
||||||
|
}).catch((err) => {
|
||||||
|
// 网络/登录异常已由 request 层统一提示
|
||||||
|
console.warn("使用优惠券失败", err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
editInvoice() {
|
editInvoice() {
|
||||||
@@ -902,9 +942,11 @@ export default {
|
|||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
Spin.hide();
|
Spin.hide();
|
||||||
if (err?.message && !err?.data?.message) {
|
// 网络错误已由 request 层统一提示,这里兜底 404 与返回结构异常等未被提示的错误
|
||||||
Message.error(err.message);
|
if (!err?.data || err?.data?.message) {
|
||||||
|
Message.error(err?.data?.message || err?.message || "提交订单失败,请稍后重试");
|
||||||
}
|
}
|
||||||
|
console.warn("提交订单失败", err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// 优惠券可用范围
|
// 优惠券可用范围
|
||||||
|
|||||||
Reference in New Issue
Block a user