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 e8c506b commit 8559bea
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 @@ -59,6 +59,7 @@
"ant-design-vue": "4.2.6",
"clipboard": "2.0.11",
"dayjs": "1.11.13",
"defu": "6.1.4",
"echarts": "5.5.1",
"json5": "2.2.3",
"nprogress": "0.2.0",
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 @@ -19,7 +19,7 @@ const antdLocale = computed(() => {
const watermarkProps = computed(() => {
const props: WatermarkProps = {
content: themeStore.watermark?.text || 'SoybeanAdmin',
content: themeStore.watermark.text,
width: 120,
height: 120,
font: {
Expand All @@ -39,7 +39,7 @@ const watermarkProps = computed(() => {
<AppProvider>
<RouterView class="bg-layout" />
<AWatermark
v-if="themeStore.watermark?.visible"
v-if="themeStore.watermark.visible"
v-bind="watermarkProps"
class="pointer-events-none absolute-lt! size-full"
/>
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 @@ -111,10 +111,10 @@ const isWrapperScrollMode = computed(() => themeStore.layout.scrollMode === 'wra
>
<ASwitch v-model:checked="themeStore.footer.right" />
</SettingItem>
<SettingItem v-if="themeStore.watermark" key="8" :label="$t('theme.watermark.visible')">
<SettingItem key="8" :label="$t('theme.watermark.visible')">
<ASwitch v-model:checked="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')">
<AInput v-model:value="themeStore.watermark.text" placeholder="SoybeanAdmin" class="w-120px" />
</SettingItem>
</TransitionGroup>
Expand Down
8 changes: 6 additions & 2 deletions src/store/modules/theme/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { theme as antdTheme } from 'ant-design-vue';
import type { ConfigProviderProps } from 'ant-design-vue';
import { getColorPalette } from '@sa/color';
import { getRgbOfColor } from '@sa/utils';
import { defu } from 'defu';
import { overrideThemeSettings, themeSettings } from '@/theme/settings';
import { themeVars } from '@/theme/vars';
import { toggleHtmlClass } from '@/utils/common';
Expand All @@ -19,12 +20,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 8559bea

Please sign in to comment.