From 623bfe652d8f1b54a35fdba983985b404958102b Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Mon, 22 Jan 2024 20:34:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=A1=E4=BB=A4=E6=8A=93=E5=8C=85?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E4=B8=8B=E8=BD=BDpcap=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/i18n/locales/en-US.ts | 2 + src/i18n/locales/zh-CN.ts | 2 + src/views/traceManage/pcap/index.vue | 129 ++++++++++++++++++++------- 3 files changed, 102 insertions(+), 31 deletions(-) diff --git a/src/i18n/locales/en-US.ts b/src/i18n/locales/en-US.ts index 41203354..dfe9b74d 100644 --- a/src/i18n/locales/en-US.ts +++ b/src/i18n/locales/en-US.ts @@ -700,6 +700,8 @@ export default { textLog: "Log", textLogMsg: "Log Info", textDown: "Download", + textDownBatch: "Batch Download", + downTip: "Are you sure you want to download the {title} capture data file?", downOk: "{title} file download complete", downErr: "{title} file download exception", textSelect: "check list", diff --git a/src/i18n/locales/zh-CN.ts b/src/i18n/locales/zh-CN.ts index c6ec8f87..55f6be79 100644 --- a/src/i18n/locales/zh-CN.ts +++ b/src/i18n/locales/zh-CN.ts @@ -700,6 +700,8 @@ export default { textLog: "日志", textLogMsg: "日志信息", textDown: "下载", + textDownBatch: "批量下载", + downTip: "确认要下载 {title} 抓包数据文件吗?", downOk: "{title} 文件下载完成", downErr: "{title} 文件下载异常", textSelect: "勾选的", diff --git a/src/views/traceManage/pcap/index.vue b/src/views/traceManage/pcap/index.vue index 467a21a8..60eda6ad 100644 --- a/src/views/traceManage/pcap/index.vue +++ b/src/views/traceManage/pcap/index.vue @@ -299,35 +299,84 @@ function fnRecordStop(row?: Record) { } /**下载PCAP文件 */ -function fnDownPCAP(id: number | string) { - const from = modalState.from[id]; - if (!from) return; - const hide = message.loading(t('common.loading'), 0); - const data = Object.assign( - { - path: '/tmp', - fileName: `${from.out}.pcap`, - }, - from.data - ); - getNeFile(data) - .then(res => { - if (res.code === RESULT_CODE_SUCCESS) { - message.success({ - content: t('views.traceManage.pcap.downOk', { title: from.out }), - duration: 3, - }); - saveAs(res.data, data.fileName); - } else { - message.error({ - content: t('views.traceManage.pcap.downErr', { title: from.out }), - duration: 3, - }); +function fnDownPCAP(row?: Record) { + let neIDs: string[] = []; + if (row) { + neIDs = [`${row.id}`]; + } else { + row = { + neName: t('views.traceManage.pcap.textSelect'), + }; + neIDs = tableState.selectedRowKeys.map(s => `${s}`); + } + + Modal.confirm({ + title: t('common.tipTitle'), + content: t('views.traceManage.pcap.downTip', { title: row.neName }), + onOk() { + const hide = message.loading(t('common.loading'), 0); + const fromArr = neIDs.map(id => modalState.from[id]); + const reqArr = []; + for (const from of fromArr) { + if (!from.out) { + message.warning({ + content: t('views.traceManage.pcap.stopNotRun', { + title: from.title, + }), + duration: 3, + }); + continue; + } + + reqArr.push( + getNeFile( + Object.assign( + { + path: '/tmp', + fileName: `${from.out}.pcap`, + }, + from.data + ) + ) + ); } - }) - .finally(() => { - hide(); - }); + + Promise.allSettled(reqArr) + .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(() => { @@ -452,7 +519,7 @@ onMounted(() => { type="primary" ghost size="small" - @click.prevent="fnDownPCAP(record.id)" + @click.prevent="fnDownPCAP(record)" v-if=" !modalState.from[record.id].loading && modalState.from[record.id].out