From 16f9ef9bef7a5d5484eda87fb1766e9fa32f3fb2 Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Fri, 24 Jul 2026 12:09:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AE=BE=E5=A4=87=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E5=B7=A5=E5=85=B7=E6=A0=8F=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=B8=85=E7=90=86=E7=A6=BB=E7=BA=BF=E8=AE=BE=E5=A4=87=E6=8C=89?= =?UTF-8?q?=E9=92=AE=EF=BC=88=E6=97=A0=E5=88=B7=E6=96=B0=E5=8B=BE=E9=80=89?= =?UTF-8?q?+=E6=89=B9=E9=87=8F=E6=93=8D=E4=BD=9C=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E5=85=A5=E5=8F=A3=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/web/ui.go | 21 +++++++++------ internal/web/ui/templates/devices.html | 35 ++++++++++++------------- safesightd-linux-arm64 | Bin 15270050 -> 15270050 bytes 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/internal/web/ui.go b/internal/web/ui.go index 9b963b5..1cdfe33 100644 --- a/internal/web/ui.go +++ b/internal/web/ui.go @@ -1595,21 +1595,21 @@ func (u *UI) actionDevicesCleanupOffline(w http.ResponseWriter, r *http.Request) continue } dev := deviceMap[id] - if dev == nil || dev.Online { - continue // only clean offline devices + if dev != nil && dev.Online { + continue // skip online devices } if strings.TrimSpace(u.dbPath) != "" { if store, err := storage.OpenSQLite(u.dbPath); err == nil { db := store.DB() - db.Exec("DELETE FROM device_assignments WHERE device_id = ?", dev.DeviceID) - db.Exec("DELETE FROM device_config_state WHERE device_id = ?", dev.DeviceID) - db.Exec("DELETE FROM device_features WHERE device_id = ?", dev.DeviceID) - db.Exec("DELETE FROM config_versions WHERE device_id = ?", dev.DeviceID) - db.Exec("DELETE FROM devices WHERE device_id = ?", dev.DeviceID) + db.Exec("DELETE FROM device_assignments WHERE device_id = ?", id) + db.Exec("DELETE FROM device_config_state WHERE device_id = ?", id) + db.Exec("DELETE FROM device_features WHERE device_id = ?", id) + db.Exec("DELETE FROM config_versions WHERE device_id = ?", id) + db.Exec("DELETE FROM devices WHERE device_id = ?", id) store.Close() + deleted++ } } - deleted++ } http.Redirect(w, r, "/devices?msg="+urlQueryEscape(fmt.Sprintf("已清理 %d 台离线设备", deleted)), http.StatusFound) } @@ -1688,6 +1688,11 @@ func (u *UI) actionDiscoverySearch(w http.ResponseWriter, r *http.Request) { func (u *UI) actionDevicesBatchAction(w http.ResponseWriter, r *http.Request) { _ = r.ParseForm() action := strings.TrimSpace(r.FormValue("action")) + // cleanup_offline handles device IDs directly (may include DB-only offline devices) + if action == "cleanup_offline" { + u.actionDevicesCleanupOffline(w, r) + return + } deviceIDs := filterSelectedDeviceIDs(u.registry.GetDevices(), r.Form["device_id"]) if len(deviceIDs) == 0 { u.render(w, r, "devices", u.deviceOverviewPageData(r, nil, "请先选择设备")) diff --git a/internal/web/ui/templates/devices.html b/internal/web/ui/templates/devices.html index 945832d..cac436a 100644 --- a/internal/web/ui/templates/devices.html +++ b/internal/web/ui/templates/devices.html @@ -43,15 +43,14 @@ + {{$allOffline := true}}{{range .SelectedDevices}}{{if .Online}}{{$allOffline = false}}{{end}}{{end}} + {{if $allOffline}} + + {{end}} 下发设备分配 清空选择 - {{$allOffline := true}}{{range .SelectedDevices}}{{if .Online}}{{$allOffline = false}}{{end}}{{end}} -
- {{range .SelectedDevices}}{{end}} - -
@@ -129,6 +128,11 @@
+ + {{/* Cleanup bar only shown by JS when all selected are offline */}} +