feat: 给toast 添加延迟
This commit is contained in:
@@ -265,7 +265,13 @@ const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => {
|
||||
|
||||
// 检查接口返回数据
|
||||
if (!res || !res.data) {
|
||||
uni.showToast({ title: res.msg || "订单创建失败,请重试", icon: "none" });
|
||||
uni.hideLoading();
|
||||
setTimeout(() => {
|
||||
uni.showToast({
|
||||
title: res.msg || "订单创建失败,请重试",
|
||||
icon: "none",
|
||||
});
|
||||
}, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -275,7 +281,9 @@ const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => {
|
||||
// 验证支付参数是否完整
|
||||
if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) {
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: "支付参数错误,请重试", icon: "none" });
|
||||
setTimeout(() => {
|
||||
uni.showToast({ title: "支付参数错误,请重试", icon: "none" });
|
||||
}, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -308,9 +316,12 @@ const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => {
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
uni.showToast({ title: "请求出错,请重试", icon: "none" });
|
||||
uni.hideLoading(); // 提前关闭 loading,确保 toast 能在安卓正常弹出
|
||||
setTimeout(() => {
|
||||
uni.showToast({ title: "请求出错,请重试", icon: "none" });
|
||||
}, 100);
|
||||
} finally {
|
||||
// 防止某些分支忘记 hide,确保最终关闭 loading(requestPayment 后也可以安全调用 hide)
|
||||
// 最终兜底关闭 loading
|
||||
uni.hideLoading();
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
@@ -90,7 +90,9 @@ const handleButtonClick = DebounceUtils.createDebounce(async (orderData) => {
|
||||
// 检查接口返回数据
|
||||
if (!res || !res.data) {
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: res.msg || "订单创建失败,请重试", icon: "none" });
|
||||
setTimeout(() => {
|
||||
uni.showToast({ title: res.msg || "订单创建失败,请重试", icon: "none" });
|
||||
}, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -100,7 +102,9 @@ const handleButtonClick = DebounceUtils.createDebounce(async (orderData) => {
|
||||
// 验证支付参数是否完整
|
||||
if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) {
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: "支付参数错误,请重试", icon: "none" });
|
||||
setTimeout(() => {
|
||||
uni.showToast({ title: "支付参数错误,请重试", icon: "none" });
|
||||
}, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -848,20 +848,24 @@ const sendMessage = async (message, isInstruct = false) => {
|
||||
// 检查连接是否成功建立
|
||||
if (!isWsConnected()) {
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: "连接服务器失败,请稍后重试",
|
||||
icon: "none",
|
||||
});
|
||||
setTimeout(() => {
|
||||
uni.showToast({
|
||||
title: "连接服务器失败,请稍后重试",
|
||||
icon: "none",
|
||||
});
|
||||
}, 100);
|
||||
return;
|
||||
}
|
||||
uni.hideLoading();
|
||||
} catch (error) {
|
||||
console.error("重新连接WebSocket失败:", error);
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: "连接服务器失败,请稍后重试",
|
||||
icon: "none",
|
||||
});
|
||||
setTimeout(() => {
|
||||
uni.showToast({
|
||||
title: "连接服务器失败,请稍后重试",
|
||||
icon: "none",
|
||||
});
|
||||
}, 100);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user