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 18:02:04 +08:00
|
|
|
const instrOptions = ref<{ yq: string; yqmc: string }[]>([]);
|
2025-10-30 18:15:17 +08:00
|
|
|
|
2025-12-12 18:02:04 +08:00
|
|
|
export const getYqData = (data?: any) => {
|
2025-12-12 15:49:03 +08:00
|
|
|
// 避免重复请求
|
2025-12-16 17:54:51 +08:00
|
|
|
// if (instrOptions.value.length > 0) return;
|
2025-12-12 18:02:04 +08:00
|
|
|
getGroupInstrdList(data).then((res: any) => {
|
|
|
|
|
if (res.code == 0) {
|
2025-12-12 15:49:03 +08:00
|
|
|
instrOptions.value = res.data.map((item: any) => ({
|
|
|
|
|
yq: item.yq.trim(),
|
|
|
|
|
yqmc: item.yqmc
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
};
|
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 18:02:04 +08:00
|
|
|
// 遍历传入的字典类型参数,动态处理赋值
|
|
|
|
|
args.forEach(key => {
|
|
|
|
|
if (dictRefs[key] !== undefined) {
|
|
|
|
|
dictData.value[key] = toRaw(dictRefs[key].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-12-26 17:22:35 +08:00
|
|
|
return dictData.value[dictType]?.find((item: any) => item.value == v.trim())?.label || v;
|
2025-10-30 18:15:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//仪器格式化方法
|
|
|
|
|
export const formatInstr = (v: string) => {
|
2025-12-26 17:22:35 +08:00
|
|
|
return instrOptions.value.find((item: any) => item.yq == v.trim())?.yqmc || v;
|
2025-10-31 15:22:51 +08:00
|
|
|
}
|
|
|
|
|
|
2025-12-12 18:02:04 +08:00
|
|
|
export { dictData, instrOptions }
|