fix: asFormItem 可能会重复包裹 (#2240)

* fix: asFormItem 可能会重复包裹

* chore: component 形式跟 renderer 形式接收的参数保持一致

* chore: component 形式跟 renderer 形式接收的参数保持一致
This commit is contained in:
liaoxuezhi 2021-07-08 14:16:47 +08:00 committed by GitHub
parent 5517f5b1d0
commit 07f5e64450
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -134,6 +134,7 @@ export class SchemaRenderer extends React.Component<SchemaRendererProps, any> {
if (
schema.component &&
!schema.component.wrapAsFormItem &&
(schema.asFormItem ||
(props.formStore && (schema.name || schema.hasOwnProperty('label'))))
) {
@ -147,6 +148,7 @@ export class SchemaRenderer extends React.Component<SchemaRendererProps, any> {
...schema.asFormItem
})(schema.component);
componentCache.set(schema.component, cache);
cache.wrapAsFormItem = true;
schema.component = cache;
}
}
@ -242,12 +244,21 @@ export class SchemaRenderer extends React.Component<SchemaRendererProps, any> {
});
} else if (typeof schema.component === 'function') {
const isSFC = !(schema.component.prototype instanceof React.Component);
const {
data: defaultData,
value: defaultValue,
activeKey: defaultActiveKey,
...restSchema
} = schema;
return rest.invisible
? null
: React.createElement(schema.component as any, {
...rest,
...restSchema,
...exprProps,
...schema,
defaultData,
defaultValue,
defaultActiveKey,
$path: $path,
$schema: schema,
ref: isSFC ? undefined : this.refFn,