feat: 添加主题管理功能,更新系统设置页面,优化用户体验
This commit is contained in:
26
src/composables/useTheme.ts
Normal file
26
src/composables/useTheme.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { usePreferredDark } from "@vueuse/core";
|
||||
|
||||
export type ThemeMode = "light" | "dark" | "auto";
|
||||
|
||||
const STORAGE_KEY = "app-theme-mode";
|
||||
|
||||
export function useTheme() {
|
||||
const prefersDark = usePreferredDark();
|
||||
const theme = useStorage<ThemeMode>(STORAGE_KEY, "auto");
|
||||
|
||||
const isDark = computed(() => {
|
||||
if (theme.value === "auto") {
|
||||
return prefersDark.value;
|
||||
}
|
||||
return theme.value === "dark";
|
||||
});
|
||||
|
||||
watch(isDark, (dark) => {
|
||||
document.documentElement.classList.toggle("ion-palette-dark", dark);
|
||||
}, { immediate: true });
|
||||
|
||||
return {
|
||||
theme,
|
||||
isDark,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user