<el-upload
class="upload"
action=""
ref="upload"
:accept="accept"
:limit="1"
:http-request="httpRequest"
:show-file-list="false"
>
<el-button size="small" type="primary"><i class="tool_upload"></i>批量上传</el-button>
</el-upload>
//批量上传
httpRequest(e) {
let file = e.file;
if (!file) {
this.$alert('没有文件', '提示', {
confirmButtonText: '确定'
});
this.$refs.upload.clearFiles();
return false
} else if (!/.(xls|xlsx)$/.test(file.name.toLowerCase())) {
// 格式根据自己需求定义
this.$alert('上传格式不正确,请上传xls或者xlsx格式', '提示', {
confirmButtonText: '确定'
});
this.$refs.upload.clearFiles();
return false
}
let formData = new FormData();
formData.append('file', e.file);
personnelControlBatchUpload(formData)
.then(res => {
this.$alert(res.message, '提示', {
confirmButtonText: '确定'
});
this.$refs.upload.clearFiles();
if (res.status == 'OK') {
this.clickRetrieval('searchForm');
}
})
.catch(() => {
this.$alert('上传失败', '提示', {
confirmButtonText: '确定'
});
this.$refs.upload.clearFiles();
})
},