|
@@ -1,6 +1,9 @@
|
|
|
import {getDeptList} from "@/api/modules/dept";
|
|
|
+import {dictDataType} from "@/api/modules/dict";
|
|
|
+import { dictionary, dictionaryDefine } from './dictionary-define'
|
|
|
|
|
|
const state = {
|
|
|
+ ...dictionary,
|
|
|
deptList: [],
|
|
|
deptMap: new Map()
|
|
|
}
|
|
@@ -9,6 +12,21 @@ const getters = {
|
|
|
}
|
|
|
|
|
|
const mutations = {
|
|
|
+ SET_DICT_LIST(state: any, { listName, mapName, objMapName, data }: any) {
|
|
|
+ const map = new Map()
|
|
|
+ const objMap = new Map()
|
|
|
+ if (data.length > 0) {
|
|
|
+ data.forEach((v: any) => {
|
|
|
+ v.selectLabel = v.dictLabel
|
|
|
+ v.selectValue = v.dictValue
|
|
|
+ map.set(v.dictValue, v.dictLabel)
|
|
|
+ objMap.set(v.dictValue, v)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ state[listName] = data
|
|
|
+ state[mapName] = map
|
|
|
+ state[objMapName] = objMap
|
|
|
+ },
|
|
|
SET_DEPT (state: any, data: Array<any>) {
|
|
|
const list: any = []
|
|
|
const map = new Map()
|
|
@@ -23,6 +41,26 @@ const mutations = {
|
|
|
}
|
|
|
|
|
|
const actions = {
|
|
|
+ LOAD_DICT_LIST({ commit }: any, type: any) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ if (state[dictionaryDefine[type][0]].length === 0) {
|
|
|
+ dictDataType(type).then((res: any) => {
|
|
|
+ commit('SET_DICT_LIST', {
|
|
|
+ listName: dictionaryDefine[type][0],
|
|
|
+ mapName: dictionaryDefine[type][1],
|
|
|
+ objMapName: dictionaryDefine[type]?.[2],
|
|
|
+ data: res.data
|
|
|
+ })
|
|
|
+ resolve(res.data)
|
|
|
+ }).catch((e: any) => {
|
|
|
+ console.log('e: ', e);
|
|
|
+ reject('获取'+dictionaryDefine[type][0]+'字典错误')
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ resolve(state[dictionaryDefine[type][0]])
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
LOAD_DEPT ({ commit }: any, refresh = false) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
if (refresh || state.deptList?.length === 0) {
|