|
@@ -1,9 +1,11 @@
|
|
import { defineStore } from 'pinia'
|
|
import { defineStore } from 'pinia'
|
|
import { store } from '../index'
|
|
import { store } from '../index'
|
|
import { DictDataVO } from '@/api/system/dict/types'
|
|
import { DictDataVO } from '@/api/system/dict/types'
|
|
|
|
+import { useCache } from '@/hooks/web/useCache'
|
|
|
|
+const { wsCache } = useCache('sessionStorage')
|
|
|
|
|
|
export interface DictValueType {
|
|
export interface DictValueType {
|
|
- value: string
|
|
|
|
|
|
+ value: any
|
|
label: string
|
|
label: string
|
|
clorType?: string
|
|
clorType?: string
|
|
cssClass?: string
|
|
cssClass?: string
|
|
@@ -13,19 +15,20 @@ export interface DictTypeType {
|
|
dictValue: DictValueType[]
|
|
dictValue: DictValueType[]
|
|
}
|
|
}
|
|
export interface DictState {
|
|
export interface DictState {
|
|
- dictMap: Recordable
|
|
|
|
|
|
+ dictMap: Map<string, any>
|
|
}
|
|
}
|
|
|
|
|
|
export const useDictStore = defineStore('dict', {
|
|
export const useDictStore = defineStore('dict', {
|
|
state: (): DictState => ({
|
|
state: (): DictState => ({
|
|
- dictMap: {}
|
|
|
|
|
|
+ dictMap: new Map<string, any>()
|
|
}),
|
|
}),
|
|
getters: {
|
|
getters: {
|
|
getDictMap(): Recordable {
|
|
getDictMap(): Recordable {
|
|
- return this.dictMap
|
|
|
|
|
|
+ const dictMap = wsCache.get('dictCache')
|
|
|
|
+ return dictMap ? dictMap : this.dictMap
|
|
},
|
|
},
|
|
getHasDictData(): boolean {
|
|
getHasDictData(): boolean {
|
|
- if (this.dictMap.length > 0) {
|
|
|
|
|
|
+ if (this.dictMap.size > 0) {
|
|
return true
|
|
return true
|
|
} else {
|
|
} else {
|
|
return false
|
|
return false
|
|
@@ -35,7 +38,7 @@ export const useDictStore = defineStore('dict', {
|
|
actions: {
|
|
actions: {
|
|
setDictMap(dictMap: Recordable) {
|
|
setDictMap(dictMap: Recordable) {
|
|
// 设置数据
|
|
// 设置数据
|
|
- const dictDataMap = {}
|
|
|
|
|
|
+ const dictDataMap = new Map<string, any>()
|
|
dictMap.forEach((dictData: DictDataVO) => {
|
|
dictMap.forEach((dictData: DictDataVO) => {
|
|
// 获得 dictType 层级
|
|
// 获得 dictType 层级
|
|
const enumValueObj = dictDataMap[dictData.dictType]
|
|
const enumValueObj = dictDataMap[dictData.dictType]
|
|
@@ -50,7 +53,8 @@ export const useDictStore = defineStore('dict', {
|
|
cssClass: dictData.cssClass
|
|
cssClass: dictData.cssClass
|
|
})
|
|
})
|
|
})
|
|
})
|
|
- this.dictMap = dictMap
|
|
|
|
|
|
+ this.dictMap = dictDataMap
|
|
|
|
+ wsCache.set('dictCache', dictDataMap, { exp: 60 }) // 60 秒 过期
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
})
|