Skip to content

Commit

Permalink
feat(Form): 在Form将BasicTitle识做为Divider一样的处理 (#3371)
Browse files Browse the repository at this point in the history
* feat(Form): 在Form将BasicTitle识做为Divider一样的处理

* refactor: 抽离是否存在SimpleComponents的校验逻辑

---------

Co-authored-by: gavin-james <meaganlindesy1258@gmail.com>
Co-authored-by: invalid w <wangjuesix@gmail.com>
  • Loading branch information
3 people committed Dec 1, 2023
1 parent dde3652 commit cd71e60
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/components/Form/src/BasicForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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[]);
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/Form/src/components/FormItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { getSlot } from '@/utils/helper/tsxHelper';
import {
createPlaceholderMessage,
isIncludeSimpleComponents,
NO_AUTO_LINK_COMPONENTS,
setComponentRuleType,
} from '../helper';
Expand Down Expand Up @@ -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' },
{
Expand Down
6 changes: 6 additions & 0 deletions src/components/Form/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '');
}
15 changes: 11 additions & 4 deletions src/components/Form/src/hooks/useFormEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) &&
Expand Down

0 comments on commit cd71e60

Please sign in to comment.