export function exportGetFile(url: string, data: any) {
return executeAndTryCatch(() =>
request<Record<string, any>>(url, {
method: 'GET',
params: data,
responseType: 'blob',
getResponse: true,
}),
);
}
export function exportGetFile(url: string, data: any) {
return executeAndTryCatch(() =>
request<Record<string, any>>(url, {
method: 'GET',
params: data,
responseType: 'blob',
getResponse: true,
}),
);
}
type DownloadFileType = {
url: string;
data?: any;
fileName?: string;
method?: string;
};
export const downloadFile = async ({
url,
fileName,
data = {},
method = 'post',
}: DownloadFileType) => {
const res: any =
method.toLowerCase() === 'get'
? ((await exportGetFile(url, data)) as Blob)
: ((await exportPostFile(url, data)) as Blob);
const。filename = (
res.response.headers.get('content-disposition').split('filename=')?.[1] || ''
).replace(/"/g, '');
const blob = new Blob([res]);
const elink = document.createElement('a');
elink.download =。filename || fileName || 'download.xlsx';
elink.style.display = 'none';
elink.href = URL.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
URL.revokeObjectURL(elink.href);
document.body.removeChild(elink);
};
const config = {
data: {},
method: 'get',
}
const url = exportFile(id);
config.url = url;
config.fileName = '参数配置.json';
downloadFile(config);