修复弹窗打开卡主问题 (#2146)

This commit is contained in:
liaoxuezhi 2021-06-23 17:31:53 +08:00 committed by GitHub
parent dcb290fdd4
commit eee47f5143
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 19 deletions

View File

@ -63,16 +63,16 @@ export class SchemaRenderer extends React.Component<SchemaRendererProps, any> {
this.resolveRenderer(this.props); this.resolveRenderer(this.props);
} }
componentWillReceiveProps(nextProps: SchemaRendererProps) { componentDidUpdate(prevProps: SchemaRendererProps) {
const props = this.props; const props = this.props;
if ( if (
prevProps.schema &&
props.schema && props.schema &&
nextProps.schema && (prevProps.schema.type !== props.schema.type ||
(props.schema.type !== nextProps.schema.type || prevProps.schema.$$id !== props.schema.$$id)
props.schema.$$id !== nextProps.schema.$$id)
) { ) {
this.resolveRenderer(nextProps); this.resolveRenderer(props);
} }
} }

View File

@ -183,13 +183,14 @@ export function HocStoreFactory(renderer: {
props.data.__super props.data.__super
) { ) {
// 这个用法很少,当 data.__super 值发生变化时,更新 store.data // 这个用法很少,当 data.__super 值发生变化时,更新 store.data
(!prevProps.data || if (
!prevProps.data ||
isObjectShallowModified( isObjectShallowModified(
props.data.__super, props.data.__super,
prevProps.data.__super, prevProps.data.__super,
false false
)) && )
// nextProps.data.__super !== props.data.__super) && ) {
store.initData( store.initData(
createObject(props.data.__super, { createObject(props.data.__super, {
...props.data, ...props.data,
@ -199,6 +200,8 @@ export function HocStoreFactory(renderer: {
store.storeType === 'FormStore' && store.storeType === 'FormStore' &&
prevProps.store?.storeType === 'CRUDStore' prevProps.store?.storeType === 'CRUDStore'
); );
}
// nextProps.data.__super !== props.data.__super) &&
} else if ( } else if (
props.scope && props.scope &&
props.data === props.store!.data && props.data === props.store!.data &&

View File

@ -5,7 +5,12 @@ import {SchemaNode, Schema, Action} from '../types';
import {filter} from '../utils/tpl'; import {filter} from '../utils/tpl';
import Modal from '../components/Modal'; import Modal from '../components/Modal';
import findLast from 'lodash/findLast'; import findLast from 'lodash/findLast';
import {guid, isVisible, autobind} from '../utils/helper'; import {
guid,
isVisible,
autobind,
isObjectShallowModified
} from '../utils/helper';
import {reaction} from 'mobx'; import {reaction} from 'mobx';
import {Icon} from '../components/icons'; import {Icon} from '../components/icons';
import {ModalStore, IModalStore} from '../store/modal'; import {ModalStore, IModalStore} from '../store/modal';
@ -591,8 +596,9 @@ export default class Dialog extends React.Component<DialogProps> {
storeType: ModalStore.name, storeType: ModalStore.name,
storeExtendsData: false, storeExtendsData: false,
isolateScope: true, isolateScope: true,
shouldSyncSuperStore: (store: IServiceStore, props: any) => shouldSyncSuperStore: (store: IServiceStore, props: any, prevProps: any) =>
store.dialogOpen || props.show (store.dialogOpen || props.show) &&
isObjectShallowModified(prevProps.data, props.data)
}) })
export class DialogRenderer extends Dialog { export class DialogRenderer extends Dialog {
static contextType = ScopedContext; static contextType = ScopedContext;

View File

@ -4,7 +4,12 @@ import {Renderer, RendererProps} from '../factory';
import {SchemaNode, Schema, Action} from '../types'; import {SchemaNode, Schema, Action} from '../types';
import {default as DrawerContainer} from '../components/Drawer'; import {default as DrawerContainer} from '../components/Drawer';
import findLast from 'lodash/findLast'; import findLast from 'lodash/findLast';
import {guid, isVisible, autobind} from '../utils/helper'; import {
guid,
isVisible,
autobind,
isObjectShallowModified
} from '../utils/helper';
import {reaction} from 'mobx'; import {reaction} from 'mobx';
import {findDOMNode} from 'react-dom'; import {findDOMNode} from 'react-dom';
import {IModalStore, ModalStore} from '../store/modal'; import {IModalStore, ModalStore} from '../store/modal';
@ -649,8 +654,9 @@ export default class Drawer extends React.Component<DrawerProps> {
storeType: ModalStore.name, storeType: ModalStore.name,
storeExtendsData: false, storeExtendsData: false,
isolateScope: true, isolateScope: true,
shouldSyncSuperStore: (store: IServiceStore, props: any) => shouldSyncSuperStore: (store: IServiceStore, props: any, prevProps: any) =>
store.drawerOpen || props.show (store.drawerOpen || props.show) &&
isObjectShallowModified(prevProps.data, props.data)
}) })
export class DrawerRenderer extends Drawer { export class DrawerRenderer extends Drawer {
static contextType = ScopedContext; static contextType = ScopedContext;

View File

@ -17,7 +17,8 @@ import {
cloneObject, cloneObject,
SkipOperation, SkipOperation,
isEmpty, isEmpty,
getVariable getVariable,
isObjectShallowModified
} from '../../utils/helper'; } from '../../utils/helper';
import debouce from 'lodash/debounce'; import debouce from 'lodash/debounce';
import flatten from 'lodash/flatten'; import flatten from 'lodash/flatten';
@ -1587,12 +1588,14 @@ export default class Form extends React.Component<FormProps, object> {
type: 'form', type: 'form',
storeType: FormStore.name, storeType: FormStore.name,
isolateScope: true, isolateScope: true,
shouldSyncSuperStore: (store, nextProps) => { shouldSyncSuperStore: (store, props, prevProps) => {
// 如果是 QuickEdit让 store 同步 __super 数据。 // 如果是 QuickEdit让 store 同步 __super 数据。
if ( if (
nextProps.canAccessSuperData && props.canAccessSuperData &&
nextProps.quickEditFormRef && props.quickEditFormRef &&
nextProps.onQuickChange props.onQuickChange &&
(isObjectShallowModified(prevProps.data, props.data) ||
isObjectShallowModified(prevProps.data.__super, props.data.__super))
) { ) {
return true; return true;
} }