Files
RuoYi-App/utils/dict.js

25 lines
750 B
JavaScript
Raw Permalink Normal View History

2025-06-14 15:23:34 +08:00
import useDictStore from "@/store/modules/dict"
import { getDicts } from "@/api/system/dict/data"
import { ref, toRefs } from "vue"
2025-04-24 10:28:23 +08:00
/**
* 获取字典数据
*/
export function useDict(...args) {
2025-06-14 15:23:34 +08:00
const res = ref({})
2025-04-24 10:28:23 +08:00
return (() => {
args.forEach((dictType, index) => {
2025-06-14 15:23:34 +08:00
res.value[dictType] = []
const dicts = useDictStore().getDict(dictType)
2025-04-24 10:28:23 +08:00
if (dicts) {
2025-06-14 15:23:34 +08:00
res.value[dictType] = dicts
2025-04-24 10:28:23 +08:00
} else {
getDicts(dictType).then((resp) => {
2025-06-14 15:23:34 +08:00
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])
})
2025-04-24 10:28:23 +08:00
}
2025-06-14 15:23:34 +08:00
})
return toRefs(res.value)
2025-04-24 10:28:23 +08:00
})()
}