mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-20 05:55:07 +08:00
refactor: dict
This commit is contained in:
@ -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 秒 过期
|
||||
}
|
||||
}
|
||||
})
|
||||
|
Reference in New Issue
Block a user