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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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