fix(json-schema-editor): 根节点输出时去除 { type, attrs } 包装

最外层根 object 不应该套 { type, attrs } 包装,
应直接输出子字段组成的原始对象。

- nodeToValue 中增加根节点判断:node === rootNode.value 时直接返回 rawValue
- 非根节点保持原有 { type, attrs/value, ...config } 格式不变
This commit is contained in:
2026-07-16 17:32:20 +08:00
parent 76be2dc85c
commit fa9ada2334
+6 -3
View File
@@ -193,6 +193,9 @@ function nodeToValue(node: JsonNodeData): any {
else if (node.type === 'boolean') rawValue = node.primitiveValue === true || node.primitiveValue === 'true';
else rawValue = String(node.primitiveValue);
// 最外层根 object 不套 { type, attrs },直接返回原始对象
if (node === rootNode.value) return rawValue;
// 容器类型(object/array)始终输出 { type, attrs, ...config }
if (node.type === 'object' || node.type === 'array') {
const result: Record<string, any> = { type: node.type, attrs: rawValue };
@@ -205,10 +208,10 @@ function nodeToValue(node: JsonNodeData): any {
// 标量类型也始终输出 { type, value, ...config }
const result: Record<string, any> = { type: node.type, value: rawValue };
if (node.config && hasAnyConfig(node)) {
Object.assign(result, node.config);
Object.assign(result, node.config);
}
return result;
}
return result;
}
function defaultFormType(jsonType: string): string {
const m: Record<string, string> = { string: 'string', number: 'number', boolean: 'switch' };