feat(components): 增加黑白模式切换功能、完善appstore类型

This commit is contained in:
Coffee-crocodile 2022-08-12 09:28:08 +08:00
parent c6b3c729ee
commit f336487fca
2 changed files with 20 additions and 3 deletions

View File

@ -1,10 +1,11 @@
<script setup lang="ts">
// import { darkTheme } from 'naive-ui';
import { useAppStore } from './store';
import { zhCN, dateZhCN, GlobalThemeOverrides } from 'naive-ui';
import json from './theme.json';
const locale = zhCN;
const dateLocale = dateZhCN;
const appStore = useAppStore();
const themeOverrides: GlobalThemeOverrides = {} || json;
</script>
@ -12,7 +13,7 @@ const themeOverrides: GlobalThemeOverrides = {} || json;
<template>
<n-config-provider
class="wh-full"
:theme="null"
:theme="appStore.darkTheme"
:locale="locale"
:date-locale="dateLocale"
:theme-overrides="themeOverrides"

View File

@ -1,11 +1,22 @@
import { defineStore } from 'pinia';
import { darkTheme, GlobalTheme } from 'naive-ui';
interface AppStatus {
collapsed: boolean;
fullScreen: boolean;
darkMode: boolean;
darkTheme: GlobalTheme | null;
title: string;
footerText: string;
}
export const useAppStore = defineStore('app-store', {
state: () => {
state: (): AppStatus => {
return {
collapsed: false,
fullScreen: false,
darkMode: false,
darkTheme: null,
title: import.meta.env.VITE_APP_TITLE,
footerText: '哲学的基本问题是思维和存在的关系问题',
};
@ -28,6 +39,11 @@ export const useAppStore = defineStore('app-store', {
/* 切换主题 亮/深色 */
toggleDarkMode() {
this.darkMode = !this.darkMode;
if (this.darkMode) {
this.darkTheme = darkTheme;
} else {
this.darkTheme = null;
}
},
},
});