From c8e55709d4b9799c99801a3160a911f5e3262896 Mon Sep 17 00:00:00 2001 From: "Alex.huxiyang" <1872591453@qq.com> Date: Fri, 5 Jul 2024 14:38:50 +0800 Subject: [PATCH] fix(uploader): pre-upload pmage preview bug (#2416) --- src/packages/uploader/uploader.taro.tsx | 6 ++---- src/packages/uploader/uploader.tsx | 9 +++------ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/packages/uploader/uploader.taro.tsx b/src/packages/uploader/uploader.taro.tsx index eebd77b238..92c5972929 100644 --- a/src/packages/uploader/uploader.taro.tsx +++ b/src/packages/uploader/uploader.taro.tsx @@ -227,8 +227,7 @@ const InternalUploader: ForwardRefRenderFunction< setUploadQueue(uploadQueue) } else { setUploadQueue([]) - fileList.splice(0, fileList.length) - setFileList([...fileList]) + setFileList([]) } } @@ -425,8 +424,7 @@ const InternalUploader: ForwardRefRenderFunction< if (preview) { fileItem.url = fileType === 'video' ? file.thumbTempFilePath : filepath } - fileList.push(fileItem) - setFileList(fileList) + setFileList([...fileList, fileItem]) executeUpload(fileItem, index) }) } diff --git a/src/packages/uploader/uploader.tsx b/src/packages/uploader/uploader.tsx index 3f4a04ce3a..db7d573f27 100644 --- a/src/packages/uploader/uploader.tsx +++ b/src/packages/uploader/uploader.tsx @@ -173,8 +173,7 @@ const InternalUploader: ForwardRefRenderFunction< setUploadQueue(uploadQueue) } else { setUploadQueue([]) - fileList.splice(0, fileList.length) - setFileList([...fileList]) + setFileList([]) } } @@ -301,13 +300,11 @@ const InternalUploader: ForwardRefRenderFunction< const reader = new FileReader() reader.onload = (event: ProgressEvent) => { fileItem.url = (event.target as FileReader).result as string - fileList.push(fileItem) - setFileList([...fileList]) + setFileList([...fileList, fileItem]) } reader.readAsDataURL(file) } else { - fileList.push(fileItem) - setFileList([...fileList]) + setFileList([...fileList, fileItem]) } }) }