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

View File

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