feat: 默认跟随系统主题和浏览器语言

This commit is contained in:
Nixevol
2026-07-05 02:05:53 +08:00
parent 4dc9528397
commit 76bdf4fa3f
7 changed files with 53 additions and 9 deletions
+6 -1
View File
@@ -7,7 +7,12 @@ const media = window.matchMedia('(prefers-color-scheme: dark)');
const systemDark = ref(media.matches);
media.addEventListener('change', (e) => (systemDark.value = e.matches));
const mode = ref<ThemeMode>((localStorage.getItem(KEY) as ThemeMode) || 'light');
function getInitialMode(): ThemeMode {
const saved = localStorage.getItem(KEY) as ThemeMode | null;
return saved === 'light' || saved === 'dark' || saved === 'auto' ? saved : 'auto';
}
const mode = ref<ThemeMode>(getInitialMode());
const isDark = computed(() => mode.value === 'dark' || (mode.value === 'auto' && systemDark.value));