2022-07-13 10:52:37 +08:00
|
|
|
import * as types from '../types'
|
|
|
|
|
import { getStore, setStore } from '@js/mUtils.js'
|
|
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
|
accountId: getStore('accountId') || '',
|
|
|
|
|
accountName: getStore('accountName') || '',
|
|
|
|
|
userName: getStore('userName') || '',
|
2022-07-13 15:19:53 +08:00
|
|
|
deptUuid: getStore('deptUuid') || '',
|
|
|
|
|
userInfo: localStorage.getItem('userInfo') || '' // 用户信息
|
2022-07-13 10:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const getters = {
|
|
|
|
|
accountId: state => state.accountId,
|
|
|
|
|
accountName: state => state.accountName,
|
|
|
|
|
userName: state => state.userName,
|
2022-07-13 15:19:53 +08:00
|
|
|
deptUuid: state => state.deptUuid,
|
|
|
|
|
userInfo: state => state.userInfo
|
2022-07-13 10:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const actions = {
|
|
|
|
|
setUserInfo ({ commit }, res) {
|
|
|
|
|
setStore('accountId', res.account_id)
|
|
|
|
|
setStore('accountName', res.account_name)
|
|
|
|
|
setStore('userName', res.user_name)
|
|
|
|
|
setStore('deptUuid', res.dept_uuid)
|
|
|
|
|
commit(types.SET_USER_INFO, res)
|
|
|
|
|
},
|
2022-07-13 15:19:53 +08:00
|
|
|
userInfo ({ commit }, res) {
|
|
|
|
|
localStorage.setItem('userInfo', res)
|
|
|
|
|
commit(types.SET_USER_INFO, res)
|
|
|
|
|
},
|
2022-07-13 10:52:37 +08:00
|
|
|
setSignOut ({ commit }) {
|
2022-07-13 15:19:53 +08:00
|
|
|
localStorage.removeItem('userInfo')
|
2022-07-13 10:52:37 +08:00
|
|
|
commit(types.SET_SIGN_OUT)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mutations = {
|
|
|
|
|
[types.SET_USER_INFO] (state, res) {
|
|
|
|
|
state.accountId = res.account_id
|
|
|
|
|
state.accountName = res.account_name
|
|
|
|
|
state.userName = res.user_name
|
|
|
|
|
state.memberName = res.member_name
|
|
|
|
|
},
|
2022-07-13 15:19:53 +08:00
|
|
|
[types.SET_USER_INFO] (state, res) {
|
|
|
|
|
state.userInfo = res
|
|
|
|
|
},
|
2022-07-13 10:52:37 +08:00
|
|
|
[types.SET_SIGN_OUT] (state) {
|
|
|
|
|
state.accountId = ''
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
state,
|
|
|
|
|
getters,
|
|
|
|
|
actions,
|
|
|
|
|
mutations
|
|
|
|
|
}
|