@@ -46,6 +46,7 @@ import {
4646 UploadRawFile ,
4747 UploadUserFile ,
4848 UploadFile ,
49+ UploadFiles ,
4950 UploadProgressEvent ,
5051 UploadRequestOptions ,
5152} from " element-plus" ;
@@ -147,7 +148,7 @@ watch(
147148function handleBeforeUpload(file : UploadRawFile ) {
148149 // 限制文件大小
149150 if (file .size > props .maxFileSize * 1024 * 1024 ) {
150- ElMessage .warning (" 上传图片不能大于 " + props .maxFileSize + " M" );
151+ ElMessage .warning (" 上传文件不能大于 " + props .maxFileSize + " M" );
151152 return false ;
152153 }
153154 return true ;
@@ -190,10 +191,34 @@ const handleProgress = (event: UploadProgressEvent) => {
190191/**
191192 * 上传成功
192193 */
193- const handleSuccess = (fileInfo : FileInfo ) => {
194+ const handleSuccess = (response : any , uploadFile : UploadFile , files : UploadFiles ) => {
194195 ElMessage .success (" 上传成功" );
195-
196- modelValue .value = [... modelValue .value , { name: fileInfo .name , url: fileInfo .url } as FileInfo ];
196+ // 只有当状态为success或者fail,代表文件上传全部完成了,失败也算完成
197+ if (
198+ files .every ((file : UploadFile ) => {
199+ return file .status === " success" || file .status === " fail" ;
200+ })
201+ ) {
202+ let fileInfos = [] as FileInfo [];
203+ files .map ((file : UploadFile ) => {
204+ if (file .status === " success" ) {
205+ // 只取携带response的才是刚上传的
206+ let res = file .response as FileInfo ;
207+ if (res ) {
208+ fileInfos .push ({ name: res .name , url: res .url } as FileInfo );
209+ }
210+ } else {
211+ // 失败上传 从fileList删掉,不展示
212+ fileList .value .splice (
213+ fileList .value .findIndex ((e ) => e .uid === file .uid ),
214+ 1
215+ );
216+ }
217+ });
218+ if (fileInfos .length > 0 ) {
219+ modelValue .value = [... modelValue .value , ... fileInfos ];
220+ }
221+ }
197222};
198223
199224/**
0 commit comments