feat(projects): 添加生产的主题配置缓存

This commit is contained in:
Soybean
2022-06-20 23:23:55 +08:00
parent 5c1b086cb4
commit 718c36263e
16 changed files with 137 additions and 48 deletions

View File

@ -1,11 +1,11 @@
import { defineStore } from 'pinia';
import { darkTheme } from 'naive-ui';
import { getThemeSettings, getNaiveThemeOverrides } from './helpers';
import { initThemeSettings, getNaiveThemeOverrides, setThemeSettings, clearThemeSettings } from './helpers';
type ThemeState = Theme.Setting;
export const useThemeStore = defineStore('theme-store', {
state: (): ThemeState => getThemeSettings(),
state: (): ThemeState => initThemeSettings(),
getters: {
/** naiveUI的主题配置 */
naiveThemeOverrides(state) {
@ -24,8 +24,16 @@ export const useThemeStore = defineStore('theme-store', {
actions: {
/** 重置theme状态 */
resetThemeStore() {
clearThemeSettings();
this.$reset();
},
/** 缓存主题配置 */
cacheThemeSettings() {
const isProd = import.meta.env.PROD;
if (isProd) {
setThemeSettings(this.$state);
}
},
/** 设置暗黑模式 */
setDarkMode(darkMode: boolean) {
this.darkMode = darkMode;