auth.js
1.78 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
import { utils } from 'glsx-common'
import { constants } from '@/common'
import { This } from '@/main'
import api from '@/api'
const auth = {
namespaced: true,
state: () => ({
session: null,
tracker: null
}),
mutations: {
SET_SESSION(state, session) {
state.session = session
},
async LOGOUT(state) {
await api.app.logout({ sessionId: state.session.token })
},
CLEAR(state) {
state.session = null
}
},
actions: {
setSession({ commit, dispatch }, session) {
commit('SET_SESSION', session)
dispatch('saveSession', session)
},
/* eslint-disable */
saveSession({ commit }, session) {
utils.storage.setSession(constants.SCRM_BASE_SESSION, session)
},
async logout({ commit }) {
await commit('LOGOUT')
},
/* eslint-disable */
async permission({ dispatch }, merchant) {
const { response, productCode } = This('$config')
/* eslint-disable */
const { sessionId, permissionMerchantIds, channelType, entmicroId, workUserId, uuid, loginList, ...merchantItems } = merchant
let { code, message, data, menus, sessionData } = await api.app.permission({ productCode, sessionId })
if (code == response.code_success_value) {
menus = data[0]?.products[0]?.merchantProTreeResponses
if (menus?.length) {
data[0].active = true
sessionData = { ...merchantItems, loginList: data, token: sessionId }
// dispatch('setSession', { ...merchantItems, loginList: data, token: sessionId })
} else {
;({ CODE: code, MESSAGE: message } = constants.SCRM_BASE_ERRORS.NO_PERMISSION_MENUS)
}
}
return { code, message, menus, sessionData }
},
clear({ commit }) {
commit('CLEAR')
}
}
}
export default auth