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

4023 医保--参保通知批量下载功能优化

上级 076a7f2c
......@@ -6,7 +6,7 @@ import { deepCopy } from '@/webPublic/zyd_public/utils/utils';
import { getTransformApi } from '@/webPublic/one_stop_public/2022beidianke/localstorageTransform';
import moment from 'moment';
import { getSassApiHeader } from '@/webPublic/one_stop_public/2023yunshangguizhou/utils';
import { showDownloadProgressFromFileName } from "./utils";
import { showDownloadProgressFromFileName, showDownloadProgressFromCacheKey } from './utils';
const apiUrl = queryOauthActionPath();
export { apiUrl };
......@@ -1208,19 +1208,16 @@ export async function downloadFile(url, params, fileName = '导出文件', ext =
headers,
})
.then(async (res) => {
if (res.status + '' !== '200') {
if (res.status + '' !== '200' || params.hasAsync) {
return res.json();
} else {
if (params && params.showDownloadProgressFromFileName) { // 2024年11月4日 解决禅道
showDownloadProgressFromFileName(res, { ext, fileName });
return true;
}
return res.blob();
}
})
.then((data) => {
if (data instanceof Blob) {
if (data && typeof data === 'object' && data.cacheKey) {
showDownloadProgressFromCacheKey(data.cacheKey, { ext, fileName });
} else if (data instanceof Blob) {
let a = document.createElement('a');
let url = window.URL.createObjectURL(data);
let filename = fileName + '.' + ext;
......
import React from 'react';
import { Modal, message, Progress } from 'antd';
import { uaaRequest } from '@/webPublic/one_stop_public/utils/request';
import { getFileInfo } from '@/webPublic/zyd_public/utils/handlePhoto';
export async function showDownloadProgressFromFileName(res, {ext, fileName}) {
export async function showDownloadProgressFromFileName(res, { ext, fileName }) {
const reader = res.body.getReader();
let contentLength = res.headers.get('Content-Disposition').split('filename=')[1]; // 文件大小从filename里面取
let nowTime = new Date().getTime();
......@@ -20,7 +22,7 @@ export async function showDownloadProgressFromFileName(res, {ext, fileName}) {
receivedLength += value.length;
// 下载进度
const progress = (receivedLength / contentLength) * 100;
if(new Date().getTime() - 1200 > nowTime) {
if (new Date().getTime() - 1200 > nowTime) {
message.info('正在获取文件,请耐心等待,下载进度为' + progress.toFixed(2) + '%', 1);
nowTime = new Date().getTime();
}
......@@ -45,3 +47,41 @@ export async function showDownloadProgressFromFileName(res, {ext, fileName}) {
}
}
}
export async function showDownloadProgressFromCacheKey(cacheKey, { ext, fileName }) {
if (cacheKey) {
const timerInterVal = window.setInterval(() => {
uaaRequest('/DataColumnApi/queryZip', {
cacheKey,
}).then((res) => {
if (res.finished) {
clearInterval(timerInterVal);
if (res.path) {
message.success('生成成功,开始下载', 2);
const a = document.createElement('a');
a.style.display = 'none';
document.body.append(a);
a.href = getFileInfo(res.path).url;
let filename = fileName;
if (ext && filename.indexOf('.') === -1) {
filename = filename + '.' + ext;
}
a.download = filename;
a.click();
document.body.removeChild(a);
} else {
message.error('生成文件失败');
}
} else {
if (typeof res.success === 'number' && res.success >= 0 && res.total > 0) {
const progress = res.success / res.total;
message.info('正在生成文件,请耐心等待,获取进度' + progress.toFixed(2) + '%', 1);
} else {
message.error('生成文件失败');
clearInterval(timerInterVal);
}
}
});
}, 2000);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论