"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
|