vue.js中使用Export2Excel导出Excel表格

  作者:chrispy

// 导出的方法loadingFun () {loadingInstance = Loading.service(options)this.dowExcelList = []this.getExportExcelData()},async getExportExcelData () {this.dowCurrentPage++const params = `?tenantId=${this.search.tenantId}&projectId=${this.searc

// 导出的方法

loadingFun () {

loadingInstance = Loading.service(options)

this.dowExcelList = []

this.getExportExcelData()

},

async getExportExcelData () {

this.dowCurrentPage++

const params = `?tenantId=${this.search.tenantId}&projectId=${this.search.projectId}&createTimeStart=${this.search.createTimeStart}

&createTimeEnd=${this.search.createTimeEnd}&identity=${this.search.identity}&sort=${this.search.sort}

&pageSize=10&currentPage=${this.dowCurrentPage}`

const result = await getDownStatisticsGetAgentRankList(params)

this.dowExcelList = this.dowExcelList.concat(result.data)

if (this.dowCurrentPage < result.page.pageCount) {

let totalPage = result.page.pageCount

let currentPage = result.page.currentPage

let Speed = parseInt((currentPage / totalPage) * 100)

loadingInstance.text = `导出进度 ${Speed}%`

this.getExportExcelData(params)

} else {

this.export2Excel()

}

},

export2Excel () {

loadingInstance.text = `导出进度完成开始下载`

require.ensure([], () => {

const { exportJsonToExcel } = require('../../vendor/Export2Excel')

const tHeader = ['渠道身份', '姓名', '全部报备'] // 上面设置Excel的表格第一行的标题

const filterVal = ['identityname', 'name', 'allNum'] // 上面的index、nickName、name是tableData里对象的属性

const list = this.dowExcelList // 把data里的tableData存到list

const data = this.formatJson(filterVal, list)

exportJsonToExcel(tHeader, data, '列表excel')

})

setTimeout(() => {

loadingInstance.close()

}, 500)

},

formatJson (filterVal, jsonData) {

return jsonData.map(v => filterVal.map(j => v[j]))

}


有用  |  无用

猜你喜欢