mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:58:07 +08:00
表单项的 visible 差异兼容
This commit is contained in:
parent
3f3947e68f
commit
e47311ec82
19
src/Root.tsx
19
src/Root.tsx
@ -133,24 +133,6 @@ export function renderChild(
|
||||
typeofnode === 'string' || typeofnode === 'number'
|
||||
? {type: 'tpl', tpl: String(node)}
|
||||
: (node as Schema);
|
||||
const detectData =
|
||||
schema &&
|
||||
(schema.detectField === '&' ? props : props[schema.detectField || 'data']);
|
||||
const exprProps = detectData
|
||||
? getExprProperties(schema, detectData, undefined, props)
|
||||
: null;
|
||||
|
||||
if (
|
||||
exprProps &&
|
||||
(exprProps.hidden ||
|
||||
exprProps.visible === false ||
|
||||
schema.hidden ||
|
||||
schema.visible === false ||
|
||||
props.hidden ||
|
||||
props.visible === false)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const transform = props.propsTransform;
|
||||
|
||||
@ -163,7 +145,6 @@ export function renderChild(
|
||||
return (
|
||||
<SchemaRenderer
|
||||
{...props}
|
||||
{...exprProps}
|
||||
schema={schema}
|
||||
$path={`${prefix ? `${prefix}/` : ''}${(schema && schema.type) || ''}`}
|
||||
/>
|
||||
|
@ -12,6 +12,7 @@ import {
|
||||
} from './factory';
|
||||
import {renderChild, renderChildren} from './Root';
|
||||
import {Schema, SchemaNode} from './types';
|
||||
import getExprProperties from './utils/filter-schema';
|
||||
import {anyChanged, chainEvents} from './utils/helper';
|
||||
|
||||
interface SchemaRendererProps extends Partial<RendererProps> {
|
||||
@ -185,11 +186,35 @@ export class SchemaRenderer extends React.Component<SchemaRendererProps, any> {
|
||||
|
||||
if (Array.isArray(schema)) {
|
||||
return renderChildren($path, schema as any, rest) as JSX.Element;
|
||||
} else if (schema.children) {
|
||||
return React.isValidElement(schema.children)
|
||||
}
|
||||
|
||||
const detectData =
|
||||
schema &&
|
||||
(schema.detectField === '&' ? rest : rest[schema.detectField || 'data']);
|
||||
const exprProps = detectData
|
||||
? getExprProperties(schema, detectData, undefined, rest)
|
||||
: null;
|
||||
|
||||
if (
|
||||
exprProps &&
|
||||
(exprProps.hidden ||
|
||||
exprProps.visible === false ||
|
||||
schema.hidden ||
|
||||
schema.visible === false ||
|
||||
rest.hidden ||
|
||||
rest.visible === false)
|
||||
) {
|
||||
(rest as any).invisible = true;
|
||||
}
|
||||
|
||||
if (schema.children) {
|
||||
return rest.invisible
|
||||
? null
|
||||
: React.isValidElement(schema.children)
|
||||
? schema.children
|
||||
: (schema.children as Function)({
|
||||
...rest,
|
||||
...exprProps,
|
||||
$path: $path,
|
||||
$schema: schema,
|
||||
render: this.renderChild,
|
||||
@ -197,21 +222,25 @@ export class SchemaRenderer extends React.Component<SchemaRendererProps, any> {
|
||||
});
|
||||
} else if (typeof schema.component === 'function') {
|
||||
const isSFC = !(schema.component.prototype instanceof React.Component);
|
||||
return React.createElement(schema.component as any, {
|
||||
...rest,
|
||||
...schema,
|
||||
$path: $path,
|
||||
$schema: schema,
|
||||
ref: isSFC ? undefined : this.refFn,
|
||||
forwardedRef: isSFC ? this.refFn : undefined,
|
||||
render: this.renderChild
|
||||
});
|
||||
return rest.invisible
|
||||
? null
|
||||
: React.createElement(schema.component as any, {
|
||||
...rest,
|
||||
...exprProps,
|
||||
...schema,
|
||||
$path: $path,
|
||||
$schema: schema,
|
||||
ref: isSFC ? undefined : this.refFn,
|
||||
forwardedRef: isSFC ? this.refFn : undefined,
|
||||
render: this.renderChild
|
||||
});
|
||||
} else if (Object.keys(schema).length === 0) {
|
||||
return null;
|
||||
} else if (!this.renderer) {
|
||||
return (
|
||||
return rest.invisible ? null : (
|
||||
<LazyComponent
|
||||
{...rest}
|
||||
{...exprProps}
|
||||
getComponent={async () => {
|
||||
const result = await rest.env.loadRenderer(
|
||||
schema,
|
||||
@ -239,11 +268,16 @@ export class SchemaRenderer extends React.Component<SchemaRendererProps, any> {
|
||||
const {data: defaultData, value: defaultValue, ...restSchema} = schema;
|
||||
const Component = renderer.component;
|
||||
|
||||
if (rest.invisible && !renderer.isFormItem) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Component
|
||||
{...theme.getRendererConfig(renderer.name)}
|
||||
{...restSchema}
|
||||
{...chainEvents(rest, restSchema)}
|
||||
{...exprProps}
|
||||
defaultData={defaultData}
|
||||
defaultValue={defaultValue}
|
||||
$path={$path}
|
||||
|
@ -585,8 +585,14 @@ export function wrapControl<
|
||||
formMode,
|
||||
$schema: control,
|
||||
store,
|
||||
data
|
||||
data,
|
||||
invisible
|
||||
} = this.props;
|
||||
|
||||
if (invisible) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const value = this.getValue();
|
||||
const model = this.model;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user