修改公共配置字典
This commit is contained in:
@@ -2,23 +2,29 @@ import useDictStore from '@/store/modules/dict'
|
||||
import { getDicts } from '@/api/system/dict/data'
|
||||
|
||||
/**
|
||||
* 获取字典数据
|
||||
* 获取字典数据(优先使用登录后全量缓存,按 dictType code 匹配)
|
||||
*/
|
||||
export function useDict(...args) {
|
||||
const res = ref({})
|
||||
return (() => {
|
||||
args.forEach((dictType, index) => {
|
||||
args.forEach((dictType) => {
|
||||
res.value[dictType] = []
|
||||
const dicts = useDictStore().getDict(dictType)
|
||||
if (dicts) {
|
||||
res.value[dictType] = dicts
|
||||
} else {
|
||||
// 缓存未命中时按类型补拉(如字典管理刚改完被 removeDict)
|
||||
getDicts(dictType).then(resp => {
|
||||
res.value[dictType] = resp.data.map(p => ({ label: p.dictLabel, value: p.dictValue, elTagType: p.listClass, elTagClass: p.cssClass }))
|
||||
res.value[dictType] = (resp.data || []).map(p => ({
|
||||
label: p.dictLabel,
|
||||
value: p.dictValue,
|
||||
elTagType: p.listClass,
|
||||
elTagClass: p.cssClass
|
||||
}))
|
||||
useDictStore().setDict(dictType, res.value[dictType])
|
||||
})
|
||||
}
|
||||
})
|
||||
return toRefs(res.value)
|
||||
})()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user