feat: 公司名称配置项,显示在侧边栏底部
This commit is contained in:
parent
2beac76088
commit
9a5313416a
@ -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
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -57,7 +57,7 @@
|
||||
<span class="mode-track"><span class="mode-thumb"></span></span>
|
||||
<span class="mode-label mode-label-right">专家</span>
|
||||
</div>
|
||||
<div>北京泰奥理科技有限公司</div>
|
||||
<div>{{if .SystemCompanyName}}{{.SystemCompanyName}}{{else}}SafeSight{{end}}</div>
|
||||
<div>© {{.Year}} V{{.Version}}</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
@ -42,6 +42,7 @@
|
||||
<form method="post" action="/system/config">
|
||||
<div class="field-grid">
|
||||
<label><span>告警保留天数</span><input type="number" name="alarm_retention_days" value="{{.SystemAlarmRetention}}" min="0" /><div class="form-hint">0=永久保留</div></label>
|
||||
<label><span>公司名称</span><input type="text" name="company_name" value="{{.SystemCompanyName}}" placeholder="将在页面底部显示" /></label>
|
||||
</div>
|
||||
<div class="actions" style="margin-top:12px">
|
||||
<button type="submit" class="secondary">保存配置</button>
|
||||
|
||||
Binary file not shown.
Loading…
Reference in New Issue
Block a user