mirror of
https://github.com/continew-org/continew-admin-ui.git
synced 2025-09-09 20:57:17 +08:00
first commit
This commit is contained in:
23
src/hooks/app/useDict.ts
Normal file
23
src/hooks/app/useDict.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
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)
|
||||
})()
|
||||
}
|
Reference in New Issue
Block a user