CzRger 1 year ago
parent
commit
e23ba56442
3 changed files with 55 additions and 0 deletions
  1. 5 0
      src/api/modules/dict.ts
  2. 12 0
      src/store/modules/dictionary-define.ts
  3. 38 0
      src/store/modules/dictionary.ts

+ 5 - 0
src/api/modules/dict.ts

@@ -29,3 +29,8 @@ export const delDictData = (id: any) => handle({
   url: `/${suffix}/dict/data/${id}`,
   method: 'delete',
 })
+//  字典管理 > 获取字典翻译
+export const dictDataType = (type: any) => handle({
+  url: `/${suffix}/dict/data/type/${type}`,
+  method: 'get',
+})

+ 12 - 0
src/store/modules/dictionary-define.ts

@@ -0,0 +1,12 @@
+export const dictionaryDefine = {
+	//接口参数 : [ '字典数据下拉', '字典数据直接翻译', '字典数据翻译对象' ],
+	login_status: ['loginStatusList', 'loginStatusMap', 'loginStatusObjMap'], //	登录日志-登录状态
+}
+
+const stateMap = {}
+Object.keys(dictionaryDefine).map(i => {
+	stateMap[dictionaryDefine[i][0]] = []
+	stateMap[dictionaryDefine[i][1]] = new Map()
+	stateMap[dictionaryDefine[i][2]] = new Map()
+})
+export const dictionary = stateMap

+ 38 - 0
src/store/modules/dictionary.ts

@@ -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) {