refactor: replace uni.showToast calls with shared toast

consolidates repeated toast display logic into a centralized utility, reducing code duplication and standardizing toast behavior across the codebase
This commit is contained in:
duanshuwen
2026-05-29 21:35:10 +08:00
parent 656c592da2
commit 71aa343efb
14 changed files with 36 additions and 106 deletions

View File

@@ -129,7 +129,7 @@ const handleChooseImage = () => {
updateImagehandle(file); updateImagehandle(file);
}, },
fail: () => { fail: () => {
uni.showToast({ title: "选择图片失败", icon: "none" }); showToast("选择图片失败");
}, },
}); });
}; };
@@ -160,7 +160,7 @@ const handleCall = async () => {
} }
if (!roomId.value.trim()) { if (!roomId.value.trim()) {
uni.showToast({ title: "请填写所在位置", icon: "none" }); showToast("请填写所在位置");
return; return;
} }
@@ -168,12 +168,12 @@ const handleCall = async () => {
? contactPhone.value ? contactPhone.value
: originalPhone.value; : originalPhone.value;
if (!phoneToSubmit.trim()) { if (!phoneToSubmit.trim()) {
uni.showToast({ title: "请填写联系电话", icon: "none" }); showToast("请填写联系电话");
return; return;
} }
if (!contactText.value.trim()) { if (!contactText.value.trim()) {
uni.showToast({ title: "请填写需求信息描述内容", icon: "none" }); showToast("请填写需求信息描述内容");
return; return;
} }
@@ -201,12 +201,12 @@ const sendCreateWorkOrder = async (phoneToSubmit) => {
// 设置成功状态 // 设置成功状态
isCallSuccess.value = true; isCallSuccess.value = true;
uni.showToast({ title: "呼叫成功", icon: "success" }); showToast("呼叫成功");
} else { } else {
uni.showToast({ title: res.message || "呼叫失败", icon: "none" }); showToast(res.message || "呼叫失败");
} }
} catch (error) { } catch (error) {
uni.showToast({ title: "网络错误,请重试", icon: "none" }); showToast("网络错误,请重试");
} }
}; };

View File

@@ -57,12 +57,12 @@ const appName = computed(() => getCurrentConfig().name);
const handleCall = async () => { const handleCall = async () => {
if (!contactPhone.value.trim()) { if (!contactPhone.value.trim()) {
uni.showToast({ title: "请填写联系电话", icon: "none" }); showToast("请填写联系电话");
return; return;
} }
if (!contactText.value.trim()) { if (!contactText.value.trim()) {
uni.showToast({ title: "请填写意见内容", icon: "none" }); showToast("请填写意见内容");
return; return;
} }
@@ -81,22 +81,13 @@ const sendFeedback = async () => {
// 设置成功状态 // 设置成功状态
isCallSuccess.value = true; isCallSuccess.value = true;
uni.showToast({ showToast("反馈意见成功");
title: "反馈意见成功",
icon: "success",
});
} else { } else {
uni.showToast({ showToast(res.message || "反馈意见失败");
title: res.message || "反馈意见失败",
icon: "none",
});
} }
} catch (error) { } catch (error) {
console.error("反馈意见失败:", error); console.error("反馈意见失败:", error);
uni.showToast({ showToast("网络错误,请重试");
title: "网络错误,请重试",
icon: "none",
});
} }
}; };

View File

@@ -1,25 +1,12 @@
<template xlang="wxml" minapp="mpvue"> <template xlang="wxml" minapp="mpvue">
<div class="tki-qrcode"> <div class="tki-qrcode">
<!-- #ifndef MP-ALIPAY --> <!-- #ifndef MP-ALIPAY -->
<canvas <canvas class="tki-qrcode-canvas" :canvas-id="cid" :style="{ width: cpSize + 'px', height: cpSize + 'px' }" />
class="tki-qrcode-canvas"
:canvas-id="cid"
:style="{ width: cpSize + 'px', height: cpSize + 'px' }"
/>
<!-- #endif --> <!-- #endif -->
<!-- #ifdef MP-ALIPAY --> <!-- #ifdef MP-ALIPAY -->
<canvas <canvas :id="cid" :width="cpSize" :height="cpSize" class="tki-qrcode-canvas" />
:id="cid"
:width="cpSize"
:height="cpSize"
class="tki-qrcode-canvas"
/>
<!-- #endif --> <!-- #endif -->
<img <img v-show="show" :src="result" :style="{ width: cpSize + 'px', height: cpSize + 'px' }" />
v-show="show"
:src="result"
:style="{ width: cpSize + 'px', height: cpSize + 'px' }"
/>
</div> </div>
</template> </template>
@@ -176,11 +163,7 @@ const _makeCode = () => {
} }
} else { } else {
console.log("二维码内容为空"); console.log("二维码内容为空");
uni.showToast({ showToast("二维码内容不能为空");
title: "二维码内容不能为空",
icon: "none",
duration: 2000,
});
} }
}; };
@@ -196,11 +179,7 @@ const _saveCode = () => {
uni.saveImageToPhotosAlbum({ uni.saveImageToPhotosAlbum({
filePath: result.value, filePath: result.value,
success: function () { success: function () {
uni.showToast({ showToast("二维码保存成功");
title: "二维码保存成功",
icon: "success",
duration: 2000,
});
}, },
}); });
} }

View File

@@ -908,10 +908,7 @@ const sendMessage = async (message, isInstruct = false) => {
if (!isWsConnected()) { if (!isWsConnected()) {
// uni.hideLoading(); // uni.hideLoading();
setTimeout(() => { setTimeout(() => {
// uni.showToast({ showToast("连接服务器失败,请稍后重试");
// title: "连接服务器失败,请稍后重试",
// icon: "none",
// });
}, 100); }, 100);
return; return;
} }
@@ -920,20 +917,14 @@ const sendMessage = async (message, isInstruct = false) => {
console.error("重新连接WebSocket失败:", error); console.error("重新连接WebSocket失败:", error);
// uni.hideLoading(); // uni.hideLoading();
setTimeout(() => { setTimeout(() => {
// uni.showToast({ showToast("连接服务器失败,请稍后重试");
// title: "连接服务器失败,请稍后重试",
// icon: "none",
// });
}, 100); }, 100);
return; return;
} }
} }
if (isSessionActive.value) { if (isSessionActive.value) {
// uni.showToast({ showToast("请等待当前回复完成");
// title: "请等待当前回复完成",
// icon: "none",
// });
return; return;
} }
isSessionActive.value = true; isSessionActive.value = true;

View File

@@ -79,7 +79,7 @@ const handleMenuClick = (item) => {
uni.navigateTo({ url: item.url }); uni.navigateTo({ url: item.url });
} else if (item.type === "action") { } else if (item.type === "action") {
if (item.action === "contactService") { if (item.action === "contactService") {
uni.showToast({ title: "联系客服功能待实现", icon: "none" }); showToast("联系客服功能待实现");
} else if (item.action === "cancelAccount") { } else if (item.action === "cancelAccount") {
handleLogout(); handleLogout();
} else if (item.action === "subscribeMessage") { } else if (item.action === "subscribeMessage") {

View File

@@ -121,10 +121,7 @@ const products = [
const faq = ["几岁的孩子能玩", "会不会全身湿透", "漂完去哪儿歇脚"]; const faq = ["几岁的孩子能玩", "会不会全身湿透", "漂完去哪儿歇脚"];
const showToast = (title) => { const showToast = (title) => {
uni.showToast({ showToast(title);
title,
icon: "none",
});
}; };
const goodsDetail = (item) => { const goodsDetail = (item) => {

View File

@@ -101,10 +101,7 @@ const getBadgeClass = (tone) => {
const openDetail = (item) => { const openDetail = (item) => {
const url = getLongTextGuideDetailRoute(item.type); const url = getLongTextGuideDetailRoute(item.type);
if (!url) { if (!url) {
uni.showToast({ showToast("暂未配置详情页");
title: "暂未配置详情页",
icon: "none",
});
return; return;
} }

View File

@@ -129,10 +129,7 @@ const predivPhoto = () => {
}; };
const showToast = (title) => { const showToast = (title) => {
uni.showToast({ showToast(title);
title,
icon: "none",
});
}; };
const jumpAigcClick = () => { const jumpAigcClick = () => {

View File

@@ -95,10 +95,7 @@ import { SEND_MESSAGE_CONTENT_TEXT } from "@/constants/constant";
const faq = ["古桥有什么传说", "最佳观赏时间", "旁边还有什么景点"]; const faq = ["古桥有什么传说", "最佳观赏时间", "旁边还有什么景点"];
const showToast = (title) => { const showToast = (title) => {
uni.showToast({ showToast(title);
title,
icon: "none",
});
}; };
// 打开地图 // 打开地图

View File

@@ -151,10 +151,7 @@ const facilities = [
const faq = ["上湖下湖哪个好玩", "玻璃船和铁皮船怎么选", "两个湖都玩来得及吗"]; const faq = ["上湖下湖哪个好玩", "玻璃船和铁皮船怎么选", "两个湖都玩来得及吗"];
const showToast = (title) => { const showToast = (title) => {
uni.showToast({ showToast(title);
title,
icon: "none",
});
}; };
const sendReply = (item) => { const sendReply = (item) => {

View File

@@ -84,10 +84,7 @@ const handleButtonClick = DebounceUtils.createDebounce(async (orderData) => {
if (!res || !res.data) { if (!res || !res.data) {
uni.hideLoading(); uni.hideLoading();
setTimeout(() => { setTimeout(() => {
uni.showToast({ showToast(res.msg || "订单创建失败,请重试");
title: res.msg || "订单创建失败,请重试",
icon: "none",
});
}, 100); }, 100);
return; return;
} }
@@ -99,7 +96,7 @@ const handleButtonClick = DebounceUtils.createDebounce(async (orderData) => {
if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) { if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) {
uni.hideLoading(); uni.hideLoading();
setTimeout(() => { setTimeout(() => {
uni.showToast({ title: "支付参数错误,请重试", icon: "none" }); showToast("支付参数错误,请重试");
}, 100); }, 100);
return; return;
} }
@@ -116,18 +113,12 @@ const handleButtonClick = DebounceUtils.createDebounce(async (orderData) => {
package: String(packageVal), // 确保为字符串类型 package: String(packageVal), // 确保为字符串类型
signType: String(signType), signType: String(signType),
paySign: String(paySign), paySign: String(paySign),
success: () => { success: async () => {
uni.showToast({ await showToast("支付成功");
title: "支付成功",
icon: "success",
success: () => {
console.log("支付成功,刷新订单详情");
emit("refresh", { orderId: orderId }); emit("refresh", { orderId: orderId });
}, },
});
},
fail: () => { fail: () => {
uni.showToast({ title: "支付失败,请重试", icon: "none" }); showToast("支付失败,请重试");
}, },
}); });
// #endif // #endif

View File

@@ -46,10 +46,7 @@ const props = defineProps({
const handleShowQrcode = (item, index) => { const handleShowQrcode = (item, index) => {
console.log("显示核销凭证二维码,凭证信息:", item); console.log("显示核销凭证二维码,凭证信息:", item);
if (item.packageStatus !== 0) { if (item.packageStatus !== 0) {
uni.showToast({ showToast("该凭证已核销使用");
title: "该凭证已核销使用",
icon: "none",
});
return; return;
} }
emit("selected", { item, index }); emit("selected", { item, index });

View File

@@ -90,13 +90,13 @@ const handleRefundConfirm = async ({ orderId }) => {
// 调用退款API // 调用退款API
await orderRefund({ orderId }); await orderRefund({ orderId });
uni.showToast({ title: "退款申请已提交", icon: "success" }); showToast("退款申请已提交");
// 刷新订单状态 // 刷新订单状态
const res = await userOrderDetail({ orderId }); const res = await userOrderDetail({ orderId });
orderData.value = res.data; orderData.value = res.data;
} catch (error) { } catch (error) {
uni.showToast({ title: "退款申请失败,请重试", icon: "none" }); showToast("退款申请失败,请重试");
} }
}; };

View File

@@ -93,10 +93,6 @@ const cancelCall = async () => {
if (res.data) { if (res.data) {
isCancelWork.value = true; isCancelWork.value = true;
} }
uni.showToast({ showToast(res.data ? "取消呼叫成功" : res.message || "取消呼叫失败");
title: res.data ? "取消呼叫成功" : res.message || "取消呼叫失败",
icon: "success",
duration: 2000,
});
}; };
</script> </script>