fix: logviewer style

This commit is contained in:
engigu
2026-03-12 17:51:17 +08:00
parent bb001a2210
commit 3ebbef591c
7 changed files with 276 additions and 53 deletions
+11 -4
View File
@@ -1,8 +1,9 @@
import { ref, watch, onMounted } from 'vue'
import { computed, onMounted, ref, watch } from 'vue'
export type Theme = 'light' | 'dark' | 'system'
const theme = ref<Theme>('system')
const systemTheme = ref<'light' | 'dark'>('light')
function getSystemTheme(): 'light' | 'dark' {
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
@@ -18,15 +19,16 @@ function applyTheme(t: Theme) {
export function useTheme() {
onMounted(() => {
// 从 localStorage 读取主题
systemTheme.value = getSystemTheme()
const saved = localStorage.getItem('theme') as Theme | null
if (saved && ['light', 'dark', 'system'].includes(saved)) {
theme.value = saved
}
applyTheme(theme.value)
// 监听系统主题变化
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
systemTheme.value = getSystemTheme()
if (theme.value === 'system') {
applyTheme('system')
}
@@ -38,12 +40,17 @@ export function useTheme() {
applyTheme(newTheme)
})
const resolvedTheme = computed<'light' | 'dark'>(() => {
return theme.value === 'system' ? systemTheme.value : theme.value
})
function setTheme(t: Theme) {
theme.value = t
}
return {
theme,
setTheme
resolvedTheme,
setTheme,
}
}