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
import { fetchSelectList } from '@/api/base/index';
import { selectTypeMapping } from '@/config';
const GET_OPTIONS_LIST = 'GET_OPTIONS_LIST';
const state = () => {
let baseState = {};
selectTypeMapping.map(typeItem => {
baseState['list' + typeItem.value] = [];
});
return baseState;
};
const initGetters = () => {
let getters = {};
selectTypeMapping.map(typeItem => {
getters['optionList' + typeItem.value] = state =>
state['list' + typeItem.value];
return {
['optionList' + typeItem.value]: state => state['list' + typeItem.value],
};
});
return getters;
};
const initActions = () => {
let actions = {};
selectTypeMapping.map(typeItem => {
actions['fetchOptionList' + typeItem.value] = ({ commit }) => {
return fetchSelectList({
params: {
type: typeItem.value,
},
}).then(res => {
const list = res.data;
if (list) {
commit(GET_OPTIONS_LIST, {
key: 'list' + typeItem.value,
list,
});
}
return list;
});
};
});
return actions;
};
const getters = initGetters();
const actions = initActions();
const mutations = {
[GET_OPTIONS_LIST](state, { key, list }) {
state[key] = list;
},
};
export default {
state,
getters,
actions,
mutations,
};