直接上代码:~~~
handleDownload() {
this.downloadLoading = true
import('@/vendor/Export2Excel').then(excel => {
const tHeader = [
'序号',
'用户名',
'访问IP',
'操作详情',
'操作结果',
'操作时间'
]
const filterVal = [
'log_id',
'user_id',
'source_ip',
'resource_type',
'message',
'create_at'
]
const list = this.list
const data = this.formatJson(filterVal, list)
excel.export_json_to_excel({
header: tHeader,
data,
filename: this.filename,
autoWidth: this.autoWidth,
bookType: this.bookType
})
this.downloadLoading = false
})
},
formatJson(filterVal, jsonData) {
return jsonData.map(v =>
filterVal.map(j => {
if (j === 'create_at') {
return v[j]
} else {
return v[j]
}
})
)
}