From 1c5f3c8cdb2d7d8d169f84ebc9983cdbd241cb99 Mon Sep 17 00:00:00 2001 From: wyuu Date: Fri, 12 Dec 2025 18:02:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B8=B8=E7=94=A8=E5=8F=96=E5=80=BC=E3=80=81?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E4=BB=AA=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/lisData/dictData.ts | 34 +++++++------------ .../labItem/tab/commonDescriptions.vue | 27 +++++++++------ src/views/liswork/labItem/tab/useInstr.vue | 8 ++--- 3 files changed, 32 insertions(+), 37 deletions(-) diff --git a/src/hooks/lisData/dictData.ts b/src/hooks/lisData/dictData.ts index 738b9d3..3363b42 100644 --- a/src/hooks/lisData/dictData.ts +++ b/src/hooks/lisData/dictData.ts @@ -5,39 +5,29 @@ import { getGroupInstrdList } from '@/api/liswork/work/LisWork'; import { comDict } from '@/utils/dict' const dictData = ref({}); -export const instrOptions = ref<{ yq: string; yqmc: string }[]>([]); +const instrOptions = ref<{ yq: string; yqmc: string }[]>([]); -// 2. 定义并导出加载数据的函数 -export const getYqData = () => { +export const getYqData = (data?: any) => { // 避免重复请求 - if (instrOptions.value.length > 0) return Promise.resolve(instrOptions.value); - return getGroupInstrdList().then((res: any) => { - if (res.code === 0) { + 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 })); } - return instrOptions.value; }) - .catch(() => { - return []; - }); }; //'XMGL','ITEMCLASS', 'YQDL' export const getDictData = async (...args: string[]) => { const dictRefs = await comDict(...args); - 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) || [] //国标代码 + // 遍历传入的字典类型参数,动态处理赋值 + args.forEach(key => { + if (dictRefs[key] !== undefined) { + dictData.value[key] = toRaw(dictRefs[key].value) || []; + } + }); } //字典数据格式化方法 @@ -51,4 +41,4 @@ export const formatInstr = (v: string) => { return instrOptions.value.find((item: any) => item.yq == v.trim())?.yqmc; } -export { dictData } \ No newline at end of file +export { dictData, instrOptions } \ No newline at end of file diff --git a/src/views/liswork/labItem/tab/commonDescriptions.vue b/src/views/liswork/labItem/tab/commonDescriptions.vue index 832284d..d2ed391 100644 --- a/src/views/liswork/labItem/tab/commonDescriptions.vue +++ b/src/views/liswork/labItem/tab/commonDescriptions.vue @@ -18,12 +18,15 @@ diff --git a/src/views/liswork/labItem/tab/useInstr.vue b/src/views/liswork/labItem/tab/useInstr.vue index 0a842bd..0f57463 100644 --- a/src/views/liswork/labItem/tab/useInstr.vue +++ b/src/views/liswork/labItem/tab/useInstr.vue @@ -37,7 +37,7 @@ import { XmInfoVs } from '@/types'; import SelectTable from '@/components/SelectTable/index.vue' import { ElMessage, ElMessageBox } from 'element-plus' import { deleteXmInfoVs } from '@/api/liswork/labItem/labItemApi'; -import { instrOptions, getYqData } from '@/hooks' +import { getYqData, instrOptions } from '@/hooks' const modelParam = defineModel() const tableRef = ref(); @@ -112,8 +112,8 @@ const getDyckz = (row: XmInfoVs) => { return `${row.ckxx || ''}--${row.cksx || ''}`; } } -onMounted(async () => { - await getYqData(); - console.log('==>', instrOptions); + +onMounted(() => { + getYqData(); }); \ No newline at end of file