From a1d7e81859f554f3a53680cc35f0f49bf1f77098 Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期四, 14 五月 2026 14:37:02 +0800
Subject: [PATCH] 导入项目

---
 src/store/modules/dict.ts |  110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 110 insertions(+), 0 deletions(-)

diff --git a/src/store/modules/dict.ts b/src/store/modules/dict.ts
new file mode 100644
index 0000000..ee7f285
--- /dev/null
+++ b/src/store/modules/dict.ts
@@ -0,0 +1,110 @@
+import { defineStore } from 'pinia'
+import { store } from '../index'
+// @ts-ignore
+import { DictDataVO } from '@/api/system/dict/types'
+import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
+const { wsCache } = useCache('sessionStorage')
+import { getSimpleDictDataList } from '@/api/system/dict/dict.data'
+
+export interface DictValueType {
+  value: any
+  label: string
+  clorType?: string
+  cssClass?: string
+}
+export interface DictTypeType {
+  dictType: string
+  dictValue: DictValueType[]
+}
+export interface DictState {
+  dictMap: Map<string, any>
+  isSetDict: boolean
+}
+
+export const useDictStore = defineStore('dict', {
+  state: (): DictState => ({
+    dictMap: new Map<string, any>(),
+    isSetDict: false
+  }),
+  getters: {
+    getDictMap(): Recordable {
+      const dictMap = wsCache.get(CACHE_KEY.DICT_CACHE)
+      if (dictMap) {
+        this.dictMap = dictMap
+      }
+      return this.dictMap
+    },
+    getIsSetDict(): boolean {
+      return this.isSetDict
+    }
+  },
+  actions: {
+    async setDictMap() {
+      const dictMap = wsCache.get(CACHE_KEY.DICT_CACHE)
+      if (dictMap) {
+        this.dictMap = dictMap
+        this.isSetDict = true
+      } else {
+        const res = await getSimpleDictDataList()
+        if (!res || res.length === 0) {
+          return
+        }
+        // 璁剧疆鏁版嵁
+        const dictDataMap = new Map<string, any>()
+        res.forEach((dictData: DictDataVO) => {
+          // 鑾峰緱 dictType 灞傜骇
+          const enumValueObj = dictDataMap[dictData.dictType]
+          if (!enumValueObj) {
+            dictDataMap[dictData.dictType] = []
+          }
+          // 澶勭悊 dictValue 灞傜骇
+          dictDataMap[dictData.dictType].push({
+            value: dictData.value,
+            label: dictData.label,
+            colorType: dictData.colorType,
+            cssClass: dictData.cssClass
+          })
+        })
+        this.dictMap = dictDataMap
+        this.isSetDict = true
+        wsCache.set(CACHE_KEY.DICT_CACHE, dictDataMap, { exp: 60 }) // 60 绉� 杩囨湡
+      }
+    },
+    getDictByType(type: string) {
+      if (!this.isSetDict) {
+        this.setDictMap()
+      }
+      return this.dictMap[type]
+    },
+    async resetDict() {
+      wsCache.delete(CACHE_KEY.DICT_CACHE)
+      const res = await getSimpleDictDataList()
+      if (!res || res.length === 0) {
+        return
+      }
+      // 璁剧疆鏁版嵁
+      const dictDataMap = new Map<string, any>()
+      res.forEach((dictData: DictDataVO) => {
+        // 鑾峰緱 dictType 灞傜骇
+        const enumValueObj = dictDataMap[dictData.dictType]
+        if (!enumValueObj) {
+          dictDataMap[dictData.dictType] = []
+        }
+        // 澶勭悊 dictValue 灞傜骇
+        dictDataMap[dictData.dictType].push({
+          value: dictData.value,
+          label: dictData.label,
+          colorType: dictData.colorType,
+          cssClass: dictData.cssClass
+        })
+      })
+      this.dictMap = dictDataMap
+      this.isSetDict = true
+      wsCache.set(CACHE_KEY.DICT_CACHE, dictDataMap, { exp: 60 }) // 60 绉� 杩囨湡
+    }
+  }
+})
+
+export const useDictStoreWithOut = () => {
+  return useDictStore(store)
+}

--
Gitblit v1.8.0