From be94bc276fa423b2fc035e44511095cbf378f22b Mon Sep 17 00:00:00 2001 From: jiang Date: Tue, 10 Sep 2024 18:01:39 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=99=BB=E5=BD=95=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/user.js | 15 +++++++++------ src/utils/configure.js | 6 +++--- src/utils/request.js | 5 ++++- src/views/login1.vue | 28 +++++++++++++++++----------- src/views/register1.vue | 2 +- 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 6520776b..6d79bc22 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -1,4 +1,4 @@ -import { login, logout, getInfo, refreshToken, getPhoneCode, isLogin,isAdmin } from '@/api/login' +import { login, logout, getInfo, refreshToken, getPhoneCode, isLogin,isAdmin} from '@/api/login' import { getToken, setToken, setExpiresIn, removeToken } from '@/utils/auth' // 更严格的手机号和邮箱正则表达式 @@ -6,7 +6,7 @@ const phonePattern = /^(\+86)?1[3-9]\d{9}$/ // 支持前缀 +86 const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/ // 构建 payload 函数 -const buildPayload = ({ loginMethod, username, password, uuid, code, mobile, verificationCode }) => { +const buildPayload = ({ loginMethod, username, password, uuid, code, mobile, verificationCode,phoneUuid }) => { let loginType = '' if (loginMethod === 'mobile') { loginType = phonePattern.test(mobile.trim()) ? 'PHONE_OTP' : emailPattern.test(mobile.trim()) ? 'EMAIL_OTP' : 'PHONE_OTP' @@ -15,7 +15,8 @@ const buildPayload = ({ loginMethod, username, password, uuid, code, mobile, ver verificationCode, uuid, code, - loginType + loginType, + phoneUuid } } else { loginType = phonePattern.test(username.trim()) ? 'PHONE_PASSWORD' : emailPattern.test(username.trim()) ? 'EMAIL_PASSWORD' : 'USERNAME_PASSWORD' @@ -25,7 +26,8 @@ const buildPayload = ({ loginMethod, username, password, uuid, code, mobile, ver verificationCode, uuid, code, - loginType + loginType, + phoneUuid } } } @@ -95,10 +97,11 @@ const user = { // 获取手机验证码 GetPhoneCode({ commit }, userInfo) { const payload = { - mobile: userInfo.mobile.trim(), + username: userInfo.mobile.trim(), uuid: userInfo.uuid, code: userInfo.code, - mobileCodeType: userInfo.mobileCodeType + phoneUuid: userInfo.phoneUuid, + verificationCodeType: userInfo.mobileCodeType } return getPhoneCode(payload) .then(res => res) diff --git a/src/utils/configure.js b/src/utils/configure.js index b0396c22..20854905 100644 --- a/src/utils/configure.js +++ b/src/utils/configure.js @@ -25,15 +25,15 @@ const AES_CONFIG = { // 登录配置 const LOGIN_CONFIG = { - CODE_PHONE_LOGIN: DATA_SETTINGS.CLOSE, // 手机号验证码登录(true:开启,false:关闭) + CODE_PHONE_LOGIN: DATA_SETTINGS.OPEN, // 手机号验证码登录(true:开启,false:关闭) CODE_EMAIL_LOGIN: DATA_SETTINGS.OPEN,// 邮箱验证码登录(true:开启,false:关闭) PHONE_LOGIN: DATA_SETTINGS.OPEN, // 手机号密码登录(true:开启,false:关闭) - EMAIL_LOGIN: DATA_SETTINGS.CLOSE // 邮箱密码登录(true:开启,false:关闭) + EMAIL_LOGIN: DATA_SETTINGS.OPEN // 邮箱密码登录(true:开启,false:关闭) } //注册配置 const REGISTER_CONFIG = { PHONE_REGISTER: DATA_SETTINGS.OPEN, // 手机号注册(true:开启,false:关闭) - EMAIL_REGISTER: DATA_SETTINGS.CLOSE // 邮箱注册(true:开启,false:关闭) + EMAIL_REGISTER: DATA_SETTINGS.OPEN // 邮箱注册(true:开启,false:关闭) } // 配置设置 diff --git a/src/utils/request.js b/src/utils/request.js index 71618ac4..d4be3306 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -9,6 +9,7 @@ import { saveAs } from 'file-saver' import { encryptCBC, decryptCBC } from '@/utils/aescbc' import { CONFIG } from '@/utils/configure' import { hashWithSM3AndSalt } from '@/utils/sm' +import data from '@/views/system/dict/data.vue' //let token = localStorage.getItem("tokens"); @@ -115,8 +116,10 @@ service.interceptors.request.use(config => { // 响应拦截器 service.interceptors.response.use(res => { - if (res.headers.encryptresponse) { + console.log(res) + if (res.headers.encryptresponse && !res.data.hasOwnProperty('code')) { res.data = JSON.parse(decryptCBC(res.data)) + console.log(res.data) } // 未设置状态码则默认成功状态 const code = res.data.code || 200 diff --git a/src/views/login1.vue b/src/views/login1.vue index 9fbf27c1..1b1bebd0 100644 --- a/src/views/login1.vue +++ b/src/views/login1.vue @@ -175,7 +175,8 @@ export default { verificationCode: '', uuid: '', loginType: '', - mobileCodeType: 'login' + phoneUuid: '', + mobileCodeType: 'LOGIN' }, passwordLoginRules: { username: [{ required: true, trigger: 'blur', message: '请输入您的账号' }], @@ -305,16 +306,21 @@ export default { sendAdminCode() { this.loginForm.mobile = this.loginForm.username this.$store.dispatch('GetPhoneCode', this.loginForm) - .then(() => { - this.isSendingCode = true - this.countdown = 60 - const timer = setInterval(() => { - this.countdown -= 1 - if (this.countdown <= 0) { - clearInterval(timer) - this.isSendingCode = false - } - }, 1000) + .then(res => { + console.log(res) + if (res.code === 200) { + this.loginForm.phoneUuid = res.data + this.$message.success('验证码发送成功') + this.isSendingCode = true + this.countdown = 60 + const timer = setInterval(() => { + this.countdown -= 1 + if (this.countdown <= 0) { + clearInterval(timer) + this.isSendingCode = false + } + }, 1000) + } }) .catch(() => { this.loading = false diff --git a/src/views/register1.vue b/src/views/register1.vue index 8e647668..ee96dbee 100644 --- a/src/views/register1.vue +++ b/src/views/register1.vue @@ -144,7 +144,7 @@ export default { nickName: '', code: '', uuid: '', - mobileCodeType: 'register' + mobileCodeType: 'REGISTER' }, registerRules: { nickName: [