WXL
昨天 c80bc467a41daa6cbae4e5515a300a8ca98cfeaa
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"use strict";
const common_vendor = require("../common/vendor.js");
const utils_dict = require("./dict.js");
const dictCache = /* @__PURE__ */ new Map();
const loadingPromises = /* @__PURE__ */ new Map();
async function loadDicts(dictTypes) {
  const key = dictTypes.sort().join(",");
  if (dictCache.has(key)) {
    return dictCache.get(key);
  }
  if (loadingPromises.has(key)) {
    return loadingPromises.get(key);
  }
  const promise = (async () => {
    try {
      const result = await utils_dict.useDict(...dictTypes);
      dictCache.set(key, result);
      return result;
    } finally {
      loadingPromises.delete(key);
    }
  })();
  loadingPromises.set(key, promise);
  return promise;
}
function useDictMapper(dictTypes = []) {
  const loading = common_vendor.ref(false);
  const dictData = common_vendor.ref({});
  const init = async () => {
    if (dictTypes.length === 0)
      return;
    loading.value = true;
    try {
      dictData.value = await loadDicts(dictTypes);
    } finally {
      loading.value = false;
    }
  };
  const getDictLabel = (dictType, value) => {
    const list = dictData.value[dictType];
    if (!list || !Array.isArray(list))
      return value;
    const item = list.find((item2) => item2.value == value);
    return item ? item.label : value;
  };
  const getGenderText = (gender) => {
    return getDictLabel("sys_user_sex", gender);
  };
  const getBloodTypeText = (bloodType) => {
    return getDictLabel("sys_BloodType", bloodType);
  };
  const getAgeUnitText = (ageunit) => {
    const unitMap = {
      year: "岁",
      month: "个月",
      day: "天"
    };
    return unitMap[ageunit] || ageunit || "";
  };
  init();
  return {
    loading,
    dictData,
    // 原始字典数据(只读)
    getDictLabel,
    // 通用方法
    getGenderText,
    getBloodTypeText,
    getAgeUnitText
    // 可扩展其他映射
  };
}
exports.useDictMapper = useDictMapper;
//# sourceMappingURL=../../.sourcemap/mp-weixin/utils/useDictMapper.js.map