拼团问题修复,增加套餐功能
This commit is contained in:
@@ -11,10 +11,18 @@ export const getPackage = (data) => {
|
||||
}
|
||||
|
||||
|
||||
export const getPackageDetail = (id) => {
|
||||
return request({
|
||||
url: prveUrl + '/user/package/detail/'+id,
|
||||
method: 'get',
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
export const order = (data) => {
|
||||
return request({
|
||||
url: prveUrl + '/user/package/order',
|
||||
method: 'get',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,138 +1,143 @@
|
||||
export default (params) => {
|
||||
let url = params.url;
|
||||
let method = params.method || "get";
|
||||
let data = params.data || {};
|
||||
let type = params.type || 1;
|
||||
let toast = params.toast || true;
|
||||
let token = uni.cache.get("token") || "";
|
||||
const shopId = uni.cache.get("shopId") * 1;
|
||||
const userInfo = uni.cache.get("userInfo") || {};
|
||||
// #ifdef H5
|
||||
token = "b61c8b0f1c9d47ad924e33c48b496ce6";
|
||||
// #endif
|
||||
let header = {
|
||||
version: uni.conf.version,
|
||||
type: uni.getSystemInfoSync().platform,
|
||||
// #ifdef APP-PLUS
|
||||
platformType: "APP",
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
platformType: "H5",
|
||||
// #endif
|
||||
// #ifdef MP-WEIXIN
|
||||
platformType: "WX",
|
||||
// #endif
|
||||
// #ifdef MP-ALIPAY
|
||||
platformType: "ALI",
|
||||
// #endif
|
||||
token,
|
||||
id: userInfo.id || "",
|
||||
shopId: shopId || "",
|
||||
userId: userInfo.id || "",
|
||||
};
|
||||
if (toast) {
|
||||
uni.showLoading({
|
||||
title: "加载中",
|
||||
mask: true,
|
||||
});
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeoutDuration = params.timeout || 10000; // 可以通过 params 传入超时时间,默认 10 秒
|
||||
uni.request({
|
||||
url: uni.conf.baseUrl + url,
|
||||
method: method,
|
||||
header: header,
|
||||
data: data,
|
||||
timeout: timeoutDuration,
|
||||
success(response) {
|
||||
const res = response.data;
|
||||
// 根据返回的状态码做出对应的操作
|
||||
//获取成功
|
||||
if (res.code == 200) {
|
||||
uni.hideLoading();
|
||||
uni.hideToast();
|
||||
resolve(res.data ? res.data : true);
|
||||
} else {
|
||||
switch (res.code) {
|
||||
case "501":
|
||||
uni.cache.remove("shopId");
|
||||
// uni.showToast({
|
||||
// title: '',
|
||||
// icon: "none",
|
||||
// success: () => {
|
||||
|
||||
// }
|
||||
// })
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({
|
||||
url: "/pages/index/index",
|
||||
});
|
||||
}, 1000);
|
||||
break;
|
||||
case 404:
|
||||
uni.showToast({
|
||||
title: "请求地址不存在...",
|
||||
duration: 2000,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
// 是否提示
|
||||
if (toast) {
|
||||
uni.showToast({
|
||||
title: (() => {
|
||||
// 1. 获取原始提示文本(兜底空字符串避免报错)
|
||||
const originMsg = res.message || res.msg || res.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);
|
||||
}
|
||||
})(),
|
||||
icon: "none",
|
||||
success: () => {
|
||||
// 修复:去掉多余的 res 参数(避免覆盖外层 res)
|
||||
setTimeout(() => {
|
||||
reject(false);
|
||||
}, 1000);
|
||||
},
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
fail(err) {
|
||||
if (err.errMsg.indexOf("request:fail") !== -1) {
|
||||
if (err.errMsg.indexOf("timeout") !== -1) {
|
||||
if (toast) {
|
||||
uni.showToast({
|
||||
title: `请求超时,请稍后重试`,
|
||||
icon: "error",
|
||||
duration: 2000,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
// 不管成功还是失败都会执行
|
||||
setTimeout((res) => {
|
||||
uni.hideLoading();
|
||||
uni.hideToast();
|
||||
}, 10000);
|
||||
},
|
||||
});
|
||||
}).catch((e) => {});
|
||||
};
|
||||
export default async (params) => {
|
||||
let url = params.url;
|
||||
let method = params.method || "get";
|
||||
let data = params.data || {};
|
||||
let type = params.type || 1;
|
||||
let toast = params.toast || true;
|
||||
let token = uni.cache.get("token") || "";
|
||||
const shopId = uni.cache.get("shopId") * 1;
|
||||
const userInfo = uni.cache.get("userInfo") || {};
|
||||
// #ifdef H5
|
||||
token = "b61c8b0f1c9d47ad924e33c48b496ce6";
|
||||
// #endif
|
||||
let header = {
|
||||
version: uni.conf.version,
|
||||
type: uni.getSystemInfoSync().platform,
|
||||
// #ifdef APP-PLUS
|
||||
platformType: "APP",
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
platformType: "H5",
|
||||
// #endif
|
||||
// #ifdef MP-WEIXIN
|
||||
platformType: "WX",
|
||||
// #endif
|
||||
// #ifdef MP-ALIPAY
|
||||
platformType: "ALI",
|
||||
// #endif
|
||||
token,
|
||||
id: userInfo.id || "",
|
||||
shopId: shopId || "",
|
||||
userId: userInfo.id || "",
|
||||
};
|
||||
if (toast) {
|
||||
uni.showLoading({
|
||||
title: "加载中",
|
||||
mask: true,
|
||||
});
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeoutDuration = params.timeout || 10000; // 可以通过 params 传入超时时间,默认 10 秒
|
||||
uni.request({
|
||||
url: uni.conf.baseUrl + url,
|
||||
method: method,
|
||||
header: header,
|
||||
data: data,
|
||||
timeout: timeoutDuration,
|
||||
success(response) {
|
||||
const res = response.data;
|
||||
// 根据返回的状态码做出对应的操作
|
||||
//获取成功
|
||||
if (res.code == 200) {
|
||||
uni.hideLoading();
|
||||
uni.hideToast();
|
||||
resolve(res.data ? res.data : true);
|
||||
} else {
|
||||
switch (res.code) {
|
||||
case "501":
|
||||
uni.cache.remove("shopId");
|
||||
// uni.showToast({
|
||||
// title: '',
|
||||
// icon: "none",
|
||||
// success: () => {
|
||||
|
||||
// }
|
||||
// })
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({
|
||||
url: "/pages/index/index",
|
||||
});
|
||||
}, 1000);
|
||||
break;
|
||||
case 404:
|
||||
uni.showToast({
|
||||
title: "请求地址不存在...",
|
||||
duration: 2000,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
// 是否提示
|
||||
if (toast) {
|
||||
uni.showToast({
|
||||
title: (() => {
|
||||
// 1. 获取原始提示文本(兜底空字符串避免报错)
|
||||
const originMsg = res.message || res.msg ||
|
||||
res
|
||||
.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);
|
||||
}
|
||||
})(),
|
||||
icon: "none",
|
||||
success: () => {
|
||||
// 修复:去掉多余的 res 参数(避免覆盖外层 res)
|
||||
setTimeout(() => {
|
||||
reject(false);
|
||||
}, 1000);
|
||||
},
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
fail(err) {
|
||||
if (err.errMsg.indexOf("request:fail") !== -1) {
|
||||
if (err.errMsg.indexOf("timeout") !== -1) {
|
||||
if (toast) {
|
||||
uni.showToast({
|
||||
title: `请求超时,请稍后重试`,
|
||||
icon: "error",
|
||||
duration: 2000,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
// 不管成功还是失败都会执行
|
||||
setTimeout((res) => {
|
||||
uni.hideLoading();
|
||||
uni.hideToast();
|
||||
}, 10000);
|
||||
},
|
||||
});
|
||||
}).catch((e) => {});
|
||||
};
|
||||
Reference in New Issue
Block a user