优化前端

This commit is contained in:
yml2213
2026-06-26 10:56:25 +08:00
parent 88a386b588
commit 54b5bd90ae
39 changed files with 6796 additions and 216 deletions
+29
View File
@@ -0,0 +1,29 @@
import { ref, watch, onMounted } from 'vue'
export type Theme = 'dark' | 'light'
const theme = ref<Theme>('dark')
export function useTheme() {
const applyTheme = (t: Theme) => {
theme.value = t
document.body.dataset.theme = t
localStorage.setItem('uiTheme', t)
}
const toggleTheme = () => {
applyTheme(theme.value === 'light' ? 'dark' : 'light')
}
const initTheme = () => {
const saved = localStorage.getItem('uiTheme') as Theme | null
const prefersLight = window.matchMedia?.('(prefers-color-scheme: light)').matches
applyTheme(saved || (prefersLight ? 'light' : 'dark'))
}
return {
theme,
toggleTheme,
initTheme
}
}