CMVR-BID/src/utils/dict.js

24 lines
712 B
JavaScript
Raw Normal View History

2025-08-21 14:11:58 +08:00
import useDictStore from '@/store/modules/dict'
import { getDicts } from '@/api/system/dict/data'
/**
* 获取字典数据
*/
export function useDict(...args) {
2026-07-28 16:26:07 +08:00
const res = ref({})
2025-08-21 14:11:58 +08:00
return (() => {
args.forEach((dictType, index) => {
2026-07-28 16:26:07 +08:00
res.value[dictType] = []
const dicts = useDictStore().getDict(dictType)
2025-08-21 14:11:58 +08:00
if (dicts) {
2026-07-28 16:26:07 +08:00
res.value[dictType] = dicts
2025-08-21 14:11:58 +08:00
} else {
getDicts(dictType).then(resp => {
res.value[dictType] = resp.data.map(p => ({ label: p.dictLabel, value: p.dictValue, elTagType: p.listClass, elTagClass: p.cssClass }))
2026-07-28 16:26:07 +08:00
useDictStore().setDict(dictType, res.value[dictType])
2025-08-21 14:11:58 +08:00
})
}
})
2026-07-28 16:26:07 +08:00
return toRefs(res.value)
2025-08-21 14:11:58 +08:00
})()
}