WXL
2 天以前 9bce51f651aad297ef9eb6df832bfdaf1de05d84
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
import useDictStore from '../stores/dict'
import { ref, toRefs,} from "vue";
 
/**
 * 获取字典数据
 */
export async function useDict(...args) {
  const res = ref({});
  
  for (const dictType of args) {
    res.value[dictType] = [];
    const dicts = useDictStore().getDict(dictType);
    
    if (dicts) {
      res.value[dictType] = dicts;
    } else {
      try {
        const resp = await uni.$uapi.get("/system/dict/data/type/" + dictType);
        res.value[dictType] = resp.map(p => ({
          label: p.dictLabel,
          value: p.dictValue,
          elTagType: p.listClass,
          elTagClass: p.cssClass
        }));
        useDictStore().setDict(dictType, res.value[dictType]);
      } catch (error) {
        console.error(`Failed to fetch dict ${dictType}:`, error);
        // 可以根据需要处理错误,比如设置默认值或抛出错误
      }
    }
  }
  // console.log(res.value.sys_user_sex,'2');
  
  return toRefs(res.value);
}