Browse Source

部门字典

CzRger 1 year ago
parent
commit
9c5eec6beb
3 changed files with 60 additions and 0 deletions
  1. 8 0
      src/api/modules/dept.ts
  2. 2 0
      src/store/index.ts
  3. 50 0
      src/store/modules/dictionary.ts

+ 8 - 0
src/api/modules/dept.ts

@@ -0,0 +1,8 @@
+import { handle } from '../index'
+
+const suffix = 'api'
+
+export const getDeptList = () => handle({
+  url: `/${suffix}/dept/list`,
+  method: 'get',
+})

+ 2 - 0
src/store/index.ts

@@ -2,6 +2,7 @@ import { createStore } from "vuex";
 // @ts-ignore
 import app from "./modules/app";
 import menu from "./modules/menu";
+import dictionary from "./modules/dictionary";
 
 export default createStore({
   state: <any>{},
@@ -10,5 +11,6 @@ export default createStore({
   modules: {
     app,
     menu,
+    dictionary,
   },
 });

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

@@ -0,0 +1,50 @@
+import {getDeptList} from "@/api/modules/dept";
+
+const state = {
+  deptList: [],
+  deptMap: new Map()
+}
+
+const getters = {
+}
+
+const mutations = {
+  SET_DEPT (state: any, data: Array<any>) {
+    const list: any = []
+    const map = new Map()
+    data.forEach(v => {
+      v.dictLabel = v.organizationName
+      v.dictValue = v.id
+      list.push(v)
+    })
+    state.deptList = list
+    state.deptMap = map
+  },
+}
+
+const actions = {
+  LOAD_DEPT ({ commit }: any, refresh = false) {
+    return new Promise((resolve, reject) => {
+      if (refresh || state.deptList?.length === 0) {
+        getDeptList().then((res) => {
+          if (res.code === 200) {
+            commit('SET_DEPT', res.data)
+            resolve(res.data)
+          } else {
+            reject(res.message)
+          }
+        })
+      } else {
+        resolve(state.deptList)
+      }
+    })
+  },
+}
+
+export default {
+  namespaced: true,
+  state,
+  getters,
+  mutations,
+  actions
+}