From 92230c9a97dc9ce9df3313d11d26999c04bb6b26 Mon Sep 17 00:00:00 2001 From: gaoluyang <2820782392@qq.com> Date: 星期二, 15 七月 2025 13:12:48 +0800 Subject: [PATCH] 项目初始化 --- src/utils/dict.ts | 30 ++++++++++++++++++++++++++++++ 1 files changed, 30 insertions(+), 0 deletions(-) diff --git a/src/utils/dict.ts b/src/utils/dict.ts new file mode 100644 index 0000000..bd4284f --- /dev/null +++ b/src/utils/dict.ts @@ -0,0 +1,30 @@ +import useDictStore from "@/store/modules/dict"; +import { getDicts } from "@/api/system/dict/data"; +import { Ref, ref, toRefs } from "vue"; + +/** + * 鑾峰彇瀛楀吀鏁版嵁 + */ +export function useDict(...args: any[]) { + const res: Ref<any> = ref({}); + return (() => { + args.forEach((dictType, index) => { + res.value[dictType] = []; + const dicts = useDictStore().getDict(dictType); + if (dicts) { + res.value[dictType] = dicts; + } else { + getDicts(dictType).then((resp) => { + res.value[dictType] = resp.data.map((p: any) => ({ + label: p.dictLabel, + value: p.dictValue, + elTagType: p.listClass, + elTagClass: p.cssClass, + })); + useDictStore().setDict(dictType, res.value[dictType]); + }); + } + }); + return toRefs(res.value); + })(); +} -- Gitblit v1.9.3