import * as types from '../types' import { getStore, setStore } from '@config/utils.js' const state = { accountId: getStore('accountId') || '', accountName: getStore('accountName') || '', userName: getStore('userName') || '', deptName: getStore('deptName') || '', deviceUuid: getStore('deviceUuid') || '', deviceCode: getStore('deviceCode') || '' } const getters = { accountId: state => state.accountId, accountName: state => state.accountName, userName: state => state.userName, deptName: state => state.deptName, deviceUuid: state => state.deviceUuid, deviceCode: state => state.deviceCode } const actions = { setUserInfo ({ commit }, res) { setStore('accountId', res.account_id) setStore('accountName', res.account_name) setStore('userName', res.user_name) setStore('deptName', res.dept_name) commit(types.SET_USER_INFO, res) }, setSignOut ({ commit }) { localStorage.removeItem('accountId') localStorage.removeItem('accountName') localStorage.removeItem('userName') localStorage.removeItem('deptName') commit(types.SET_SIGN_OUT) }, setDevice ({commit}, res) { setStore('deviceUuid', res.deviceUuid) setStore('deviceCode', res.deviceCode) commit(types.SET_DEVICE, res) } } const mutations = { [types.SET_USER_INFO] (state, res) { state.accountId = res.account_id state.accountName = res.account_name state.userName = res.user_name state.deptName = res.dept_name }, [types.SET_SIGN_OUT] (state) { state.accountId = '' state.accountName = '' state.userName = '' state.deptName = '' }, [types.SET_DEVICE] (state, res) { state.deviceUuid = res.deviceUuid state.deviceCode = res.deviceCode } } export default { state, getters, actions, mutations }