//仪器,字典数据自动格式化类 import { DictData } from '@/types/index'; import { getGroupInstrdList } from '@/api/liswork/work/LisWork'; //@ts-ignore import { comDict } from '@/utils/dict' const dictData = ref({}); const instrOptions = ref<{ yq: string; yqmc: string }[]>([]); export const getYqData = (data?: any) => { // 避免重复请求 if (instrOptions.value.length > 0) return; getGroupInstrdList(data).then((res: any) => { if (res.code == 0) { instrOptions.value = res.data.map((item: any) => ({ yq: item.yq.trim(), yqmc: item.yqmc })); } }) }; //'XMGL','ITEMCLASS', 'YQDL' export const getDictData = async (...args: string[]) => { const dictRefs = await comDict(...args); // 遍历传入的字典类型参数,动态处理赋值 args.forEach(key => { if (dictRefs[key] !== undefined) { dictData.value[key] = toRaw(dictRefs[key].value) || []; } }); } //字典数据格式化方法 export const formatDict = (v: string, dictType: string) => { if (v == undefined) return; return dictData.value[dictType]?.find((item: any) => item.value == v.trim())?.label; } //仪器格式化方法 export const formatInstr = (v: string) => { return instrOptions.value.find((item: any) => item.yq == v.trim())?.yqmc; } export { dictData, instrOptions }