日志文件下载功能,支持多实例

This commit is contained in:
2026-01-29 19:38:11 +08:00
parent 6e269ac987
commit 6ae5e62d42
3 changed files with 132 additions and 113 deletions
+39 -33
View File
@@ -3,41 +3,47 @@ import { useMessage } from '/@/hooks/web/useMessage';
const { createConfirm } = useMessage();
enum Api {
logFilesList = '/health-system/service/log/files',
logFilesDelete = '/health-system/service/log/file/delete',
logFilesLDown = '/health-system/service/log/file/down',
logFilesList = '/service/log/files',
logFilesDelete = '/service/log/file/delete',
logFilesLDown = '/service/log/file/down',
}
export const logFilesListApi = (params: any) => defHttp.get({ url: Api.logFilesList, params: params });
export const logFilesListApi = (params: any) => defHttp.get({ url: '/' + params.service + Api.logFilesList, params: params });
//文档删除
export const logFilesDeleteApi = (params: any, handleSuccess: Function) => {
createConfirm({
iconType: 'warning',
title: '确认删除',
content: '是否删除数据',
okText: '确认',
cancelText: '取消',
onOk: () => {
return defHttp
.get(
{
url: Api.logFilesDelete,
params,
},
{ joinParamsToUrl: true }
)
.then(() => {
handleSuccess();
});
},
});
createConfirm({
iconType: 'warning',
title: '确认删除',
content: '是否删除数据',
okText: '确认',
cancelText: '取消',
onOk: () => {
const { service } = params;
const url = '/' + service + Api.logFilesDelete;
return defHttp
.get(
{
url: url,
params,
},
{ joinParamsToUrl: true }
)
.then(() => {
handleSuccess();
});
},
});
};
export const logFilesLDownApi = (params: any) => {
const { service } = params;
const url = '/' + service + Api.logFilesLDown;
return defHttp.get(
{
url: url,
params: params,
responseType: 'blob',
},
{ isTransformResponse: false }
);
};
export const logFilesLDownApi = (params: any) =>
defHttp.get(
{
url: Api.logFilesLDown,
params: params,
responseType: 'blob',
},
{ isTransformResponse: false }
);
+24 -6
View File
@@ -1,12 +1,30 @@
import { BasicColumn, FormSchema } from '/@/components/Table';
export const columns: BasicColumn[] = [
{
title: '文件名',
dataIndex: 'fileName',
align: 'center',
width: 100,
},
{
title: '文件名',
dataIndex: 'fileName',
align: 'center',
width: 100,
},
{
title: '最新修改时间',
dataIndex: 'lastModified',
align: 'center',
width: 100,
},
{
title: '文件大小',
dataIndex: 'fileSize',
align: 'center',
width: 100,
},
{
title: '实例地址',
dataIndex: 'instance',
align: 'center',
width: 100,
},
];
export const searchFormSchema: FormSchema[] = [
{
+69 -74
View File
@@ -1,79 +1,74 @@
<template>
<BasicTable @register="registerTable">
<template #action="{ record }">
<TableAction :actions="getTableAction(record)" />
</template>
</BasicTable>
<BasicTable @register="registerTable">
<template #action="{ record }">
<TableAction :actions="getTableAction(record)" />
</template>
</BasicTable>
</template>
<script setup lang="ts">
import BasicTable from '/@/components/Table/src/BasicTable.vue';
import { logFilesDeleteApi, logFilesLDownApi, logFilesListApi } from '/@/views/monitor/filelog/filelog.api';
import { columns, searchFormSchema } from '/@/views/monitor/filelog/filelog.data';
import { useListPage } from '/@/hooks/system/useListPage';
import { TableAction } from '/@/components/Table';
import { ref } from 'vue';
<script setup lang="ts" name="sys-log">
import BasicTable from '/@/components/Table/src/BasicTable.vue';
import { logFilesDeleteApi, logFilesLDownApi, logFilesListApi } from '/@/views/monitor/filelog/filelog.api';
import { columns, searchFormSchema } from '/@/views/monitor/filelog/filelog.data';
import { useListPage } from '/@/hooks/system/useListPage';
import { TableAction } from '/@/components/Table';
const data = ref(['a.txt']);
const { tableContext } = useListPage({
tableProps: {
api: logFilesListApi,
canResize: false,
columns,
afterFetch: (v) => {
return v.map((item) => {
return {
fileName: item,
};
});
},
formConfig: {
labelWidth: 120,
schemas: searchFormSchema,
},
actionColumn: {
fixed: 'right',
},
},
});
const [registerTable, { reload, getForm }] = tableContext;
function getTableAction(record: Recordable) {
return [
{
label: '删除',
onClick: hanldeDelete.bind(null, record),
},
{
label: '下载',
onClick: hanldeDownload.bind(null, record),
},
];
}
function hanldeDelete(record) {
const params = {
filename: record.fileName,
service: getForm().getFieldsValue().service,
};
logFilesDeleteApi(params, reload);
}
async function hanldeDownload(record) {
const params = {
filename: record.fileName,
service: getForm().getFieldsValue().service,
};
try {
const v = await logFilesLDownApi(params);
const url = window.URL.createObjectURL(v);
const link = document.createElement('a');
link.style.display = 'none';
link.href = url;
link.download = record.fileName;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
} catch (e) {
console.log(e);
}
const { tableContext } = useListPage({
tableProps: {
api: logFilesListApi,
canResize: false,
columns,
beforeFetch: (params) => {
params.service = getForm().getFieldsValue().service;
return params;
},
formConfig: {
labelWidth: 120,
schemas: searchFormSchema,
},
actionColumn: {
fixed: 'right',
},
},
});
const [registerTable, { reload, getForm }] = tableContext;
function getTableAction(record: Recordable) {
return [
{
label: '删除',
onClick: hanldeDelete.bind(null, record),
},
{
label: '下载',
onClick: hanldeDownload.bind(null, record),
},
];
}
function hanldeDelete(record) {
const params = {
filename: record.fileName,
service: getForm().getFieldsValue().service,
};
logFilesDeleteApi(params, reload);
}
async function hanldeDownload(record) {
const params = {
filename: record.fileName,
service: getForm().getFieldsValue().service,
instance: record.instance,
};
try {
const v = await logFilesLDownApi(params);
const url = window.URL.createObjectURL(v);
const link = document.createElement('a');
link.style.display = 'none';
link.href = url;
link.download = record.fileName;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
} catch (e) {
console.log(e);
}
}
</script>