feat: 看板页面添加告警覆盖层勾选,下发时自动应用

This commit is contained in:
tian 2026-07-27 16:12:24 +08:00
parent 6f8d4e8c93
commit 6abfa7024b
5 changed files with 40 additions and 17 deletions

View File

@ -306,8 +306,9 @@ func (r *FeatureRegistry) ValidateFeatureKeys(keys []string) error {
// AutoConfigRequest is a single device's configuration intent from the console.
type AutoConfigRequest struct {
DeviceID string `json:"device_id"`
Features []string `json:"features"` // feature keys: "face", "shoe", ...
SourceNames []string `json:"source_names"` // assigned video source names
Features []string `json:"features"`
SourceNames []string `json:"source_names"`
Overlays []string `json:"overlays,omitempty"`
}
// AutoConfigResult reports what happened for a single device.
@ -470,7 +471,7 @@ func (s *AutoConfigService) BuildPipeline(req AutoConfigRequest, deploy bool) (*
}
if !deploy {
preview, err := s.preview.RenderDeviceAssignment(req.DeviceID)
preview, err := s.preview.RenderDeviceAssignment(req.DeviceID, req.Overlays)
if err != nil {
result.Error = fmt.Sprintf("配置渲染失败: %v", err)
return result, fmt.Errorf(result.Error)

View File

@ -212,7 +212,7 @@ func (s *ConfigPreviewService) BuildProfileEditorForDeviceAssignment(deviceID st
return editor, assignment, nil
}
func (s *ConfigPreviewService) RenderDeviceAssignment(deviceID string) (*ConfigPreviewResult, error) {
func (s *ConfigPreviewService) RenderDeviceAssignment(deviceID string, overlays ...[]string) (*ConfigPreviewResult, error) {
editor, assignment, err := s.BuildProfileEditorForDeviceAssignment(deviceID)
if err != nil {
return nil, err
@ -224,28 +224,20 @@ func (s *ConfigPreviewService) RenderDeviceAssignment(deviceID string) (*ConfigP
if strings.TrimSpace(templateName) == "" {
templateName = editor.RawTemplateName()
}
var ol []string
if len(overlays) > 0 {
ol = overlays[0]
}
return s.RenderProfileEditor(*editor, ConfigPreviewRequest{
Template: templateName,
Profile: assignment.ProfileName,
ConfigID: "assignment_" + deviceID,
ConfigVersion: time.Now().Format("20060102.150405"),
DeviceID: deviceID,
Overlays: s.listAutoOverlays(),
Overlays: ol,
})
}
func (s *ConfigPreviewService) listAutoOverlays() []string {
// Auto-apply overlays whose name starts with "production_"
var out []string
overlays, _ := s.assets.ListOverlays()
for _, o := range overlays {
if strings.HasPrefix(o.Name, "production_") {
out = append(out, o.Name)
}
}
return out
}
func profileOverlayNames(raw map[string]any) []string {
items, _ := raw["overlays"].([]any)
if len(items) == 0 {

View File

@ -1200,6 +1200,14 @@ func (u *UI) pageConsole(w http.ResponseWriter, r *http.Request) {
}
// Build console device data
var allOverlays []ConsoleOverlay
if u.preview != nil {
if overlays, err := u.preview.ListOverlayAssets(); err == nil {
for _, o := range overlays {
allOverlays = append(allOverlays, ConsoleOverlay{Name: o.Name, Description: o.Description})
}
}
}
var consoleDevices []ConsoleDeviceData
for _, dev := range devices {
if dev == nil {
@ -1275,6 +1283,7 @@ func (u *UI) pageConsole(w http.ResponseWriter, r *http.Request) {
MaxUnits: maxUnits,
Channels: channels,
Features: features,
Overlays: allOverlays,
Cameras: cameras,
})
}
@ -1369,6 +1378,7 @@ func (u *UI) actionConsoleSave(w http.ResponseWriter, r *http.Request) {
DeviceID: dev.DeviceID,
Features: features,
SourceNames: sources,
Overlays: cleanFormList(r.Form["device_"+dev.DeviceID+"_overlay"]),
})
}
@ -6178,11 +6188,18 @@ type ConsoleDeviceData struct {
MaxUnits int
Channels []ConsoleChannel
Features []ConsoleFeature
Overlays []ConsoleOverlay
Cameras []string
Busy bool
BusyMsg string
}
type ConsoleOverlay struct {
Name string
Description string
Enabled bool
}
type ConsoleChannel struct {
Name string
Display string

View File

@ -68,6 +68,19 @@
{{end}}
</table>
</div>
{{if $cd.Overlays}}
<div class="console-section">
<div class="console-section-title">告警覆盖层</div>
<table class="console-feature-table">
{{range $o := $cd.Overlays}}
<tr>
<td class="console-feature-check"><input type="checkbox" name="device_{{$cd.Device.DeviceID}}_overlay" value="{{$o.Name}}"{{if $o.Enabled}} checked{{end}}></td>
<td class="console-feature-label" title="{{$o.Description}}">{{$o.Name}}</td>
</tr>
{{end}}
</table>
</div>
{{end}}
<div class="console-section">
<div class="console-section-title">设备负载</div>
<div class="console-metrics">

Binary file not shown.