You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.5 KiB
80 lines
2.5 KiB
4 years ago
|
|
||
|
import Setting from '@/setting'
|
||
|
import util from '@/libs/util'
|
||
|
import {post,get,del,put} from '@/plugins/requests/index.js'
|
||
|
import api from '@/api'
|
||
|
import addRoutes from '@/libs/route/addRoutes'
|
||
|
|
||
|
/**
|
||
|
* 用户信息
|
||
|
* */
|
||
|
export default {
|
||
|
namespaced: true,
|
||
|
state: {
|
||
|
avatar: 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png',
|
||
|
userId: '',
|
||
|
userName: '',
|
||
|
schoolId: '',
|
||
|
roleId: '',
|
||
|
dataTime: ''
|
||
|
},
|
||
|
mutations: {
|
||
|
SET_INFO: (state, info) => {
|
||
|
if(info.avatar) state.avatar = info.userAvatars
|
||
|
state.userId = info.userId
|
||
|
state.schoolId = info.schoolId
|
||
|
state.userName = info.userName
|
||
|
state.roleId = info.roleId
|
||
|
state.dataTime = info.dataTime
|
||
|
},
|
||
|
SET_AVATAR: (state, avatar) => {
|
||
|
state.avatar = avatar
|
||
|
},
|
||
|
SET_USERNAME: (state, userName) => {
|
||
|
state.userName = userName
|
||
|
},
|
||
|
},
|
||
|
actions: {
|
||
|
login({ state,commit }, userInfo) {
|
||
|
const { account, password, source } = userInfo
|
||
|
return new Promise((resolve, reject) => {
|
||
|
get(api.logins,{
|
||
|
account,
|
||
|
password,
|
||
|
source,
|
||
|
}).then(res => {
|
||
|
if(res.status == 200){
|
||
|
let data = res.message.retvalue
|
||
|
res.message.listValue && Setting.dynamicRoute && addRoutes(res.message.listValue)
|
||
|
util.local.set(Setting.tokenKey,data.token,Setting.tokenExpires)
|
||
|
util.successMsg('登录成功')
|
||
|
commit('SET_INFO',data)
|
||
|
resolve()
|
||
|
}else{
|
||
|
util.errorMsg(res.errmessage)
|
||
|
reject(res)
|
||
|
}
|
||
|
}).catch(error => {
|
||
|
reject(error)
|
||
|
})
|
||
|
})
|
||
|
},
|
||
|
logout({ commit, state, dispatch }) {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
util.local.remove(Setting.storeKey)
|
||
|
util.local.remove(Setting.tokenKey)
|
||
|
location.reload()
|
||
|
resolve()
|
||
|
})
|
||
|
},
|
||
|
setAvatar({ state,commit },avatar) {
|
||
|
commit('SET_AVATAR',avatar)
|
||
|
},
|
||
|
setInfo({ state,commit },info) {
|
||
|
commit('SET_INFO',info)
|
||
|
},
|
||
|
setUserName({ state,commit },userName) {
|
||
|
commit('SET_USERNAME',userName)
|
||
|
},
|
||
|
}
|
||
|
}
|