fix(projects): 修复主题相关,自适应操作系统暗黑模式

This commit is contained in:
Soybean
2021-10-25 17:57:43 +08:00
parent 4c85569b76
commit bfa42d769d
11 changed files with 301 additions and 187 deletions

View File

@ -20,7 +20,7 @@
</template>
<script lang="ts" setup>
import { computed } from 'vue';
import { computed, watch } from 'vue';
import {
NConfigProvider,
darkTheme,
@ -31,18 +31,29 @@ import {
NNotificationProvider,
NMessageProvider
} from 'naive-ui';
import { useDark } from '@vueuse/core';
import { AppProviderContent } from '@/components';
import { useThemeStore } from '@/store';
import { addColorAlpha } from '@/utils';
const osDark = useDark();
const theme = useThemeStore();
const { handleDarkMode } = useThemeStore();
/** 系统暗黑模式 */
const dark = computed(() => (theme.darkMode ? darkTheme : undefined));
// 主题颜色
const primary = computed(() => theme.themeColor);
const primaryWithAlpha = computed(() => {
const alpha = theme.darkMode ? 0.15 : 0.1;
return addColorAlpha(primary.value, alpha);
});
// 操作系统的暗黑模式
watch(osDark, newValue => {
handleDarkMode(newValue);
});
</script>
<style>
/* 全局与主题颜色相关 */