From 216c0a867c14e559b66c09bccfe94ab8601bda23 Mon Sep 17 00:00:00 2001 From: liaoxuezhi Date: Mon, 21 Jun 2021 22:30:43 +0800 Subject: [PATCH] Compat3 (#2134) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * persistData 有可能是 boolean * 有可能无限 setState * QuickEdit 默认类型错误 * 恢复 formitem 逻辑 --- src/SchemaRenderer.tsx | 16 +++++++++++++--- src/renderers/Carousel.tsx | 2 +- src/renderers/QuickEdit.tsx | 2 +- src/store/form.ts | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/SchemaRenderer.tsx b/src/SchemaRenderer.tsx index 7e8d091d3..25d24125d 100644 --- a/src/SchemaRenderer.tsx +++ b/src/SchemaRenderer.tsx @@ -191,9 +191,9 @@ export class SchemaRenderer extends React.Component { const detectData = schema && (schema.detectField === '&' ? rest : rest[schema.detectField || 'data']); - const exprProps = detectData + const exprProps: any = detectData ? getExprProperties(schema, detectData, undefined, rest) - : null; + : {}; if ( exprProps && @@ -268,7 +268,17 @@ export class SchemaRenderer extends React.Component { const {data: defaultData, value: defaultValue, ...restSchema} = schema; const Component = renderer.component; - if (rest.invisible && !renderer.isFormItem) { + // 原来表单项的 visible: false 和 hidden: true 表单项的值和验证是有效的 + // 而 visibleOn 和 hiddenOn 是无效的, + // 这个本来就是个bug,但是已经被广泛使用了 + // 我只能继续实现这个bug了 + if ( + rest.invisible && + (exprProps.hidden || + exprProps.visible === false || + !renderer.isFormItem || + (schema.visible !== false && !schema.hidden)) + ) { return null; } diff --git a/src/renderers/Carousel.tsx b/src/renderers/Carousel.tsx index 2cf48d6fe..95a171bc0 100644 --- a/src/renderers/Carousel.tsx +++ b/src/renderers/Carousel.tsx @@ -159,7 +159,7 @@ export class Carousel extends React.Component { componentDidUpdate(prevProps: CarouselProps) { const props = this.props; - const nextOptions = props.options || getPropValue(props); + const nextOptions = props.options || getPropValue(props) || []; const prevOptions = prevProps.options || getPropValue(prevProps) || []; if (isArrayChildrenModified(prevOptions, nextOptions)) { diff --git a/src/renderers/QuickEdit.tsx b/src/renderers/QuickEdit.tsx index 35df09b43..6e9463b52 100644 --- a/src/renderers/QuickEdit.tsx +++ b/src/renderers/QuickEdit.tsx @@ -399,7 +399,7 @@ export const HocQuickEdit = (config: Partial = {}) => ( mode: 'normal', body: [ { - type: quickEdit.type || 'text', + type: quickEdit.type || 'input-text', name: quickEdit.name || name, ...quickEdit, mode: undefined diff --git a/src/store/form.ts b/src/store/form.ts index e9dfc0a98..f7bb70da4 100644 --- a/src/store/form.ts +++ b/src/store/form.ts @@ -40,7 +40,7 @@ export const FormStore = ServiceStore.named('FormStore') savedData: types.frozen(), // items: types.optional(types.array(types.late(() => FormItemStore)), []), canAccessSuperData: true, - persistData: '', + persistData: types.optional(types.union(types.string, types.boolean), ''), restError: types.optional(types.array(types.string), []) // 没有映射到表达项上的 errors }) .views(self => {