Skip to content

Commit 97d4013

Browse files
committed
v3.8.4:修复多文件上传报错出现的异常问题
1 parent c43096b commit 97d4013

File tree

1 file changed

+36
-22
lines changed

1 file changed

+36
-22
lines changed

src/components/FileUpload/index.vue

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<template>
22
<div class="upload-file">
33
<el-upload
4-
multiple
5-
:action="uploadFileUrl"
6-
:before-upload="handleBeforeUpload"
7-
:file-list="fileList"
8-
:limit="limit"
9-
:on-error="handleUploadError"
10-
:on-exceed="handleExceed"
11-
:on-success="handleUploadSuccess"
12-
:show-file-list="false"
13-
:headers="headers"
14-
class="upload-file-uploader"
15-
ref="upload"
4+
multiple
5+
:action="uploadFileUrl"
6+
:before-upload="handleBeforeUpload"
7+
:file-list="fileList"
8+
:limit="limit"
9+
:on-error="handleUploadError"
10+
:on-exceed="handleExceed"
11+
:on-success="handleUploadSuccess"
12+
:show-file-list="false"
13+
:headers="headers"
14+
class="upload-file-uploader"
15+
ref="fileUpload"
1616
>
1717
<!-- 上传按钮 -->
1818
<el-button size="mini" type="primary">选取文件</el-button>
@@ -72,6 +72,7 @@ export default {
7272
return {
7373
number: 0,
7474
uploadList: [],
75+
baseUrl: process.env.VUE_APP_BASE_API,
7576
uploadFileUrl: process.env.VUE_APP_BASE_API + "/admin-api/infra/file/upload", // 请求地址
7677
headers: { Authorization: "Bearer " + getAccessToken() }, // 设置上传的请求头部
7778
fileList: [],
@@ -118,7 +119,8 @@ export default {
118119
}
119120
const isTypeOk = this.fileType.some((type) => {
120121
if (file.type.indexOf(type) > -1) return true;
121-
return !!(fileExtension && fileExtension.indexOf(type) > -1);
122+
if (fileExtension && fileExtension.indexOf(type) > -1) return true;
123+
return false;
122124
});
123125
if (!isTypeOk) {
124126
this.$modal.msgError(`文件格式不正确, 请上传${this.fileType.join("/")}格式文件!`);
@@ -147,22 +149,34 @@ export default {
147149
this.$modal.closeLoading()
148150
},
149151
// 上传成功回调
150-
handleUploadSuccess(res) {
151-
// edit by 芋道源码
152-
this.uploadList.push({ name: res.data, url: res.data });
153-
if (this.uploadList.length === this.number) {
154-
this.fileList = this.fileList.concat(this.uploadList);
155-
this.uploadList = [];
156-
this.number = 0;
157-
this.$emit("input", this.listToString(this.fileList));
152+
handleUploadSuccess(res, file) {
153+
if (res.code === 200) {
154+
// edit by 芋道源码
155+
this.uploadList.push({ name: res.data, url: res.data });
156+
this.uploadedSuccessfully();
157+
} else {
158+
this.number--;
158159
this.$modal.closeLoading();
160+
this.$modal.msgError(res.msg);
161+
this.$refs.fileUpload.handleRemove(file);
162+
this.uploadedSuccessfully();
159163
}
160164
},
161165
// 删除文件
162166
handleDelete(index) {
163167
this.fileList.splice(index, 1);
164168
this.$emit("input", this.listToString(this.fileList));
165169
},
170+
// 上传结束处理
171+
uploadedSuccessfully() {
172+
if (this.number > 0 && this.uploadList.length === this.number) {
173+
this.fileList = this.fileList.concat(this.uploadList);
174+
this.uploadList = [];
175+
this.number = 0;
176+
this.$emit("input", this.listToString(this.fileList));
177+
this.$modal.closeLoading();
178+
}
179+
},
166180
// 获取文件名称
167181
getFileName(name) {
168182
if (name.lastIndexOf("/") > -1) {
@@ -178,7 +192,7 @@ export default {
178192
for (let i in list) {
179193
strs += list[i].url + separator;
180194
}
181-
return strs !== '' ? strs.substr(0, strs.length - 1) : '';
195+
return strs != '' ? strs.substr(0, strs.length - 1) : '';
182196
}
183197
}
184198
};

0 commit comments

Comments
 (0)