默认只从父级同步 form 内的数据, 如果想强制开启,需要配置 syncSuperStore 为 true

This commit is contained in:
2betop 2020-05-12 17:58:02 +08:00
parent 94363cd1c5
commit b258bb4361
2 changed files with 20 additions and 14 deletions

View File

@ -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<SchemaRendererProps, any> {
@ -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) {

View File

@ -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<string> = [];
// 如果是 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])
) {