From ef66e8a59863f9ffeb7292adcb314e5620c238ef Mon Sep 17 00:00:00 2001 From: roymondchen Date: Mon, 20 Jul 2026 19:09:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(form,editor):=20=E5=AE=8C=E5=96=84=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=E6=A0=A1=E9=AA=8C=E4=B8=8E=E6=A0=B7=E5=BC=8F=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/design/src/FormItem.vue | 11 + packages/design/src/formValidateMessage.ts | 47 +++ packages/design/src/index.ts | 1 + .../editor/src/fields/StyleSetter/Index.vue | 10 +- .../src/fields/StyleSetter/pro/Background.vue | 149 ++++++---- .../src/fields/StyleSetter/pro/Border.vue | 20 +- .../src/fields/StyleSetter/pro/Font.vue | 130 ++++---- .../src/fields/StyleSetter/pro/Layout.vue | 278 +++++++++--------- .../src/fields/StyleSetter/pro/Position.vue | 142 ++++----- .../src/fields/StyleSetter/pro/Transform.vue | 48 ++- .../src/layouts/props-panel/FormPanel.vue | 27 +- .../sidebar/layer/LayerNodeContent.vue | 21 +- packages/editor/src/utils/props.ts | 3 + packages/editor/src/utils/type-match-rules.ts | 251 +++++++++++++--- .../unit/fields/StyleSetter/Index.spec.ts | 24 +- .../unit/fields/StyleSetter/Layout.spec.ts | 13 +- .../unit/fields/StyleSetter/Position.spec.ts | 9 +- .../tests/unit/fields/StyleSetter/pro.spec.ts | 1 + .../layouts/props-panel/FormPanel.spec.ts | 1 + .../sidebar/layer/LayerNodeContent.spec.ts | 35 +++ .../tests/unit/utils/typeMatchRules.spec.ts | 89 +++--- packages/form-schema/src/base.ts | 4 + packages/form/src/Form.vue | 11 +- packages/form/src/FormBox.vue | 3 + packages/form/src/FormDialog.vue | 3 + packages/form/src/FormDrawer.vue | 3 + packages/form/src/containers/Container.vue | 6 +- packages/form/src/schema.ts | 3 +- packages/form/src/submitForm.ts | 2 + packages/form/src/utils/form.ts | 17 +- packages/form/src/utils/typeMatch.ts | 272 +++++++++++++++-- .../form/tests/unit/utils/typeMatch.spec.ts | 190 +++++++++--- 32 files changed, 1256 insertions(+), 568 deletions(-) create mode 100644 packages/design/src/formValidateMessage.ts diff --git a/packages/design/src/FormItem.vue b/packages/design/src/FormItem.vue index ce7d7b0c..5a83bf83 100644 --- a/packages/design/src/FormItem.vue +++ b/packages/design/src/FormItem.vue @@ -8,6 +8,10 @@
+ + @@ -15,6 +19,7 @@ import { computed } from 'vue'; import { getDesignConfig } from './config'; +import { stripValidateSuggestion } from './formValidateMessage'; import type { FormItemProps } from './types'; defineOptions({ @@ -33,4 +38,10 @@ const uiProps = computed(() => { const { extra, ...rest } = ui?.props(props) || props; return rest; }); + +/** + * 校验错误文案中,「修改建议」仅用于错误汇总展示。 + * form-item 行内错误只展示主错误描述,不展示修改建议。 + */ +const resolveErrorText = (error?: string) => stripValidateSuggestion(error); diff --git a/packages/design/src/formValidateMessage.ts b/packages/design/src/formValidateMessage.ts new file mode 100644 index 00000000..7c4735c2 --- /dev/null +++ b/packages/design/src/formValidateMessage.ts @@ -0,0 +1,47 @@ +/* + * Tencent is pleased to support the open source community by making TMagicEditor available. + * + * Copyright (C) 2025 Tencent. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * 校验错误文案中,「主错误描述」与「修改建议」之间的分隔符。 + * + * 约定:typeMatch 等校验器产出的文案形如 + * `主错误描述${VALIDATE_SUGGESTION_SEPARATOR}修改建议`。 + * - 行内 form-item 错误、组件树 tooltip 仅展示「主错误描述」; + * - 错误汇总(如属性面板报错弹窗)展示完整文案(含修改建议)。 + * + * 该常量为「主错误描述 / 修改建议」这一隐式协议的唯一真源, + * 所有生产/消费该文案的位置都应复用这里的常量与 helper,避免魔法字符串散落。 + */ +export const VALIDATE_SUGGESTION_SEPARATOR = '\n\n'; + +/** + * 在「主错误描述」后追加「修改建议」;无建议时原样返回主错误描述。 + * + * @param message 主错误描述 + * @param suggestion 可选的修改建议(示例值等) + */ +export const appendValidateSuggestion = (message: string, suggestion?: string): string => + suggestion ? `${message}${VALIDATE_SUGGESTION_SEPARATOR}${suggestion}` : message; + +/** + * 去掉校验文案中的「修改建议」部分,仅保留「主错误描述」。 + * + * @param text 完整校验文案(可能形如 `主错误描述\n\n修改建议`) + */ +export const stripValidateSuggestion = (text?: string): string => + String(text ?? '').split(VALIDATE_SUGGESTION_SEPARATOR)[0]; diff --git a/packages/design/src/index.ts b/packages/design/src/index.ts index c439c316..e9cfd324 100644 --- a/packages/design/src/index.ts +++ b/packages/design/src/index.ts @@ -8,6 +8,7 @@ import './theme/index.scss'; export * from './types'; export * from './config'; +export * from './formValidateMessage'; export { default as TMagicAutocomplete } from './Autocomplete.vue'; export { default as TMagicBadge } from './Badge.vue'; diff --git a/packages/editor/src/fields/StyleSetter/Index.vue b/packages/editor/src/fields/StyleSetter/Index.vue index 13aa759a..9c02d637 100644 --- a/packages/editor/src/fields/StyleSetter/Index.vue +++ b/packages/editor/src/fields/StyleSetter/Index.vue @@ -7,6 +7,7 @@ v-if="item.component" :is="item.component" :values="model[name]" + :prop="prop ? `${prop}.${name}` : name" :last-values="lastValues?.[name]" :is-compare="isCompare" :size="size" @@ -35,7 +36,7 @@ defineOptions({ name: 'MFieldsStyleSetter', }); -const props = defineProps>(); +defineProps>(); const emit = defineEmits<{ change: [v: any, eventData: ContainerChangeEventData]; @@ -77,13 +78,6 @@ const collapseValue = shallowRef( ); const change = (v: any, eventData: ContainerChangeEventData) => { - eventData.changeRecords?.forEach((record) => { - if (props.prop) { - record.propPath = `${props.prop}.${record.propPath}`; - } else if (props.name) { - record.propPath = `${props.name}.${record.propPath}`; - } - }); emit('change', v, eventData); }; diff --git a/packages/editor/src/fields/StyleSetter/pro/Background.vue b/packages/editor/src/fields/StyleSetter/pro/Background.vue index 601dfa6b..fa0adb5e 100644 --- a/packages/editor/src/fields/StyleSetter/pro/Background.vue +++ b/packages/editor/src/fields/StyleSetter/pro/Background.vue @@ -1,6 +1,9 @@