2025-02-28 09:56:01 +08:00
|
|
|
<script setup>
|
2025-04-19 15:28:32 +08:00
|
|
|
import {defineModel, defineProps, ref} from 'vue';
|
|
|
|
|
import {Message, Notification} from "@arco-design/web-vue";
|
|
|
|
|
import Api from "../../api/index.js";
|
2025-02-28 09:56:01 +08:00
|
|
|
|
|
|
|
|
const verificationCode = defineModel('verificationCode', {type: String});
|
2025-04-29 19:43:06 +08:00
|
|
|
const {mobile, api} = defineProps({
|
2025-04-19 15:28:32 +08:00
|
|
|
mobile: {
|
2025-02-28 09:56:01 +08:00
|
|
|
type: String,
|
|
|
|
|
default: null,
|
2025-04-29 19:43:06 +08:00
|
|
|
},
|
|
|
|
|
api: {
|
|
|
|
|
type: Function,
|
|
|
|
|
default: Api.admin.sendSms
|
2025-02-28 09:56:01 +08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const time = ref(null);
|
|
|
|
|
let timer = null;
|
|
|
|
|
|
2025-04-19 15:28:32 +08:00
|
|
|
const verifyPhone = async () => {
|
|
|
|
|
if (/^1[3-9]\d{9}$/.test(mobile)) {
|
2025-02-28 09:56:01 +08:00
|
|
|
if (timer === null) {
|
2025-04-29 19:43:06 +08:00
|
|
|
const {msg, code} = await api(mobile);
|
2025-04-19 15:28:32 +08:00
|
|
|
if (code === 1) Message.success(msg);
|
2025-02-28 09:56:01 +08:00
|
|
|
time.value = 10;
|
|
|
|
|
timer = setInterval(() => {
|
|
|
|
|
if (time.value <= 0) {
|
|
|
|
|
time.value = null;
|
|
|
|
|
clearInterval(timer);
|
|
|
|
|
timer = null;
|
|
|
|
|
} else {
|
|
|
|
|
time.value--;
|
|
|
|
|
}
|
|
|
|
|
}, 1000);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
Notification.error({
|
|
|
|
|
title: '手机号错误',
|
|
|
|
|
content: '请检查后重新输入'
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
2025-04-19 15:28:32 +08:00
|
|
|
<a-input v-model:model-value="verificationCode" placeholder="验证码">
|
2025-02-28 09:56:01 +08:00
|
|
|
<template #append>
|
|
|
|
|
<a-link @click="verifyPhone" :disabled="Boolean(time)" :hoverable="false">
|
|
|
|
|
{{ time ? `${time}s后重新获取` : '发送验证码' }}
|
|
|
|
|
</a-link>
|
|
|
|
|
</template>
|
|
|
|
|
</a-input>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
|
|
|
|
</style>
|