|
|
|
|
@ -9,6 +9,7 @@ import { getSimpleDictDataList } from '@/api/system/dict/dict.data'
|
|
|
|
|
export interface DictValueType {
|
|
|
|
|
value: any
|
|
|
|
|
label: string
|
|
|
|
|
labelEn?: string
|
|
|
|
|
clorType?: string
|
|
|
|
|
cssClass?: string
|
|
|
|
|
}
|
|
|
|
|
@ -42,33 +43,41 @@ export const useDictStore = defineStore('dict', {
|
|
|
|
|
async setDictMap() {
|
|
|
|
|
const dictMap = wsCache.get(CACHE_KEY.DICT_CACHE)
|
|
|
|
|
if (dictMap) {
|
|
|
|
|
this.dictMap = dictMap
|
|
|
|
|
this.isSetDict = true
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
const res = await getSimpleDictDataList()
|
|
|
|
|
const dictDataMap = new Map<string, any>()
|
|
|
|
|
res.forEach((dictData: DictDataVO) => {
|
|
|
|
|
const enumValueObj = dictDataMap[dictData.dictType]
|
|
|
|
|
if (!enumValueObj) {
|
|
|
|
|
dictDataMap[dictData.dictType] = []
|
|
|
|
|
}
|
|
|
|
|
dictDataMap[dictData.dictType].push({
|
|
|
|
|
value: dictData.value,
|
|
|
|
|
label: dictData.label,
|
|
|
|
|
colorType: dictData.colorType,
|
|
|
|
|
cssClass: dictData.cssClass
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
this.dictMap = dictDataMap
|
|
|
|
|
wsCache.set(CACHE_KEY.DICT_CACHE, dictDataMap, { exp: 60 })
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('加载数据字典失败', error)
|
|
|
|
|
this.dictMap = new Map<string, any>()
|
|
|
|
|
} finally {
|
|
|
|
|
const dictTypes = Object.keys(dictMap || {})
|
|
|
|
|
const firstDictType = dictTypes[0]
|
|
|
|
|
const firstList = firstDictType ? dictMap[firstDictType] : undefined
|
|
|
|
|
const needsUpgrade =
|
|
|
|
|
Array.isArray(firstList) && firstList.length > 0 && !('labelEn' in (firstList[0] || {}))
|
|
|
|
|
if (!needsUpgrade) {
|
|
|
|
|
this.dictMap = dictMap
|
|
|
|
|
this.isSetDict = true
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
const res = await getSimpleDictDataList()
|
|
|
|
|
const dictDataMap = new Map<string, any>()
|
|
|
|
|
res.forEach((dictData: DictDataVO) => {
|
|
|
|
|
const enumValueObj = dictDataMap[dictData.dictType]
|
|
|
|
|
if (!enumValueObj) {
|
|
|
|
|
dictDataMap[dictData.dictType] = []
|
|
|
|
|
}
|
|
|
|
|
dictDataMap[dictData.dictType].push({
|
|
|
|
|
value: dictData.value,
|
|
|
|
|
label: dictData.label,
|
|
|
|
|
labelEn: (dictData as any).labelEn,
|
|
|
|
|
colorType: dictData.colorType,
|
|
|
|
|
cssClass: dictData.cssClass
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
this.dictMap = dictDataMap
|
|
|
|
|
wsCache.set(CACHE_KEY.DICT_CACHE, dictDataMap, { exp: 60 })
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('加载数据字典失败', error)
|
|
|
|
|
this.dictMap = new Map<string, any>()
|
|
|
|
|
} finally {
|
|
|
|
|
this.isSetDict = true
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
getDictByType(type: string) {
|
|
|
|
|
if (!this.isSetDict) {
|
|
|
|
|
@ -89,6 +98,7 @@ export const useDictStore = defineStore('dict', {
|
|
|
|
|
dictDataMap[dictData.dictType].push({
|
|
|
|
|
value: dictData.value,
|
|
|
|
|
label: dictData.label,
|
|
|
|
|
labelEn: (dictData as any).labelEn,
|
|
|
|
|
colorType: dictData.colorType,
|
|
|
|
|
cssClass: dictData.cssClass
|
|
|
|
|
})
|
|
|
|
|
|