From 0e385b057d8c6e7f0cd9975e3a13c30bbbf6870b Mon Sep 17 00:00:00 2001 From: dekun Date: Mon, 15 Jun 2026 16:29:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B7=B1=E8=89=B2=E4=B8=8E?= =?UTF-8?q?=E6=B5=85=E8=89=B2=E4=B8=BB=E9=A2=98=E6=97=A0=E6=B3=95=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修正 CSS 选择器避免 :root 始终应用深色变量,并改进 theme.js 点击绑定与首屏主题恢复。 Co-authored-by: Cursor --- static/js/theme.js | 22 +++++++++++++++------- templates/base.html | 14 ++++++++++---- templates/login.html | 12 +++++++++--- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/static/js/theme.js b/static/js/theme.js index 04b2ac3..532d9cd 100644 --- a/static/js/theme.js +++ b/static/js/theme.js @@ -33,13 +33,21 @@ apply(prefersLight ? 'light' : 'dark'); } - document.addEventListener('DOMContentLoaded', function () { + document.addEventListener('click', function (e) { + var btn = e.target.closest('[data-theme-pick]'); + if (!btn) return; + e.preventDefault(); + apply(btn.getAttribute('data-theme-pick')); + }); + + function syncButtons() { var cur = document.documentElement.getAttribute('data-theme') || 'dark'; updateButtons(cur); - document.querySelectorAll('[data-theme-pick]').forEach(function (btn) { - btn.addEventListener('click', function () { - apply(btn.getAttribute('data-theme-pick')); - }); - }); - }); + } + + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', syncButtons); + } else { + syncButtons(); + } })(); diff --git a/templates/base.html b/templates/base.html index 9ea9173..5e53117 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,12 +1,18 @@ - + {% block title %}国内期货监控系统{% endblock %} +