fix:文件下载接口修改
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { download, get, getDownload, post, upload } from '@/api/request';
|
import { download, get, post, upload } from '@/api/request';
|
||||||
|
|
||||||
const env = import.meta.env;
|
const env = import.meta.env;
|
||||||
const PREFIX = env.VITE_API_PREFIX_DATA;
|
const PREFIX = env.VITE_API_PREFIX_DATA;
|
||||||
@@ -205,5 +205,5 @@ export const dataTreeListDirApi = (params: any) => {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export const systemDataDownloadFileApi = (params: any) => {
|
export const systemDataDownloadFileApi = (params: any) => {
|
||||||
return getDownload(`${PREFIX}data/downloadFile?fileId=${params.fileId}`);
|
return download(`${PREFIX}data/downloadFile`, params);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ const download = (url: string, params = {}, filename = 'download') => {
|
|||||||
let fileName = filename;
|
let fileName = filename;
|
||||||
|
|
||||||
if (contentDisposition) {
|
if (contentDisposition) {
|
||||||
|
fileName = contentDisposition;
|
||||||
const parts = contentDisposition
|
const parts = contentDisposition
|
||||||
.split(';')
|
.split(';')
|
||||||
.map((p: string) => p.trim())
|
.map((p: string) => p.trim())
|
||||||
@@ -156,31 +157,4 @@ const download = (url: string, params = {}, filename = 'download') => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const getDownload = (url: string, filename = 'download') => {
|
export { get, post, upload, download };
|
||||||
return service
|
|
||||||
.get(url, {
|
|
||||||
responseType: 'blob',
|
|
||||||
})
|
|
||||||
.then(async (res: any) => {
|
|
||||||
const xFileName = res.headers?.['x-file-name'];
|
|
||||||
let fileName = filename;
|
|
||||||
|
|
||||||
if (xFileName) {
|
|
||||||
fileName = xFileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
const blob = new Blob([res.data]);
|
|
||||||
const link = document.createElement('a');
|
|
||||||
link.href = window.URL.createObjectURL(blob);
|
|
||||||
link.download = fileName;
|
|
||||||
document.body.appendChild(link);
|
|
||||||
link.click();
|
|
||||||
document.body.removeChild(link);
|
|
||||||
window.URL.revokeObjectURL(link.href);
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
ElMessage.warning('下载失败');
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export { get, post, upload, download, getDownload };
|
|
||||||
|
|||||||
Reference in New Issue
Block a user