下载文件优化
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
dea612422e
commit
0444cee0b5
|
|
@ -29,6 +29,21 @@ service.interceptors.request.use(
|
|||
service.interceptors.response.use(
|
||||
response => {
|
||||
const res = response.data
|
||||
let contentDisposition = response.headers['content-disposition']
|
||||
if (contentDisposition) {
|
||||
if (contentDisposition.includes('zip')) {
|
||||
let fileName = contentDisposition.split('; ')[1].split('=')[1]
|
||||
fileName = decodeURI(fileName)
|
||||
const a = document.createElement('a')
|
||||
const href = URL.createObjectURL(new Blob([res], { type: response.headers['content-type'] }))
|
||||
a.download = fileName
|
||||
a.href = href
|
||||
a.click()
|
||||
URL.revokeObjectURL(href)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
let fileReader = new FileReader();
|
||||
fileReader.onload = function () {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in New Issue