feat: 工况库

This commit is contained in:
JiangSheng
2025-11-13 16:03:19 +08:00
parent 5f87e6f5cb
commit ef59bad21d
3 changed files with 79 additions and 40 deletions

View File

@@ -75,13 +75,35 @@ const download = (url: string, params = {}, filename = 'download') => {
responseType: 'blob',
})
.then((res: any) => {
// 从响应头获取文件名
const contentDisposition = res.headers?.['content-disposition'] || '';
const contentDisposition =
res.headers?.['content-disposition'] ||
res.headers?.['Content-Disposition'] ||
'';
let fileName = filename;
const match = contentDisposition.match(/filename\*?=(?:UTF-8'')?["']?([^;"']+)/i);
if (match && match[1]) {
fileName = decodeURIComponent(match[1]);
if (contentDisposition) {
const regex = /(filename\*?)\s*=\s*(?:UTF-8'')?["']?([^;"']+)["']?/ig;
let match: RegExpExecArray | null = null;
while ((match = regex.exec(contentDisposition)) !== null) {
const key = match[1];
const val = match[2];
if (!val) continue;
if (key.endsWith('*')) {
if (val.toLowerCase() === 'utf-8') {
continue;
}
try {
fileName = decodeURIComponent(val);
} catch {
fileName = val;
}
} else {
fileName = val.replace(/^["']|["']$/g, '');
}
break;
}
}
const blob = new Blob([res.data]);
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);