|
@@ -40,7 +40,9 @@
|
|
|
<el-icon><Message /></el-icon>
|
|
<el-icon><Message /></el-icon>
|
|
|
</template>
|
|
</template>
|
|
|
<template #suffix>
|
|
<template #suffix>
|
|
|
- <span class="code" @click="sendSmsCode">{{ smsCodeText }}</span>
|
|
|
|
|
|
|
+ <span @click="sendSmsCode" :class="['code', countdown > 0 ? 'disabled' : '']">
|
|
|
|
|
+ {{ codeText }}
|
|
|
|
|
+ </span>
|
|
|
</template>
|
|
</template>
|
|
|
</el-input>
|
|
</el-input>
|
|
|
</el-form-item>
|
|
</el-form-item>
|
|
@@ -79,6 +81,7 @@
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
|
import { useUserStore } from '@/store/modules/user';
|
|
import { useUserStore } from '@/store/modules/user';
|
|
|
|
|
+import { smsCode } from '@/api/breg/index';
|
|
|
import { LoginData } from '@/api/types';
|
|
import { LoginData } from '@/api/types';
|
|
|
import { to } from 'await-to-js';
|
|
import { to } from 'await-to-js';
|
|
|
import { User, Lock, Iphone, Message } from '@element-plus/icons-vue';
|
|
import { User, Lock, Iphone, Message } from '@element-plus/icons-vue';
|
|
@@ -89,11 +92,12 @@ const router = useRouter();
|
|
|
|
|
|
|
|
const type = ref<number>(1);
|
|
const type = ref<number>(1);
|
|
|
const loading = ref(false);
|
|
const loading = ref(false);
|
|
|
-const smsCodeText = ref('发送验证码');
|
|
|
|
|
-const smsCountdown = ref(0);
|
|
|
|
|
|
|
+const timer = ref<any>(null);
|
|
|
|
|
+
|
|
|
const loginRef = ref<ElFormInstance>();
|
|
const loginRef = ref<ElFormInstance>();
|
|
|
const redirect = ref('/');
|
|
const redirect = ref('/');
|
|
|
-
|
|
|
|
|
|
|
+const codeText = ref<string>('发送验证码');
|
|
|
|
|
+const countdown = ref<number>(0);
|
|
|
const loginForm = ref<LoginData>({
|
|
const loginForm = ref<LoginData>({
|
|
|
username: import.meta.env.VITE_APP_USERNAME,
|
|
username: import.meta.env.VITE_APP_USERNAME,
|
|
|
password: import.meta.env.VITE_APP_PASSWORD,
|
|
password: import.meta.env.VITE_APP_PASSWORD,
|
|
@@ -161,27 +165,64 @@ const handleLogin = () => {
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+// 启动倒计时
|
|
|
|
|
+const startCountdown = () => {
|
|
|
|
|
+ countdown.value = 60;
|
|
|
|
|
+ codeText.value = `${countdown.value}s 后重新发送`;
|
|
|
|
|
+
|
|
|
|
|
+ timer.value = setInterval(() => {
|
|
|
|
|
+ countdown.value--;
|
|
|
|
|
+ if (countdown.value > 0) {
|
|
|
|
|
+ codeText.value = `${countdown.value}s 后重新发送`;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ clearInterval(timer.value);
|
|
|
|
|
+ timer.value = null;
|
|
|
|
|
+ codeText.value = '发送验证码';
|
|
|
|
|
+ }
|
|
|
|
|
+ }, 1000);
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 发送短信验证码
|
|
* 发送短信验证码
|
|
|
*/
|
|
*/
|
|
|
const sendSmsCode = () => {
|
|
const sendSmsCode = () => {
|
|
|
- if (smsCountdown.value > 0) return;
|
|
|
|
|
- if (!loginForm.value.mobile) {
|
|
|
|
|
- ElMessage.warning('请输入手机号');
|
|
|
|
|
|
|
+ // 防止倒计时期间重复点击
|
|
|
|
|
+ if (countdown.value > 0) return;
|
|
|
|
|
+
|
|
|
|
|
+ const phone = loginForm.value.mobile;
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 基础格式校验
|
|
|
|
|
+ if (!validateMobile(phone)) {
|
|
|
|
|
+ ElMessage({
|
|
|
|
|
+ message: '请输入正确的手机号码',
|
|
|
|
|
+ type: 'warning'
|
|
|
|
|
+ });
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
// TODO: 调用发送短信验证码接口
|
|
// TODO: 调用发送短信验证码接口
|
|
|
- ElMessage.success('验证码已发送');
|
|
|
|
|
- smsCountdown.value = 60;
|
|
|
|
|
- const timer = setInterval(() => {
|
|
|
|
|
- smsCountdown.value--;
|
|
|
|
|
- if (smsCountdown.value > 0) {
|
|
|
|
|
- smsCodeText.value = `${smsCountdown.value}s后重发`;
|
|
|
|
|
- } else {
|
|
|
|
|
- smsCodeText.value = '发送验证码';
|
|
|
|
|
- clearInterval(timer);
|
|
|
|
|
- }
|
|
|
|
|
- }, 1000);
|
|
|
|
|
|
|
+ smsCode({ phonenumber: phone })
|
|
|
|
|
+ .then((smsRes: any) => {
|
|
|
|
|
+ if (smsRes.code === 200) {
|
|
|
|
|
+ ElMessage({
|
|
|
|
|
+ message: '验证码已发送',
|
|
|
|
|
+ type: 'success'
|
|
|
|
|
+ });
|
|
|
|
|
+ startCountdown(); // 开始倒计时
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 发送短信接口业务失败
|
|
|
|
|
+ ElMessage.error(smsRes.msg || '发送验证码失败');
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch((err: any) => {
|
|
|
|
|
+ // 发送短信接口网络错误或异常
|
|
|
|
|
+ ElMessage.error(err.msg || '发送验证码请求异常');
|
|
|
|
|
+ });
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+// 验证手机号
|
|
|
|
|
+const validateMobile = (phone: any) => {
|
|
|
|
|
+ const reg = /^1[3-9]\d{9}$/;
|
|
|
|
|
+ return reg.test(phone);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
/**
|