mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-11-07 02:57:13 +08:00
新增:新增公共查询枚举字典 API,优化前端获取枚举数据的方式
This commit is contained in:
27
continew-admin-ui/src/utils/dict.ts
Normal file
27
continew-admin-ui/src/utils/dict.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { ref, toRefs } from 'vue';
|
||||
import { listEnumDict } from '@/api/common';
|
||||
import { useDictStore } from '@/store';
|
||||
|
||||
/**
|
||||
* 获取字典数据
|
||||
*
|
||||
* @param names 字典名列表
|
||||
*/
|
||||
export default function useDict(...names: Array<string>) {
|
||||
const res = ref<any>({});
|
||||
return (() => {
|
||||
names.forEach((name: string) => {
|
||||
res.value[name] = [];
|
||||
const dict = useDictStore().getDict(name);
|
||||
if (dict) {
|
||||
res.value[name] = dict;
|
||||
} else {
|
||||
listEnumDict(name).then((resp) => {
|
||||
res.value[name] = resp.data;
|
||||
useDictStore().setDict(name, res.value[name]);
|
||||
});
|
||||
}
|
||||
});
|
||||
return toRefs(res.value);
|
||||
})();
|
||||
}
|
||||
Reference in New Issue
Block a user