图片上传自动填充逻辑调整 (#4692)

* v2.0.0-rc.16

* fix: 图片上传自动填充逻辑调整

Co-authored-by: wutong25 <wutong25@baidu.com>
This commit is contained in:
igrowp 2022-06-24 11:52:21 +08:00 committed by GitHub
parent 0896ed77ed
commit 8aead05f1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 18 deletions

View File

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

View File

@ -1,6 +1,6 @@
{
"name": "amis-formula",
"version": "2.0.0-rc.15",
"version": "2.0.0-rc.16",
"description": "负责 amis 里面的表达式实现,内置公式,编辑器等",
"main": "lib/index.js",
"scripts": {

View File

@ -950,11 +950,14 @@ export default class FileControl extends React.Component<FileProps, FileState> {
);
const toSync = dataMapping(
excludeSelfAutoFill,
multiple
? {
items: files
}
: files[0]
createObject(
data,
multiple
? {
items: files
}
: files[0]
)
);
Object.keys(toSync).forEach(key => {
if (isPlainObject(toSync[key]) && isPlainObject(data[key])) {

View File

@ -394,6 +394,7 @@ export default class ImageControl extends React.Component<
resolve?: (value?: any) => void;
emitValue: any;
unmounted = false;
firstLoad = true; // 是否为初始加载
initAutoFill: boolean;
constructor(props: ImageProps) {
@ -497,16 +498,12 @@ export default class ImageControl extends React.Component<
})
.filter(item => item);
}
this.setState(
{
files: (this.files = files)
},
this.syncAutoFill
);
} else if (prevProps.value !== props.value && !this.initAutoFill) {
this.initAutoFill = true;
this.syncAutoFill();
}
if (prevProps.crop !== props.crop) {
@ -719,6 +716,7 @@ export default class ImageControl extends React.Component<
}
async removeFile(file: FileValue, index: number) {
this.firstLoad = false;
const files = this.files.concat();
const dispatcher = await this.dispatchEvent('remove', file);
if (dispatcher?.prevented) {
@ -815,7 +813,9 @@ export default class ImageControl extends React.Component<
}
onChange((this.emitValue = newValue || ''), undefined, changeImmediately);
this.syncAutoFill();
if (this.initAutoFill || !this.firstLoad) {
this.syncAutoFill();
}
}
syncAutoFill() {
@ -827,17 +827,20 @@ export default class ImageControl extends React.Component<
// 排除自身的字段否则会无限更新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)
);
const toSync = dataMapping(
excludeSelfAutoFill,
multiple
? {
items: files
}
: files[0]
createObject(
data,
multiple
? {
items: files
}
: files[0]
)
);
Object.keys(toSync).forEach(key => {
@ -854,6 +857,7 @@ export default class ImageControl extends React.Component<
}
handleRetry(index: number) {
this.firstLoad = false;
const files = this.files.concat();
const file = files[index];
@ -874,6 +878,7 @@ export default class ImageControl extends React.Component<
handleDrop(files: Array<FileX>) {
const {multiple, crop} = this.props;
this.firstLoad = false;
if (crop && !multiple) {
const file = files[0] as any;
@ -915,6 +920,7 @@ export default class ImageControl extends React.Component<
}
handleCrop() {
this.firstLoad = false;
const {cropFormat, cropQuality} = this.props;
this.cropper.getCroppedCanvas().toBlob(
(file: File) => {