// @ 捆包下载
submitCard() {
const object = this.filter_HW()
//# 获取表单的数据
if (!object.category) {
object.category = ''
}
const d = (object['time'] || []).length
object.startTime = d > 0 && (object['time'][0]) || ''
object.endTime = d > 0 && (object['time'][1]) || ''
delete object.time
//@处理时间格式
const dto = {
...object
}
this.loading_ = true
this.ajaxExportExcel(请求的接口, dto, '准发捆包')
}
// @ 下载文件流
ajaxExportExcel(url, params = {}, fileName = '下载') {
this.submitBtn = params.stackId // ? 下载pdf
this.submitBtn_ = params.dto?.warrantyId // @ 导出
this.loading_ = true
if (!url) return
const obj = {
method: 'POST',
url: url,
data: {
...params
},
responseType: 'arraybuffer'
}
this.$http(obj).then(res => {
try {
const enc = new TextDecoder('utf-8')
const data = JSON.parse(enc.decode(new Uint8Array(res))) // 转化成json对象
this.$message.error(data.msg)
this.submitBtn = null
this.submitBtn_ = null
this.loading_ = false
} catch (error) {
const blob = new Blob([res], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }) // 拿到文件流生成地址
const date = this.$XEUtils.toDateString(new Date(), 'yyyy-MM-dd')
const name = fileName + '-' + date
const elink = document.createElement('a')
elink.download = name
elink.style.display = 'none'
elink.href = URL.createObjectURL(blob)
document.body.appendChild(elink)
elink.click()
URL.revokeObjectURL(elink.href)
document.body.removeChild(elink)
this.submitBtn = null
this.submitBtn_ = null
this.loading_ = false
}
}).catch(_ => {
this.submitBtn = null
this.submitBtn_ = null
this.loading_ = false
})
},
批量下载或当下载时,处理数据流的解决方案
最新推荐文章于 2022-07-27 09:51:12 发布