feat: PCAP历史目录下载为zip

This commit is contained in:
TsMask
2025-03-13 11:05:05 +08:00
parent fec1ee0f68
commit 2678ab3bfb
4 changed files with 88 additions and 22 deletions

View File

@@ -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",

View File

@@ -1200,6 +1200,7 @@ export default {
size: "文件大小",
modifiedTime: "修改时间",
fileName: "文件名称",
downTipZip: "确认将目录 【{fileName}】 下载为ZIP文件?",
downTip: "确认下载文件名为 【{fileName}】 文件?",
downTipErr: "文件获取失败",
dirCd: "进入目录",

View File

@@ -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}`;
}

View File

@@ -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<string, any>) {
});
}
/**信息文件下载 */
function fnDownloadFileZIP(row: Record<string, any>) {
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<boolean>(false);
@@ -386,16 +425,6 @@ onMounted(() => {
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'fileName'">
<a-space :size="8" align="center">
<a-tooltip
v-if="
record.fileType === 'file' && record.fileName.endsWith('.log')
"
>
<template #title>{{ t('common.viewText') }}</template>
<a-button type="link" @click.prevent="fnDrawerOpen(record)">
<template #icon><ProfileOutlined /></template>
</a-button>
</a-tooltip>
<a-button
type="link"
:loading="downLoading"
@@ -405,15 +434,36 @@ onMounted(() => {
<template #icon><DownloadOutlined /></template>
{{ t('common.downloadText') }}
</a-button>
<a-button
type="link"
:loading="downLoading"
@click.prevent="fnDirCD(record.fileName)"
v-if="record.fileType === 'dir'"
@click.prevent="fnDrawerOpen(record)"
v-if="
record.fileType === 'file' && record.fileName.endsWith('.log')
"
>
<template #icon><FolderOutlined /></template>
{{ t('views.logManage.neFile.dirCd') }}
<template #icon><ProfileOutlined /></template>
{{ t('common.viewText') }}
</a-button>
<template v-if="record.fileType === 'dir'">
<a-button
type="link"
:loading="downLoading"
@click.prevent="fnDownloadFileZIP(record)"
>
<template #icon><DownloadOutlined /></template>
{{ t('common.downloadText') }}
</a-button>
<a-button
type="link"
:loading="downLoading"
@click.prevent="fnDirCD(record.fileName)"
>
<template #icon><FolderOutlined /></template>
{{ t('views.logManage.neFile.dirCd') }}
</a-button>
</template>
</a-space>
</template>
</template>