|
- import {
- getInfo,
- } from '@/api/login'
- import {
- getToken,
- setToken,
- removeToken
- } from '@/utils/auth'
- const user = {
- state: {
- token: getToken(),
- name: '',
- type: '',
- orgId: '',
- },
-
- mutations: {
- SET_TOKEN: (state, token) => {
- state.token = token
- },
- SET_NAME: (state, name) => {
- state.name = name
- },
- SET_TYPE: (state, type) => {
- state.type = type
- },
- SET_ORGID: (state, orgId) => {
- state.orgId = orgId
- },
-
- },
-
- actions: {
- // 登录
- Login({
- commit
- }, userInfo) {
- setToken(userInfo.token)
- commit('SET_TOKEN', userInfo.token)
- commit('SET_NAME', userInfo.name)
- commit('SET_TYPE', userInfo.type)
- commit('SET_ORGID', userInfo.orgId)
-
- },
- // 获取用户信息
- GetInfo({
- commit,
- state
- }) {
- return new Promise((resolve, reject) => {
- getInfo().then(response => {
- const userInfo = response.result
- commit('SET_NAME', userInfo.name)
- commit('SET_TYPE', userInfo.type)
- commit('SET_ORGID', userInfo.orgId)
- resolve()
- }).catch(error => {
- reject(error)
- })
- })
- },
- }
- }
-
- export default user
|