提交 2e40fd66 authored 作者: 钟是志's avatar 钟是志

导出修改

上级 7ca410cf
...@@ -6,6 +6,7 @@ import React from 'react'; ...@@ -6,6 +6,7 @@ import React from 'react';
import moment from 'moment'; import moment from 'moment';
import { Icon, message, notification } from 'antd'; import { Icon, message, notification } from 'antd';
import { getOnestopKey } from '../../Services'; import { getOnestopKey } from '../../Services';
import FormdataWrapper from './object-to-formdata-custom';
let messageTime = new Date().getTime() - 3000; let messageTime = new Date().getTime() - 3000;
...@@ -254,3 +255,43 @@ export function diGuiTree(treeData = [], i = 0) { ...@@ -254,3 +255,43 @@ export function diGuiTree(treeData = [], i = 0) {
// } // }
return treeData; return treeData;
} }
export function downloadFile(url, params, fileName = '导出文件', ext = 'xlsx') {
fetch(url, {
method: 'POST',
body: FormdataWrapper(params),
})
.then((res) => {
if (res.status + '' !== '200') {
return res.json();
} else {
return res.blob();
}
})
.then((data) => {
if (data instanceof Blob) {
let a = document.createElement('a');
let url = window.URL.createObjectURL(data);
let filename = fileName + '.' + ext;
a.href = url;
a.download = filename;
a.click();
window.URL.revokeObjectURL(url);
a = null;
} else {
notification.error({
message: `文件导出错误`,
description: data.errMsg,
});
}
})
.catch((err) => {
notification.error({
message: `网络请求超时`,
});
})
.finally(() => {
return true;
});
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论