iter(g203): 文档站亮暗切换与 demo 主题参数联动
This commit is contained in:
+3
-2
@@ -283,9 +283,10 @@ const orgTree = [
|
||||
{ key: 'qa', label: '质量中心', children: [{ key: 'reg', label: '回归测试', disabled: true }] },
|
||||
];
|
||||
|
||||
// —— 主题:优先读上次选择,其次跟随系统;写 html[data-theme] 让令牌换色 ——
|
||||
// —— 主题:优先读 URL 参数(文档站 iframe 联动入口),其次上次选择,最后跟随系统;写 html[data-theme] 让令牌换色 ——
|
||||
const THEME_KEY = 'ua-demo-theme';
|
||||
const dark = signal((localStorage.getItem(THEME_KEY) ?? (matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')) === 'dark');
|
||||
const themeParam = new URLSearchParams(location.search).get('theme'); // ?theme=dark|light,iframe 带参重载时生效
|
||||
const dark = signal(((themeParam === 'dark' || themeParam === 'light' ? themeParam : null) ?? localStorage.getItem(THEME_KEY) ?? (matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')) === 'dark');
|
||||
effect(() => {
|
||||
const mode = dark() ? 'dark' : 'light';
|
||||
document.documentElement.dataset.theme = mode; // 令牌按 data-theme 切换
|
||||
|
||||
Reference in New Issue
Block a user