This commit is contained in:
Mrx
2026-02-28 12:29:15 +08:00
parent b2da12f3ed
commit a5d9de5736
3 changed files with 61 additions and 32 deletions

View File

@@ -1,8 +1,11 @@
<script setup>
import { ref, computed, nextTick } from "vue";
import { showToast } from "vant";
import { useDialogStore } from "@/stores/dialogStore";
import { useAliyunCaptcha } from "@/composables/useAliyunCaptcha";
const emit = defineEmits(['bind-success'])
const { runWithCaptcha } = useAliyunCaptcha();
const router = useRouter();
const dialogStore = useDialogStore();
const agentStore = useAgentStore();
@@ -36,25 +39,26 @@ async function sendVerificationCode() {
showToast({ message: "请输入有效的手机号" });
return;
}
const { data, error } = await useApiFetch("auth/sendSms")
.post({ mobile: phoneNumber.value, actionType: "bindMobile" })
.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: "bindMobile", captchaVerifyParam })
.json(),
(res) => {
if (res && res.code === 200) {
showToast({ message: "获取成功" });
startCountdown();
nextTick(() => {
const verificationCodeInput = document.getElementById('verificationCode');
if (verificationCodeInput) {
verificationCodeInput.focus();
}
});
} else {
showToast(res?.msg || "发送失败");
}
}
}
);
}
function startCountdown() {