init
This commit is contained in:
29
src/hooks/dict.ts
Normal file
29
src/hooks/dict.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { dict } from '/@/stores/dict';
|
||||
import { getDicts } from '/@/api/admin/dict';
|
||||
import { ref, toRefs } from 'vue';
|
||||
|
||||
/**
|
||||
* 获取字典数据
|
||||
*/
|
||||
export function useDict(...args: any): any {
|
||||
const res = ref({});
|
||||
return (() => {
|
||||
args.forEach((dictType: String) => {
|
||||
// @ts-ignore
|
||||
res.value[dictType] = [];
|
||||
const dicts = dict().getDict(dictType);
|
||||
if (dicts) {
|
||||
// @ts-ignore
|
||||
res.value[dictType] = dicts;
|
||||
} else {
|
||||
getDicts(dictType).then((resp) => {
|
||||
// @ts-ignore
|
||||
res.value[dictType] = resp.data.map((p: any) => ({ label: p.label, value: p.value, elTagType: p.listClass, elTagClass: p.cssClass }));
|
||||
// @ts-ignore
|
||||
dict().setDict(dictType, res.value[dictType]);
|
||||
});
|
||||
}
|
||||
});
|
||||
return toRefs(res.value);
|
||||
})();
|
||||
}
|
||||
Reference in New Issue
Block a user