From 2c32758e3478fe037a20a58a9b8fe062a18aec34 Mon Sep 17 00:00:00 2001 From: yunyingk Date: Thu, 15 Oct 2026 11:02:57 +0800 Subject: [PATCH] fix(datalink): compact reference and card object flattening in normalizeDatalinkRecord --- src/domains/datalink/services.ts | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/domains/datalink/services.ts b/src/domains/datalink/services.ts index 1f061d3..5b387af 100644 --- a/src/domains/datalink/services.ts +++ b/src/domains/datalink/services.ts @@ -275,15 +275,30 @@ export function normalizeDatalinkRecord( const obj = val as Record; if ("standard" in obj) { val = obj.standard; - } else if ("name" in obj && typeof obj.name === "string") { + } else if ("name" in obj && typeof obj.name === "string" && obj.name) { val = obj.name; } else if ("dataLink" in obj && typeof obj.dataLink === "object" && obj.dataLink) { const nested = obj.dataLink as Record; - const subEntityId = String(obj.entityId || ""); - const subBareId = subEntityId.startsWith("$") ? subEntityId.slice(1) : subEntityId; - const subName = nested.name ?? nested["名称"] ?? nested[`E_${subBareId}_name`]; - const subCode = nested.code ?? nested["编码"] ?? nested[`E_${subBareId}_code`]; - val = subName || subCode || obj.id || val; + const form = (nested.form && typeof nested.form === "object" ? nested.form : {}) as Record; + const combined = { ...nested, ...form }; + let subDisplay: string | undefined = undefined; + for (const [k, v] of Object.entries(combined)) { + if (typeof v === "string" && v.trim() && (k === "name" || k === "title" || k === "名称" || k === "标题" || k.endsWith("_name") || k.endsWith("_title"))) { + subDisplay = v; + break; + } + } + if (!subDisplay) { + for (const [k, v] of Object.entries(combined)) { + if (typeof v === "string" && v.trim() && (k === "code" || k === "编码" || k.endsWith("_code"))) { + subDisplay = v; + break; + } + } + } + val = subDisplay || (obj.id ? String(obj.id) : undefined); + } else if (obj.id && typeof obj.id === "string") { + val = obj.id; } } fields[field.label || field.name] = val;