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
import { deptList } from '@/api/baseData'
const getDefaultState = () => {
return {
departList: null,
departMap: {}
}
}
const state = getDefaultState()
const mutations = {
RESET_STATE: state => {
Object.assign(state, getDefaultState())
},
SET_DEPART: (state, payload) => {
state.departList = handleDepart(payload)
state.departMap = listToMap(payload)
},
}
const actions = {
getDepart({ commit }) {
deptList({}).then(res => {
if (!res) return
commit('SET_DEPART', res)
})
},
}
const getters = {
departMap(state) {
return state.departMap
},
departList(state) {
return state.departList
},
}
function handleDepart(list) {
if (!list) return
return list.map(item => {
let data = {}
data.label = item.dictValue
data.name = item.dictValue
data.id = item.id
data.value = item.id
data.data = item
return data
})
}
function listToMap(arr, mapKey = 'id') {
let map = {}
arr.forEach(item => {
map[item[mapKey]] = item
})
return map
}
export default {
namespaced: true,
state,
mutations,
actions,
getters
}