Переглянути джерело

[demo]修复文档站点切换主题时示例站点未跟随显示的问题

dufu1991 10 місяців тому
батько
коміт
a3707fa1cf

+ 3 - 1
packages/stdf/src/routes/+layout.svelte

@@ -13,6 +13,7 @@
 	import themes from '../data/themes/index.js';
 
 	let { children } = $props();
+	let currentColor = $state('STDF');
 
 	// 循环 menuList,将所有元素的 childs 组成一个数组
 	// Cycle menuList, and combine the childs of all elements into an array
@@ -42,6 +43,7 @@
 		const urlTheme = urlParams.get('theme');
 		const urlDarkMode = urlParams.get('darkMode');
 		const currentTheme = themes.find((item) => item.name === urlTheme);
+		currentColor = urlTheme || 'STDF';
 		if (currentTheme) {
 			switchTheme(currentTheme.theme);
 		}
@@ -205,5 +207,5 @@
 		? 'right-0'
 		: '-right-80'} top-12 rounded-lg bg-white px-2 shadow-sm transition-all duration-500 dark:bg-black"
 >
-	<ThemeSwitch />
+	<ThemeSwitch {currentColor} />
 </div>

+ 1 - 1
packages/stdf/src/routes/components/ThemeSwitch.svelte

@@ -4,7 +4,7 @@
 
 	const isZh = sessionStorage.getItem('lang') === 'zh_CN';
 
-	let currentColor = $state('STDF');
+	let { currentColor } = $props();
 
 	const selectColorFunc = (e: MouseEvent, item: (typeof themes)[number]) => {
 		// 阻止冒泡