diff --git a/internal/web/ui.go b/internal/web/ui.go index 702997e..8103146 100644 --- a/internal/web/ui.go +++ b/internal/web/ui.go @@ -662,6 +662,7 @@ func (u *UI) Routes() (chi.Router, error) { r.Get("/diagnostics", u.pageDiagnostics) r.Get("/alarms", u.pageAlarms) r.Get("/monitor", u.pageMonitor) + r.Get("/api/monitor/channels", u.apiMonitorChannels) r.Get("/recognition", u.pageRecognition) r.Get("/logs", u.pageLogs) @@ -3869,3 +3870,24 @@ func (u *UI) pageMonitor(w http.ResponseWriter, r *http.Request) { u.ensureDevicesLoaded() u.render(w, r, "monitor", PageData{Title: "视频监控", Devices: u.registry.GetDevices()}) } + +func (u *UI) apiMonitorChannels(w http.ResponseWriter, r *http.Request) { + deviceID := r.URL.Query().Get("device_id") + if deviceID == "" { + http.Error(w, "missing device_id", http.StatusBadRequest) + return + } + dev, ok := u.findDevice(deviceID) + if !ok { + http.Error(w, "device not found", http.StatusNotFound) + return + } + body, code, err := u.agent.Do("GET", dev.IP, dev.AgentPort, "/v1/preview/channels", nil) + if err != nil { + http.Error(w, err.Error(), http.StatusBadGateway) + return + } + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(code) + w.Write(body) +} diff --git a/internal/web/ui/templates/monitor.html b/internal/web/ui/templates/monitor.html index 40b7c3d..250f9bd 100644 --- a/internal/web/ui/templates/monitor.html +++ b/internal/web/ui/templates/monitor.html @@ -19,10 +19,9 @@ (function() { var grid = document.getElementById("channels-grid"); - function loadChannels(deviceId, deviceIP, agentPort) { - var url = "http://" + deviceIP + ":" + agentPort + "/v1/preview/channels"; + function loadChannels(deviceId) { grid.innerHTML = '
| 设备 | 地址 | 操作 |
|---|---|---|
| {{.DisplayName}} | {{.IP}}:{{.AgentPort}} | |
| {{.DisplayName}} | {{.IP}}:{{.AgentPort}} |