feat: 实现PCAP文件分批下载,避免浏览器限制同时下载10个文件的问题
This commit is contained in:
@@ -454,6 +454,9 @@ function fnDownPCAP(row?: Record<string, any>) {
|
|||||||
const hide = message.loading(t('common.loading'), 0);
|
const hide = message.loading(t('common.loading'), 0);
|
||||||
Promise.allSettled(reqArr)
|
Promise.allSettled(reqArr)
|
||||||
.then(resArr => {
|
.then(resArr => {
|
||||||
|
type successType = { data: Blob; filename: string }[];
|
||||||
|
const successResults: successType = [];
|
||||||
|
|
||||||
resArr.forEach((res, idx) => {
|
resArr.forEach((res, idx) => {
|
||||||
const title = fromArr[idx].title;
|
const title = fromArr[idx].title;
|
||||||
const taskCode = fromArr[idx].taskCode;
|
const taskCode = fromArr[idx].taskCode;
|
||||||
@@ -466,11 +469,14 @@ function fnDownPCAP(row?: Record<string, any>) {
|
|||||||
duration: 3,
|
duration: 3,
|
||||||
});
|
});
|
||||||
// 文件名
|
// 文件名
|
||||||
|
let filename = `${title}_${Date.now()}.zip`;
|
||||||
if (taskCode.startsWith('/tmp')) {
|
if (taskCode.startsWith('/tmp')) {
|
||||||
saveAs(resV.data, `${title}_${Date.now()}.pcap`);
|
filename = `${title}_${Date.now()}.pcap`;
|
||||||
} else {
|
|
||||||
saveAs(resV.data, `${title}_${Date.now()}.zip`);
|
|
||||||
}
|
}
|
||||||
|
successResults.push({
|
||||||
|
data: resV.data,
|
||||||
|
filename: filename,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
message.warning({
|
message.warning({
|
||||||
content: `${resV.msg}`,
|
content: `${resV.msg}`,
|
||||||
@@ -484,6 +490,26 @@ function fnDownPCAP(row?: Record<string, any>) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 分批下载函数,每批3个,间隔300ms
|
||||||
|
const batchDownload = async (results: successType) => {
|
||||||
|
const batchSize = 3;
|
||||||
|
const delay = 3_000; // 毫秒
|
||||||
|
|
||||||
|
for (let i = 0; i < results.length; i += batchSize) {
|
||||||
|
const batch = results.slice(i, i + batchSize);
|
||||||
|
|
||||||
|
// 处理当前批次
|
||||||
|
batch.forEach(item => {
|
||||||
|
saveAs(item.data, item.filename);
|
||||||
|
});
|
||||||
|
|
||||||
|
await new Promise(resolve => setTimeout(() => resolve(true), delay));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 开始分批下载
|
||||||
|
batchDownload(successResults);
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
hide();
|
hide();
|
||||||
|
|||||||
Reference in New Issue
Block a user