fix: 文件上传自动填充问题修复 (#4688)

Co-authored-by: wutong25 <wutong25@baidu.com>
This commit is contained in:
igrowp 2022-06-24 10:12:22 +08:00 committed by GitHub
parent 6c1eed74da
commit 0896ed77ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 12 deletions

View File

@ -316,6 +316,7 @@ order: 21
| concurrency | `number` | | 分块上传时并行个数 |
| documentation | `string` | | 文档内容 |
| documentLink | `string` | | 文档链接 |
| initAutoFill | `boolean` | `true` | 初始化时是否自动填充 |
## 事件表

View File

@ -318,6 +318,7 @@ export default class FileControl extends React.Component<FileProps, FileState> {
multiple: false,
autoUpload: true,
hideUploadButton: false,
initAutoFill: true,
stateTextMap: {
init: '',
pending: '等待上传',
@ -428,7 +429,12 @@ export default class FileControl extends React.Component<FileProps, FileState> {
}
componentDidMount() {
this.syncAutoFill();
if (this.initAutoFill) {
const {formInited, addHook} = this.props;
formInited || !addHook
? this.syncAutoFill()
: addHook(this.syncAutoFill, 'init');
}
}
componentDidUpdate(prevProps: FileProps) {
@ -473,16 +479,14 @@ export default class FileControl extends React.Component<FileProps, FileState> {
return obj;
})
.filter(item => item);
this.setState(
{
files: files
},
this.syncAutoFill
);
} else if (prevProps.value !== props.value && !this.initAutoFill) {
this.initAutoFill = true;
this.syncAutoFill();
}
this.setState(
{
files: files
},
this.syncAutoFill
);
}
}
@ -940,7 +944,7 @@ export default class FileControl extends React.Component<FileProps, FileState> {
// 排除自身的字段否则会无限更新state
const excludeSelfAutoFill = omit(autoFill, name || '');
if (!isEmpty(excludeSelfAutoFill) && onBulkChange && this.initAutoFill) {
if (!isEmpty(excludeSelfAutoFill) && onBulkChange) {
const files = this.state.files.filter(
file => ~['uploaded', 'init', 'ready'].indexOf(file.state as string)
);

View File

@ -448,7 +448,12 @@ export default class ImageControl extends React.Component<
}
componentDidMount() {
this.syncAutoFill();
if (this.initAutoFill) {
const {formInited, addHook} = this.props;
formInited || !addHook
? this.syncAutoFill()
: addHook(this.syncAutoFill, 'init');
}
}
componentDidUpdate(prevProps: ImageProps) {