import useDictStore from "@/store/modules/dict";
|
import { getDicts } from "@/api/system/dict/data";
|
/**
|
* 获取字典数据
|
*/
|
export function useDict(...args: string[]) {
|
const res = ref<Dict.resDictType>({});
|
return (() => {
|
args.forEach((dictName: string, index: number) => {
|
res.value[dictName] = [] as Array<Dict.dictType>;
|
const dicts: Array<Dict.dictType> = useDictStore().getDict(dictName);
|
if (dicts) {
|
res.value[dictName] = dicts;
|
} else {
|
getDicts(dictName).then((resp) => {
|
res.value[dictName] = resp.data.map((p: any) => ({ label: p.dictLabel, value: p.dictValue, elTagType: p.listClass, elTagClass: p.cssClass }));
|
useDictStore().setDict(dictName, res.value[dictName]);
|
});
|
}
|
});
|
return toRefs(res.value);
|
})();
|
}
|
|
// export default {
|
// install(app: App<Element>) {
|
// app.config.globalProperties.$useDict = useDict;
|
// },
|
// };
|