fix: 修复 inputFile 中 receiver 获取的数据没有更新的问题 (#3529)

This commit is contained in:
liaoxuezhi 2022-01-28 16:07:06 +08:00 committed by GitHub
parent e87fe135af
commit af8459b9cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -9,7 +9,12 @@ import {Payload, ApiObject, ApiString, Action} from '../../types';
import {filter} from '../../utils/tpl';
import Alert from '../../components/Alert2';
import {qsstringify, createObject, guid, isEmpty} from '../../utils/helper';
import {buildApi, normalizeApi} from '../../utils/api';
import {
buildApi,
isEffectiveApi,
normalizeApi,
isApiOutdated
} from '../../utils/api';
import Button from '../../components/Button';
import {Icon} from '../../components/icons';
import DropZone from 'react-dropzone';
@ -1421,6 +1426,14 @@ export default class FileControl extends React.Component<FileProps, FileState> {
@FormItem({
type: 'input-file',
sizeMutable: false,
renderDescription: false
renderDescription: false,
shouldComponentUpdate: (props: any, prevProps: any) =>
!!isEffectiveApi(props.receiver, props.data) &&
isApiOutdated(
props.receiver,
prevProps.receiver,
props.data,
prevProps.data
)
})
export class FileControlRenderer extends FileControl {}

View File

@ -291,6 +291,7 @@ export interface FormItemBasicConfig extends Partial<RendererConfig> {
storeType?: string;
validations?: string;
strictMode?: boolean;
shouldComponentUpdate?: (props: any, prevProps: any) => boolean;
descriptionClassName?: string;
storeExtendsData?: boolean;
sizeMutable?: boolean;
@ -1187,7 +1188,11 @@ export function asFormItem(config: Omit<FormItemConfig, 'component'>) {
}
shouldComponentUpdate(nextProps: FormControlProps) {
if (nextProps.strictMode === false || config.strictMode === false) {
if (
config.shouldComponentUpdate?.(this.props, nextProps) ||
nextProps.strictMode === false ||
config.strictMode === false
) {
return true;
}