|
@@ -262,7 +262,7 @@ export const RECYCLE = (url) => {
|
|
|
export const REPORT = async (
|
|
export const REPORT = async (
|
|
|
url,
|
|
url,
|
|
|
params,
|
|
params,
|
|
|
- filename = '导出数据',
|
|
|
|
|
|
|
+ filename = 'Export Data',
|
|
|
typeName = 'report',
|
|
typeName = 'report',
|
|
|
method = null,
|
|
method = null,
|
|
|
) => {
|
|
) => {
|
|
@@ -303,32 +303,8 @@ export const REPORT = async (
|
|
|
const link = document.createElement('a');
|
|
const link = document.createElement('a');
|
|
|
link.href = downloadUrl;
|
|
link.href = downloadUrl;
|
|
|
|
|
|
|
|
- // 优先从响应头的 content-disposition 中获取文件名
|
|
|
|
|
- let finalFilename = `${filename}_${new Date().toISOString().slice(0, 10)}.xlsx`;
|
|
|
|
|
-
|
|
|
|
|
- // 尝试多种方式获取 content-disposition
|
|
|
|
|
- const contentDisposition =
|
|
|
|
|
- response.headers['content-disposition'] ||
|
|
|
|
|
- response.headers['Content-Disposition'] ||
|
|
|
|
|
- response.headers.get?.('content-disposition') ||
|
|
|
|
|
- response.headers.get?.('Content-Disposition');
|
|
|
|
|
-
|
|
|
|
|
- if (contentDisposition) {
|
|
|
|
|
- // 尝试从 content-disposition 中提取文件名
|
|
|
|
|
- const filenameMatch = contentDisposition.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/);
|
|
|
|
|
- if (filenameMatch && filenameMatch[1]) {
|
|
|
|
|
- let extractedFilename = filenameMatch[1].replace(/['"]/g, '');
|
|
|
|
|
- // 处理 URL 编码的文件名
|
|
|
|
|
- try {
|
|
|
|
|
- extractedFilename = decodeURIComponent(extractedFilename);
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- // 如果解码失败,使用原始文件名
|
|
|
|
|
- }
|
|
|
|
|
- if (extractedFilename) {
|
|
|
|
|
- finalFilename = extractedFilename;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 使用前端传入的文件名,不使用服务器返回的文件名(以支持国际化)
|
|
|
|
|
+ const finalFilename = `${filename}_${new Date().toISOString().slice(0, 10)}.xlsx`;
|
|
|
|
|
|
|
|
link.download = finalFilename;
|
|
link.download = finalFilename;
|
|
|
document.body.appendChild(link);
|
|
document.body.appendChild(link);
|