<el-upload ref="importUPload" action="//www.***.com/api/v1" :on-remove="handleRemove"
:auto-upload="false" :before-upload="beforeUploadfile" :on-change="changeHandle" :limit="1"
:multiple="false">
<div class="upload-button">选择导入文件</div>
</el-upload>
const suffixReg = /\.[^\.]+$/;
const excelTypes = [".xls", ".xlsx", ".xlt", ".xlsm"];
handleRemove() {
this.file = null;
},
beforeUploadfile() {
return false;
},
changeHandle(file) {
this.file = file;
},
handleSubmitFile() {
if (!this.file) {
this.$message({
message: "请上传文件再尝试提交",
type: "warning"
});
return;
}
const {name} = this.file;
const fileSuffixName = suffixReg.exec(name).toString();
if (!excelTypes.includes(fileSuffixName)) {
this.$message({
message: "请确定上传的文件类型为excel",
type: "warning"
});
return;
}
let fd = new FormData();
fd.append("excelFile", this.file.raw);
batchImport(fd).then(res => {
if (res.data.code === 0) {
this.$message.success("同步成功!!");
this.handleGetShopStaffList();
} else if (res.data.msg === '通讯录未授权') {
let urlpushempower = confirm('您未对"通讯录"应用进行授权,是否前往授权页面进行授权');
if (urlpushempower) {
this.$router.push({path: '/auth/empowerManagement'})
}
} else {
this.$alert(`${res.data.msg}`, '提示', {
confirmButtonText: '确定',
callback: () => {
this.handleGetShopStaffList();
}
})
}
this.importBox = false;
})
},