mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
refactor(projects): 生产环境缓存主题变更为sessionStorage
This commit is contained in:
@ -1,19 +1,19 @@
|
||||
import type { GlobalThemeOverrides } from 'naive-ui';
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
import { themeSetting } from '@/settings';
|
||||
import { localStg, addColorAlpha, getColorPalette } from '@/utils';
|
||||
import { sessionStg, addColorAlpha, getColorPalette } from '@/utils';
|
||||
|
||||
/** 初始化主题配置 */
|
||||
export function initThemeSettings() {
|
||||
const isProd = import.meta.env.PROD;
|
||||
// 生产环境才缓存主题配置,本地开发实时调整配置更改配置的json
|
||||
const storageSettings = localStg.get('themeSettings');
|
||||
const storageSettings = sessionStg.get('themeSettings');
|
||||
|
||||
if (isProd && storageSettings) {
|
||||
return storageSettings;
|
||||
}
|
||||
|
||||
const themeColor = localStg.get('themeColor') || themeSetting.themeColor;
|
||||
const themeColor = sessionStg.get('themeColor') || themeSetting.themeColor;
|
||||
const info = themeSetting.isCustomizeInfoColor ? themeSetting.otherColor.info : getColorPalette(themeColor, 7);
|
||||
const otherColor = { ...themeSetting.otherColor, info };
|
||||
const setting = cloneDeep({ ...themeSetting, themeColor, otherColor });
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { darkTheme } from 'naive-ui';
|
||||
import { localStg } from '@/utils';
|
||||
import { sessionStg } from '@/utils';
|
||||
import { getNaiveThemeOverrides, initThemeSettings } from './helpers';
|
||||
|
||||
type ThemeState = Theme.Setting;
|
||||
@ -25,14 +25,14 @@ export const useThemeStore = defineStore('theme-store', {
|
||||
actions: {
|
||||
/** 重置theme状态 */
|
||||
resetThemeStore() {
|
||||
localStg.remove('themeSettings');
|
||||
sessionStg.remove('themeSettings');
|
||||
this.$reset();
|
||||
},
|
||||
/** 缓存主题配置 */
|
||||
cacheThemeSettings() {
|
||||
const isProd = import.meta.env.PROD;
|
||||
if (isProd) {
|
||||
localStg.set('themeSettings', this.$state);
|
||||
sessionStg.set('themeSettings', this.$state);
|
||||
}
|
||||
},
|
||||
/** 设置暗黑模式 */
|
||||
|
Reference in New Issue
Block a user