This commit is contained in:
Mrx
2026-02-27 12:53:33 +08:00
parent 6fb4800283
commit ca32d17eb3
9 changed files with 311 additions and 102 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("");
@@ -12,6 +13,7 @@ const isAgreed = ref(false);
const isCountingDown = ref(false);
const countdown = ref(60);
let timer = null;
const { runWithCaptcha } = useAliyunCaptcha();
// 验证组件状态
const showCaptcha = ref(false);
@@ -41,26 +43,31 @@ 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(res.msg || "获取失败");
}
},
);
}
function startCountdown() {