增加前端格式检查配置
This commit is contained in:
@@ -1,63 +1,62 @@
|
||||
import { onUnmounted, ref } from "vue";
|
||||
import { showToast } from "vant";
|
||||
import { sendSmsCode } from "@/features/auth/api/auth";
|
||||
import { onUnmounted, ref } from 'vue'
|
||||
import { showToast } from 'vant'
|
||||
import { sendSmsCode } from '@/features/auth/api/auth'
|
||||
|
||||
export function useSmsCountdown() {
|
||||
const countDown = ref(0);
|
||||
const sending = ref(false);
|
||||
let timer: ReturnType<typeof setInterval> | null = null;
|
||||
const countDown = ref(0)
|
||||
const sending = ref(false)
|
||||
let timer: ReturnType<typeof setInterval> | null = null
|
||||
|
||||
function startCountDown() {
|
||||
countDown.value = 60;
|
||||
countDown.value = 60
|
||||
timer = setInterval(() => {
|
||||
countDown.value--;
|
||||
countDown.value--
|
||||
if (countDown.value <= 0) {
|
||||
clearInterval(timer!);
|
||||
timer = null;
|
||||
clearInterval(timer!)
|
||||
timer = null
|
||||
}
|
||||
}, 1000);
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
onUnmounted(() => {
|
||||
if (timer) {
|
||||
clearInterval(timer);
|
||||
timer = null;
|
||||
clearInterval(timer)
|
||||
timer = null
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
async function handleSendCode(phone: string) {
|
||||
if (!phone.trim()) {
|
||||
showToast({ message: "请输入手机号", icon: "warning-o" });
|
||||
return false;
|
||||
showToast({ message: '请输入手机号', icon: 'warning-o' })
|
||||
return false
|
||||
}
|
||||
|
||||
sending.value = true;
|
||||
sending.value = true
|
||||
try {
|
||||
await sendSmsCode(phone);
|
||||
await sendSmsCode(phone)
|
||||
showToast({
|
||||
message: "验证码已发送,请注意查收",
|
||||
icon: "passed",
|
||||
});
|
||||
startCountDown();
|
||||
return true;
|
||||
message: '验证码已发送,请注意查收',
|
||||
icon: 'passed',
|
||||
})
|
||||
startCountDown()
|
||||
return true
|
||||
} catch (error) {
|
||||
showToast({
|
||||
message: readError(error, "验证码发送失败,请稍后重试"),
|
||||
icon: "cross",
|
||||
});
|
||||
return false;
|
||||
message: readError(error, '验证码发送失败,请稍后重试'),
|
||||
icon: 'cross',
|
||||
})
|
||||
return false
|
||||
} finally {
|
||||
sending.value = false;
|
||||
sending.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === "object" && error && "response" in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } })
|
||||
.response;
|
||||
return response?.data?.message || fallback;
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback;
|
||||
return fallback
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -65,5 +64,5 @@ export function useSmsCountdown() {
|
||||
sending,
|
||||
handleSendCode,
|
||||
readError,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user