From b258bb4361961a42c97ea3bffed1ded9fed70011 Mon Sep 17 00:00:00 2001 From: 2betop <2betop.cn@gmail.com> Date: Tue, 12 May 2020 17:58:02 +0800 Subject: [PATCH] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=8F=AA=E4=BB=8E=E7=88=B6?= =?UTF-8?q?=E7=BA=A7=E5=90=8C=E6=AD=A5=20form=20=E5=86=85=E7=9A=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE,=20=E5=A6=82=E6=9E=9C=E6=83=B3=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E5=BC=80=E5=90=AF,=E9=9C=80=E8=A6=81=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=20syncSuperStore=20=E4=B8=BA=20true?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/factory.tsx | 22 ++++++++++++++-------- src/utils/helper.ts | 12 ++++++------ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/factory.tsx b/src/factory.tsx index 7de3fd10b..8ad83fcf1 100644 --- a/src/factory.tsx +++ b/src/factory.tsx @@ -105,6 +105,7 @@ export interface RendererProps { classnames: ClassNamesFn; $path: string; // 当前组件所在的层级信息 store?: IIRendererStore; + syncSuperStore?: boolean; data: { [propName: string]: any; }; @@ -437,7 +438,8 @@ const defaultOmitList = [ 'component', 'detectField', 'required', - 'requiredOn' + 'requiredOn', + 'syncSuperStore' ]; class SchemaRenderer extends React.Component { @@ -746,13 +748,17 @@ export function HocStoreFactory(renderer: { store.initData( createObject( nextProps.store.data, - syncDataFromSuper( - store.data, - nextProps.store.data, - props.scope, - nextProps.dataUpdatedAt !== props.dataUpdatedAt, - store - ) + nextProps.syncSuperStore === false + ? { + ...store.data + } + : syncDataFromSuper( + store.data, + nextProps.store.data, + props.scope, + store, + nextProps.syncSuperStore === true + ) ) ); } else if (nextProps.data && (nextProps.data as any).__super) { diff --git a/src/utils/helper.ts b/src/utils/helper.ts index c81bf5d84..7128be40d 100644 --- a/src/utils/helper.ts +++ b/src/utils/helper.ts @@ -69,14 +69,14 @@ export function syncDataFromSuper( data: any, superObject: any, prevSuperObject: any, - force?: boolean, - store?: IIRendererStore + store: IIRendererStore, + force: boolean ) { const obj = { ...data }; - let keys = Object.keys(obj); + let keys: Array = []; // 如果是 form store,则从父级同步 formItem 种东西。 if (store && store.storeType === 'FormStore') { @@ -85,7 +85,8 @@ export function syncDataFromSuper( `${item.name}`.replace(/\..*$/, '') ) ); - force = false; + } else if (force) { + keys = Object.keys(obj); } if (superObject || prevSuperObject) { @@ -97,8 +98,7 @@ export function syncDataFromSuper( if ( ((superObject && typeof superObject[key] !== 'undefined') || (prevSuperObject && typeof prevSuperObject[key] !== 'undefined')) && - (force || - (prevSuperObject && !superObject) || + ((prevSuperObject && !superObject) || (!prevSuperObject && superObject) || prevSuperObject[key] !== superObject[key]) ) {