diff --git a/src/core/request.js b/src/core/request.js index 7ff4804..64b18b0 100644 --- a/src/core/request.js +++ b/src/core/request.js @@ -20,10 +20,10 @@ request.interceptors.response.use( // 未设置状态码则默认成功状态 const code = res.data.code || 200; switch (code) { - case 200: - return res.data; - default: - return Promise.reject(res); + case 200: + return res.data; + default: + return Promise.reject(res); } }, (error) => { diff --git a/src/views/Invest/BusinessPartner/Index.vue b/src/views/Invest/BusinessPartner/Index.vue index 8d891f2..6e237dc 100644 --- a/src/views/Invest/BusinessPartner/Index.vue +++ b/src/views/Invest/BusinessPartner/Index.vue @@ -308,18 +308,43 @@ - - + - 上传 - - + + 上传 + +
+ 请上传 + + + 的文件 +
+ + + + +
  • + + {{ getFileName(file.name) }} + +
    + 删除 +
    +
  • +
    +
    @@ -442,6 +467,7 @@ export default { fieldType: [], advantageConcept: '', cooperationIntention: '', + imageurl: '' }, formRules: { companyName: [ @@ -512,20 +538,23 @@ export default { relevantQualifications: [], advantageConcept: '', cooperationIntention: '', + imageurl: '' }, // 数量限制 limit: 10, // 大小限制(MB) fileSize: 10, // 文件类型, 例如['png', 'jpg', 'jpeg'] - fileType: ["doc", "docx", "xls","xlsx", "ppt", "txt", "pdf"], + fileType: ["doc", "docx", "xls","xlsx", "ppt","pptx", "txt", "pdf"], // 是否显示提示 isShowTip: true, number: 0, uploadList: [], + uploadList1: [], // 上传文件服务器地址 - uploadFileUrl: process.env.VUE_APP_API_TARGET_URL + "/system/oss/upload", + uploadFileUrl: process.env.VUE_APP_API_TARGET_URL + "system/oss/addFilesUpload", fileList: [], + fileList1: [], loadingModal: undefined, }; }, @@ -564,6 +593,7 @@ export default { this.$refs["Partnerform"].validate(valid => { if (valid) { this.form1.fieldType = this.form1.fieldType.toString(); + this.form1.imageurl = this.fileList.map(item => item.url).toString(); this.$request.post( '/official/companymessage/add', this.form1, @@ -578,7 +608,9 @@ export default { fieldType: [], advantageConcept: '', cooperationIntention: '', + imageurl: '' } + this.fileList = [] } }); } @@ -595,6 +627,7 @@ export default { this.form.productCertification = this.form.productCertification.toString(); this.form.qualitySystem = this.form.qualitySystem.toString(); this.form.relevantQualifications = this.form.relevantQualifications.toString(); + this.form.imageurl = this.fileList1.map(item => item.url).toString() this.$request.post( '/official/companymessage/add', this.form, @@ -619,7 +652,9 @@ export default { relevantQualifications: [], advantageConcept: '', cooperationIntention: '', + imageurl: '' } + this.fileList1 = [] } }); } @@ -661,7 +696,7 @@ export default { }, // 上传失败 handleUploadError(err) { - this.$message.error(`上传文件失败,请重试`); + this.$message.error(`上传文件失败,请重试`, err); this.loadingModal.close(); }, // 上传成功回调 @@ -679,8 +714,8 @@ export default { }, // 删除文件 handleDelete(index) { - let ossId = this.fileList[index].ossId; - delOss(ossId); + // let ossId = this.fileList[index].ossId; + // delOss(ossId); this.fileList.splice(index, 1); }, // 上传结束处理 @@ -701,6 +736,70 @@ export default { return name; } }, + // 上传前校检格式和大小 + handleBeforeUpload1(file) { + // 校检文件类型 + if (this.fileType) { + const fileName = file.name.split('.'); + const fileExt = fileName[fileName.length - 1]; + const isTypeOk = this.fileType.indexOf(fileExt) >= 0; + if (!isTypeOk) { + this.$message.error(`文件格式不正确, 请上传${this.fileType.join("/")}格式文件!`); + return false; + } + } + // 校检文件大小 + if (this.fileSize) { + const isLt = file.size / 1024 / 1024 < this.fileSize; + if (!isLt) { + this.$message.error(`上传文件大小不能超过 ${this.fileSize} MB!`); + return false; + } + } + this.loadingModal = this.$loading({ + lock: true, + text: '正在上传文件,请稍候...', + spinner: 'el-icon-loading', + background: 'rgba(0, 0, 0, 0.7)' + }); + this.number++; + return true; + }, + // 文件个数超出 + handleExceed1() { + this.$message.error(`上传文件数量不能超过 ${this.limit} 个!`); + }, + // 上传失败 + handleUploadError1(err) { + this.$message.error(`上传文件失败,请重试`, err); + this.loadingModal.close(); + }, + // 上传成功回调 + handleUploadSuccess1(res, file) { + if (res.code === 200) { + this.uploadList1.push({ name: res.data.fileName, url: res.data.url, ossId: res.data.ossId }); + this.uploadedSuccessfully1(); + } else { + this.number--; + this.loadingModal.close(); + this.$message.error(res.msg); + this.$refs.fileUpload1.handleRemove(file); + this.uploadedSuccessfully1(); + } + }, + // 删除文件 + handleDelete1(index) { + this.fileList1.splice(index, 1); + }, + // 上传结束处理 + uploadedSuccessfully1() { + if (this.number > 0 && this.uploadList1.length === this.number) { + this.fileList1 = this.fileList1.concat(this.uploadList1); + this.uploadList1 = []; + this.number = 0; + this.loadingModal.close(); + } + }, }, }; @@ -822,9 +921,6 @@ export default { font-size: 12rem; border-radius: 3rem; } -/deep/.el-upload-list{ - display: inline-flex; -} /deep/.el-upload-list__item-name { margin-right: 40rem; padding-left: 4rem; @@ -877,7 +973,6 @@ export default { margin-bottom: 5rem; } .upload-file-list .el-upload-list__item { - border: 1rem solid #e4e7ed; line-height: 2rem; margin-bottom: 10rem; position: relative;