refactor: dict

This commit is contained in:
xingyu
2022-11-16 23:15:14 +08:00
parent 7c0c123b9a
commit 7455348a6e
39 changed files with 155 additions and 54 deletions

View File

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