const loading = this.$loading({
lock: true,
text: '下载中...',
spinner: 'el-icon-loading'
})
batchDownload(params).then((res) => {
//res格式:{data:二进制文件流
fileName:'xxxxx.zip'
}
loading.close()
const firstIndex = res.filename.indexOf('.')
const lastIndex = res.filename.lastIndexOf('.')
let name = ''
let suffix = ''
if (lastIndex !== -1) {
name = res.filename.slice(0, firstIndex)
suffix = res.filename.slice(lastIndex + 1)
}
///////////////如果返回的是 res.data 是 二进制文件流
const url = window.URL.createObjectURL(new Blob([res]))
/////////////////////如果返回的是 res.data 是 blob 格式,
const url = window.URL.createObjectURL(res.data)
const link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', decodeURI(name + '.' + suffix))
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
})