用户登录问题修改
This commit is contained in:
parent
8bb10191ea
commit
be94bc276f
|
|
@ -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'
|
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,}$/
|
const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/
|
||||||
|
|
||||||
// 构建 payload 函数
|
// 构建 payload 函数
|
||||||
const buildPayload = ({ loginMethod, username, password, uuid, code, mobile, verificationCode }) => {
|
const buildPayload = ({ loginMethod, username, password, uuid, code, mobile, verificationCode,phoneUuid }) => {
|
||||||
let loginType = ''
|
let loginType = ''
|
||||||
if (loginMethod === 'mobile') {
|
if (loginMethod === 'mobile') {
|
||||||
loginType = phonePattern.test(mobile.trim()) ? 'PHONE_OTP' : emailPattern.test(mobile.trim()) ? 'EMAIL_OTP' : 'PHONE_OTP'
|
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,
|
verificationCode,
|
||||||
uuid,
|
uuid,
|
||||||
code,
|
code,
|
||||||
loginType
|
loginType,
|
||||||
|
phoneUuid
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
loginType = phonePattern.test(username.trim()) ? 'PHONE_PASSWORD' : emailPattern.test(username.trim()) ? 'EMAIL_PASSWORD' : 'USERNAME_PASSWORD'
|
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,
|
verificationCode,
|
||||||
uuid,
|
uuid,
|
||||||
code,
|
code,
|
||||||
loginType
|
loginType,
|
||||||
|
phoneUuid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -95,10 +97,11 @@ const user = {
|
||||||
// 获取手机验证码
|
// 获取手机验证码
|
||||||
GetPhoneCode({ commit }, userInfo) {
|
GetPhoneCode({ commit }, userInfo) {
|
||||||
const payload = {
|
const payload = {
|
||||||
mobile: userInfo.mobile.trim(),
|
username: userInfo.mobile.trim(),
|
||||||
uuid: userInfo.uuid,
|
uuid: userInfo.uuid,
|
||||||
code: userInfo.code,
|
code: userInfo.code,
|
||||||
mobileCodeType: userInfo.mobileCodeType
|
phoneUuid: userInfo.phoneUuid,
|
||||||
|
verificationCodeType: userInfo.mobileCodeType
|
||||||
}
|
}
|
||||||
return getPhoneCode(payload)
|
return getPhoneCode(payload)
|
||||||
.then(res => res)
|
.then(res => res)
|
||||||
|
|
|
||||||
|
|
@ -25,15 +25,15 @@ const AES_CONFIG = {
|
||||||
|
|
||||||
// 登录配置
|
// 登录配置
|
||||||
const LOGIN_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:关闭)
|
CODE_EMAIL_LOGIN: DATA_SETTINGS.OPEN,// 邮箱验证码登录(true:开启,false:关闭)
|
||||||
PHONE_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 = {
|
const REGISTER_CONFIG = {
|
||||||
PHONE_REGISTER: DATA_SETTINGS.OPEN, // 手机号注册(true:开启,false:关闭)
|
PHONE_REGISTER: DATA_SETTINGS.OPEN, // 手机号注册(true:开启,false:关闭)
|
||||||
EMAIL_REGISTER: DATA_SETTINGS.CLOSE // 邮箱注册(true:开启,false:关闭)
|
EMAIL_REGISTER: DATA_SETTINGS.OPEN // 邮箱注册(true:开启,false:关闭)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 配置设置
|
// 配置设置
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import { saveAs } from 'file-saver'
|
||||||
import { encryptCBC, decryptCBC } from '@/utils/aescbc'
|
import { encryptCBC, decryptCBC } from '@/utils/aescbc'
|
||||||
import { CONFIG } from '@/utils/configure'
|
import { CONFIG } from '@/utils/configure'
|
||||||
import { hashWithSM3AndSalt } from '@/utils/sm'
|
import { hashWithSM3AndSalt } from '@/utils/sm'
|
||||||
|
import data from '@/views/system/dict/data.vue'
|
||||||
|
|
||||||
//let token = localStorage.getItem("tokens");
|
//let token = localStorage.getItem("tokens");
|
||||||
|
|
||||||
|
|
@ -115,8 +116,10 @@ service.interceptors.request.use(config => {
|
||||||
|
|
||||||
// 响应拦截器
|
// 响应拦截器
|
||||||
service.interceptors.response.use(res => {
|
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))
|
res.data = JSON.parse(decryptCBC(res.data))
|
||||||
|
console.log(res.data)
|
||||||
}
|
}
|
||||||
// 未设置状态码则默认成功状态
|
// 未设置状态码则默认成功状态
|
||||||
const code = res.data.code || 200
|
const code = res.data.code || 200
|
||||||
|
|
|
||||||
|
|
@ -175,7 +175,8 @@ export default {
|
||||||
verificationCode: '',
|
verificationCode: '',
|
||||||
uuid: '',
|
uuid: '',
|
||||||
loginType: '',
|
loginType: '',
|
||||||
mobileCodeType: 'login'
|
phoneUuid: '',
|
||||||
|
mobileCodeType: 'LOGIN'
|
||||||
},
|
},
|
||||||
passwordLoginRules: {
|
passwordLoginRules: {
|
||||||
username: [{ required: true, trigger: 'blur', message: '请输入您的账号' }],
|
username: [{ required: true, trigger: 'blur', message: '请输入您的账号' }],
|
||||||
|
|
@ -305,16 +306,21 @@ export default {
|
||||||
sendAdminCode() {
|
sendAdminCode() {
|
||||||
this.loginForm.mobile = this.loginForm.username
|
this.loginForm.mobile = this.loginForm.username
|
||||||
this.$store.dispatch('GetPhoneCode', this.loginForm)
|
this.$store.dispatch('GetPhoneCode', this.loginForm)
|
||||||
.then(() => {
|
.then(res => {
|
||||||
this.isSendingCode = true
|
console.log(res)
|
||||||
this.countdown = 60
|
if (res.code === 200) {
|
||||||
const timer = setInterval(() => {
|
this.loginForm.phoneUuid = res.data
|
||||||
this.countdown -= 1
|
this.$message.success('验证码发送成功')
|
||||||
if (this.countdown <= 0) {
|
this.isSendingCode = true
|
||||||
clearInterval(timer)
|
this.countdown = 60
|
||||||
this.isSendingCode = false
|
const timer = setInterval(() => {
|
||||||
}
|
this.countdown -= 1
|
||||||
}, 1000)
|
if (this.countdown <= 0) {
|
||||||
|
clearInterval(timer)
|
||||||
|
this.isSendingCode = false
|
||||||
|
}
|
||||||
|
}, 1000)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,7 @@ export default {
|
||||||
nickName: '',
|
nickName: '',
|
||||||
code: '',
|
code: '',
|
||||||
uuid: '',
|
uuid: '',
|
||||||
mobileCodeType: 'register'
|
mobileCodeType: 'REGISTER'
|
||||||
},
|
},
|
||||||
registerRules: {
|
registerRules: {
|
||||||
nickName: [
|
nickName: [
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue