user.js
3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { login, logout, getInfo } from '@/api/auth'
import { getToken, removeToken } from '@/utils/auth'
import { resetRouter } from '@/router'
const state = {
token: getToken(),
name: null,
key: null,
userType: null,
orderStatusDict: {}
}
const mutations = {
SET_TOKEN: (state, token) => {
state.token = token
},
SET_NAME: (state, name) => {
state.name = name
},
SET_USER_TYPE: (state, type) => {
state.userType = type
},
SET_STATUS_DICT: (state, userType) => {
console.log('userType', userType)
state.orderStatusDict = {
CREATE: {
name: '待确认',
color: '#9BE405',
dialogTitle: '订单确认',
confirmButtonText: userType === 2 ? '保 存' : '确认订单',
tableButtonTest: userType === 2 ? '编辑' : '确认订单'
},
DELIVER_GOODS: {
name: '待发货',
color: '#FFAA25',
dialogTitle: '发货确认',
confirmButtonText: '确认发货',
tableButtonTest: '确认发货'
},
RECEIVE_GOODS: {
name: userType === 2 ? '已发货' : '待收货',
color: '#4DAAF5',
dialogTitle: '收货确认',
confirmButtonText: '确认收货',
tableButtonTest: '确认收货'
},
WAITING_BILLING: {
name: '待开票',
color: '#005CF2',
dialogTitle: '录入发票号',
confirmButtonText: '确认开票',
tableButtonTest: '确认开票'
},
BILLING: {
name: userType === 2 ? '已开票' : '待收票',
color: '#3553A4',
dialogTitle: '收票确认',
confirmButtonText: '确认收票',
tableButtonTest: '确认收票'
},
RECEIPT: {
name: userType === 2 ? '待收款' : '待付款',
color: '#3553A4',
dialogTitle: '收款确认',
confirmButtonText: '确认收款',
tableButtonTest: '确认收款'
},
FINISH: {
name: '已完成',
color: '#737373'
}
}
}
}
const actions = {
async login({ commit }, userInfo) {
const response = await login(userInfo)
console.log('登录成功', response)
const { data: { key, userType } } = response
localStorage.setItem('checkSum', key)
localStorage.setItem('apiUser', userInfo?.p?.username)
commit('SET_TOKEN', key)
commit('SET_NAME', userInfo?.p?.username)
commit('SET_USER_TYPE', userType)
commit('SET_STATUS_DICT', userType)
},
async getInfo({ commit }) {
const response = await getInfo({
checkSum: localStorage.getItem('checkSum'),
apiUser: localStorage.getItem('apiUser')
})
const { data } = response
if (!data) {
throw new Error('请重新登录')
}
console.log('获取登录信息成功')
commit('SET_NAME', data.userName)
commit('SET_USER_TYPE', data.userType)
commit('SET_STATUS_DICT', data.userType)
return data
},
async logout({ commit, state }) {
await logout({ apiUser: localStorage.getItem('apiUser'), checkSum: localStorage.getItem('checkSum') })
localStorage.setItem('apiUser', null)
commit('SET_TOKEN', null)
removeToken()
resetRouter()
},
resetToken({ commit }) {
commit('SET_TOKEN', null)
commit('SET_NAME', null)
removeToken()
}
}
export default {
namespaced: true,
state,
mutations,
actions
}