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

@@ -2,6 +2,7 @@
import { ref, computed, onUnmounted, nextTick } from 'vue'
import { showToast } from 'vant'
import ClickCaptcha from '@/components/ClickCaptcha.vue'
import { useAliyunCaptcha } from "@/composables/useAliyunCaptcha";
const router = useRouter()
const phoneNumber = ref('')
@@ -13,6 +14,8 @@ const isCountingDown = ref(false)
const countdown = ref(60)
let timer = null
const { runWithCaptcha } = useAliyunCaptcha();
// 验证组件状态
const showCaptcha = ref(false)
const captchaVerified = ref(false)
@@ -41,25 +44,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() {