This commit is contained in:
Mrx
2026-02-27 12:07:16 +08:00
parent 2df104acea
commit 9937097d7c
8 changed files with 247 additions and 69 deletions

View File

@@ -5,6 +5,7 @@ import { showToast } from 'vant'
import ClickCaptcha from '@/components/ClickCaptcha.vue'
import { useDialogStore } from '@/stores/dialogStore'
import { useUserStore } from '@/stores/userStore'
import { useAliyunCaptcha } from "@/composables/useAliyunCaptcha";
const emit = defineEmits(['login-success'])
const dialogStore = useDialogStore()
@@ -19,6 +20,8 @@ const isCountingDown = ref(false)
const countdown = ref(60)
let timer = null
const { runWithCaptcha } = useAliyunCaptcha();
// 验证组件状态
const showCaptcha = ref(false)
const captchaVerified = ref(false)
@@ -47,25 +50,26 @@ async function sendVerificationCode() {
showToast({ message: "请输入有效的手机号" });
return
}
const { data, error } = await useApiFetch('auth/sendSms')
.post({ mobile: phoneNumber.value, actionType: 'login' })
.json()
if (data.value && !error.value) {
if (data.value.code === 200) {
showToast({ message: "获取成功" });
startCountdown()
// 聚焦到验证码输入框
nextTick(() => {
const verificationCodeInput = document.getElementById('verificationCode');
if (verificationCodeInput) {
verificationCodeInput.focus();
}
});
} else {
showToast(data.value.msg)
await runWithCaptcha(
(captchaVerifyParam) =>
useApiFetch('auth/sendSms')
.post({ mobile: phoneNumber.value, actionType: 'login', captchaVerifyParam })
.json(),
(res) => {
if (res.code === 200) {
showToast({ message: "获取成功" });
startCountdown();
nextTick(() => {
const verificationCodeInput = document.getElementById('verificationCode');
if (verificationCodeInput) {
verificationCodeInput.focus();
}
});
} else {
showToast({ message: res.msg || "发送失败" });
}
}
}
);
}
function startCountdown() {