This commit is contained in:
gyq 2025-11-12 11:12:33 +08:00
commit 89f0a8d87e
3 changed files with 34 additions and 6 deletions

View File

@ -199,8 +199,8 @@ export const useCartsStore = defineStore("carts", () => {
goods.value = res.records.map(item => {
return {
...item,
isLimitDiscount: limitDiscountRes.value !== null && canUseLimitTimeDiscount(item, limitDiscountRes.value, shopInfo, shopUser.userInfo),
limitDiscountPrice: limitDiscountRes.value !== null && returnPrice({ goods: { ...item, memberPrice: item.lowMemberPrice, salePrice: item.lowPrice }, shopInfo: shopInfo, limitTimeDiscountRes: limitDiscountRes.value, shopUserInfo: shopUser.userInfo, idKey: 'id' })
isLimitDiscount: limitDiscountRes.value !== null && canUseLimitTimeDiscount(item, limitDiscountRes.value, shopInfo, vipUser.value),
limitDiscountPrice: limitDiscountRes.value !== null && returnPrice({ goods: { ...item, memberPrice: item.lowMemberPrice, salePrice: item.lowPrice }, shopInfo: shopInfo, limitTimeDiscountRes: limitDiscountRes.value, shopUserInfo: vipUser.value, idKey: 'id' })
}
});
@ -315,7 +315,7 @@ export const useCartsStore = defineStore("carts", () => {
fullReductionActivities: [fullReductionActivities.value],
currentDinnerType: dinnerType.value,
limitTimeDiscount: limitDiscountRes.value,
shopUserInfo: shopUser.userInfo,
shopUserInfo: vipUser.value,
newUserDiscount: newUserDiscount.value
}));

View File

@ -12,6 +12,30 @@ const service = axios.create({
paramsSerializer: (params) => qs.stringify(params),
});
/**
* msg
*/
function formatErrorMsg(error: string) {
// 1. 获取原始提示文本(兜底空字符串避免报错)
const originMsg = error
// 2. 定义要匹配的前缀
const exceptionPrefix = "Exception:";
// 3. 判断是否包含目标前缀
if (originMsg.includes(exceptionPrefix)) {
// 截取前缀后的内容 → 去除首尾空格 → 限制最大20个字符
return originMsg
.slice(
originMsg.indexOf(exceptionPrefix) +
exceptionPrefix.length
)
.trim()
.slice(0, 20);
} else {
// 不包含则按原逻辑截取前20个字符
return originMsg.slice(0, 20);
}
}
// 请求拦截器
service.interceptors.request.use(
(config: InternalAxiosRequestConfig) => {
@ -66,10 +90,11 @@ service.interceptors.response.use(
});
return;
}
ElMessage.error(msg || "系统出错");
return Promise.reject(new Error(msg || "Error"));
ElMessage.error(formatErrorMsg(msg || "Error"));
return Promise.reject(new Error(formatErrorMsg(msg || "Error")));
},
async (error: any) => {
// 非 2xx 状态码处理 401、403、500 等
const { config, response } = error;
if (response) {

View File

@ -128,7 +128,7 @@ export function returnIsSeatFee(item) {
/**
* 计算购物车会员优惠价格
*/
export function returnVipDiscountPrice() {}
export function returnVipDiscountPrice() { }
//计算商品券优惠价格
export function returnProductCouponPrice(coup, goodsArr, vipUser) {
@ -243,6 +243,9 @@ export function returnCartPrice(goods, vipUser) {
// 价格保留两位小数不四舍五入
export function customTruncateToTwoDecimals(number) {
if (!number) {
return 0;
}
let stringNumber = number.toString();
let dotIndex = stringNumber.indexOf(".");
if (dotIndex === -1) {