File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed
src/components/UploadFile/src Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -122,7 +122,9 @@ const beforeUpload: UploadProps['beforeUpload'] = (file: UploadRawFile) => {
122
122
return false
123
123
}
124
124
message .success (' 正在上传文件,请稍候...' )
125
+ // 只有在验证通过后才增加计数器
125
126
uploadNumber .value ++
127
+ return true
126
128
}
127
129
// 处理上传的文件发生变化
128
130
// const handleFileChange = (uploadFile: UploadFile): void => {
@@ -149,6 +151,8 @@ const handleExceed: UploadProps['onExceed'] = (): void => {
149
151
// 上传错误提示
150
152
const excelUploadError: UploadProps [' onError' ] = (): void => {
151
153
message .error (' 导入数据失败,请您重新上传!' )
154
+ // 上传失败时减少计数器,避免后续上传被阻塞
155
+ uploadNumber .value = Math .max (0 , uploadNumber .value - 1 )
152
156
}
153
157
// 删除上传文件
154
158
const handleRemove = (file : UploadFile ) => {
Original file line number Diff line number Diff line change @@ -97,20 +97,28 @@ const uploadList = ref<UploadUserFile[]>([])
97
97
const beforeUpload: UploadProps [' beforeUpload' ] = (rawFile ) => {
98
98
const imgSize = rawFile .size / 1024 / 1024 < props .fileSize
99
99
const imgType = props .fileType
100
- if (! imgType .includes (rawFile .type as FileTypes ))
100
+ const isValidType = imgType .includes (rawFile .type as FileTypes )
101
+ const isValidSize = imgSize
102
+
103
+ if (! isValidType )
101
104
ElNotification ({
102
105
title: ' 温馨提示' ,
103
106
message: ' 上传图片不符合所需的格式!' ,
104
107
type: ' warning'
105
108
})
106
- if (! imgSize )
109
+ if (! isValidSize )
107
110
ElNotification ({
108
111
title: ' 温馨提示' ,
109
112
message: ` 上传图片大小不能超过 ${props .fileSize }M! ` ,
110
113
type: ' warning'
111
114
})
112
- uploadNumber .value ++
113
- return imgType .includes (rawFile .type as FileTypes ) && imgSize
115
+
116
+ // 只有在验证通过后才增加计数器
117
+ if (isValidType && isValidSize ) {
118
+ uploadNumber .value ++
119
+ }
120
+
121
+ return isValidType && isValidSize
114
122
}
115
123
116
124
// 图片上传成功
@@ -172,6 +180,8 @@ const uploadError = () => {
172
180
message: ' 图片上传失败,请您重新上传!' ,
173
181
type: ' error'
174
182
})
183
+ // 上传失败时减少计数器,避免后续上传被阻塞
184
+ uploadNumber .value = Math .max (0 , uploadNumber .value - 1 )
175
185
}
176
186
177
187
// 文件数超出提示
You can’t perform that action at this time.
0 commit comments