mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 20:09:08 +08:00
parent
216c0a867c
commit
64bfbbd19c
@ -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
|
||||
})
|
||||
|
@ -405,7 +405,8 @@ const maybeStatic = [
|
||||
'status',
|
||||
'json',
|
||||
'video',
|
||||
'qrcode'
|
||||
'qrcode',
|
||||
'plain'
|
||||
];
|
||||
|
||||
function wrapStatic(item: any) {
|
||||
|
@ -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({
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user