|
|
@ -233,12 +233,28 @@ function handleDownloadData(response) { |
|
|
link.href = url; |
|
|
link.href = url; |
|
|
|
|
|
|
|
|
// 从消息头获取文件名
|
|
|
// 从消息头获取文件名
|
|
|
let str = _.isUndefined(response.headers['content-disposition']) |
|
|
let contentDisposition = response.headers['content-disposition'] || response.headers['Content-Disposition']; |
|
|
? response.headers['Content-Disposition'].split(';')[1] |
|
|
if (!contentDisposition) { |
|
|
: response.headers['content-disposition'].split(';')[1]; |
|
|
link.setAttribute('download', 'download'); |
|
|
|
|
|
} else { |
|
|
let filename = _.isUndefined(str.split('fileName=')[1]) ? str.split('filename=')[1] : str.split('fileName=')[1]; |
|
|
let filenameMatch = contentDisposition.match(/filename[\*]?=['\"]([^'\"]+)['\"]/i); |
|
|
link.setAttribute('download', decodeURIComponent(filename)); |
|
|
if (filenameMatch && filenameMatch[1]) { |
|
|
|
|
|
link.setAttribute('download', decodeURIComponent(filenameMatch[1])); |
|
|
|
|
|
} else { |
|
|
|
|
|
// 备用方案:尝试从 content-disposition 中提取文件名
|
|
|
|
|
|
let parts = contentDisposition.split(';'); |
|
|
|
|
|
for (let part of parts) { |
|
|
|
|
|
let trimmedPart = part.trim(); |
|
|
|
|
|
if (trimmedPart.startsWith('filename=') || trimmedPart.startsWith('fileName=')) { |
|
|
|
|
|
let filename = trimmedPart.substring(trimmedPart.indexOf('=') + 1).trim(); |
|
|
|
|
|
// 移除可能的引号
|
|
|
|
|
|
filename = filename.replace(/^["']|["']$/g, ''); |
|
|
|
|
|
link.setAttribute('download', decodeURIComponent(filename)); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 触发点击下载
|
|
|
// 触发点击下载
|
|
|
document.body.appendChild(link); |
|
|
document.body.appendChild(link); |
|
|
|