From dd8a887399cd4b3142b379765aed40d15f7a5488 Mon Sep 17 00:00:00 2001 From: engigu Date: Sat, 28 Feb 2026 08:40:14 +0800 Subject: [PATCH] feat: add log page status filter --- internal/controllers/log_controller.go | 4 +++ web/src/api/index.ts | 3 +- web/src/views/dashboard/Dashboard.vue | 2 +- web/src/views/history/History.vue | 42 ++++++++++++++++++++++---- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/internal/controllers/log_controller.go b/internal/controllers/log_controller.go index 760f124..a17a68c 100644 --- a/internal/controllers/log_controller.go +++ b/internal/controllers/log_controller.go @@ -21,6 +21,7 @@ func (lc *LogController) GetLogs(c *gin.Context) { p := utils.ParsePagination(c) taskID, _ := strconv.Atoi(c.DefaultQuery("task_id", "0")) taskName := c.DefaultQuery("task_name", "") + status := c.DefaultQuery("status", "") var logs []models.TaskLog var total int64 @@ -29,6 +30,9 @@ func (lc *LogController) GetLogs(c *gin.Context) { if taskID > 0 { query = query.Where("task_id = ?", taskID) } + if status != "" { + query = query.Where("status = ?", status) + } // 按任务名称过滤 if taskName != "" { diff --git a/web/src/api/index.ts b/web/src/api/index.ts index 5c1a417..858573d 100644 --- a/web/src/api/index.ts +++ b/web/src/api/index.ts @@ -98,12 +98,13 @@ export const api = { results: () => request('/execute/results') }, logs: { - list: (params?: { page?: number; page_size?: number; task_id?: number; task_name?: string }) => { + list: (params?: { page?: number; page_size?: number; task_id?: number; task_name?: string; status?: string }) => { const query = new URLSearchParams() if (params?.page) query.set('page', String(params.page)) if (params?.page_size) query.set('page_size', String(params.page_size)) if (params?.task_id) query.set('task_id', String(params.task_id)) if (params?.task_name) query.set('task_name', params.task_name) + if (params?.status) query.set('status', params.status) return request(`/logs?${query}`) }, get: (id: number) => request(`/logs/${id}`), diff --git a/web/src/views/dashboard/Dashboard.vue b/web/src/views/dashboard/Dashboard.vue index e1e950c..83024b5 100644 --- a/web/src/views/dashboard/Dashboard.vue +++ b/web/src/views/dashboard/Dashboard.vue @@ -27,7 +27,7 @@ const statItems = [ { key: 'envs', label: '环境变量', icon: Variable, route: '/environments' }, { key: 'logs', label: '日志总数', icon: ScrollText, route: '/history' }, { key: 'scheduled', label: '调度注册', icon: Clock, route: '/tasks' }, - { key: 'running', label: '正在运行', icon: Play, route: '/tasks' }, + { key: 'running', label: '正在运行', icon: Play, route: '/history?status=running' }, ] const isDark = ref(document.documentElement.classList.contains('dark')) diff --git a/web/src/views/history/History.vue b/web/src/views/history/History.vue index 82641d0..2d32309 100644 --- a/web/src/views/history/History.vue +++ b/web/src/views/history/History.vue @@ -5,6 +5,7 @@ import { TASK_STATUS, TASK_TYPE } from '@/constants' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import Pagination from '@/components/Pagination.vue' +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import LogViewer from './LogViewer.vue' import { RefreshCw, X, Search, Maximize2, GitBranch, Terminal, @@ -33,6 +34,7 @@ const logs = ref([]) const selectedLog = ref(null) const filterKeyword = ref('') const filterTaskId = ref(undefined) +const filterStatus = ref(undefined) const currentPage = ref(1) const total = ref(0) @@ -60,7 +62,7 @@ const decompressedOutput = computed(() => { async function loadLogs() { try { - const params: { page: number; page_size: number; task_id?: number; task_name?: string } = { + const params: { page: number; page_size: number; task_id?: number; task_name?: string; status?: string } = { page: currentPage.value, page_size: pageSize.value } @@ -70,6 +72,9 @@ async function loadLogs() { if (filterKeyword.value.trim()) { params.task_name = filterKeyword.value.trim() } + if (filterStatus.value && filterStatus.value !== 'all') { + params.status = filterStatus.value + } const response = await api.logs.list(params) logs.value = response.data total.value = response.total @@ -86,6 +91,11 @@ function handleSearch() { }, 300) } +function handleStatusChange() { + currentPage.value = 1 + loadLogs() +} + function handlePageChange(page: number) { currentPage.value = page loadLogs() @@ -278,20 +288,25 @@ function getTaskTypeTitle(type: string) { } onMounted(() => { - // 从 URL 读取 task_id 参数 + // 从 URL 读取参数 const taskIdParam = route.query.task_id if (taskIdParam) { filterTaskId.value = Number(taskIdParam) } + const statusParam = route.query.status + if (statusParam) { + filterStatus.value = String(statusParam) + } loadLogs() }) // 监听路由变化 -watch(() => route.query.task_id, (newTaskId) => { - filterTaskId.value = newTaskId ? Number(newTaskId) : undefined +watch(() => route.query, (newQuery) => { + filterTaskId.value = newQuery.task_id ? Number(newQuery.task_id) : undefined + filterStatus.value = newQuery.status ? String(newQuery.status) : undefined currentPage.value = 1 loadLogs() -}) +}, { deep: true })