From 3330af818eea7ff46cc7545377facbab85763ed6 Mon Sep 17 00:00:00 2001 From: CNWei Date: Tue, 3 Nov 2026 20:09:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(theme):=20=E6=B6=88=E9=99=A4=E9=A6=96?= =?UTF-8?q?=E5=B8=A7=E4=B8=BB=E9=A2=98=E9=97=AA=E5=8A=A8=E5=B9=B6=E6=9F=94?= =?UTF-8?q?=E5=8C=96=E6=98=8E=E6=9A=97=E8=BF=87=E6=B8=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - index.html 首帧按本机偏好设置 dark/light,避免先浅后深 - 实际 scheme 只写 dark/light(之前 auto 会覆盖成浅色) - 切换时给所有表面加 240ms 颜色/边框/阴影过渡,结束后移除 - 背景图深色下淡出而不是 display:none - 页头操作图标与分组导航等设置加载后再渲染,避免先显示后消失 --- stash-web/index.html | 10 ++- stash-web/src/App.css | 29 +++++++- stash-web/src/AppNext.tsx | 21 ++++-- .../src/components/header/SiteHeader.tsx | 67 +++++++++++-------- stash-web/src/index.css | 4 ++ 5 files changed, 94 insertions(+), 37 deletions(-) diff --git a/stash-web/index.html b/stash-web/index.html index 0210b7f..49b8e73 100644 --- a/stash-web/index.html +++ b/stash-web/index.html @@ -4,7 +4,15 @@ - + + { - document.documentElement.dataset.scheme = effectiveTheme - }, [effectiveTheme]) - /** 当前实际是深色吗(auto 时按系统偏好算) */ const isDark = isDarkScheme(effectiveTheme) + const scheme = isDark ? 'dark' : 'light' + + useEffect(() => { + const root = document.documentElement + if (root.dataset.scheme === scheme) return + root.classList.add('theme-transition') + root.dataset.scheme = scheme + const timer = window.setTimeout(() => root.classList.remove('theme-transition'), 260) + return () => { + window.clearTimeout(timer) + root.classList.remove('theme-transition') + } + }, [scheme]) /** 页头的明暗切换:只写本机偏好,不需要登录;站点默认值在后台改 */ const toggleTheme = () => { @@ -663,6 +671,7 @@ export default function AppNext() { headerSpeed={site.header.speed} headerGap={site.header.gap} site={site.site} + ready={settings !== null} authenticated={session?.authenticated === true} username={session?.username ?? undefined} refreshing={refreshing} @@ -707,7 +716,7 @@ export default function AppNext() { onOpenApi={() => navigate('/interface')} /> )} - {settings !== null && site.sidebar.show_nav !== false && ( + {settings !== null && !loading && site.sidebar.show_nav !== false && (
- {headerEnabled && ( + {ready && headerEnabled && ( {headerItems.map((item, index) => ( @@ -94,34 +97,42 @@ export function SiteHeader({
- {site.actions.theme && ( - } - onClick={onToggleTheme} - /> + {ready && ( + <> + {site.actions.theme && ( + } + onClick={onToggleTheme} + /> + )} + {site.actions.refresh && ( + } + spinning={refreshing} + onClick={onRefresh} + /> + )} + {site.actions.settings && authenticated && ( + } + onClick={onSettings} + /> + )} + {site.actions.session && + (authenticated ? ( + } + onClick={onLogout} + /> + ) : ( + } onClick={onLogin} /> + ))} + )} - {site.actions.refresh && ( - } - spinning={refreshing} - onClick={onRefresh} - /> - )} - {site.actions.settings && authenticated && ( - } onClick={onSettings} /> - )} - {site.actions.session && - (authenticated ? ( - } - onClick={onLogout} - /> - ) : ( - } onClick={onLogin} /> - ))}
) diff --git a/stash-web/src/index.css b/stash-web/src/index.css index de2cc67..ef8fa43 100644 --- a/stash-web/src/index.css +++ b/stash-web/src/index.css @@ -11,6 +11,10 @@ -moz-osx-font-smoothing: grayscale; } +html[data-scheme='dark'] { + color-scheme: dark; +} + * { box-sizing: border-box; margin: 0;