fix(web): 时间统一 12 小时制(上午/下午),修复后台时间错误

- 后台页面此前直接 Format 输出库内时间(服务器 UTC),比北京时间慢 8 小时
- 新增模板函数 time12/time12m:先按 Web 时区转换,输出「2026-08-20 下午 2:35:05」
- shortDate 改为 12 小时制且非今天的邮件也显示完整时间(今天「下午 2:35」,
  今年「08-20 下午 2:35」,更早「2026-08-20 下午 2:35」)
- 统一替换:admin/mails、admin/outbound 用 time12m;protocol-logs、
  connections、bans、mail_view、banned、view 用 time12
- 时区修正:协议日志 from/to 筛选与「今日」统计边界按 Web 时区计算
  (此前 time.Local 在服务器 UTC 时差 8 小时)
- 邮件列表日期列自适应宽度适配更长格式;新增 timefmt_test.go 回归测试
This commit is contained in:
2026-08-20 02:00:10 +08:00
parent 87a85ef7ca
commit 37b4816573
13 changed files with 164 additions and 32 deletions
+1 -1
View File
@@ -55,7 +55,7 @@
</td>
<td>{{.FailCount}}</td>
<td>{{if .Reason}}{{.Reason}}{{else}}—{{end}}</td>
<td>{{.ExpiresAt.Format "2006-01-02 15:04:05"}}{{if not .Active}}(已过期){{end}}</td>
<td>{{time12 .ExpiresAt}}{{if not .Active}}(已过期){{end}}</td>
<td>
<form method="POST" action="/admin/bans/{{.ID}}/unban" style="display:inline;"
onsubmit="return confirm('确定要解封 IP {{.IPAddress}} 吗?解封后该 IP 的封禁档位将清零。');">
@@ -77,9 +77,9 @@
<td>{{.Port}}</td>
<td>{{if .User}}{{.User}}{{else}}—{{end}}</td>
<td>{{if .TLS}}<span class="badge" style="background:#27ae60;color:#fff;">TLS</span>{{else}}<span class="badge" style="background:#95a5a6;color:#fff;">明文</span>{{end}}</td>
<td>{{.Connected.Format "2006-01-02 15:04:05"}}</td>
<td>{{time12 .Connected}}</td>
<td>{{durationSeconds ($.now.Sub .Connected)}}s</td>
<td>{{.LastActive.Format "2006-01-02 15:04:05"}}</td>
<td>{{time12 .LastActive}}</td>
<td>
<form method="POST" action="/admin/connections/{{.ID}}/disconnect" style="display:inline;"
onsubmit="return confirm('确定要断开 IP {{.IP}} 的所有连接并加入黑名单(180 天)吗?');">
+1 -1
View File
@@ -43,7 +43,7 @@
{{if .message.CcAddr}}<p><strong>抄送:</strong> {{.message.CcAddr}}</p>{{end}}
<p><strong>所属用户:</strong> {{if .message.User.ID}}{{.message.User.Username}}{{else}}—{{end}}</p>
<p><strong>文件夹:</strong> {{.message.Folder}}</p>
<p><strong>时间:</strong> {{.message.Date.Format "2006-01-02 15:04:05"}}</p>
<p><strong>时间:</strong> {{time12 .message.Date}}</p>
</div>
<div class="mail-body">
{{if .message.HtmlBody}}
+1 -1
View File
@@ -54,7 +54,7 @@
<td>{{.Subject}}</td>
<td>{{if .User.ID}}{{.User.Username}}{{else}}—{{end}}</td>
<td>{{.Folder}}</td>
<td>{{.Date.Format "2006-01-02 15:04"}}</td>
<td>{{time12m .Date}}</td>
</tr>
{{end}}
</tbody>
+2 -2
View File
@@ -82,9 +82,9 @@
{{else}}<span class="badge" style="background:#95a5a6;color:#fff;">{{call $.statusText .Status}}</span>{{end}}
</td>
<td>{{.Attempts}}</td>
<td>{{if or (eq .Status "pending") (eq .Status "deferred")}}{{.NextAttemptAt.Format "2006-01-02 15:04"}}{{else}}—{{end}}</td>
<td>{{if or (eq .Status "pending") (eq .Status "deferred")}}{{time12m .NextAttemptAt}}{{else}}—{{end}}</td>
<td style="max-width:280px;word-break:break-all;">{{if .LastResponse}}{{.LastResponse}}{{else}}{{.LastError}}{{end}}</td>
<td>{{.CreatedAt.Format "2006-01-02 15:04"}}</td>
<td>{{time12m .CreatedAt}}</td>
<td>
{{if or (eq .Status "failed") (eq .Status "deferred") (eq .Status "canceled") (eq .Status "pending")}}
<form method="POST" action="/admin/outbound/{{.ID}}/retry" style="display:inline;">
@@ -92,7 +92,7 @@
<tbody>
{{range .logs}}
<tr>
<td style="white-space:nowrap;">{{.CreatedAt.Format "2006-01-02 15:04:05"}}</td>
<td style="white-space:nowrap;">{{time12 .CreatedAt}}</td>
<td>
{{if eq .Protocol "smtp"}}<span class="badge" style="background:#3498db;color:#fff;">SMTP</span>
{{else if eq .Protocol "imap"}}<span class="badge" style="background:#9b59b6;color:#fff;">IMAP</span>
+1 -1
View File
@@ -65,7 +65,7 @@
</div>
<div class="detail-row">
<span class="detail-label">解封时间</span>
<span class="detail-value">{{.entry.ExpiresAt.Format "2006-01-02 15:04:05"}}</span>
<span class="detail-value">{{time12 .entry.ExpiresAt}}</span>
</div>
</div>
{{end}}
+3 -3
View File
@@ -165,7 +165,7 @@
font-size: 12.5px; color: var(--text-3);
}
.cell-date {
width: 78px; flex-shrink: 0; text-align: right;
flex: 0 0 auto; white-space: nowrap; text-align: right;
font-size: 12.5px; color: var(--text-3);
}
.mail-row.unread .cell-date { color: var(--text-2); }
@@ -388,11 +388,11 @@
.page-info { font-size: 12px; }
.mail-row { padding: 0 10px; height: 60px; gap: 8px; }
.avatar { width: 32px; height: 32px; font-size: 13px; }
.cell-from { width: 88px; font-size: 13px; }
.cell-from { width: 76px; font-size: 13px; }
.cell-subject-wrap { flex: 1; min-width: 0; }
.cell-subject { font-size: 13px; }
.cell-snippet { display: none; }
.cell-date { width: 56px; font-size: 11.5px; }
.cell-date { width: auto; font-size: 10.5px; }
.row-del { opacity: 1; }
.list-footer { padding: 8px 10px; }
.pager { margin-left: auto; gap: 4px; }
+1 -1
View File
@@ -54,7 +54,7 @@
<div class="mail-from-name">{{mailName (decodeHeader .message.FromAddr)}}</div>
<div class="mail-from-addr" title="{{decodeHeader .message.FromAddr}}">{{mailEmail .message.FromAddr}}</div>
</div>
<span class="mail-date">{{(localTime .message.Date).Format "2006-01-02 15:04:05"}}</span>
<span class="mail-date">{{time12 .message.Date}}</span>
</div>
{{if .message.CcAddr}}
<div class="mail-from-addr" style="margin:-8px 0 16px 48px;">