fix: 信令抓包批量下载pcap文件

This commit is contained in:
TsMask
2024-01-22 20:34:20 +08:00
parent 076d3a75a4
commit 623bfe652d
3 changed files with 102 additions and 31 deletions

View File

@@ -700,6 +700,8 @@ export default {
textLog: "Log", textLog: "Log",
textLogMsg: "Log Info", textLogMsg: "Log Info",
textDown: "Download", textDown: "Download",
textDownBatch: "Batch Download",
downTip: "Are you sure you want to download the {title} capture data file?",
downOk: "{title} file download complete", downOk: "{title} file download complete",
downErr: "{title} file download exception", downErr: "{title} file download exception",
textSelect: "check list", textSelect: "check list",

View File

@@ -700,6 +700,8 @@ export default {
textLog: "日志", textLog: "日志",
textLogMsg: "日志信息", textLogMsg: "日志信息",
textDown: "下载", textDown: "下载",
textDownBatch: "批量下载",
downTip: "确认要下载 {title} 抓包数据文件吗?",
downOk: "{title} 文件下载完成", downOk: "{title} 文件下载完成",
downErr: "{title} 文件下载异常", downErr: "{title} 文件下载异常",
textSelect: "勾选的", textSelect: "勾选的",

View File

@@ -299,35 +299,84 @@ function fnRecordStop(row?: Record<string, any>) {
} }
/**下载PCAP文件 */ /**下载PCAP文件 */
function fnDownPCAP(id: number | string) { function fnDownPCAP(row?: Record<string, any>) {
const from = modalState.from[id]; let neIDs: string[] = [];
if (!from) return; if (row) {
const hide = message.loading(t('common.loading'), 0); neIDs = [`${row.id}`];
const data = Object.assign( } else {
{ row = {
path: '/tmp', neName: t('views.traceManage.pcap.textSelect'),
fileName: `${from.out}.pcap`, };
}, neIDs = tableState.selectedRowKeys.map(s => `${s}`);
from.data }
);
getNeFile(data) Modal.confirm({
.then(res => { title: t('common.tipTitle'),
if (res.code === RESULT_CODE_SUCCESS) { content: t('views.traceManage.pcap.downTip', { title: row.neName }),
message.success({ onOk() {
content: t('views.traceManage.pcap.downOk', { title: from.out }), const hide = message.loading(t('common.loading'), 0);
duration: 3, const fromArr = neIDs.map(id => modalState.from[id]);
}); const reqArr = [];
saveAs(res.data, data.fileName); for (const from of fromArr) {
} else { if (!from.out) {
message.error({ message.warning({
content: t('views.traceManage.pcap.downErr', { title: from.out }), content: t('views.traceManage.pcap.stopNotRun', {
duration: 3, title: from.title,
}); }),
duration: 3,
});
continue;
}
reqArr.push(
getNeFile(
Object.assign(
{
path: '/tmp',
fileName: `${from.out}.pcap`,
},
from.data
)
)
);
} }
})
.finally(() => { Promise.allSettled(reqArr)
hide(); .then(resArr => {
}); resArr.forEach((res, idx) => {
const title = fromArr[idx].title;
if (res.status === 'fulfilled') {
const resV = res.value;
if (resV.code === RESULT_CODE_SUCCESS) {
message.success({
content: t('views.traceManage.pcap.downOk', { title }),
duration: 3,
});
// 文件名
const fileName = `${fromArr[idx].out}.pcap`;
if (fileName.length > 6) {
saveAs(resV.data, fileName);
}
} else {
message.warning({
content: `${resV.msg}`,
duration: 3,
});
}
} else {
message.error({
content: t('views.traceManage.pcap.downErr', { title }),
duration: 3,
});
}
});
})
.finally(() => {
hide();
});
},
});
} }
/** /**
@@ -362,12 +411,30 @@ onMounted(() => {
<!-- 插槽-卡片左侧侧 --> <!-- 插槽-卡片左侧侧 -->
<template #title> <template #title>
<a-space :size="8" align="center"> <a-space :size="8" align="center">
<a-button type="primary" @click.prevent="fnRecordStart()"> <a-button
type="primary"
:disabled="tableState.selectedRowKeys.length <= 0"
@click.prevent="fnRecordStart()"
>
<template #icon><PlayCircleOutlined /> </template>
{{ t('views.traceManage.pcap.textStartBatch') }} {{ t('views.traceManage.pcap.textStartBatch') }}
</a-button> </a-button>
<a-button danger @click.prevent="fnRecordStop()"> <a-button
danger
:disabled="tableState.selectedRowKeys.length <= 0"
@click.prevent="fnRecordStop()"
>
<template #icon><CloseSquareOutlined /> </template>
{{ t('views.traceManage.pcap.textStopBatch') }} {{ t('views.traceManage.pcap.textStopBatch') }}
</a-button> </a-button>
<a-button
type="dashed"
:disabled="tableState.selectedRowKeys.length <= 0"
@click.prevent="fnDownPCAP()"
>
<template #icon><DownloadOutlined /></template>
{{ t('views.traceManage.pcap.textDownBatch') }}
</a-button>
</a-space> </a-space>
</template> </template>
@@ -452,7 +519,7 @@ onMounted(() => {
type="primary" type="primary"
ghost ghost
size="small" size="small"
@click.prevent="fnDownPCAP(record.id)" @click.prevent="fnDownPCAP(record)"
v-if=" v-if="
!modalState.from[record.id].loading && !modalState.from[record.id].loading &&
modalState.from[record.id].out modalState.from[record.id].out