diff --git a/web/src/pages/app/modules/models.ts b/web/src/pages/app/modules/models.ts index 785d80f..68cfe5b 100644 --- a/web/src/pages/app/modules/models.ts +++ b/web/src/pages/app/modules/models.ts @@ -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) }; + 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, 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(`button[data-id="${id}"]`)?.closest(".model-card"); const oldName = card?.querySelector("strong")?.textContent ?? ""; diff --git a/web/src/types/OperationTree.ts b/web/src/types/OperationTree.ts index 0bd04f9..97bde0e 100644 --- a/web/src/types/OperationTree.ts +++ b/web/src/types/OperationTree.ts @@ -1,6 +1,8 @@ // 数据库存储的数据 interface OperationTreeDB { OperationTree: string; // JSON字符串,格式化之后是 OperationTree[] 列表 + ModelProcess?: string; // JSON字符串,格式化之后是 ModelProcess[] 列表 + ProcesslLabelList?: string; // JSON字符串,格式化之后是 ProcesslLabelList[] 列表 } // 工艺数据机构