optimize(projects): use defu to fill added theme config

This commit is contained in:
Soybean
2024-12-16 16:32:12 +08:00
parent 3e0eb72025
commit 101b6f9000
7 changed files with 18 additions and 16 deletions

View File

@ -1,4 +1,5 @@
import type { GlobalThemeOverrides } from 'naive-ui';
import { defu } from 'defu';
import { addColorAlpha, getColorPalette, getPaletteColorByNumber, getRgb } from '@sa/color';
import { overrideThemeSettings, themeSettings } from '@/theme/settings';
import { themeVars } from '@/theme/vars';
@ -17,12 +18,15 @@ export function initThemeSettings() {
// if it is production mode, the theme settings will be cached in localStorage
// if want to update theme settings when publish new version, please update `overrideThemeSettings` in `src/theme/settings.ts`
const settings = localStg.get('themeSettings') || themeSettings;
const localSettings = localStg.get('themeSettings');
let settings = defu(localSettings, themeSettings);
const isOverride = localStg.get('overrideThemeFlag') === BUILD_TIME;
if (!isOverride) {
Object.assign(settings, overrideThemeSettings);
settings = defu(overrideThemeSettings, settings);
localStg.set('overrideThemeFlag', BUILD_TIME);
}