exportInventory(fileName) {
if (!fileName || typeof fileName !== 'string') {
fileName = '导出文件'
}
let params = {}
if (this.selectedRows.length < 1) {
params = { ...this.queryParam }
} else {
let arr = []
let ids = ''
for (let i = 0; i < this.selectedRows.length; i++) {
arr.push(this.selectedRows[i].id)
}
ids = arr.join(',')
params = Object.assign({ ...this.queryParam }, { id: ids })
}
console.log('this.params', params)
exportExcel(params).then(data => {
if (!data) {
this.$message.warning('文件下载失败')
return
}
if (typeof window.navigator.msSaveBlob !== 'undefined') {
window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xlsx')
} else {
console.log('typeof window.navigator.msSaveBlob3333333')
let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', fileName + '.xlsx')
document.body.appendChild(link)
link.click()
document.body.removeChild(link) // 下载完成移除元素
window.URL.revokeObjectURL(url) // 释放掉blob对象
}
})
},
vue后台管理项目浏览器下载excel文件用blob二进制文件流
最新推荐文章于 2024-08-19 16:07:19 发布