feat: 给toast 添加延迟

This commit is contained in:
2026-04-07 21:03:33 +08:00
parent 13d81f602a
commit 677333cc5f
3 changed files with 33 additions and 14 deletions

View File

@@ -265,7 +265,13 @@ const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => {
// 检查接口返回数据 // 检查接口返回数据
if (!res || !res.data) { if (!res || !res.data) {
uni.showToast({ title: res.msg || "订单创建失败,请重试", icon: "none" }); uni.hideLoading();
setTimeout(() => {
uni.showToast({
title: res.msg || "订单创建失败,请重试",
icon: "none",
});
}, 100);
return; return;
} }
@@ -275,7 +281,9 @@ const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => {
// 验证支付参数是否完整 // 验证支付参数是否完整
if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) { if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) {
uni.hideLoading(); uni.hideLoading();
setTimeout(() => {
uni.showToast({ title: "支付参数错误,请重试", icon: "none" }); uni.showToast({ title: "支付参数错误,请重试", icon: "none" });
}, 100);
return; return;
} }
@@ -308,9 +316,12 @@ const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => {
}); });
} catch (error) { } catch (error) {
console.error(error); console.error(error);
uni.hideLoading(); // 提前关闭 loading确保 toast 能在安卓正常弹出
setTimeout(() => {
uni.showToast({ title: "请求出错,请重试", icon: "none" }); uni.showToast({ title: "请求出错,请重试", icon: "none" });
}, 100);
} finally { } finally {
// 防止某些分支忘记 hide确保最终关闭 loadingrequestPayment 后也可以安全调用 hide // 最终兜底关闭 loading
uni.hideLoading(); uni.hideLoading();
} }
}, 1000); }, 1000);

View File

@@ -90,7 +90,9 @@ const handleButtonClick = DebounceUtils.createDebounce(async (orderData) => {
// 检查接口返回数据 // 检查接口返回数据
if (!res || !res.data) { if (!res || !res.data) {
uni.hideLoading(); uni.hideLoading();
setTimeout(() => {
uni.showToast({ title: res.msg || "订单创建失败,请重试", icon: "none" }); uni.showToast({ title: res.msg || "订单创建失败,请重试", icon: "none" });
}, 100);
return; return;
} }
@@ -100,7 +102,9 @@ const handleButtonClick = DebounceUtils.createDebounce(async (orderData) => {
// 验证支付参数是否完整 // 验证支付参数是否完整
if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) { if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) {
uni.hideLoading(); uni.hideLoading();
setTimeout(() => {
uni.showToast({ title: "支付参数错误,请重试", icon: "none" }); uni.showToast({ title: "支付参数错误,请重试", icon: "none" });
}, 100);
return; return;
} }

View File

@@ -848,20 +848,24 @@ const sendMessage = async (message, isInstruct = false) => {
// 检查连接是否成功建立 // 检查连接是否成功建立
if (!isWsConnected()) { if (!isWsConnected()) {
uni.hideLoading(); uni.hideLoading();
setTimeout(() => {
uni.showToast({ uni.showToast({
title: "连接服务器失败,请稍后重试", title: "连接服务器失败,请稍后重试",
icon: "none", icon: "none",
}); });
}, 100);
return; return;
} }
uni.hideLoading(); uni.hideLoading();
} catch (error) { } catch (error) {
console.error("重新连接WebSocket失败:", error); console.error("重新连接WebSocket失败:", error);
uni.hideLoading(); uni.hideLoading();
setTimeout(() => {
uni.showToast({ uni.showToast({
title: "连接服务器失败,请稍后重试", title: "连接服务器失败,请稍后重试",
icon: "none", icon: "none",
}); });
}, 100);
return; return;
} }
} }