From fc678c5088b084311f7c11cb2793dbe62049ca9e Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期四, 20 二月 2025 11:08:07 +0800
Subject: [PATCH] 字典改为树结构

---
 src/components/DictData/index.js |   91 +++++++++++++++++++++++----------------------
 1 files changed, 47 insertions(+), 44 deletions(-)

diff --git a/src/components/DictData/index.js b/src/components/DictData/index.js
index 7b85d4a..85292ce 100644
--- a/src/components/DictData/index.js
+++ b/src/components/DictData/index.js
@@ -2,48 +2,51 @@
 import store from '@/store'
 import DataDict from '@/utils/dict'
 import { getDicts as getDicts } from '@/api/system/dict/data'
+import { handleTree } from '@/utils/ruoyi'
 
-function searchDictByKey(dict, key) {
-  if (key == null && key == "") {
-    return null
-  }
-  try {
-    for (let i = 0; i < dict.length; i++) {
-      if (dict[i].key == key) {
-        return dict[i].value
-      }
-    }
-  } catch (e) {
-    return null
-  }
-}
-
-function install() {
-  Vue.use(DataDict, {
-    metas: {
-      '*': {
-        labelField: 'dictLabel',
-        valueField: 'dictValue',
-        request(dictMeta) {
-          const storeDict = searchDictByKey(store.getters.dict, dictMeta.type)
-          if (storeDict) {
-            return new Promise(resolve => { resolve(storeDict) })
-          } else {
-            return new Promise((resolve, reject) => {
-              getDicts(dictMeta.type).then(res => {
-                store.dispatch('dict/setDict', { key: dictMeta.type, value: res.data })
-                resolve(res.data)
-              }).catch(error => {
-                reject(error)
-              })
-            })
-          }
-        },
-      },
-    },
-  })
-}
-
-export default {
-  install,
-}
\ No newline at end of file
+ function searchDictByKey(dict, key) {
+   if (key == null && key == '') {
+     return null
+   }
+   try {
+     for (let i = 0; i < dict.length; i++) {
+       if (dict[i].key == key) {
+         return dict[i].value
+       }
+     }
+   } catch (e) {
+     return null
+   }
+ }
+ function install() {
+   Vue.use(DataDict, {
+     metas: {
+       '*': {
+         labelField: 'dictLabel',
+         valueField: 'dictValue',
+         childrenField: 'children',
+         request(dictMeta) {
+           const storeDict = searchDictByKey(store.getters.dict, dictMeta.type)
+           if (storeDict) {
+             return new Promise(resolve => {
+               resolve(storeDict)
+             })
+           } else {
+             return new Promise((resolve, reject) => {
+               getDicts(dictMeta.type).then(res => {
+                 const dictData = handleTree(res.data, 'dictCode', null, null)
+                 store.dispatch('dict/setDict', { key: dictMeta.type, value: dictData })
+                 resolve(dictData)
+               }).catch(error => {
+                 reject(error)
+               })
+             })
+           }
+         }
+       }
+     }
+   })
+ }
+ export default {
+   install
+ }

--
Gitblit v1.8.0