refactor(projects): 系统暗黑主题模式抽离成composables

This commit is contained in:
Soybean
2021-11-19 13:02:29 +08:00
parent 4e1a09c779
commit 195e5b9e57
3 changed files with 33 additions and 20 deletions

View File

@ -0,0 +1,29 @@
import { computed, watch } from 'vue';
import { darkTheme } from 'naive-ui';
import { useDark } from '@vueuse/core';
import { useThemeStore } from '@/store';
/** 系统暗黑模式 */
export function useDarkMode() {
const osDark = useDark();
const theme = useThemeStore();
const { handleDarkMode } = useThemeStore();
/** naive-ui暗黑主题 */
const naiveTheme = computed(() => (theme.darkMode ? darkTheme : undefined));
// 监听操作系统主题模式
watch(
osDark,
newValue => {
handleDarkMode(newValue);
},
{
immediate: true
}
);
return {
naiveTheme
};
}