This commit is contained in:
Mrx
2026-02-26 17:45:28 +08:00
parent 74b0c0e918
commit 62675a6137
2 changed files with 55 additions and 30 deletions

View File

@@ -118,10 +118,15 @@
</template>
<script setup>
import { ref, computed, nextTick } from 'vue'
const router = useRouter();
const show = defineModel("show");
import { useCascaderAreaData } from "@vant/area-data";
import { showToast } from "vant"; // 引入 showToast 方法
import { useAliyunCaptcha } from '@/composables/useAliyunCaptcha'
const { runWithCaptcha } = useAliyunCaptcha()
const emit = defineEmits(); // 确保 emit 可以正确使用
const props = defineProps({
ancestor: {
@@ -171,20 +176,31 @@ const getSmsCode = async () => {
loadingSms.value = true;
const { data, error } = await useApiFetch("auth/sendSms")
.post({ mobile: form.value.mobile, actionType: "agentApply" })
.json();
runWithCaptcha(
(captchaVerifyParam) =>
useApiFetch('auth/sendSms')
.post({
mobile: form.value.mobile,
actionType: 'agentApply',
captchaVerifyParam
})
.json(),
(res) => {
loadingSms.value = false;
if (data.value && !error.value) {
if (data.value.code === 200) {
if (res.code === 200) {
showToast({ message: "获取成功" });
startCountdown(); // 启动倒计时
startCountdown();
nextTick(() => {
const codeInput = document.querySelector('input[name="code"]');
if (codeInput) {
codeInput.focus();
}
});
} else {
showToast(data.value.msg);
showToast(res.msg || "获取失败");
}
}
);
};
let timer = null;

View File

@@ -5,6 +5,9 @@ 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 { runWithCaptcha } = useAliyunCaptcha()
const emit = defineEmits(['login-success'])
const dialogStore = useDialogStore()
@@ -47,15 +50,20 @@ 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) {
runWithCaptcha(
(captchaVerifyParam) =>
useApiFetch('auth/sendSms')
.post({
mobile: phoneNumber.value,
actionType: 'login',
captchaVerifyParam
})
.json(),
(res) => {
if (res.code === 200) {
showToast({ message: "获取成功" });
startCountdown()
// 聚焦到验证码输入框
startCountdown();
nextTick(() => {
const verificationCodeInput = document.getElementById('verificationCode');
if (verificationCodeInput) {
@@ -63,9 +71,10 @@ async function sendVerificationCode() {
}
});
} else {
showToast(data.value.msg)
showToast(res.msg || "获取失败");
}
}
);
}
function startCountdown() {