From 2678ab3bfb18712bda2e44511a905ba6f5fdf126 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Thu, 13 Mar 2025 11:05:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20PCAP=E5=8E=86=E5=8F=B2=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E4=B8=8B=E8=BD=BD=E4=B8=BAzip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/i18n/locales/en-US.ts | 1 + src/i18n/locales/zh-CN.ts | 1 + src/utils/parse-utils.ts | 24 +++++++-- src/views/traceManage/pcap/file.vue | 84 +++++++++++++++++++++++------ 4 files changed, 88 insertions(+), 22 deletions(-) diff --git a/src/i18n/locales/en-US.ts b/src/i18n/locales/en-US.ts index 954991e1..7f541799 100644 --- a/src/i18n/locales/en-US.ts +++ b/src/i18n/locales/en-US.ts @@ -1200,6 +1200,7 @@ export default { size: "Size", modifiedTime: "Modified Time", fileName: "File Name", + downTipZip: "Confirm downloading the directory [{fileName}] as a ZIP file?", downTip: "Confirm the download file name is [{fileName}] File?", downTipErr: "Failed to get file", dirCd: "Enter Dir", diff --git a/src/i18n/locales/zh-CN.ts b/src/i18n/locales/zh-CN.ts index 1abf090f..bdcd1688 100644 --- a/src/i18n/locales/zh-CN.ts +++ b/src/i18n/locales/zh-CN.ts @@ -1200,6 +1200,7 @@ export default { size: "文件大小", modifiedTime: "修改时间", fileName: "文件名称", + downTipZip: "确认将目录 【{fileName}】 下载为ZIP文件?", downTip: "确认下载文件名为 【{fileName}】 文件?", downTipErr: "文件获取失败", dirCd: "进入目录", diff --git a/src/utils/parse-utils.ts b/src/utils/parse-utils.ts index 49a89ddd..8e13fd43 100644 --- a/src/utils/parse-utils.ts +++ b/src/utils/parse-utils.ts @@ -192,17 +192,31 @@ export function parseSizeFromBits(bits: number | string): string { /** * 字节数转换单位 * @param byte 字节Byte大小 64009540 = 512.08 MB + * @param unit 指定单位 B / KB / MB / GB / TB / PB / EB / ZB / YB * @returns xx B / KB / MB / GB / TB / PB / EB / ZB / YB */ -export function parseSizeFromByte(byte: number | string): string { +export function parseSizeFromByte( + byte: number | string, + unit?: string +): string { byte = Number(byte) || 0; if (byte <= 0) return '0 B'; const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; - const unitIndex = Math.floor(Math.log2(byte) / 10); - const unti = units[unitIndex]; + let unitIndex = 0; + let unitStr = 'B'; + if (unit) { + const index = units.indexOf(unit); + if (index > -1) { + unitIndex = index; + unitStr = unit; + } + } else { + unitIndex = Math.floor(Math.log2(byte) / 10); + unitStr = units[unitIndex]; + } const value = byte / Math.pow(1000, unitIndex); if (unitIndex > 0) { - return `${value.toFixed(2)} ${unti}`; + return `${value.toFixed(2)} ${unitStr}`; } - return `${value} ${unti}`; + return `${value} ${unitStr}`; } diff --git a/src/views/traceManage/pcap/file.vue b/src/views/traceManage/pcap/file.vue index 0dd11e07..cba89530 100644 --- a/src/views/traceManage/pcap/file.vue +++ b/src/views/traceManage/pcap/file.vue @@ -5,7 +5,7 @@ import { SizeType } from 'ant-design-vue/es/config-provider'; import { ColumnsType } from 'ant-design-vue/es/table'; import { Modal, message } from 'ant-design-vue/es'; import { parseDateToStr } from '@/utils/date-utils'; -import { getNeFile, listNeFiles } from '@/api/tool/neFile'; +import { getNeDirZip, getNeFile, listNeFiles } from '@/api/tool/neFile'; import { RESULT_CODE_SUCCESS } from '@/constants/result-constants'; import ViewDrawer from '@/views/logManage/neFile/components/ViewDrawer.vue'; import useNeInfoStore from '@/store/modules/neinfo'; @@ -79,7 +79,7 @@ let tableColumns: ColumnsType = reactive([ if (!opt.value) return ''; return parseDateToStr(opt.value * 1000); }, - width: 150, + width: 200, }, { title: t('views.logManage.neFile.fileName'), @@ -168,6 +168,45 @@ function fnDownloadFile(row: Record) { }); } +/**信息文件下载 */ +function fnDownloadFileZIP(row: Record) { + if (downLoading.value) return; + Modal.confirm({ + title: t('common.tipTitle'), + content: t('views.logManage.neFile.downTipZip', { fileName: row.fileName }), + onOk() { + downLoading.value = true; + const hide = message.loading(t('common.loading'), 0); + getNeDirZip({ + neType: queryParams.neType, + neId: queryParams.neId, + path: `${queryParams.path}/${row.fileName}`, + delTemp: true, + }) + .then(res => { + if (res.code === RESULT_CODE_SUCCESS) { + message.success({ + content: t('common.msgSuccess', { + msg: t('common.downloadText'), + }), + duration: 2, + }); + saveAs(res.data, `${row.fileName}.zip`); + } else { + message.error({ + content: t('views.logManage.neFile.downTipErr'), + duration: 2, + }); + } + }) + .finally(() => { + hide(); + downLoading.value = false; + }); + }, + }); +} + /**tmp目录下,UPF标准版内部输出目录 */ let tmp = ref(false); @@ -386,16 +425,6 @@ onMounted(() => {