fix(datalink): compact reference and card object flattening in normalizeDatalinkRecord
This commit is contained in:
1 parent
1ee26d786a
commit
2c32758e34
1 file changed
+21
-6
@@ -275,15 +275,30 @@ export function normalizeDatalinkRecord(
|
||||
const obj = val as Record<string, unknown>;
|
||||
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<string, unknown>;
|
||||
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<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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
||||
Reference in new issue
Block a user