From 697505fdf26d81dcce42cc0958efd82f999a185a Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Wed, 6 May 2026 16:45:01 +0800 Subject: [PATCH] feat: merge audit records into diagnostics page, remove redundant sections --- internal/web/ui.go | 14 +++- internal/web/ui/templates/diagnostics.html | 79 ++++++++++++++++++---- internal/web/ui_test.go | 2 +- 3 files changed, 78 insertions(+), 17 deletions(-) diff --git a/internal/web/ui.go b/internal/web/ui.go index a20beb6..5c8049f 100644 --- a/internal/web/ui.go +++ b/internal/web/ui.go @@ -1418,7 +1418,19 @@ func (u *UI) actionModelSync(w http.ResponseWriter, r *http.Request) { } func (u *UI) pageDiagnostics(w http.ResponseWriter, r *http.Request) { - u.render(w, r, "diagnostics", PageData{Title: "日志审计", Devices: u.registry.GetDevices()}) + data := PageData{Title: "日志审计", Devices: u.registry.GetDevices()} + if u.auditRepo != nil { + items, err := u.auditRepo.List() + if err != nil { + data.Error = err.Error() + } else { + data.AuditEntries = items + } + } + if len(data.AuditEntries) == 0 && u.tasks != nil { + data.Tasks = u.tasks.ListTasks() + } + u.render(w, r, "diagnostics", data) } func (u *UI) pageResources(w http.ResponseWriter, r *http.Request) { diff --git a/internal/web/ui/templates/diagnostics.html b/internal/web/ui/templates/diagnostics.html index 6d48b40..997600e 100644 --- a/internal/web/ui/templates/diagnostics.html +++ b/internal/web/ui/templates/diagnostics.html @@ -2,15 +2,74 @@
-

日志审计

-
按设备查看日志与运行指标,并进入审计记录和高级调试。
+

{{icon "audit"}}审计记录

- 高级调试 +
+
+ {{if .AuditEntries}} + + + + + + + + + + + + {{range .AuditEntries}} + + + + + + + + {{end}} + +
动作目标任务配置结果
{{auditActionLabel .Action}}{{.TargetID}}{{if auditField .DetailsJSON "task_id"}}{{auditField .DetailsJSON "task_id"}}{{else}}-{{end}}{{if auditField .DetailsJSON "profile"}}{{auditField .DetailsJSON "profile"}}{{else if auditField .DetailsJSON "config_id"}}{{auditField .DetailsJSON "config_id"}}{{else}}-{{end}}{{if auditField .DetailsJSON "status"}}{{auditStatusLabel (auditField .DetailsJSON "status")}}{{else}}{{.Actor}}{{end}}
+ {{else}} + + + + + + + + + + + + {{range .Tasks}} + + + + + + + + {{else}} + + + + {{end}} + +
类型任务目标设备数结果说明
+ {{taskGroupLabel .Type}} +
{{taskActionLabel .Type}}
+
{{.ID}}
{{len .DeviceIDs}} 台{{taskStatusLabel .Status}}{{if .Payload}}已记录任务参数{{else}}无附加参数{{end}}
+
+
暂无审计记录
+
当前后台还没有记录到任何任务或设备操作。
+
+
+ {{end}}
-

日志分析

+

{{icon "logs"}}日志分析

@@ -33,20 +92,10 @@ {{else}} - + {{end}}
暂无设备。请先在“新增设备”页扫描或手动添加。
暂无设备。请先在“设备”页扫描或手动添加。
- -
-
-
-

审计记录

-
- 进入审计记录 -
-
查看任务执行、设备操作和配置下发相关的审计记录。
-
{{end}} diff --git a/internal/web/ui_test.go b/internal/web/ui_test.go index 96e78f2..27eb83f 100644 --- a/internal/web/ui_test.go +++ b/internal/web/ui_test.go @@ -2068,7 +2068,7 @@ func TestUI_LogAuditPageRendersLogAndMetricLinks(t *testing.T) { t.Fatalf("expected 200, got %d: %s", rr.Code, rr.Body.String()) } body := rr.Body.String() - for _, want := range []string{"日志审计", "日志分析", "审计记录", "入口识别节点", "诊断日志", "运行指标", "高级调试"} { + for _, want := range []string{"日志分析", "审计记录", "入口识别节点", "诊断日志", "运行指标"} { if !strings.Contains(body, want) { t.Fatalf("expected diagnostics HTML to contain %q", want) }