v3.8.4:修复多文件上传报错出现的异常问题

This commit is contained in:
YunaiV 2022-11-13 10:40:27 +08:00
parent 1a60d0ceb3
commit 803bd5e3c4

View File

@ -12,7 +12,7 @@
:show-file-list="false" :show-file-list="false"
:headers="headers" :headers="headers"
class="upload-file-uploader" class="upload-file-uploader"
ref="upload" ref="fileUpload"
> >
<!-- 上传按钮 --> <!-- 上传按钮 -->
<el-button size="mini" type="primary">选取文件</el-button> <el-button size="mini" type="primary">选取文件</el-button>
@ -72,6 +72,7 @@ export default {
return { return {
number: 0, number: 0,
uploadList: [], uploadList: [],
baseUrl: process.env.VUE_APP_BASE_API,
uploadFileUrl: process.env.VUE_APP_BASE_API + "/admin-api/infra/file/upload", // uploadFileUrl: process.env.VUE_APP_BASE_API + "/admin-api/infra/file/upload", //
headers: { Authorization: "Bearer " + getAccessToken() }, // headers: { Authorization: "Bearer " + getAccessToken() }, //
fileList: [], fileList: [],
@ -118,7 +119,8 @@ export default {
} }
const isTypeOk = this.fileType.some((type) => { const isTypeOk = this.fileType.some((type) => {
if (file.type.indexOf(type) > -1) return true; if (file.type.indexOf(type) > -1) return true;
return !!(fileExtension && fileExtension.indexOf(type) > -1); if (fileExtension && fileExtension.indexOf(type) > -1) return true;
return false;
}); });
if (!isTypeOk) { if (!isTypeOk) {
this.$modal.msgError(`文件格式不正确, 请上传${this.fileType.join("/")}格式文件!`); this.$modal.msgError(`文件格式不正确, 请上传${this.fileType.join("/")}格式文件!`);
@ -147,15 +149,17 @@ export default {
this.$modal.closeLoading() this.$modal.closeLoading()
}, },
// //
handleUploadSuccess(res) { handleUploadSuccess(res, file) {
if (res.code === 200) {
// edit by // edit by
this.uploadList.push({ name: res.data, url: res.data }); this.uploadList.push({ name: res.data, url: res.data });
if (this.uploadList.length === this.number) { this.uploadedSuccessfully();
this.fileList = this.fileList.concat(this.uploadList); } else {
this.uploadList = []; this.number--;
this.number = 0;
this.$emit("input", this.listToString(this.fileList));
this.$modal.closeLoading(); this.$modal.closeLoading();
this.$modal.msgError(res.msg);
this.$refs.fileUpload.handleRemove(file);
this.uploadedSuccessfully();
} }
}, },
// //
@ -163,6 +167,16 @@ export default {
this.fileList.splice(index, 1); this.fileList.splice(index, 1);
this.$emit("input", this.listToString(this.fileList)); this.$emit("input", this.listToString(this.fileList));
}, },
//
uploadedSuccessfully() {
if (this.number > 0 && this.uploadList.length === this.number) {
this.fileList = this.fileList.concat(this.uploadList);
this.uploadList = [];
this.number = 0;
this.$emit("input", this.listToString(this.fileList));
this.$modal.closeLoading();
}
},
// //
getFileName(name) { getFileName(name) {
if (name.lastIndexOf("/") > -1) { if (name.lastIndexOf("/") > -1) {
@ -178,7 +192,7 @@ export default {
for (let i in list) { for (let i in list) {
strs += list[i].url + separator; strs += list[i].url + separator;
} }
return strs !== '' ? strs.substr(0, strs.length - 1) : ''; return strs != '' ? strs.substr(0, strs.length - 1) : '';
} }
} }
}; };