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

View File

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

View File

@ -1171,6 +1171,11 @@ export function asFormItem(config: Omit<FormItemConfig, 'component'>) {
}
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);
return registerRenderer({

View File

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

View File

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