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

下载文件函数修改

上级 036dde3c
......@@ -755,13 +755,16 @@ function FormdataWrapper(obj, fd, pre) {
export async function downloadFile(url, params, fileName = '导出文件', ext = 'xlsx') {
// console.log("downloadFile",url);
const { transformApi, headersApi } = await getTransformApi(url);
let headers = {
Authorization: `bearer ${localStorage.getItem('antd-pro-token-onestop')}`,
};
if(headersApi){
headers.apis = headersApi;
}
fetch(transformApi, {
method: 'POST',
body: FormdataWrapper(params),
headers: {
Authorization: `bearer ${localStorage.getItem('antd-pro-token-onestop')}`,
apis: headersApi,
},
headers,
})
.then((res) => {
if (res.status + '' !== '200') {
......@@ -777,6 +780,7 @@ export async function downloadFile(url, params, fileName = '导出文件', ext =
let filename = fileName + '.' + ext;
a.href = url;
a.download = filename;
a.target = '_blank';
a.click();
window.URL.revokeObjectURL(url);
a = null;
......@@ -795,13 +799,16 @@ export async function downloadFile(url, params, fileName = '导出文件', ext =
export async function downloadFileAndShowModal(url, params, fileName = '导出文件', ext = 'xlsx') {
// console.log("downloadFile",url);
const { transformApi, headersApi } = await getTransformApi(url);
let headers = {
Authorization: `bearer ${localStorage.getItem('antd-pro-token-onestop')}`,
};
if(headersApi){
headers.apis = headersApi;
}
fetch(transformApi, {
method: 'POST',
body: FormdataWrapper(params),
headers: {
Authorization: `bearer ${localStorage.getItem('antd-pro-token-onestop')}`,
apis: headersApi,
},
headers,
})
.then((res) => {
if (res.status + '' !== '200') {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论