按钮
<el-upload class="upload-demo" action=""
:on-preview="handlePreview" :on-remove="handleRemove"
:file-list="fileList" :limit="1" accept=".docx, .pdf, .doc"
:on-exceed="handleExceed" :http-request="modeUpload">
<el-button type="primary" icon="el-icon-upload2" size="small">
上传文件
</el-button>
</el-upload>
<el-button type="primary" @click="submitFormFile" :disabled="isDisable">
确 定
</el-button>
上传
modeUpload(item) {
this.mode = item.file;
},
handleRemove(file, fileList) {
},
handlePreview(file) {
},
handleExceed(files, fileList) {
this.$message.warning(
`当前限制选择 1 个文件,本次选择了 ${files.length} 个文件,共选择了 ${
files.length + fileList.length
} 个文件`
);
},
beforeRemove(file, fileList) {
return this.$confirm(`确定移除 ${file.name}?`);
},
submitFormFile() {
this.$refs["form2"].validate((valid) => {
if (valid) {
if (this.form2.id != null) {
this.isDisable=true
updateFile(this.form2).then((response) => {
if (response.code === 200) {
this.msgSuccess("修改成功");
this.open2 = false;
this.getListFile();
}
});
} else {
this.form2.archivesDataId = this.select.id;
this.form2.archivesId = this.id;
if (this.mode === null) {
this.$message({
showClose: true,
message: "文件不能为空",
type: "warning",
});
} else {
this.isDisable=true
let fd = new FormData();
fd.append("file", this.mode);
uploadArchivesFile(this.form2,fd).then((response) => {
if (response.code === 200) {
this.msgSuccess("新增成功");
this.open2 = false;
this.getListFile();
}
});
}
}
}
});
},