实现前端xlsx和csv文件的解析,解析完成以后将文件数据传给后端
·
// 导入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>
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐



所有评论(0)