用户登录问题修改
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'
|
||||
|
||||
// 更严格的手机号和邮箱正则表达式
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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:关闭)
|
||||
}
|
||||
|
||||
// 配置设置
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ export default {
|
|||
nickName: '',
|
||||
code: '',
|
||||
uuid: '',
|
||||
mobileCodeType: 'register'
|
||||
mobileCodeType: 'REGISTER'
|
||||
},
|
||||
registerRules: {
|
||||
nickName: [
|
||||
|
|
|
|||
Loading…
Reference in New Issue