沈丘营商办后台前端项目
王恒
5 天以前 cd95b584fe7da1ea63476871eabf512213a31e69
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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 function useDictPer(...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.dictCode, 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;
//   },
// };