feat(datalink): support card data.dataLink unwrapping in normalizeDatalinkRecord

This commit is contained in:
gitea committed 2026-10-15 11:05:12 +08:00
1 parent 0e2fb6a9b8
commit 0b3b022edf
1 file changed
+23 -15
+23 -15
View File
@@ -277,28 +277,36 @@ export function normalizeDatalinkRecord(
val = obj.standard;
} 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<string, unknown>;
const form = (nested.form && typeof nested.form === "object" ? nested.form : {}) as Record<string, unknown>;
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;
}
} else {
let targetDataLink: Record<string, unknown> | undefined = undefined;
if ("dataLink" in obj && typeof obj.dataLink === "object" && obj.dataLink) {
targetDataLink = obj.dataLink as Record<string, unknown>;
} else if ("data" in obj && typeof obj.data === "object" && obj.data && "dataLink" in (obj.data as Record<string, unknown>)) {
targetDataLink = (obj.data as Record<string, unknown>).dataLink as Record<string, unknown>;
}
if (!subDisplay) {
if (targetDataLink) {
const form = (targetDataLink.form && typeof targetDataLink.form === "object" ? targetDataLink.form : {}) as Record<string, unknown>;
const combined = { ...targetDataLink, ...form };
let subDisplay: string | undefined = undefined;
for (const [k, v] of Object.entries(combined)) {
if (typeof v === "string" && v.trim() && (k === "code" || k === "编码" || k.endsWith("_code"))) {
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") || k.includes("编号"))) {
subDisplay = v;
break;
}
}
}
val = subDisplay || (targetDataLink.id ? String(targetDataLink.id) : undefined) || (obj.id ? String(obj.id) : undefined);
} else if (obj.id && typeof obj.id === "string") {
val = obj.id;
}
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;