|
@@ -278,21 +278,35 @@
|
|
|
method: 'get',
|
|
|
params: this.$http.adornParams({
|
|
|
'inventoryId': inventoryId
|
|
|
- })
|
|
|
+ }),
|
|
|
+ responseType: 'blob'
|
|
|
}).then((res) => {
|
|
|
let data = res.data
|
|
|
+ // console.log(res)
|
|
|
if (!data) {
|
|
|
return
|
|
|
}
|
|
|
- const url = window.URL.createObjectURL(new Blob([data]))
|
|
|
- let a = document.createElement('a')
|
|
|
- let _fileName = res.headers['content-disposition'].split(';')[1].split('=')[1]
|
|
|
+ debugger
|
|
|
+ let blob = new Blob([data])
|
|
|
+ // let blob = new Blob([data])
|
|
|
+ console.log(blob)
|
|
|
+ const a = document.createElement('a')
|
|
|
+ const url = window.URL.createObjectURL(blob)
|
|
|
+
|
|
|
+ // 设置文件名
|
|
|
+ let contentDisposition
|
|
|
+ if (res.headers['content-disposition']) contentDisposition = res.headers['content-disposition']
|
|
|
+ if (res.headers['Content-Disposition']) contentDisposition = res.headers['Content-Disposition']
|
|
|
+ const pat = new RegExp('filename=([^;]+\\.[^\\.;]+)')
|
|
|
+ const result = pat.exec(decodeURI(contentDisposition))
|
|
|
+ let _fileName = result && result[1]
|
|
|
+
|
|
|
a.style.display = 'none'
|
|
|
a.href = url
|
|
|
a.setAttribute('download', _fileName)
|
|
|
document.body.appendChild(a)
|
|
|
a.click() // 执行下载
|
|
|
- window.URL.revokeObjectURL(a.href)
|
|
|
+ window.URL.revokeObjectURL(url)
|
|
|
document.body.removeChild(a)
|
|
|
}).catch((error) => { console.log(error) })
|
|
|
},
|