Skip to content

Commit

Permalink
optimize(projects): use defu to fill added theme config
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Dec 16, 2024
1 parent 3e0eb72 commit 101b6f9
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@vueuse/core": "12.0.0",
"clipboard": "2.0.11",
"dayjs": "1.11.13",
"defu": "6.1.4",
"echarts": "5.5.1",
"json5": "2.2.3",
"naive-ui": "2.40.3",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const naiveDateLocale = computed(() => {
const watermarkProps = computed<WatermarkProps>(() => {
return {
content: themeStore.watermark?.text || 'SoybeanAdmin',
content: themeStore.watermark.text,
cross: true,
fullscreen: true,
fontSize: 16,
Expand All @@ -50,7 +50,7 @@ const watermarkProps = computed<WatermarkProps>(() => {
>
<AppProvider>
<RouterView class="bg-layout" />
<NWatermark v-if="themeStore.watermark?.visible" v-bind="watermarkProps" />
<NWatermark v-if="themeStore.watermark.visible" v-bind="watermarkProps" />
</AppProvider>
</NConfigProvider>
</template>
Expand Down
4 changes: 2 additions & 2 deletions src/layouts/modules/theme-drawer/modules/page-fun.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ const isWrapperScrollMode = computed(() => themeStore.layout.scrollMode === 'wra
>
<NSwitch v-model:value="themeStore.footer.right" />
</SettingItem>
<SettingItem v-if="themeStore.watermark" key="8" :label="$t('theme.watermark.visible')">
<SettingItem key="8" :label="$t('theme.watermark.visible')">
<NSwitch v-model:value="themeStore.watermark.visible" />
</SettingItem>
<SettingItem v-if="themeStore.watermark?.visible" key="8-1" :label="$t('theme.watermark.text')">
<SettingItem v-if="themeStore.watermark.visible" key="8-1" :label="$t('theme.watermark.text')">
<NInput
v-model:value="themeStore.watermark.text"
autosize
Expand Down
8 changes: 6 additions & 2 deletions src/store/modules/theme/shared.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);
}

Expand Down
8 changes: 1 addition & 7 deletions src/theme/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,4 @@ export const themeSettings: App.Theme.ThemeSetting = {
*
* If publish new version, use `overrideThemeSettings` to override certain theme settings
*/
export const overrideThemeSettings: Partial<App.Theme.ThemeSetting> = {
resetCacheStrategy: 'close',
watermark: {
visible: false,
text: 'SoybeanAdmin'
}
};
export const overrideThemeSettings: Partial<App.Theme.ThemeSetting> = {};
6 changes: 3 additions & 3 deletions src/typings/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ declare namespace App {
/** Whether info color is followed by the primary color */
isInfoFollowPrimary: boolean;
/** Reset cache strategy */
resetCacheStrategy?: UnionKey.ResetCacheStrategy;
resetCacheStrategy: UnionKey.ResetCacheStrategy;
/** Layout */
layout: {
/** Layout mode */
Expand All @@ -33,7 +33,7 @@ declare namespace App {
*
* if true, the vertical child level menus in left and horizontal first level menus in top
*/
reverseHorizontalMix?: boolean;
reverseHorizontalMix: boolean;
};
/** Page */
page: {
Expand Down Expand Up @@ -98,7 +98,7 @@ declare namespace App {
right: boolean;
};
/** Watermark */
watermark?: {
watermark: {
/** Whether to show the watermark */
visible: boolean;
/** Watermark text */
Expand Down

0 comments on commit 101b6f9

Please sign in to comment.