From 21e3c3b7e9522adff085a6544612603fec84dfbf Mon Sep 17 00:00:00 2001 From: sankeyangshu <1260323835@qq.com> Date: Tue, 17 Dec 2024 16:45:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=A0=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 4 ++-- src/api/System/user.ts | 10 ++++++++++ src/store/modules/user.ts | 8 ++++++-- src/types/user.ts | 1 + src/views/Login/index.vue | 38 +++++++++++++++++++++++++++++++++----- src/views/Notice/index.vue | 10 +++++++++- 6 files changed, 61 insertions(+), 10 deletions(-) diff --git a/.env.development b/.env.development index 0ef80c4..4cff53f 100644 --- a/.env.development +++ b/.env.development @@ -7,6 +7,6 @@ NODE_ENV = 'development' # 本地环境接口地址 # 如果没有跨域问题,直接在这里配置即可 -# VITE_APP_BASE_API = 'http://192.168.1.116:8080' +VITE_APP_BASE_API = 'http://192.168.1.135:8080' # VITE_APP_BASE_API = 'http://121.41.36.72:8080' -VITE_APP_BASE_API = 'http://www.cvlip.com:9003' +# VITE_APP_BASE_API = 'http://www.cvlip.com:9003' diff --git a/src/api/System/user.ts b/src/api/System/user.ts index d47182f..e69b4d2 100644 --- a/src/api/System/user.ts +++ b/src/api/System/user.ts @@ -13,6 +13,7 @@ const api = { userPassword: '/admin/user/password', // 用户修改密码 userGet: '/admin/user/get', // 用户详情 userInfo: '/admin/user/info', // 用户信息 + sendMail: '/admin/sms/send', // 发送短信 }; /** @@ -53,3 +54,12 @@ export function getUserGetAPI(data: { id: number | string }) { export function getUserInfoAPI() { return http.postParams(api.userInfo); } + +/** + * 发送短信 + * @param {string} data 手机号 + * @return 返回请求发送短信接口的结果 + */ +export function sendMailAPI(data: { phone: string }) { + return http.postParams(api.sendMail, data); +} diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index a4fda3a..804540f 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -36,10 +36,14 @@ export const useUserStore = defineStore({ * 用户登录 */ login(userInfo: loginDataType) { - const { username, password } = userInfo; + const { username, password, verifyCode } = userInfo; return new Promise(async (resolve, reject) => { try { - const { data } = await postLoginAPI({ username: username.trim(), password: password }); + const { data } = await postLoginAPI({ + username: username.trim(), + password: password, + verifyCode, + }); this.setToken(data.accessToken); // 保存用户token const { data: userInfoData } = await getUserInfoAPI(); this.setUserInfo(userInfoData); diff --git a/src/types/user.ts b/src/types/user.ts index eb0e451..3035c34 100644 --- a/src/types/user.ts +++ b/src/types/user.ts @@ -6,6 +6,7 @@ import { PageRowsType } from './index'; export type loginDataType = { username: string; password: string; + verifyCode?: string; }; /** diff --git a/src/views/Login/index.vue b/src/views/Login/index.vue index 368eae0..2a7a6e0 100644 --- a/src/views/Login/index.vue +++ b/src/views/Login/index.vue @@ -37,14 +37,17 @@ - + -
发送短信
+ +
+ {{ countdown > 0 ? `${countdown} 秒后重试` : '发送短信' }} +
@@ -207,6 +210,7 @@ import { reactive, ref } from 'vue'; import { useRouter } from 'vue-router'; import { postEnterpriseRegAPI } from '@/api/Enterprise/company'; import { postPortListAPI } from '@/api/Port'; +import { sendMailAPI } from '@/api/System/user'; import RemoteSelect from '@/components/RemoteSelect/index.vue'; import { useUserStore } from '@/store/modules/user'; import { getTimeStateStr } from '@/utils'; @@ -234,7 +238,7 @@ const loginRules = reactive({ const loginForm = reactive({ username: '', // 用户名 password: '', // 密码 - code: '', + verifyCode: '', }); // 按钮加载状态 @@ -246,6 +250,30 @@ const router = useRouter(); // store const userStore = useUserStore(); +// 短信验证码倒计时 +const countdown = ref(0); +const countdownInterval = ref(); + +// 获取短信验证码 +const getVerifyCode = async () => { + if (!validPhone(loginForm.username)) { + ElMessage.error('请输入正确的手机号码'); + return; + } + if (countdown.value > 0) { + ElMessage.error(`请${countdown.value}秒后重试`); + return; + } + await sendMailAPI({ phone: loginForm.username }); + countdown.value = 60; + countdownInterval.value = setInterval(() => { + countdown.value -= 1; + if (countdown.value === 0) { + clearInterval(countdownInterval.value); + } + }, 1000); +}; + // 用户登录 const onClickSubmit = (formEl: FormInstance | undefined) => { // 进行表单校验 diff --git a/src/views/Notice/index.vue b/src/views/Notice/index.vue index c15ad5d..d5ef4c9 100644 --- a/src/views/Notice/index.vue +++ b/src/views/Notice/index.vue @@ -39,7 +39,8 @@