fix: 恢复登录手机号和短信倒计时

This commit is contained in:
2026-07-10 17:13:21 +08:00
parent fc8a593393
commit dc4b1bfce9
2 changed files with 12 additions and 5 deletions

View File

@@ -21,6 +21,7 @@ const emit = defineEmits<{
const COUNTDOWN_SECONDS = 60;
const COUNTDOWN_PREFIX = "ai-kb-sms-countdown:";
const PHONE_STORAGE_KEY = "ai-kb-login-phone";
const PHONE_PATTERN = /^1[3-9]\d{9}$/;
const phone = ref("");
@@ -56,7 +57,11 @@ const sendButtonText = computed(() => {
let countdownTimer: ReturnType<typeof setInterval> | null = null;
let toastTimer: ReturnType<typeof setTimeout> | null = null;
onMounted(() => restoreCountdown());
onMounted(() => {
const storedPhone = window.localStorage.getItem(PHONE_STORAGE_KEY) ?? "";
if (PHONE_PATTERN.test(storedPhone)) phone.value = storedPhone;
restoreCountdown();
});
onUnmounted(() => {
stopCountdownTimer();
if (toastTimer) clearTimeout(toastTimer);
@@ -64,6 +69,7 @@ onUnmounted(() => {
watch(phone, () => {
code.value = sanitizeDigits(code.value, 6);
if (phoneValid.value) window.localStorage.setItem(PHONE_STORAGE_KEY, phone.value);
restoreCountdown();
});
@@ -82,6 +88,7 @@ function sanitizeDigits(value: string, maxLength: number) {
function clearPhone() {
phone.value = "";
phoneTouched.value = false;
window.localStorage.removeItem(PHONE_STORAGE_KEY);
}
async function sendCode() {