feat: 移除重复的 toast 函数调用,优化交易密码提示逻辑

This commit is contained in:
2026-01-24 17:54:53 +07:00
parent 0b50a52845
commit 8aeb6024e9

View File

@@ -8,16 +8,6 @@ const { data: status, execute } = await safeClient(() => client.api.user.securit
const hasPaymentPassword = computed(() => status.value?.enabled ?? false);
const toggleInst = ref<HTMLIonToggleElement | null>(null);
async function showToast(message: string, color: "success" | "danger" | "warning" = "success") {
const toast = await toastController.create({
message,
duration: 2000,
position: "top",
color,
});
await toast.present();
}
function handleChangePassword() {
router.push("/security/change_password");
}
@@ -47,17 +37,20 @@ async function handleTogglePaymentPassword() {
{
text: "取消",
role: "cancel",
handler: () => {
(toggleInst.value as any)!.$el.checked = !(toggleInst.value as any)!.$el.checked;
},
},
{
text: "确认",
role: "confirm",
handler: async (data) => {
if (!data.oldPassword) {
await showToast("请输入交易密码", "danger");
showToast("请输入交易密码");
return false;
}
if (data.oldPassword.length < 6) {
await showToast("交易密码至少6位", "danger");
showToast("交易密码至少6位");
return false;
}
@@ -66,7 +59,7 @@ async function handleTogglePaymentPassword() {
}));
if (!error.value) {
await showToast("交易密码功能已关闭", "warning");
showToast("交易密码功能已关闭");
await execute();
return true;
}
@@ -106,24 +99,27 @@ async function handleTogglePaymentPassword() {
{
text: "取消",
role: "cancel",
handler: () => {
(toggleInst.value as any)!.$el.checked = !(toggleInst.value as any)!.$el.checked;
},
},
{
text: "确认",
handler: async (data) => {
if (!data.password || !data.confirmPassword) {
await showToast("请输入交易密码", "danger");
showToast("请输入交易密码");
return false;
}
if (data.password.length < 6) {
await showToast("交易密码至少6位", "danger");
showToast("交易密码至少6位");
return false;
}
if (data.password !== data.confirmPassword) {
await showToast("两次输入的密码不一致", "danger");
showToast("两次输入的密码不一致");
return false;
}
if (!/^\d+$/.test(data.password)) {
await showToast("交易密码只能包含数字", "danger");
showToast("交易密码只能包含数字");
return false;
}
@@ -132,7 +128,7 @@ async function handleTogglePaymentPassword() {
}));
if (!error.value) {
await showToast("交易密码设置成功");
showToast("交易密码设置成功");
await execute();
return true;
}