diff --git a/internal/web/ui.go b/internal/web/ui.go index 4e85412..269511f 100644 --- a/internal/web/ui.go +++ b/internal/web/ui.go @@ -119,6 +119,9 @@ type PageData struct { SystemCompanyName string AlarmFilterDevices []string AlarmFilterRuleTypes []string + AlarmDeviceNames map[string]string + AlarmDeviceIPs map[string]string + AlarmChannelSources map[string]string SelectedAlarmDevice string SelectedAlarmRuleType string DeviceMetrics []DeviceMetric @@ -2573,6 +2576,27 @@ func (u *UI) pageAlarms(w http.ResponseWriter, r *http.Request) { data.AlarmFilterDevices = u.alarmCollector.GetDistinctDeviceIDs() data.AlarmFilterRuleTypes = u.alarmCollector.GetDistinctRuleTypes() } + // Build device name/IP maps and channel→source map for template + data.AlarmDeviceNames = map[string]string{} + data.AlarmDeviceIPs = map[string]string{} + data.AlarmChannelSources = map[string]string{} + for _, dev := range data.Devices { + if dev != nil { + data.AlarmDeviceNames[dev.DeviceID] = dev.DisplayName() + data.AlarmDeviceIPs[dev.DeviceID] = dev.IP + } + } + if u.preview != nil { + if assignments, err := u.preview.ListDeviceAssignments(); err == nil { + for _, a := range assignments { + for _, ref := range a.RecognitionUnits { + if unit, err := u.preview.GetRecognitionUnit(ref); err == nil && unit != nil && unit.VideoSourceRef != "" { + data.AlarmChannelSources[unit.Name] = unit.VideoSourceRef + } + } + } + } + } // Calculate total pages and build page list: 1, ..., cur-2, cur-1, cur, cur+1, cur+2, ..., N if data.TotalAlarmCount > 0 { data.TotalAlarmPages = (data.TotalAlarmCount + perPage - 1) / perPage @@ -2722,7 +2746,7 @@ func (u *UI) apiAlarmExport(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="alarms_%s_%s.csv"`, from, to)) w.Header().Set("Cache-Control", "no-cache") w.Write([]byte("\xef\xbb\xbf")) - w.Write([]byte("设备名,IP,视频源,规则,目标,状态,时间\n")) + w.Write([]byte("时间,设备名,IP,视频源,规则,目标,状态\n")) for _, a := range records { devName := a.DeviceID devIP := "" @@ -2745,9 +2769,9 @@ func (u *UI) apiAlarmExport(w http.ResponseWriter, r *http.Request) { } } fmt.Fprintf(w, "%s,%s,%s,%s,%s,%s,%s\n", - escapeCSV(devName), escapeCSV(devIP), escapeCSV(sourceName), + escapeCSV(a.Timestamp), escapeCSV(devName), escapeCSV(devIP), escapeCSV(sourceName), escapeCSV(alarmRuleLabel(a.RuleName)), escapeCSV(a.ObjectLabel), - escapeCSV(alarmStatusLabel(a.Status)), escapeCSV(a.Timestamp)) + escapeCSV(alarmStatusLabel(a.Status))) } } diff --git a/internal/web/ui/templates/alarms.html b/internal/web/ui/templates/alarms.html index b9d5821..35f98c6 100644 --- a/internal/web/ui/templates/alarms.html +++ b/internal/web/ui/templates/alarms.html @@ -9,7 +9,7 @@ {{end}} @@ -59,9 +59,10 @@ {{.Timestamp}} - {{shortID .DeviceID}} + {{index $.AlarmDeviceNames .DeviceID}} +
{{index $.AlarmDeviceIPs .DeviceID}}
- {{.Channel}} + {{index $.AlarmChannelSources .Channel}} {{ruleLabel .RuleName}} diff --git a/safesightd-linux-arm64 b/safesightd-linux-arm64 index 43a2e27..5fc25f4 100644 Binary files a/safesightd-linux-arm64 and b/safesightd-linux-arm64 differ