fix: default alarm range to past 7 days, '全部' from 2020
This commit is contained in:
parent
ad98dee68f
commit
7a2e82db0d
@ -1912,20 +1912,14 @@ func (u *UI) pageAlarms(w http.ResponseWriter, r *http.Request) {
|
||||
u.ensureDevicesLoaded()
|
||||
data := PageData{Title: "告警中心", Devices: u.registry.GetDevices()}
|
||||
|
||||
// Parse date filter: ?date=2026-05-12 or ?from=...&to=... (default: today)
|
||||
// Parse date filter: default to past 7 days.
|
||||
q := r.URL.Query()
|
||||
today := time.Now().Format("2006-01-02")
|
||||
weekAgo := time.Now().AddDate(0, 0, -7).Format("2006-01-02")
|
||||
from := strings.TrimSpace(q.Get("from"))
|
||||
to := strings.TrimSpace(q.Get("to"))
|
||||
date := strings.TrimSpace(q.Get("date"))
|
||||
if date != "" {
|
||||
from = date
|
||||
to = date
|
||||
}
|
||||
if from == "" {
|
||||
from = today
|
||||
}
|
||||
if to == "" {
|
||||
if from == "" && to == "" {
|
||||
from = weekAgo
|
||||
to = today
|
||||
}
|
||||
// Parse page: ?page=N (default 1), ?per_page=N (default 20)
|
||||
|
||||
@ -1,15 +1,18 @@
|
||||
{{define "alarms"}}
|
||||
<div class="card">
|
||||
<form method="get" action="/ui/alarms" style="display:flex;gap:8px;align-items:center;margin-bottom:12px;flex-wrap:wrap">
|
||||
<input type="date" name="from" value="{{.SelectedFrom}}" style="width:150px;font-size:12px">
|
||||
<form method="get" action="/ui/alarms" style="display:flex;gap:8px;align-items:center;margin-bottom:12px;justify-content:space-between">
|
||||
<span style="display:flex;gap:8px;align-items:center;flex-wrap:wrap">
|
||||
<input type="date" name="from" value="{{.SelectedFrom}}" style="width:140px;font-size:12px">
|
||||
<span class="muted small">至</span>
|
||||
<input type="date" name="to" value="{{.SelectedTo}}" style="width:150px;font-size:12px">
|
||||
<input type="date" name="to" value="{{.SelectedTo}}" style="width:140px;font-size:12px">
|
||||
<button class="btn" style="font-size:12px;padding:4px 12px">筛选</button>
|
||||
<a href="/ui/alarms" class="btn ghost" style="font-size:11px">今天</a>
|
||||
<a href="/ui/alarms?from={{.WeekStart}}&to={{.WeekEnd}}" class="btn ghost" style="font-size:11px">本周</a>
|
||||
<a href="/ui/alarms?from={{.MonthStart}}&to={{.MonthEnd}}" class="btn ghost" style="font-size:11px">本月</a>
|
||||
<a href="/ui/alarms?from=2000-01-01&to=2099-12-31" class="btn ghost" style="font-size:11px">全部</a>
|
||||
<select name="per_page" onchange="this.form.submit()" style="font-size:11px;padding:2px 4px;margin-left:auto">
|
||||
<a href="/ui/alarms?from=2020-01-01&to={{.SelectedTo}}" class="btn ghost" style="font-size:11px">全部</a>
|
||||
</span>
|
||||
<select name="per_page" onchange="this.form.submit()" style="font-size:11px;padding:2px 4px;width:90px;flex-shrink:0">
|
||||
<option value="10" {{if eq .PerPage 10}}selected{{end}}>10条/页</option>
|
||||
<option value="20" {{if eq .PerPage 20}}selected{{end}}>20条/页</option>
|
||||
<option value="50" {{if eq .PerPage 50}}selected{{end}}>50条/页</option>
|
||||
<option value="100" {{if eq .PerPage 100}}selected{{end}}>100条/页</option>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user