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

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 ?? "";

View File

@@ -1,6 +1,8 @@
// 数据库存储的数据
interface OperationTreeDB {
OperationTree: string; // JSON字符串格式化之后是 OperationTree[] 列表
ModelProcess?: string; // JSON字符串格式化之后是 ModelProcess[] 列表
ProcesslLabelList?: string; // JSON字符串格式化之后是 ProcesslLabelList[] 列表
}
// 工艺数据机构