:action="上传地址"
:data="fileData" //附件项
listFileList=上传的文件列表
<el-upload :action="uploadUrl" style="margin-left: 10px;" name="multipartFile "
:on-success="uploadIntegritySuccess" :before-upload="beforeUpload" :data="fileData"
accept=".pdf," :file-list="replyFileList" :limit="1" :on-exceed="handleExceed"
:on-remove="handleIntegrityRemove">
<el-button size="small" type="primary">点击上传</el-button>
</el-upload>
// 谈话上传前
beforeUpload(file) {
// 特殊字符
if (file.name.indexOf('#') > -1 || file.name.indexOf('%') > -1) {
this.$message.info('上传图片文件名称不能包含"%、#"等特殊字符')
return false
}
},
//上传成功
uploadIntegritySuccess(res, file, fileList) {
if (res.success) {
this.ruleForm.replyOpinionUrl = res.obj
this.ruleForm.coverName = file.name
} else {
this.$message.error(res.msg)
this.ruleForm.replyOpinionUrl = ''
this.ruleForm.coverName = ''
}
},
//上传文件限制
handleExceed() {
this.$message.warning(`只能上传1个文件`);
},
//移出
handleListRemove() {
this.deleteOssFile(this.ruleForm.identificationUrl)
.then(() => {
this.ruleForm.identificationUrl = ''
this.ruleForm.identificationName = ''
})
},
导入附件
<el-upload
:action="uploadUrl" //地址
ref="upload"
name="file"
:limit="1"
:data="{ type: 2 }"
:show-file-list="false"
:auto-upload="false"
:on-change="uploadExcel"
accept=".xls,.xlsx"
>
<el-button type="primary" plain icon="el-icon-upload2">导入</el-button>
</el-upload>
//上传文件
uploadExcel(file) {
const isLt500M = file.raw.size / 1024 / 1024 < 500 if (!isLt500M) {
this.$refs.upload.clearFiles()
return this.$message.info('上传文件大小不能超过 500MB!')
}
this.importExcel(file.raw)
},
// 导入
importExcel(value) {
this.isShowMask = true
const formdata = new FormData()
formdata.append('file', value)
parkEconomyDataServer.enterpriseEconomy
.importEnterpriseEconomy(formdata)
.then((res) => {
if (res.success) {
if (res?.obj) {
this.enterpriseEconomyData = res.obj
this.isShowDialog = true
}
} else {
this.$message.error(res.msg)
}
this.isShowMask = false
// 清除浏览器上传历史记录文件(必须调用上传不管成功失败,否则上传一次之后不能继续)
this.handleClear()
})
.catch((error) => {
this.$message.error(error.message)
this.isShowMask = false
})
},
// 清除浏览器上传历史记录文件
handleClear(res, file) {
this.$refs.upload.clearFiles()
},