40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
|
|
//仪器,字典数据自动格式化类
|
||
|
|
import { DictData } from '@/types/index';
|
||
|
|
import { getGroupInstrdList } from '@/api/liswork/work/LisWork';
|
||
|
|
//@ts-ignore
|
||
|
|
import { comDict } from '@/utils/dict'
|
||
|
|
|
||
|
|
const dictData = ref<DictData>({});
|
||
|
|
const instrOptions = ref<{ yq: string; yqmc: string }[]>([])
|
||
|
|
|
||
|
|
export const getYqData = () => {
|
||
|
|
getGroupInstrdList()
|
||
|
|
.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);
|
||
|
|
// 从 ref 中获取实际数据
|
||
|
|
dictData.value = {
|
||
|
|
XMGL: toRaw(dictRefs.XMGL.value) || [],
|
||
|
|
ITEMCLASS: toRaw(dictRefs.ITEMCLASS.value) || [],
|
||
|
|
YQDL: toRaw(dictRefs.YQDL.value) || []
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
// 格式化字典数据方法
|
||
|
|
export const formatDict = async (v: string, dictType: string) => {
|
||
|
|
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;
|
||
|
|
}
|