Fix Bug #477: 住院医生工作站-住院检查申请详情弹窗中"发往科室"字段显示为短横线(-),未正常获取数据

修复 examineApplication.vue 中 recursionFun 函数的空指针异常:
1. 增加 orgOptions.value 数组有效性校验,防止接口未返回数据时崩溃
2. 增加 obj.children 的 Array.isArray 检查,原代码直接访问 children.length 在 children 为 undefined 时抛 TypeError
3. 匹配成功后增加 break 提前退出循环
4. handleViewDetail 增加 targetDepartment 存在性检查,递归查找失败时回退显示原始 ID 值
This commit is contained in:
关羽
2026-05-10 23:56:09 +08:00
committed by 赵云
parent 7790a64eab
commit 6725cef643

View File

@@ -457,19 +457,26 @@ const getLocationInfo = () => {
}; };
const recursionFun = (targetDepartment) => { const recursionFun = (targetDepartment) => {
if (!targetDepartment) return '';
if (!Array.isArray(orgOptions.value) || orgOptions.value.length === 0) return '';
let name = ''; let name = '';
for (let index = 0; index < orgOptions.value.length; index++) { for (let index = 0; index < orgOptions.value.length; index++) {
const obj = orgOptions.value[index]; const obj = orgOptions.value[index];
if (obj.id == targetDepartment) { if (obj.id == targetDepartment) {
name = obj.name; name = obj.name;
break;
} }
const subObjArray = obj['children']; const subObjArray = obj['children'];
for (let index = 0; index < subObjArray.length; index++) { if (Array.isArray(subObjArray)) {
const item = subObjArray[index]; for (let i = 0; i < subObjArray.length; i++) {
if (item.id == targetDepartment) { const item = subObjArray[i];
name = item.name; if (item.id == targetDepartment) {
name = item.name;
break;
}
} }
} }
if (name) break;
} }
return name; return name;
}; };
@@ -482,7 +489,10 @@ const handleViewDetail = (row) => {
if (row.descJson) { if (row.descJson) {
try { try {
const obj = JSON.parse(row.descJson); const obj = JSON.parse(row.descJson);
obj.targetDepartment = recursionFun(obj.targetDepartment); if (obj.targetDepartment) {
const deptName = recursionFun(obj.targetDepartment);
obj.targetDepartment = deptName || obj.targetDepartment;
}
descJsonData.value = obj; descJsonData.value = obj;
} catch (e) { } catch (e) {
console.error('解析 descJson 失败:', e); console.error('解析 descJson 失败:', e);