From 03b6180a029eda97cdc22654b6da232a17912b49 Mon Sep 17 00:00:00 2001 From: roymondchen Date: Mon, 29 Dec 2025 19:22:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(editor):=20=E6=95=B0=E6=8D=AE=E6=BA=90?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E7=BC=96=E8=BE=91=E5=90=8Econtent=E5=8F=98?= =?UTF-8?q?=E6=88=90=E5=AD=97=E7=AC=A6=E4=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../editor/src/components/CodeBlockEditor.vue | 31 ++++++++++++++++++- .../editor/src/fields/DataSourceMethods.vue | 8 ----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/packages/editor/src/components/CodeBlockEditor.vue b/packages/editor/src/components/CodeBlockEditor.vue index 884d1523..5c63a6a5 100644 --- a/packages/editor/src/components/CodeBlockEditor.vue +++ b/packages/editor/src/components/CodeBlockEditor.vue @@ -217,9 +217,38 @@ const functionConfig = computed(() => [ }, ]); +const parseContent = (content: any) => { + if (typeof content === 'string') { + // 如果是字符串则转换为函数 + const parseDSL = getEditorConfig('parseDSL'); + return parseDSL<(..._args: any[]) => any>(content); + } + return content; +}; + const submitForm = (values: CodeBlockContent, data: ContainerChangeEventData) => { changedValue.value = undefined; - emit('submit', values, data); + + emit( + 'submit', + { + ...values, + content: parseContent(values.content), + }, + { + ...data, + changeRecords: data.changeRecords?.map((record) => { + let { value } = record; + if (record.propPath === 'content' && typeof value === 'string') { + value = parseContent(value); + } + return { + ...record, + value, + }; + }), + }, + ); }; const errorHandler = (error: any) => { diff --git a/packages/editor/src/fields/DataSourceMethods.vue b/packages/editor/src/fields/DataSourceMethods.vue index 44abf600..902c7f88 100644 --- a/packages/editor/src/fields/DataSourceMethods.vue +++ b/packages/editor/src/fields/DataSourceMethods.vue @@ -31,7 +31,6 @@ import { type ColumnConfig, MagicTable } from '@tmagic/table'; import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue'; import type { CodeParamStatement } from '@editor/type'; -import { getEditorConfig } from '@editor/utils/config'; defineOptions({ name: 'MFieldsDataSourceMethods', @@ -119,13 +118,6 @@ const createCodeHandler = () => { }; const submitCodeHandler = (value: CodeBlockContent, data: ContainerChangeEventData) => { - if (value.content) { - // 在保存的时候转换代码内容 - const parseDSL = getEditorConfig('parseDSL'); - if (typeof value.content === 'string') { - value.content = parseDSL<(..._args: any[]) => any>(value.content); - } - } if (editIndex > -1) { emit('change', value, { modifyKey: editIndex,