feat: add dark/light theme

This commit is contained in:
engigu
2025-09-30 22:24:29 +08:00
parent f3f378115d
commit 415bed6093
11 changed files with 175 additions and 56 deletions
+15
View File
@@ -5,6 +5,21 @@ import pinia from './store';
//@ts-ignore
import router from './router';
// 初始化主题:优先本地存储,其次系统偏好
(() => {
try {
const storageKey = 'theme';
const stored = localStorage.getItem(storageKey);
const systemPrefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
const theme = stored || (systemPrefersDark ? 'dark' : 'light');
if (theme === 'dark') {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
} catch (_) {}
})();
const app = createApp(App)
app.use(router)
app.use(pinia)