* dropdown-button 也需要兼容一下

* 兼容一下产品线用法

* combo 数据同步问题调整
This commit is contained in:
liaoxuezhi 2021-06-22 14:40:32 +08:00 committed by GitHub
parent 216c0a867c
commit 64bfbbd19c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 54 deletions

View File

@ -116,13 +116,13 @@ export function HocStoreFactory(renderer: {
} }
} }
componentWillReceiveProps(nextProps: RendererProps) { componentDidUpdate(prevProps: RendererProps) {
const props = this.props; const props = this.props;
const store = this.store; const store = this.store;
const shouldSync = renderer.shouldSyncSuperStore?.( const shouldSync = renderer.shouldSyncSuperStore?.(
store, store,
nextProps, props,
props prevProps
); );
if (shouldSync === false) { if (shouldSync === false) {
@ -132,80 +132,80 @@ export function HocStoreFactory(renderer: {
if (renderer.extendsData === false) { if (renderer.extendsData === false) {
if ( if (
shouldSync === true || shouldSync === true ||
props.defaultData !== nextProps.defaultData || prevProps.defaultData !== props.defaultData ||
isObjectShallowModified(props.data, nextProps.data) || isObjectShallowModified(prevProps.data, props.data) ||
// //
// 特殊处理 CRUD。 // 特殊处理 CRUD。
// CRUD 中 toolbar 里面的 data 是空对象,但是 __super 会不一样 // CRUD 中 toolbar 里面的 data 是空对象,但是 __super 会不一样
(nextProps.data && (props.data &&
props.data && prevProps.data &&
nextProps.data.__super !== props.data.__super) props.data.__super !== prevProps.data.__super)
) { ) {
store.initData( store.initData(
extendObject(nextProps.data, { extendObject(props.data, {
...(store.hasRemoteData ? store.data : null), // todo 只保留 remote 数据 ...(store.hasRemoteData ? store.data : null), // todo 只保留 remote 数据
...this.formatData(nextProps.defaultData), ...this.formatData(props.defaultData),
...this.formatData(nextProps.data) ...this.formatData(props.data)
}) })
); );
} }
} else if ( } else if (
shouldSync === true || shouldSync === true ||
isObjectShallowModified(props.data, nextProps.data) isObjectShallowModified(prevProps.data, props.data)
) { ) {
if (nextProps.store && nextProps.store.data === nextProps.data) { if (props.store && props.store.data === props.data) {
store.initData( store.initData(
createObject( createObject(
nextProps.store.data, props.store.data,
nextProps.syncSuperStore === false props.syncSuperStore === false
? { ? {
...store.data ...store.data
} }
: syncDataFromSuper( : syncDataFromSuper(
store.data, store.data,
nextProps.store.data, props.store.data,
props.scope, prevProps.scope,
store, store,
nextProps.syncSuperStore === true props.syncSuperStore === true
) )
) )
); );
} else if (nextProps.data && (nextProps.data as any).__super) { } else if (props.data && (props.data as any).__super) {
store.initData(extendObject(nextProps.data)); store.initData(extendObject(props.data));
} else { } else {
store.initData(createObject(nextProps.scope, nextProps.data)); store.initData(createObject(props.scope, props.data));
} }
} else if ( } else if (
(shouldSync === true || (shouldSync === true ||
!nextProps.store || !props.store ||
nextProps.data !== nextProps.store.data) && props.data !== props.store.data) &&
nextProps.data && props.data &&
nextProps.data.__super props.data.__super
) { ) {
// 这个用法很少,当 data.__super 值发生变化时,更新 store.data // 这个用法很少,当 data.__super 值发生变化时,更新 store.data
(!props.data || (!prevProps.data ||
isObjectShallowModified( isObjectShallowModified(
nextProps.data.__super,
props.data.__super, props.data.__super,
prevProps.data.__super,
false false
)) && )) &&
// nextProps.data.__super !== props.data.__super) && // nextProps.data.__super !== props.data.__super) &&
store.initData( store.initData(
createObject(nextProps.data.__super, { createObject(props.data.__super, {
...nextProps.data, ...props.data,
...store.data ...store.data
}), }),
store.storeType === 'FormStore' && store.storeType === 'FormStore' &&
props.store?.storeType === 'CRUDStore' prevProps.store?.storeType === 'CRUDStore'
); );
} else if ( } else if (
nextProps.scope && props.scope &&
nextProps.data === nextProps.store!.data && props.data === props.store!.data &&
(shouldSync === true || props.data !== nextProps.data) (shouldSync === true || prevProps.data !== props.data)
) { ) {
store.initData( store.initData(
createObject(nextProps.scope, { createObject(props.scope, {
// ...nextProps.data, // ...nextProps.data,
...store.data ...store.data
}) })

View File

@ -405,7 +405,8 @@ const maybeStatic = [
'status', 'status',
'json', 'json',
'video', 'video',
'qrcode' 'qrcode',
'plain'
]; ];
function wrapStatic(item: any) { function wrapStatic(item: any) {

View File

@ -1171,6 +1171,11 @@ export function asFormItem(config: Omit<FormItemConfig, 'component'>) {
} }
export function registerFormItem(config: FormItemConfig): RendererConfig { export function registerFormItem(config: FormItemConfig): RendererConfig {
// 不知道业务线之前是为啥是这样注册的,兼容一下这个用法。
if ((config as any).name?.type) {
config.type = config.name = (config as any).name.type;
}
let Control = asFormItem(config)(config.component); let Control = asFormItem(config)(config.component);
return registerRenderer({ return registerRenderer({

View File

@ -106,7 +106,6 @@ export function wrapControl<
rootStore, rootStore,
store, store,
onChange, onChange,
canAccessSuperData,
data, data,
$schema: { $schema: {
name, name,
@ -296,17 +295,14 @@ export function wrapControl<
(!model.emitedValue || model.emitedValue === model.tmpValue) (!model.emitedValue || model.emitedValue === model.tmpValue)
) { ) {
model.changeEmitedValue(undefined); model.changeEmitedValue(undefined);
const value = getVariable( const value = getVariable(props.data, model.name);
props.data, const prevValue = getVariable(prevProps.data, model.name);
model.name, if (
props.canAccessSuperData !== false (value !== prevValue ||
); getVariable(props.data, model.name, false) !==
const prevValue = getVariable( getVariable(prevProps.data, model.name, false)) &&
prevProps.data, value !== model.tmpValue
model.name, ) {
props.canAccessSuperData !== false
);
if (value !== prevValue && value !== model.tmpValue) {
model.changeTmpValue(value); model.changeTmpValue(value);
} }
} }
@ -479,7 +475,6 @@ export function wrapControl<
onChange, onChange,
$schema: {name, onChange: onFormItemChange}, $schema: {name, onChange: onFormItemChange},
data, data,
canAccessSuperData,
validateOnChange, validateOnChange,
formSubmited formSubmited
} = this.props; } = this.props;
@ -488,11 +483,7 @@ export function wrapControl<
return; return;
} }
const value = this.model.tmpValue; const value = this.model.tmpValue;
const oldValue = getVariable( const oldValue = getVariable(data, this.model.name);
data,
this.model.name,
canAccessSuperData !== false
);
if (oldValue === value) { if (oldValue === value) {
return; return;

View File

@ -56,7 +56,7 @@ export class TableCell extends React.Component<RendererProps> {
}; };
// 如果本来就是 type 为 button不要删除其他情况下都应该删除。 // 如果本来就是 type 为 button不要删除其他情况下都应该删除。
if (schema.type !== 'button') { if (schema.type !== 'button' && schema.type !== 'dropdown-button') {
delete schema.label; delete schema.label;
} }