背景:v1.9.0 把界面迁到 Bootstrap 5 时保留了旧自研 CSS,v1.9.2 又叠加了一层 「墨绿渐变」覆盖层,形成三套令牌(--paper/--ink、prefers-color-scheme、 data-bs-theme)并存。系统偏好与 Cookie 不一致时,页面会出现半亮半暗、表单 标签/抽屉标题/订阅页签不可见、输入框变黑块等问题。 本次改动: - 样式加载顺序改为 bootstrap → app.css;删除旧纸墨令牌与 v1.9.2 覆盖层, app.css 重写为单一主题层(:root/[data-bs-theme=light] 与 [data-bs-theme=dark] 两套语义令牌)。组件只读 --app-*,解决 --ink-2 同时被当作「次级文字色」和 「卡片底色」的语义冲突。 - 主题只认 <html data-bs-theme>:服务端按 Cookie 直出;没有 Cookie 时由 <head> 内联脚本在首屏按系统偏好补齐,修好「跟随系统」并避免闪白。大屏同理。 - 修复 Bootstrap 覆盖自研设计的问题:正文 14px + 中文字体栈、22/16/14px 标题、 按钮/输入框/焦点环/卡片回到设计值;普通按钮新增 .btn-soft,不再变透明文字。 - 布局修复:客户/套餐表单的 .grid-2 不再塞 3 个字段;包详情页把筛选独立成 GET 表单(在搜索框回车不再误触批量开通);客户详情操作区与 meta 重排; 抽屉时钟改为固定 46px 并用它对齐抽屉头的 sticky 偏移;追加面板在抽屉里 两列月历、不再 1100px 竖排;手机端日历数字不再换行溢出,移动端表格隐藏 低优先级列,不再被裁切。 - 大屏:KPI/面板去掉 Bootstrap utility,统一由 screen.css 控制;TOP/今日待打 改为固定列宽 + grid-column 对齐;浅色主题的链接、热力、图例对比度补齐; 热力格不再整体降透明度;当日浮层可滚动并支持点击/键盘打开。 - 配色与可读性:普通文本对比度全部达标(截图 lint 由 65 处降到 0);日历 外月日期改为浅底深字,不再整格 opacity;archived 行改为中性底色而非降透明。 - 缓存:新增内嵌静态资源内容指纹 AssetVersion(12 位 sha256),所有 /static 链接带 ?v=;带指纹的响应 public, max-age=31536000, immutable,不带指纹的 回源 no-cache;HTML 继续 no-store。改样式重新编译即自动破缓存,不再依赖 手改版本号(仍保留 v1.10.0 作为产品版本)。 - 认证页重做:登录/初始化页改用 .auth 卡片(品牌、主题切换、绿色焦点环), 去掉 min-height:100vh 叠加 main padding 造成的 40px 纵向滚动。 - JS:修 toISOString 计算自然日差一天的时区 bug;主题切换读 data-bs-theme 并同步 aria-pressed;全选支持半选;大屏切主题同时更新 data-bs-theme; 提示条改为固定定位、淡出不再顶动页面。 - README 更新主题与缓存说明;版本号 1.9.5 → 1.10.0。 验证:gofmt / go vet / go test 全绿;1440、1100、390 三档,明暗两套,工作台/ 客户/套餐/订阅/设置/日志/大屏/登录全部截图走查,无横向溢出与控制台错误。
This commit is contained in:
+55
-20
@@ -5,6 +5,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"embed"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
@@ -50,11 +51,12 @@ type Config struct {
|
||||
|
||||
// Server 是应用服务。
|
||||
type Server struct {
|
||||
db *store.DB
|
||||
cfg Config
|
||||
tpl *renderer
|
||||
handler http.Handler
|
||||
started time.Time
|
||||
db *store.DB
|
||||
cfg Config
|
||||
tpl *renderer
|
||||
handler http.Handler
|
||||
started time.Time
|
||||
assetVersion string
|
||||
}
|
||||
|
||||
type ctxKey int
|
||||
@@ -67,11 +69,33 @@ func New(db *store.DB, cfg Config) (*Server, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s := &Server{db: db, cfg: cfg, tpl: r, started: time.Now()}
|
||||
s := &Server{db: db, cfg: cfg, tpl: r, started: time.Now(), assetVersion: staticAssetVersion()}
|
||||
s.handler = s.routes()
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// staticAssetVersion 计算内嵌静态资源的内容指纹。
|
||||
// 资源 URL 带上它之后可以放心长缓存;改了 CSS/JS 重新编译就会自动换 URL。
|
||||
func staticAssetVersion() string {
|
||||
h := sha256.New()
|
||||
if err := fs.WalkDir(staticFS, "static", func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil || d.IsDir() {
|
||||
return nil
|
||||
}
|
||||
data, rerr := fs.ReadFile(staticFS, path)
|
||||
if rerr != nil {
|
||||
return nil
|
||||
}
|
||||
h.Write([]byte(path))
|
||||
h.Write([]byte{0})
|
||||
h.Write(data)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return "dev"
|
||||
}
|
||||
return hex.EncodeToString(h.Sum(nil))[:12]
|
||||
}
|
||||
|
||||
// Handler 返回 HTTP 处理器。
|
||||
func (s *Server) Handler() http.Handler { return s.handler }
|
||||
|
||||
@@ -82,7 +106,7 @@ func (s *Server) routes() http.Handler {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
mux.Handle("GET /static/", cacheControl(http.StripPrefix("/static/", http.FileServerFS(sub))))
|
||||
mux.Handle("GET /static/", s.staticFiles(http.StripPrefix("/static/", http.FileServerFS(sub))))
|
||||
mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||
_, _ = w.Write([]byte("ok"))
|
||||
@@ -153,9 +177,16 @@ func (s *Server) routes() http.Handler {
|
||||
return s.noCacheHTML(mux)
|
||||
}
|
||||
|
||||
func cacheControl(h http.Handler) http.Handler {
|
||||
// staticFiles 给内嵌静态资源加缓存策略:
|
||||
// 只有带当前内容指纹(?v=)的 URL 才允许一年不可变缓存,其它一律回源。
|
||||
func (s *Server) staticFiles(h http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Cache-Control", "public, max-age=300")
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
if r.URL.Query().Get("v") == s.assetVersion {
|
||||
w.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
|
||||
} else {
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
}
|
||||
h.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
@@ -337,14 +368,16 @@ type page struct {
|
||||
TodayStr string
|
||||
WarnDays int
|
||||
Version string
|
||||
Query string
|
||||
Next string
|
||||
DueToday int
|
||||
Due3 int
|
||||
Due7 int
|
||||
Addr string
|
||||
Theme string // "" = 跟随系统;light / dark
|
||||
D any
|
||||
// AssetVersion 是内嵌静态资源的内容指纹,用于 /static/*.css?v=... 的长缓存
|
||||
AssetVersion string
|
||||
Query string
|
||||
Next string
|
||||
DueToday int
|
||||
Due3 int
|
||||
Due7 int
|
||||
Addr string
|
||||
Theme string // "" = 跟随系统;light / dark
|
||||
D any
|
||||
}
|
||||
|
||||
func (s *Server) warnDays() int {
|
||||
@@ -374,9 +407,11 @@ func (s *Server) newPage(r *http.Request, title, nav string) *page {
|
||||
TodayStr: domain.Date(today),
|
||||
WarnDays: s.warnDays(),
|
||||
Version: s.cfg.Version,
|
||||
Query: r.URL.Query().Get("q"),
|
||||
Next: r.URL.Query().Get("next"),
|
||||
Theme: themeFromRequest(r),
|
||||
|
||||
AssetVersion: s.assetVersion,
|
||||
Query: r.URL.Query().Get("q"),
|
||||
Next: r.URL.Query().Get("next"),
|
||||
Theme: themeFromRequest(r),
|
||||
}
|
||||
if u != nil {
|
||||
if due, due3, due7, err := s.db.Badges(today); err == nil {
|
||||
|
||||
Reference in New Issue
Block a user