From cd71e60dd16e87706deb2d06310bc507c55d6a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E9=A3=9E?= <62117658+gavin-james@users.noreply.github.com> Date: Fri, 1 Dec 2023 17:48:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(Form):=20=E5=9C=A8Form=E5=B0=86BasicTitle?= =?UTF-8?q?=E8=AF=86=E5=81=9A=E4=B8=BADivider=E4=B8=80=E6=A0=B7=E7=9A=84?= =?UTF-8?q?=E5=A4=84=E7=90=86=20(#3371)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(Form): 在Form将BasicTitle识做为Divider一样的处理 * refactor: 抽离是否存在SimpleComponents的校验逻辑 --------- Co-authored-by: gavin-james Co-authored-by: invalid w --- src/components/Form/src/BasicForm.vue | 6 ++++-- src/components/Form/src/components/FormItem.vue | 3 ++- src/components/Form/src/helper.ts | 6 ++++++ src/components/Form/src/hooks/useFormEvents.ts | 15 +++++++++++---- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/components/Form/src/BasicForm.vue b/src/components/Form/src/BasicForm.vue index 97c4cf3bc..5c040ff1f 100644 --- a/src/components/Form/src/BasicForm.vue +++ b/src/components/Form/src/BasicForm.vue @@ -47,7 +47,7 @@ import FormItem from './components/FormItem.vue'; import FormAction from './components/FormAction.vue'; - import { dateItemType } from './helper'; + import { dateItemType, isIncludeSimpleComponents } from './helper'; import { dateUtil } from '@/utils/dateUtil'; import { deepMerge } from '@/utils'; @@ -163,7 +163,9 @@ } } if (unref(getProps).showAdvancedButton) { - return cloneDeep(schemas.filter((schema) => schema.component !== 'Divider') as FormSchema[]); + return cloneDeep( + schemas.filter((schema) => !isIncludeSimpleComponents(schema.component)) as FormSchema[], + ); } else { return cloneDeep(schemas as FormSchema[]); } diff --git a/src/components/Form/src/components/FormItem.vue b/src/components/Form/src/components/FormItem.vue index 9def55091..c00215198 100644 --- a/src/components/Form/src/components/FormItem.vue +++ b/src/components/Form/src/components/FormItem.vue @@ -17,6 +17,7 @@ import { getSlot } from '@/utils/helper/tsxHelper'; import { createPlaceholderMessage, + isIncludeSimpleComponents, NO_AUTO_LINK_COMPONENTS, setComponentRuleType, } from '../helper'; @@ -89,7 +90,7 @@ if (isFunction(componentProps)) { componentProps = componentProps({ schema, tableAction, formModel, formActionType }) ?? {}; } - if (schema.component === 'Divider') { + if (isIncludeSimpleComponents(schema.component)) { componentProps = Object.assign( { type: 'horizontal' }, { diff --git a/src/components/Form/src/helper.ts b/src/components/Form/src/helper.ts index 77e9fbf6f..6312931b0 100644 --- a/src/components/Form/src/helper.ts +++ b/src/components/Form/src/helper.ts @@ -95,3 +95,9 @@ export const NO_AUTO_LINK_COMPONENTS: ComponentType[] = [ 'ImageUpload', 'ApiSelect', ]; + +export const simpleComponents = ['Divider', 'BasicTitle']; + +export function isIncludeSimpleComponents(component?: ComponentType) { + return simpleComponents.includes(component || ''); +} diff --git a/src/components/Form/src/hooks/useFormEvents.ts b/src/components/Form/src/hooks/useFormEvents.ts index 6982c611c..d27f5af86 100644 --- a/src/components/Form/src/hooks/useFormEvents.ts +++ b/src/components/Form/src/hooks/useFormEvents.ts @@ -4,7 +4,12 @@ import type { NamePath } from 'ant-design-vue/lib/form/interface'; import { unref, toRaw, nextTick } from 'vue'; import { isArray, isFunction, isObject, isString, isDef, isNil } from '@/utils/is'; import { deepMerge } from '@/utils'; -import { dateItemType, handleInputNumberValue, defaultValueComponents } from '../helper'; +import { + dateItemType, + handleInputNumberValue, + defaultValueComponents, + isIncludeSimpleComponents, +} from '../helper'; import { dateUtil } from '@/utils/dateUtil'; import { cloneDeep, set, uniqBy, get } from 'lodash-es'; import { error } from '@/utils/log'; @@ -245,7 +250,8 @@ export function useFormEvents({ } const hasField = updateData.every( - (item) => item.component === 'Divider' || (Reflect.has(item, 'field') && item.field), + (item) => + isIncludeSimpleComponents(item.component) || (Reflect.has(item, 'field') && item.field), ); if (!hasField) { @@ -267,7 +273,8 @@ export function useFormEvents({ } const hasField = updateData.every( - (item) => item.component === 'Divider' || (Reflect.has(item, 'field') && item.field), + (item) => + isIncludeSimpleComponents(item.component) || (Reflect.has(item, 'field') && item.field), ); if (!hasField) { @@ -309,7 +316,7 @@ export function useFormEvents({ const currentFieldsValue = getFieldsValue(); schemas.forEach((item) => { if ( - item.component != 'Divider' && + !isIncludeSimpleComponents(item.component) && Reflect.has(item, 'field') && item.field && !isNil(item.defaultValue) &&