From daf9f5147b0e413a73e940d6b285e44de44553d7 Mon Sep 17 00:00:00 2001 From: 2910410219 <2910410219@qq.com> Date: Thu, 20 Aug 2026 17:31:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E7=AE=A1=E7=90=86v2=EF=BC=9A?= =?UTF-8?q?schema=20=E4=BF=9D=E5=AD=98=E6=97=B6=E7=BB=9F=E4=B8=80=E5=B0=86?= =?UTF-8?q?=E6=A0=87=E9=87=8F=E5=AD=97=E6=AE=B5=20value=20=E7=BD=AE?= =?UTF-8?q?=E7=A9=BA=EF=BC=8C=E6=95=B0=E6=8D=AE=E5=80=BC=E4=B8=8D=E5=9C=A8?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E4=B8=AD=E9=A2=84=E8=AE=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude --- .../modelConfigV2/component/editModule.vue | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/views/settings/modelConfigV2/component/editModule.vue b/src/views/settings/modelConfigV2/component/editModule.vue index 7405600..0448955 100644 --- a/src/views/settings/modelConfigV2/component/editModule.vue +++ b/src/views/settings/modelConfigV2/component/editModule.vue @@ -602,8 +602,53 @@ const openMappingEditor = (key: string) => { jsonEditorVisible.value = true; }; +/** 递归将 schema 中所有标量字段的 value 重置为 null。 + * 模型配置保存的是「结构模板」:保留 value 键与结构、defaultValue 等配置,但数据值不预设。 + * defaultValue 已有专门字段承载默认值,value 不再携带任何值,统一置 null。 + * 根节点经 nodeToValue 输出时不带 type/attrs 包装(普通对象),故需对无 type 节点也递归子键。 + */ +function resetSchemaValues(schema: any): any { + if (schema === null || schema === undefined) return schema; + if (Array.isArray(schema)) { + schema.forEach((item, i) => { + schema[i] = resetSchemaValues(item); + }); + return schema; + } + if (typeof schema !== 'object') return schema; + if (typeof schema.type === 'string') { + switch (schema.type) { + case 'object': + if (schema.attrs && typeof schema.attrs === 'object') { + Object.keys(schema.attrs).forEach((k) => { + schema.attrs[k] = resetSchemaValues(schema.attrs[k]); + }); + } + break; + case 'array': + if (Array.isArray(schema.attrs)) { + schema.attrs = schema.attrs.map((item: any) => resetSchemaValues(item)); + } + break; + case 'string': + case 'number': + case 'boolean': + case 'null': + schema.value = null; + break; + } + return schema; + } + // 普通对象(如根 object 或未包装节点):递归子键 + Object.keys(schema).forEach((k) => { + schema[k] = resetSchemaValues(schema[k]); + }); + return schema; +} + const confirmJsonEditor = () => { - setMappingValue(editingMappingKey.value, { ...jsonEditorData.value }); + const cleaned = resetSchemaValues(JSON.parse(JSON.stringify(jsonEditorData.value))); + setMappingValue(editingMappingKey.value, cleaned); jsonEditorVisible.value = false; };