保留工艺模型上传扩展数据
This commit is contained in:
@@ -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 ?? "";
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// 数据库存储的数据
|
||||
interface OperationTreeDB {
|
||||
OperationTree: string; // JSON字符串,格式化之后是 OperationTree[] 列表
|
||||
ModelProcess?: string; // JSON字符串,格式化之后是 ModelProcess[] 列表
|
||||
ProcesslLabelList?: string; // JSON字符串,格式化之后是 ProcesslLabelList[] 列表
|
||||
}
|
||||
|
||||
// 工艺数据机构
|
||||
|
||||
Reference in New Issue
Block a user