This commit is contained in:
wangchengming 2024-12-16 17:25:55 +08:00
parent 15ad33aa82
commit 41fa04d9c9
2 changed files with 119 additions and 24 deletions

View File

@ -20,10 +20,10 @@ request.interceptors.response.use(
// 未设置状态码则默认成功状态 // 未设置状态码则默认成功状态
const code = res.data.code || 200; const code = res.data.code || 200;
switch (code) { switch (code) {
case 200: case 200:
return res.data; return res.data;
default: default:
return Promise.reject(res); return Promise.reject(res);
} }
}, },
(error) => { (error) => {

View File

@ -308,18 +308,43 @@
</el-col> </el-col>
</el-row> </el-row>
<el-form-item label="附件"> <el-form-item label="附件">
<el-upload <div class="upload-file">
class="upload-demo" <el-upload
action="https://jsonplaceholder.typicode.com/posts/" multiple
:file-list="fileList2" :action="uploadFileUrl"
> :before-upload="handleBeforeUpload1"
<el-button :file-list="fileList1"
size="small" :limit="limit"
type="primary" :on-error="handleUploadError1"
:on-exceed="handleExceed1"
:on-success="handleUploadSuccess1"
:show-file-list="false"
class="upload-file-uploader"
ref="fileUpload1"
> >
上传 <!-- 上传按钮 -->
</el-button> <el-button size="small" type="primary">上传</el-button>
</el-upload> <!-- 上传提示 -->
<div class="el-upload__tip" slot="tip" v-if="isShowTip">
请上传
<template v-if="fileSize"> 大小不超过 <b style="color: #f56c6c">{{ fileSize }}MB</b> </template>
<template v-if="fileType"> 格式为 <b style="color: #f56c6c">{{ fileType.join("/") }}</b> </template>
的文件
</div>
</el-upload>
<!-- 文件列表 -->
<transition-group class="upload-file-list el-upload-list el-upload-list--text" name="el-fade-in-linear" tag="ul">
<li :key="file.url" class="el-upload-list__item ele-upload-list__item-content" v-for="(file, index) in fileList1">
<el-link :href="`${file.url}`" :underline="false" target="_blank">
<span class="el-icon-document"> {{ getFileName(file.name) }} </span>
</el-link>
<div class="ele-upload-list__item-content-action">
<el-link :underline="false" @click="handleDelete1(index)" type="danger">删除</el-link>
</div>
</li>
</transition-group>
</div>
</el-form-item> </el-form-item>
</div> </div>
<el-form-item style="text-align: center;border-top:1rem solid #B0B0B0;padding: 20rem 0rem"> <el-form-item style="text-align: center;border-top:1rem solid #B0B0B0;padding: 20rem 0rem">
@ -442,6 +467,7 @@ export default {
fieldType: [], fieldType: [],
advantageConcept: '', advantageConcept: '',
cooperationIntention: '', cooperationIntention: '',
imageurl: ''
}, },
formRules: { formRules: {
companyName: [ companyName: [
@ -512,20 +538,23 @@ export default {
relevantQualifications: [], relevantQualifications: [],
advantageConcept: '', advantageConcept: '',
cooperationIntention: '', cooperationIntention: '',
imageurl: ''
}, },
// //
limit: 10, limit: 10,
// (MB) // (MB)
fileSize: 10, fileSize: 10,
// , ['png', 'jpg', 'jpeg'] // , ['png', 'jpg', 'jpeg']
fileType: ["doc", "docx", "xls","xlsx", "ppt", "txt", "pdf"], fileType: ["doc", "docx", "xls","xlsx", "ppt","pptx", "txt", "pdf"],
// //
isShowTip: true, isShowTip: true,
number: 0, number: 0,
uploadList: [], 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: [], fileList: [],
fileList1: [],
loadingModal: undefined, loadingModal: undefined,
}; };
}, },
@ -564,6 +593,7 @@ export default {
this.$refs["Partnerform"].validate(valid => { this.$refs["Partnerform"].validate(valid => {
if (valid) { if (valid) {
this.form1.fieldType = this.form1.fieldType.toString(); this.form1.fieldType = this.form1.fieldType.toString();
this.form1.imageurl = this.fileList.map(item => item.url).toString();
this.$request.post( this.$request.post(
'/official/companymessage/add', '/official/companymessage/add',
this.form1, this.form1,
@ -578,7 +608,9 @@ export default {
fieldType: [], fieldType: [],
advantageConcept: '', advantageConcept: '',
cooperationIntention: '', cooperationIntention: '',
imageurl: ''
} }
this.fileList = []
} }
}); });
} }
@ -595,6 +627,7 @@ export default {
this.form.productCertification = this.form.productCertification.toString(); this.form.productCertification = this.form.productCertification.toString();
this.form.qualitySystem = this.form.qualitySystem.toString(); this.form.qualitySystem = this.form.qualitySystem.toString();
this.form.relevantQualifications = this.form.relevantQualifications.toString(); this.form.relevantQualifications = this.form.relevantQualifications.toString();
this.form.imageurl = this.fileList1.map(item => item.url).toString()
this.$request.post( this.$request.post(
'/official/companymessage/add', '/official/companymessage/add',
this.form, this.form,
@ -619,7 +652,9 @@ export default {
relevantQualifications: [], relevantQualifications: [],
advantageConcept: '', advantageConcept: '',
cooperationIntention: '', cooperationIntention: '',
imageurl: ''
} }
this.fileList1 = []
} }
}); });
} }
@ -661,7 +696,7 @@ export default {
}, },
// //
handleUploadError(err) { handleUploadError(err) {
this.$message.error(`上传文件失败,请重试`); this.$message.error(`上传文件失败,请重试`, err);
this.loadingModal.close(); this.loadingModal.close();
}, },
// //
@ -679,8 +714,8 @@ export default {
}, },
// //
handleDelete(index) { handleDelete(index) {
let ossId = this.fileList[index].ossId; // let ossId = this.fileList[index].ossId;
delOss(ossId); // delOss(ossId);
this.fileList.splice(index, 1); this.fileList.splice(index, 1);
}, },
// //
@ -701,6 +736,70 @@ export default {
return name; 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();
}
},
}, },
}; };
</script> </script>
@ -822,9 +921,6 @@ export default {
font-size: 12rem; font-size: 12rem;
border-radius: 3rem; border-radius: 3rem;
} }
/deep/.el-upload-list{
display: inline-flex;
}
/deep/.el-upload-list__item-name { /deep/.el-upload-list__item-name {
margin-right: 40rem; margin-right: 40rem;
padding-left: 4rem; padding-left: 4rem;
@ -877,7 +973,6 @@ export default {
margin-bottom: 5rem; margin-bottom: 5rem;
} }
.upload-file-list .el-upload-list__item { .upload-file-list .el-upload-list__item {
border: 1rem solid #e4e7ed;
line-height: 2rem; line-height: 2rem;
margin-bottom: 10rem; margin-bottom: 10rem;
position: relative; position: relative;