From 2ae83e9aa469e080da55fdc3eaa14af0d5d742b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E4=B8=B9?= <365533093@qq.com> Date: Thu, 22 Dec 2022 18:50:05 +0800 Subject: [PATCH] =?UTF-8?q?fix(InputImage):=20=E7=BB=86=E8=8A=82=E8=B0=83?= =?UTF-8?q?=E6=95=B4=20(#5964)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis/src/renderers/Form/InputImage.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/amis/src/renderers/Form/InputImage.tsx b/packages/amis/src/renderers/Form/InputImage.tsx index ba0ac0500..7f1f1a399 100644 --- a/packages/amis/src/renderers/Form/InputImage.tsx +++ b/packages/amis/src/renderers/Form/InputImage.tsx @@ -783,7 +783,7 @@ export default class ImageControl extends React.Component< }); } - async onChange(changeImmediately?: boolean, changeEvent: boolean = true) { + async onChange(changeImmediately?: boolean, changeEvent: boolean = true, initAutoFill?: boolean) { const { multiple, onChange, @@ -792,6 +792,7 @@ export default class ImageControl extends React.Component< delimiter, valueField } = this.props; + const curInitAutoFill = initAutoFill ?? true; const files = this.files.filter( file => file.state == 'uploaded' || file.state == 'init' @@ -825,7 +826,7 @@ export default class ImageControl extends React.Component< } onChange((this.emitValue = newValue || ''), undefined, changeImmediately); - this.syncAutoFill(); + curInitAutoFill && this.syncAutoFill(); } syncAutoFill() { @@ -1244,7 +1245,11 @@ export default class ImageControl extends React.Component< this.setState( { files: (this.files = files) - } // , !needUploading ? this.onChange : undefined + }, () => { + if (!needUploading) { + this.onChange(false, true, this.initAutoFill); + } + } ); }; img.src = imgDom.src;