2021-01-08 01:28:41 +08:00
|
|
|
|
import { listSimpleDictDatas } from '@/api/system/dict/data'
|
|
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
|
/**
|
|
|
|
|
* 数据字典 MAP
|
|
|
|
|
* key:数据字典大类枚举值 dictType
|
|
|
|
|
* dictValue:数据字典小类数值 {dictValue: '', dictLabel: ''} 的数组
|
|
|
|
|
*/
|
|
|
|
|
dictDatas: {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mutations = {
|
|
|
|
|
SET_DICT_DATAS: (state, dictDatas) => {
|
|
|
|
|
state.dictDatas = dictDatas
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const actions = {
|
|
|
|
|
loadDictDatas({ commit }) {
|
|
|
|
|
listSimpleDictDatas().then(response => {
|
2022-02-01 22:59:43 +08:00
|
|
|
|
// 如果未加载到数据,则直接返回
|
2022-02-02 01:27:04 +08:00
|
|
|
|
if (!response || !response.data) {
|
2022-02-01 22:59:43 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2021-01-08 01:28:41 +08:00
|
|
|
|
// 设置数据
|
|
|
|
|
const dictDataMap = {}
|
|
|
|
|
response.data.forEach(dictData => {
|
|
|
|
|
// 获得 dictType 层级
|
|
|
|
|
const enumValueObj = dictDataMap[dictData.dictType]
|
|
|
|
|
if (!enumValueObj) {
|
|
|
|
|
dictDataMap[dictData.dictType] = []
|
|
|
|
|
}
|
|
|
|
|
// 处理 dictValue 层级
|
|
|
|
|
dictDataMap[dictData.dictType].push({
|
2021-01-08 20:08:20 +08:00
|
|
|
|
value: dictData.value,
|
2022-02-16 13:27:17 +08:00
|
|
|
|
label: dictData.label,
|
|
|
|
|
colorType: dictData.colorType,
|
|
|
|
|
cssClass: dictData.cssClass,
|
2021-01-08 01:28:41 +08:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
// 存储到 Store 中
|
|
|
|
|
commit('SET_DICT_DATAS', dictDataMap)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
namespaced: true,
|
|
|
|
|
state,
|
|
|
|
|
mutations,
|
|
|
|
|
actions
|
|
|
|
|
}
|