mirror of
https://github.com/continew-org/continew-admin-ui.git
synced 2025-09-09 08:57:14 +08:00
24 lines
611 B
TypeScript
24 lines
611 B
TypeScript
import { ref, toRefs } from 'vue'
|
|
import { listCommonDict } from '@/apis'
|
|
import { useDictStore } from '@/stores'
|
|
|
|
export function useDict(...codes: Array<string>) {
|
|
const res = ref<any>({})
|
|
return (() => {
|
|
const dictStore = useDictStore()
|
|
codes.forEach((code) => {
|
|
res.value[code] = []
|
|
const dict = dictStore.getDict(code)
|
|
if (dict) {
|
|
res.value[code] = dict
|
|
} else {
|
|
listCommonDict(code).then((resp) => {
|
|
res.value[code] = resp.data
|
|
dictStore.setDict(code, res.value[code])
|
|
})
|
|
}
|
|
})
|
|
return toRefs(res.value)
|
|
})()
|
|
}
|