feat: 修复toast异常问题
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<view class="booking h-screen flex flex-col">
|
||||
<TopNavBar
|
||||
titleAlign="center"
|
||||
:backgroundColor="$theme-color-100"
|
||||
:backgroundColor="$theme - color - 100"
|
||||
backIconColor="#000"
|
||||
:shadow="false"
|
||||
>
|
||||
@@ -147,7 +147,7 @@ watch(
|
||||
if (newQuantity > currentLength) {
|
||||
// 数量增加,添加新的表单项
|
||||
const newForms = Array.from({ length: newQuantity - currentLength }, () =>
|
||||
createEmptyUserForm(),
|
||||
createEmptyUserForm()
|
||||
);
|
||||
userFormList.value.push(...newForms);
|
||||
} else if (newQuantity < currentLength) {
|
||||
@@ -158,7 +158,7 @@ watch(
|
||||
// 等待DOM更新完成
|
||||
await nextTick();
|
||||
},
|
||||
{ immediate: false },
|
||||
{ immediate: false }
|
||||
);
|
||||
|
||||
onLoad((options) => {
|
||||
@@ -184,7 +184,7 @@ const getGoodsDetail = async (commodityId) => {
|
||||
// 取commodityFacilityList前3个
|
||||
orderData.value.commodityFacilityList = res.data.commodityFacilityList.slice(
|
||||
0,
|
||||
3,
|
||||
3
|
||||
);
|
||||
};
|
||||
|
||||
@@ -211,119 +211,120 @@ const validateUserForms = () => {
|
||||
|
||||
// 处理支付点击事件
|
||||
const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => {
|
||||
try {
|
||||
console.log("处理支付点击事件", userFormList.value);
|
||||
// 校验用户姓名
|
||||
if (!validateUserForms()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 校验手机号
|
||||
if (!PhoneUtils.validatePhone(userFormList.value[0].contactPhone)) {
|
||||
uni.showToast({ title: "请输入正确的手机号", icon: "none" });
|
||||
return;
|
||||
}
|
||||
|
||||
// 购买的商品id
|
||||
const commodityId = goodsData.commodityId;
|
||||
// 消费者信息
|
||||
const consumerInfoEntityList = userFormList.value;
|
||||
// 购买数量
|
||||
const purchaseAmount = consumerInfoEntityList.length;
|
||||
// 支付方式 0-微信 1-支付宝 2-云闪付
|
||||
const payWay = "0";
|
||||
// 支付渠道 0-app 1-小程序 2-h5
|
||||
const paySource = "1";
|
||||
|
||||
const params = {
|
||||
commodityId,
|
||||
purchaseAmount,
|
||||
payWay,
|
||||
paySource,
|
||||
consumerInfoEntityList,
|
||||
};
|
||||
|
||||
// 预约日期,酒店类型不需要
|
||||
if (orderData.value.orderType != 0) {
|
||||
params.reservationDate = selectedReservationDate.value;
|
||||
}
|
||||
|
||||
//酒店类型添加入住时间、离店时间
|
||||
if (goodsData.orderType == 0 && selectedDate.value) {
|
||||
const { startDate, endDate } = selectedDate.value;
|
||||
// 入住时间
|
||||
params.checkInData = startDate;
|
||||
// 离店时间
|
||||
params.checkOutData = endDate;
|
||||
}
|
||||
|
||||
// 点击后立即展示 loading
|
||||
uni.showLoading({ title: "正在提交订单..." });
|
||||
const res = await orderPay(params);
|
||||
console.log("确认订单---2:", res);
|
||||
uni.hideLoading();
|
||||
|
||||
// 检查接口返回数据
|
||||
if (!res || !res.data) {
|
||||
uni.hideLoading();
|
||||
setTimeout(() => {
|
||||
uni.showToast({
|
||||
title: res.msg || "订单创建失败,请重试",
|
||||
icon: "none",
|
||||
});
|
||||
}, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
const { data } = res;
|
||||
const { nonceStr, packageVal, paySign, signType, timeStamp } = data;
|
||||
|
||||
// 验证支付参数是否完整
|
||||
if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) {
|
||||
uni.hideLoading();
|
||||
setTimeout(() => {
|
||||
uni.showToast({ title: "支付参数错误,请重试", icon: "none" });
|
||||
}, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
// 在发起微信支付前关闭 loading(避免与原生支付 UI 冲突)
|
||||
uni.hideLoading();
|
||||
|
||||
// 调用微信支付
|
||||
uni.requestPayment({
|
||||
provider: "wxpay",
|
||||
timeStamp: String(timeStamp), // 确保为字符串类型
|
||||
nonceStr: String(nonceStr),
|
||||
package: String(packageVal), // 确保为字符串类型
|
||||
signType: String(signType),
|
||||
paySign: String(paySign),
|
||||
success: () => {
|
||||
uni.showToast({
|
||||
title: "支付成功",
|
||||
icon: "success",
|
||||
success: () => {
|
||||
uni.navigateTo({
|
||||
url: "/pages-order/order/list",
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
fail: (e) => {
|
||||
console.error("支付失败:", e);
|
||||
uni.showToast({ title: "支付失败,请重试", icon: "none" });
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
uni.hideLoading(); // 提前关闭 loading,确保 toast 能在安卓正常弹出
|
||||
setTimeout(() => {
|
||||
uni.showToast({ title: "请求出错,请重试", icon: "none" });
|
||||
}, 100);
|
||||
} finally {
|
||||
// 最终兜底关闭 loading
|
||||
uni.hideLoading();
|
||||
console.log("处理支付点击事件", userFormList.value);
|
||||
// 校验用户姓名
|
||||
if (!validateUserForms()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 校验手机号
|
||||
if (!PhoneUtils.validatePhone(userFormList.value[0].contactPhone)) {
|
||||
uni.showToast({ title: "请输入正确的手机号", icon: "none" });
|
||||
return;
|
||||
}
|
||||
|
||||
// 购买的商品id
|
||||
const commodityId = goodsData.commodityId;
|
||||
// 消费者信息
|
||||
const consumerInfoEntityList = userFormList.value;
|
||||
// 购买数量
|
||||
const purchaseAmount = consumerInfoEntityList.length;
|
||||
// 支付方式 0-微信 1-支付宝 2-云闪付
|
||||
const payWay = "0";
|
||||
// 支付渠道 0-app 1-小程序 2-h5
|
||||
const paySource = "1";
|
||||
|
||||
const params = {
|
||||
commodityId,
|
||||
purchaseAmount,
|
||||
payWay,
|
||||
paySource,
|
||||
consumerInfoEntityList,
|
||||
};
|
||||
|
||||
// 预约日期,酒店类型不需要
|
||||
if (orderData.value.orderType != 0) {
|
||||
params.reservationDate = selectedReservationDate.value;
|
||||
}
|
||||
|
||||
//酒店类型添加入住时间、离店时间
|
||||
if (goodsData.orderType == 0 && selectedDate.value) {
|
||||
const { startDate, endDate } = selectedDate.value;
|
||||
// 入住时间
|
||||
params.checkInData = startDate;
|
||||
// 离店时间
|
||||
params.checkOutData = endDate;
|
||||
}
|
||||
|
||||
// 点击后立即展示 loading
|
||||
uni.showLoading({ title: "正在提交订单..." });
|
||||
const res = await orderPay(params);
|
||||
console.log("确认订单---2:", res);
|
||||
uni.hideLoading();
|
||||
|
||||
// 检查接口返回数据
|
||||
if (!res || !res.data) {
|
||||
uni.hideLoading();
|
||||
setTimeout(() => {
|
||||
uni.showToast({
|
||||
title: res.msg || "订单创建失败,请重试",
|
||||
icon: "none",
|
||||
});
|
||||
}, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
const { data } = res;
|
||||
const { nonceStr, packageVal, paySign, signType, timeStamp } = data;
|
||||
|
||||
// 验证支付参数是否完整
|
||||
if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) {
|
||||
uni.hideLoading();
|
||||
setTimeout(() => {
|
||||
uni.showToast({ title: "支付参数错误,请重试", icon: "none" });
|
||||
}, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
// 在发起微信支付前关闭 loading(避免与原生支付 UI 冲突)
|
||||
uni.hideLoading();
|
||||
|
||||
// 调用微信支付
|
||||
uni.requestPayment({
|
||||
provider: "wxpay",
|
||||
timeStamp: String(timeStamp), // 确保为字符串类型
|
||||
nonceStr: String(nonceStr),
|
||||
package: String(packageVal), // 确保为字符串类型
|
||||
signType: String(signType),
|
||||
paySign: String(paySign),
|
||||
success: () => {
|
||||
uni.showToast({
|
||||
title: "支付成功",
|
||||
icon: "success",
|
||||
success: () => {
|
||||
uni.navigateTo({
|
||||
url: "/pages-order/order/list",
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
fail: (e) => {
|
||||
console.error("支付失败:", e);
|
||||
uni.showToast({ title: "支付失败,请重试", icon: "none" });
|
||||
},
|
||||
});
|
||||
// try {
|
||||
|
||||
// } catch (error) {
|
||||
// console.error(error);
|
||||
// uni.hideLoading(); // 提前关闭 loading,确保 toast 能在安卓正常弹出
|
||||
// setTimeout(() => {
|
||||
// uni.showToast({ title: "请求出错,请重试", icon: "none" });
|
||||
// }, 100);
|
||||
// } finally {
|
||||
// // 最终兜底关闭 loading
|
||||
// uni.hideLoading();
|
||||
// }
|
||||
}, 1000);
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user