From 5b6f33912daecf1c8222bfcb44611f90fedb5ac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=B3=E7=BE=BD?= <关羽@gentronhealth.com> Date: Thu, 14 May 2026 03:21:55 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20Bug=20#477:=20=E4=BD=8F=E9=99=A2=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E7=94=B3=E8=AF=B7=E8=AF=A6=E6=83=85=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E4=B8=AD"=E5=8F=91=E5=BE=80=E7=A7=91=E5=AE=A4"=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E6=98=BE=E7=A4=BA=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:recursionFun 使用嵌套循环搜索科室树,但 API 返回扁平列表导致匹配失败。 修复:改用递归 findTreeItem 搜索(与 medicalExaminations.vue 一致),添加 API 错误处理, 并在 ID 匹配失败时回退显示原始值而非空白。 Co-Authored-By: Claude Opus 4.7 --- .../applicationShow/examineApplication.vue | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/openhis-ui-vue3/src/views/inpatientDoctor/home/components/applicationShow/examineApplication.vue b/openhis-ui-vue3/src/views/inpatientDoctor/home/components/applicationShow/examineApplication.vue index 94e1e7b70..7f5f022cf 100755 --- a/openhis-ui-vue3/src/views/inpatientDoctor/home/components/applicationShow/examineApplication.vue +++ b/openhis-ui-vue3/src/views/inpatientDoctor/home/components/applicationShow/examineApplication.vue @@ -310,32 +310,26 @@ const hasMatchedFields = computed(() => { /** 查询科室 */ const getLocationInfo = async () => { - const res = await getDepartmentList(); - orgOptions.value = res.data || []; + try { + const res = await getDepartmentList(); + orgOptions.value = Array.isArray(res.data) ? res.data : []; + } catch (e) { + console.warn('科室列表加载失败:', e.message); + orgOptions.value = []; + } }; -const recursionFun = (targetDepartment) => { - if (!targetDepartment) return ''; - let name = ''; - for (let index = 0; index < orgOptions.value.length; index++) { - const obj = orgOptions.value[index]; - if (obj.id == targetDepartment) { - name = obj.name; - break; +// 递归查找树形科室节点 +const findTreeItem = (list, id) => { + if (!list || list.length === 0) return null; + for (const item of list) { + if (item.id == id) return item; + if (item.children && item.children.length > 0) { + const found = findTreeItem(item.children, id); + if (found) return found; } - const subObjArray = obj['children']; - if (subObjArray && subObjArray.length > 0) { - for (let i = 0; i < subObjArray.length; i++) { - const item = subObjArray[i]; - if (item.id == targetDepartment) { - name = item.name; - break; - } - } - } - if (name) break; } - return name; + return null; }; const handleViewDetail = async (row) => { @@ -349,7 +343,11 @@ const handleViewDetail = async (row) => { if (row.descJson) { try { const obj = JSON.parse(row.descJson); - obj.targetDepartment = recursionFun(obj.targetDepartment); + // 将发往科室 ID 转换为名称 + if (obj.targetDepartment) { + const deptItem = findTreeItem(orgOptions.value, obj.targetDepartment); + obj.targetDepartment = deptItem ? deptItem.name : obj.targetDepartment; + } descJsonData.value = obj; } catch (e) { console.error('解析 descJson 失败:', e);