diff --git a/internal/config/config.go b/internal/config/config.go index 9cefaf6..9e45038 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -19,6 +19,7 @@ type Config struct { LogDir string `json:"log_dir,omitempty"` MediaRepoPath string `json:"media_repo_path,omitempty"` // explicit import-only source; not used for runtime rendering AlarmRetentionDays int `json:"alarm_retention_days"` // auto-delete alarms older than N days, 0=keep forever + CompanyName string `json:"company_name,omitempty"` DeviceAliases map[string]string `json:"device_aliases,omitempty"` path string } diff --git a/internal/web/ui.go b/internal/web/ui.go index b7417cb..054d0e5 100644 --- a/internal/web/ui.go +++ b/internal/web/ui.go @@ -116,6 +116,7 @@ type PageData struct { StaleCount int SystemAlarmRetention int SystemConcurrency int + SystemCompanyName string AlarmFilterDevices []string AlarmFilterRuleTypes []string SelectedAlarmDevice string @@ -879,6 +880,11 @@ func (u *UI) Routes() (chi.Router, error) { func (u *UI) render(w http.ResponseWriter, r *http.Request, content string, data PageData) { data.Version = version data.Year = time.Now().Year() + if u.cfg != nil { + if data.SystemCompanyName == "" { + data.SystemCompanyName = u.cfg.CompanyName + } + } if u.alarmCollector != nil { data.UnacknowledgedAlarmCount = u.alarmCollector.GetUnacknowledgedCount() } @@ -4283,32 +4289,35 @@ func (u *UI) renderSystemPage(w http.ResponseWriter, r *http.Request, status int } if u.cfg != nil { data.SystemAlarmRetention = u.cfg.AlarmRetentionDays + data.SystemCompanyName = u.cfg.CompanyName } u.render(w, r, "system", data) } func (u *UI) actionSystemConfig(w http.ResponseWriter, r *http.Request) { _ = r.ParseForm() + changed := false if days, err := strconv.Atoi(strings.TrimSpace(r.FormValue("alarm_retention_days"))); err == nil && days >= 0 { if u.alarmCollector != nil { u.alarmCollector.SetRetention(days) go u.alarmCollector.RunCleanup() } - // Write back to config file - if u.cfg != nil && strings.TrimSpace(u.configPath) != "" { + if u.cfg != nil { u.cfg.AlarmRetentionDays = days - if data, err := json.MarshalIndent(u.cfg, "", " "); err == nil { - os.WriteFile(u.configPath, data, 0o644) - } } - msg := "告警保留已设为 " + strconv.Itoa(days) + " 天" - if days == 0 { - msg = "告警将永久保留" - } - u.renderSystemPage(w, r, http.StatusOK, msg, "") - return + changed = true } - u.renderSystemPage(w, r, http.StatusBadRequest, "", "请输入有效的保留天数") + company := strings.TrimSpace(r.FormValue("company_name")) + if company != "" && u.cfg != nil { + u.cfg.CompanyName = company + changed = true + } + if changed && u.cfg != nil && strings.TrimSpace(u.configPath) != "" { + if data, err := json.MarshalIndent(u.cfg, "", " "); err == nil { + os.WriteFile(u.configPath, data, 0o644) + } + } + u.renderSystemPage(w, r, http.StatusOK, "配置已保存", "") } func (u *UI) actionSystemDBRestore(w http.ResponseWriter, r *http.Request) { diff --git a/internal/web/ui/templates/layout.html b/internal/web/ui/templates/layout.html index 199d8c7..a2fcdd3 100644 --- a/internal/web/ui/templates/layout.html +++ b/internal/web/ui/templates/layout.html @@ -57,7 +57,7 @@ 专家 -
北京泰奥理科技有限公司
+
{{if .SystemCompanyName}}{{.SystemCompanyName}}{{else}}SafeSight{{end}}
© {{.Year}} V{{.Version}}
diff --git a/internal/web/ui/templates/system.html b/internal/web/ui/templates/system.html index 8dda8e2..c1eda83 100644 --- a/internal/web/ui/templates/system.html +++ b/internal/web/ui/templates/system.html @@ -42,6 +42,7 @@
+
diff --git a/safesightd-linux-arm64 b/safesightd-linux-arm64 index f8504b7..9dfddf1 100644 Binary files a/safesightd-linux-arm64 and b/safesightd-linux-arm64 differ