Export file, export as Excel file

1. Install dependent packages

npm install -S file-savernpm

install -S xlsxnpm

install -D script-loader

2. Create a new folder vendor in the project (the name can be taken at will):

Put the two folders Blob.js and Export2Excel.js into the newly created folder

<el-button :loading="downloadLoading" class="filter-item" type="info" icon="el-icon-download" @click="handleDownload">
        导出报表
</el-button>
data(){
    return{
      downloadLoading: false,//控制是否下载
    }
}
metheds:{
 // 导出报表功能
 handleDownload() {
      this.downloadLoading = true
      import('@/vendor/Export2Excel').then(excel => {
        const tHeader = ['订单编号', '联系人', '联系电话', '报修地址', '申请时间', '实际上门时间', '维修人', '分配人', '订单分类', '状态']
        const filterVal = ['orderNumber', 'userName', 'userPhone', 'house_address', 'recordDate2', 'callTime', 'disposeName', 'manageUserName', 'classify', 'status']
        const list = this.lists
        const data = this.formatJson(filterVal, list)
        excel.export_json_to_excel({
          header: tHeader,
          data,
          filename: 'allRepair',
          autoWidth: this.autoWidth,
          bookType: this.bookType
        })
        this.downloadLoading = false
      })
    },
    //
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => {
        if (j === 'timestamp') {
          // eslint-disable-next-line no-undef
          return parseTime(v[j])
        } else {
          return v[j]
        }
      }))
    },
}

Guess you like

Origin blog.csdn.net/i96249264_bo/article/details/119321134