54 lines
2.3 KiB
TypeScript
Raw Normal View History

2025-10-30 18:15:17 +08:00
//仪器,字典数据自动格式化类
import { DictData } from '@/types/index';
import { getGroupInstrdList } from '@/api/liswork/work/LisWork';
//@ts-ignore
import { comDict } from '@/utils/dict'
const dictData = ref<DictData>({});
2025-12-12 15:49:03 +08:00
export const instrOptions = ref<{ yq: string; yqmc: string }[]>([]);
2025-10-30 18:15:17 +08:00
2025-12-12 15:49:03 +08:00
// 2. 定义并导出加载数据的函数
2025-10-30 18:15:17 +08:00
export const getYqData = () => {
2025-12-12 15:49:03 +08:00
// 避免重复请求
if (instrOptions.value.length > 0) return Promise.resolve(instrOptions.value);
return getGroupInstrdList().then((res: any) => {
if (res.code === 0) {
instrOptions.value = res.data.map((item: any) => ({
yq: item.yq.trim(),
yqmc: item.yqmc
}));
}
return instrOptions.value;
})
.catch(() => {
return [];
});
};
2025-10-30 18:15:17 +08:00
//'XMGL','ITEMCLASS', 'YQDL'
export const getDictData = async (...args: string[]) => {
const dictRefs = await comDict(...args);
2025-12-12 15:49:03 +08:00
if (dictRefs.XMGL != undefined) dictData.value.XMGL = toRaw(dictRefs.XMGL.value) || []
if (dictRefs.ITEMCLASS != undefined) dictData.value.ITEMCLASS = toRaw(dictRefs.ITEMCLASS.value) || []
if (dictRefs.YQDL != undefined) dictData.value.YQDL = toRaw(dictRefs.YQDL.value) || []
if (dictRefs.VA != undefined) dictData.value.VA = toRaw(dictRefs.VA.value) || []
if (dictRefs.LF != undefined) dictData.value.LF = toRaw(dictRefs.LF.value) || []
if (dictRefs.BT != undefined) dictData.value.BT = toRaw(dictRefs.BT.value) || []
if (dictRefs.SLZQ != undefined) dictData.value.SLZQ = toRaw(dictRefs.SLZQ.value) || []
if (dictRefs.UT != undefined) dictData.value.UT = toRaw(dictRefs.UT.value) || [] //单位
if (dictRefs.MD != undefined) dictData.value.MD = toRaw(dictRefs.MD.value) || [] //测试方法
if (dictRefs.ITEMCLASS != undefined) dictData.value.ITEMCLASS = toRaw(dictRefs.ITEMCLASS.value) || [] //细菌项目类别
if (dictRefs.GBDM != undefined) dictData.value.GBDM = toRaw(dictRefs.GBDM.value) || [] //国标代码
2025-10-30 18:15:17 +08:00
}
2025-10-31 15:22:51 +08:00
//字典数据格式化方法
2025-12-12 15:49:03 +08:00
export const formatDict = (v: string, dictType: string) => {
if (v == undefined) return;
2025-10-31 15:22:51 +08:00
return dictData.value[dictType]?.find((item: any) => item.value == v.trim())?.label;
2025-10-30 18:15:17 +08:00
}
//仪器格式化方法
export const formatInstr = (v: string) => {
return instrOptions.value.find((item: any) => item.yq == v.trim())?.yqmc;
2025-10-31 15:22:51 +08:00
}
2025-12-12 15:49:03 +08:00
export { dictData }