保留工艺模型上传扩展数据

This commit is contained in:
zhangshun
2026-05-29 17:56:18 +08:00
parent 0b99801b26
commit bda06279df
2 changed files with 24 additions and 3 deletions

View File

@@ -637,19 +637,38 @@ function normalizeOperationTreeInput(value?: string) {
}
if (parsed && typeof parsed === "object" && "OperationTree" in parsed) {
const operationTree = (parsed as { OperationTree: unknown }).OperationTree;
const normalized = { ...(parsed as Record<string, unknown>) };
const operationTree = normalized.OperationTree;
if (typeof operationTree === "string") {
JSON.parse(operationTree);
return JSON.stringify({ OperationTree: operationTree });
normalized.OperationTree = operationTree;
normalizeOptionalJsonListField(normalized, "ModelProcess");
normalizeOptionalJsonListField(normalized, "ProcesslLabelList");
return JSON.stringify(normalized);
}
if (Array.isArray(operationTree)) {
return JSON.stringify({ OperationTree: JSON.stringify(operationTree) });
normalized.OperationTree = JSON.stringify(operationTree);
normalizeOptionalJsonListField(normalized, "ModelProcess");
normalizeOptionalJsonListField(normalized, "ProcesslLabelList");
return JSON.stringify(normalized);
}
}
throw new Error('工艺数据格式必须是 {"OperationTree":"[...]"} 或 OperationTree[] 数组');
}
function normalizeOptionalJsonListField(target: Record<string, unknown>, field: string) {
const value = target[field];
if (value === undefined || value === null || value === "") return;
if (typeof value === "string") {
JSON.parse(value);
return;
}
if (Array.isArray(value)) {
target[field] = JSON.stringify(value);
}
}
async function editModel(id: number) {
const card = document.querySelector<HTMLButtonElement>(`button[data-id="${id}"]`)?.closest(".model-card");
const oldName = card?.querySelector("strong")?.textContent ?? "";