// 导入excel,csv格式
importExcel(file) {
if (file.status !== 'ready') return
// 通过截取字符串获取文件格式
const types = file.name.split('.')[1]
判断当前文件格式是否是xlsx
if (types !== 'xlsx') {
this.$notify({
title: '提示',
message: `文件格式不正确,只支持.xlsx文件`,
type: 'error',
})
return
}
this.fileExcel(file).then((tabJson) => {
console.log('解析文件', tabJson)
if (tabJson && tabJson.length > 0) {
this.xlsxJson = tabJson
console.log('解析文件1', this.xlsxJson)
}
if (this.totalLength > 5000) {
this.openError()
return
}
if (this.tableData.length) {
// 有错误!!!!
this.dialogVisible = true
} else {
this.importLoading = true
this.submitUpload()
}
})
},
<div class="dialogUploadProduct-upload">
<!-- <el-button plain size="small" @click="importProductInformation"
>上传文件</el-button
> -->
<el-upload
class="avatar-uploader"
:on-change="importExcel"
:action="excelUrl"
:show-file-list="false"
:http-request="httpRequest"
:before-upload="beforeAvatarUpload"
>
<!-- :on-success="handleAvatarSuccess" -->
<el-button size="small" type="primary">点击上传</el-button>
<div slot="tip" class="el-upload__tip">
支持扩展名:'xlsx'
</div>
</el-upload>
<!-- <span style="color: #a4a4a2">支持扩展名:'xls、xlsx、csv'</span> -->
<a @click="downloadTemplate">点击下载商品清单模版</a>
</div>