perf: 优化日志保留与分页查询
- 降低普通只读请求的日志写入并保留敏感 GET 审计 - 增加数据库分批清理、时间索引和文件滚动容量上限 - 增加近 30 天筛选、稳定倒序和分页大小限制
This commit is contained in:
@@ -37,7 +37,7 @@ const props = defineProps({
|
||||
},
|
||||
});
|
||||
|
||||
const emit = defineEmits(['search', 'buttonClick']);
|
||||
const emit = defineEmits(['search', 'buttonClick', 'reset']);
|
||||
|
||||
const searchValue = ref('');
|
||||
|
||||
@@ -70,6 +70,7 @@ const handleSearch = () => {
|
||||
|
||||
const handleReset = () => {
|
||||
searchValue.value = '';
|
||||
emit('reset');
|
||||
emit('search', '');
|
||||
};
|
||||
|
||||
|
||||
@@ -10,5 +10,8 @@
|
||||
"actionParams": "ActionParams",
|
||||
"actionBody": "ActionBody",
|
||||
"status": "Status",
|
||||
"created": "Created"
|
||||
"created": "Created",
|
||||
"searchPlaceholder": "Search action name",
|
||||
"startDate": "Start date",
|
||||
"endDate": "End date"
|
||||
}
|
||||
|
||||
@@ -10,5 +10,8 @@
|
||||
"actionParams": "操作请求参数",
|
||||
"actionBody": "操作请求body",
|
||||
"status": "操作状态 1 成功 9 失败",
|
||||
"created": "操作时间"
|
||||
"created": "操作时间",
|
||||
"searchPlaceholder": "搜索操作名称",
|
||||
"startDate": "开始日期",
|
||||
"endDate": "结束日期"
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@ import type { FormInstance } from 'element-plus';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { ElTable, ElTableColumn } from 'element-plus';
|
||||
import { formatDate } from '@easyflow/utils';
|
||||
|
||||
import { ElDatePicker, ElTable, ElTableColumn } from 'element-plus';
|
||||
|
||||
import HeaderSearch from '#/components/headerSearch/HeaderSearch.vue';
|
||||
import ListPageShell from '#/components/page/ListPageShell.vue';
|
||||
@@ -14,12 +16,45 @@ import SysLogModal from './SysLogModal.vue';
|
||||
|
||||
const pageDataRef = ref();
|
||||
const saveDialog = ref();
|
||||
const DEFAULT_RANGE_DAYS = 30;
|
||||
const timeRange = ref<string[]>(createDefaultTimeRange());
|
||||
const actionName = ref('');
|
||||
const initialQueryParams = buildTimeQuery(timeRange.value);
|
||||
|
||||
function createDefaultTimeRange(): string[] {
|
||||
const end = new Date();
|
||||
const start = new Date(end);
|
||||
start.setDate(start.getDate() - (DEFAULT_RANGE_DAYS - 1));
|
||||
return [formatDate(start), formatDate(end)];
|
||||
}
|
||||
|
||||
function buildTimeQuery(range: string[]) {
|
||||
return {
|
||||
createdStart: range?.[0] ? `${range[0]} 00:00:00` : undefined,
|
||||
createdEnd: range?.[1] ? `${range[1]} 23:59:59` : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
function applyQuery() {
|
||||
pageDataRef.value?.setQuery({
|
||||
actionName: actionName.value || undefined,
|
||||
...buildTimeQuery(timeRange.value),
|
||||
});
|
||||
}
|
||||
|
||||
const handleSearch = (params: string) => {
|
||||
pageDataRef.value.setQuery({ actionName: params, isQueryOr: true });
|
||||
actionName.value = params.trim();
|
||||
applyQuery();
|
||||
};
|
||||
const handleTimeRangeChange = () => {
|
||||
applyQuery();
|
||||
};
|
||||
const handleFilterReset = () => {
|
||||
timeRange.value = createDefaultTimeRange();
|
||||
};
|
||||
function reset(formEl?: FormInstance) {
|
||||
formEl?.resetFields();
|
||||
pageDataRef.value.setQuery({});
|
||||
applyQuery();
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -28,12 +63,30 @@ function reset(formEl?: FormInstance) {
|
||||
<SysLogModal ref="saveDialog" @reload="reset" />
|
||||
<ListPageShell>
|
||||
<template #filters>
|
||||
<HeaderSearch @search="handleSearch" />
|
||||
<HeaderSearch
|
||||
:search-placeholder="$t('sysLog.searchPlaceholder')"
|
||||
@reset="handleFilterReset"
|
||||
@search="handleSearch"
|
||||
>
|
||||
<template #middle>
|
||||
<ElDatePicker
|
||||
v-model="timeRange"
|
||||
class="w-full sm:w-[280px]"
|
||||
type="daterange"
|
||||
unlink-panels
|
||||
value-format="YYYY-MM-DD"
|
||||
:start-placeholder="$t('sysLog.startDate')"
|
||||
:end-placeholder="$t('sysLog.endDate')"
|
||||
@change="handleTimeRangeChange"
|
||||
/>
|
||||
</template>
|
||||
</HeaderSearch>
|
||||
</template>
|
||||
<PageData
|
||||
ref="pageDataRef"
|
||||
page-url="/api/v1/sysLog/page"
|
||||
:page-size="10"
|
||||
:extra-query-params="initialQueryParams"
|
||||
>
|
||||
<template #default="{ pageList }">
|
||||
<ElTable :data="pageList" border>
|
||||
|
||||
Reference in New Issue
Block a user