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

下载文件函数修改

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