|
@@ -4,6 +4,7 @@ import { encrypt } from '@/utils/jsencrypt'
|
|
|
import { Message } from 'element-ui'
|
|
|
import router, { resetRouter } from '@/router'
|
|
|
import errorCode from '@/utils/errorCode'
|
|
|
+import { getCode } from '@/api/user'
|
|
|
|
|
|
const state = {
|
|
|
token: getToken(),
|
|
@@ -28,7 +29,9 @@ const state = {
|
|
|
}, {
|
|
|
'name': '管理端用户',
|
|
|
'value': 1
|
|
|
- }]
|
|
|
+ }],
|
|
|
+ // 验证码路径
|
|
|
+ verifyCode: ''
|
|
|
}
|
|
|
|
|
|
const mutations = {
|
|
@@ -49,10 +52,29 @@ const mutations = {
|
|
|
},
|
|
|
SET_ROLES: (state, roles) => {
|
|
|
state.roles = roles
|
|
|
+ },
|
|
|
+ SET_VERIFYCODE: (state, code) => {
|
|
|
+ state.verifyCode = 'data:image/gif;base64,' + code
|
|
|
}
|
|
|
}
|
|
|
|
|
|
const actions = {
|
|
|
+
|
|
|
+ /** 获取验证码 */
|
|
|
+ GetCode({ state, commit }) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ getCode(true).then(res => {
|
|
|
+ console.log(res)
|
|
|
+ const { publicKey, verifyCode } = res.data
|
|
|
+ setPubKey(publicKey)
|
|
|
+ commit('SET_VERIFYCODE', verifyCode)
|
|
|
+ resolve()
|
|
|
+ }).catch(err => {
|
|
|
+ reject(err)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
/**
|
|
|
* 用户登录
|
|
|
* @param commit
|
|
@@ -60,10 +82,9 @@ const actions = {
|
|
|
* @returns {Promise<unknown>}
|
|
|
* @constructor
|
|
|
*/
|
|
|
- Login({ commit }, userInfo) {
|
|
|
- const { userName, password, code, uid, publicKey } = userInfo
|
|
|
- setPubKey(publicKey)
|
|
|
- const pwd = encrypt(password, publicKey)
|
|
|
+ Login({ commit, state }, userInfo) {
|
|
|
+ const { userName, password, code, uid } = userInfo
|
|
|
+ const pwd = encrypt(password, state.publicKey)
|
|
|
return new Promise((resolve, reject) => {
|
|
|
login(userName, pwd, code, uid).then(response => {
|
|
|
const { token, user } = response.data
|