Skip to content

Commit 101b6f9

Browse files
committed
optimize(projects): use defu to fill added theme config
1 parent 3e0eb72 commit 101b6f9

File tree

7 files changed

+18
-16
lines changed

7 files changed

+18
-16
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"@vueuse/core": "12.0.0",
5858
"clipboard": "2.0.11",
5959
"dayjs": "1.11.13",
60+
"defu": "6.1.4",
6061
"echarts": "5.5.1",
6162
"json5": "2.2.3",
6263
"naive-ui": "2.40.3",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const naiveDateLocale = computed(() => {
2525
2626
const watermarkProps = computed<WatermarkProps>(() => {
2727
return {
28-
content: themeStore.watermark?.text || 'SoybeanAdmin',
28+
content: themeStore.watermark.text,
2929
cross: true,
3030
fullscreen: true,
3131
fontSize: 16,
@@ -50,7 +50,7 @@ const watermarkProps = computed<WatermarkProps>(() => {
5050
>
5151
<AppProvider>
5252
<RouterView class="bg-layout" />
53-
<NWatermark v-if="themeStore.watermark?.visible" v-bind="watermarkProps" />
53+
<NWatermark v-if="themeStore.watermark.visible" v-bind="watermarkProps" />
5454
</AppProvider>
5555
</NConfigProvider>
5656
</template>

src/layouts/modules/theme-drawer/modules/page-fun.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ const isWrapperScrollMode = computed(() => themeStore.layout.scrollMode === 'wra
114114
>
115115
<NSwitch v-model:value="themeStore.footer.right" />
116116
</SettingItem>
117-
<SettingItem v-if="themeStore.watermark" key="8" :label="$t('theme.watermark.visible')">
117+
<SettingItem key="8" :label="$t('theme.watermark.visible')">
118118
<NSwitch v-model:value="themeStore.watermark.visible" />
119119
</SettingItem>
120-
<SettingItem v-if="themeStore.watermark?.visible" key="8-1" :label="$t('theme.watermark.text')">
120+
<SettingItem v-if="themeStore.watermark.visible" key="8-1" :label="$t('theme.watermark.text')">
121121
<NInput
122122
v-model:value="themeStore.watermark.text"
123123
autosize

src/store/modules/theme/shared.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { GlobalThemeOverrides } from 'naive-ui';
2+
import { defu } from 'defu';
23
import { addColorAlpha, getColorPalette, getPaletteColorByNumber, getRgb } from '@sa/color';
34
import { overrideThemeSettings, themeSettings } from '@/theme/settings';
45
import { themeVars } from '@/theme/vars';
@@ -17,12 +18,15 @@ export function initThemeSettings() {
1718
// if it is production mode, the theme settings will be cached in localStorage
1819
// if want to update theme settings when publish new version, please update `overrideThemeSettings` in `src/theme/settings.ts`
1920

20-
const settings = localStg.get('themeSettings') || themeSettings;
21+
const localSettings = localStg.get('themeSettings');
22+
23+
let settings = defu(localSettings, themeSettings);
2124

2225
const isOverride = localStg.get('overrideThemeFlag') === BUILD_TIME;
2326

2427
if (!isOverride) {
25-
Object.assign(settings, overrideThemeSettings);
28+
settings = defu(overrideThemeSettings, settings);
29+
2630
localStg.set('overrideThemeFlag', BUILD_TIME);
2731
}
2832

src/theme/settings.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,4 @@ export const themeSettings: App.Theme.ThemeSetting = {
8383
*
8484
* If publish new version, use `overrideThemeSettings` to override certain theme settings
8585
*/
86-
export const overrideThemeSettings: Partial<App.Theme.ThemeSetting> = {
87-
resetCacheStrategy: 'close',
88-
watermark: {
89-
visible: false,
90-
text: 'SoybeanAdmin'
91-
}
92-
};
86+
export const overrideThemeSettings: Partial<App.Theme.ThemeSetting> = {};

src/typings/app.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ declare namespace App {
2121
/** Whether info color is followed by the primary color */
2222
isInfoFollowPrimary: boolean;
2323
/** Reset cache strategy */
24-
resetCacheStrategy?: UnionKey.ResetCacheStrategy;
24+
resetCacheStrategy: UnionKey.ResetCacheStrategy;
2525
/** Layout */
2626
layout: {
2727
/** Layout mode */
@@ -33,7 +33,7 @@ declare namespace App {
3333
*
3434
* if true, the vertical child level menus in left and horizontal first level menus in top
3535
*/
36-
reverseHorizontalMix?: boolean;
36+
reverseHorizontalMix: boolean;
3737
};
3838
/** Page */
3939
page: {
@@ -98,7 +98,7 @@ declare namespace App {
9898
right: boolean;
9999
};
100100
/** Watermark */
101-
watermark?: {
101+
watermark: {
102102
/** Whether to show the watermark */
103103
visible: boolean;
104104
/** Watermark text */

0 commit comments

Comments
 (0)