optimize(projects): use defu
to fill added theme config
This commit is contained in:
parent
3e0eb72025
commit
101b6f9000
@ -57,6 +57,7 @@
|
|||||||
"@vueuse/core": "12.0.0",
|
"@vueuse/core": "12.0.0",
|
||||||
"clipboard": "2.0.11",
|
"clipboard": "2.0.11",
|
||||||
"dayjs": "1.11.13",
|
"dayjs": "1.11.13",
|
||||||
|
"defu": "6.1.4",
|
||||||
"echarts": "5.5.1",
|
"echarts": "5.5.1",
|
||||||
"json5": "2.2.3",
|
"json5": "2.2.3",
|
||||||
"naive-ui": "2.40.3",
|
"naive-ui": "2.40.3",
|
||||||
|
@ -38,6 +38,9 @@ importers:
|
|||||||
dayjs:
|
dayjs:
|
||||||
specifier: 1.11.13
|
specifier: 1.11.13
|
||||||
version: 1.11.13
|
version: 1.11.13
|
||||||
|
defu:
|
||||||
|
specifier: ^6.1.4
|
||||||
|
version: 6.1.4
|
||||||
echarts:
|
echarts:
|
||||||
specifier: 5.5.1
|
specifier: 5.5.1
|
||||||
version: 5.5.1
|
version: 5.5.1
|
||||||
|
@ -25,7 +25,7 @@ const naiveDateLocale = computed(() => {
|
|||||||
|
|
||||||
const watermarkProps = computed<WatermarkProps>(() => {
|
const watermarkProps = computed<WatermarkProps>(() => {
|
||||||
return {
|
return {
|
||||||
content: themeStore.watermark?.text || 'SoybeanAdmin',
|
content: themeStore.watermark.text,
|
||||||
cross: true,
|
cross: true,
|
||||||
fullscreen: true,
|
fullscreen: true,
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
@ -50,7 +50,7 @@ const watermarkProps = computed<WatermarkProps>(() => {
|
|||||||
>
|
>
|
||||||
<AppProvider>
|
<AppProvider>
|
||||||
<RouterView class="bg-layout" />
|
<RouterView class="bg-layout" />
|
||||||
<NWatermark v-if="themeStore.watermark?.visible" v-bind="watermarkProps" />
|
<NWatermark v-if="themeStore.watermark.visible" v-bind="watermarkProps" />
|
||||||
</AppProvider>
|
</AppProvider>
|
||||||
</NConfigProvider>
|
</NConfigProvider>
|
||||||
</template>
|
</template>
|
||||||
|
@ -114,10 +114,10 @@ const isWrapperScrollMode = computed(() => themeStore.layout.scrollMode === 'wra
|
|||||||
>
|
>
|
||||||
<NSwitch v-model:value="themeStore.footer.right" />
|
<NSwitch v-model:value="themeStore.footer.right" />
|
||||||
</SettingItem>
|
</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" />
|
<NSwitch v-model:value="themeStore.watermark.visible" />
|
||||||
</SettingItem>
|
</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
|
<NInput
|
||||||
v-model:value="themeStore.watermark.text"
|
v-model:value="themeStore.watermark.text"
|
||||||
autosize
|
autosize
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import type { GlobalThemeOverrides } from 'naive-ui';
|
import type { GlobalThemeOverrides } from 'naive-ui';
|
||||||
|
import { defu } from 'defu';
|
||||||
import { addColorAlpha, getColorPalette, getPaletteColorByNumber, getRgb } from '@sa/color';
|
import { addColorAlpha, getColorPalette, getPaletteColorByNumber, getRgb } from '@sa/color';
|
||||||
import { overrideThemeSettings, themeSettings } from '@/theme/settings';
|
import { overrideThemeSettings, themeSettings } from '@/theme/settings';
|
||||||
import { themeVars } from '@/theme/vars';
|
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 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`
|
// 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;
|
const isOverride = localStg.get('overrideThemeFlag') === BUILD_TIME;
|
||||||
|
|
||||||
if (!isOverride) {
|
if (!isOverride) {
|
||||||
Object.assign(settings, overrideThemeSettings);
|
settings = defu(overrideThemeSettings, settings);
|
||||||
|
|
||||||
localStg.set('overrideThemeFlag', BUILD_TIME);
|
localStg.set('overrideThemeFlag', BUILD_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,10 +83,4 @@ export const themeSettings: App.Theme.ThemeSetting = {
|
|||||||
*
|
*
|
||||||
* If publish new version, use `overrideThemeSettings` to override certain theme settings
|
* If publish new version, use `overrideThemeSettings` to override certain theme settings
|
||||||
*/
|
*/
|
||||||
export const overrideThemeSettings: Partial<App.Theme.ThemeSetting> = {
|
export const overrideThemeSettings: Partial<App.Theme.ThemeSetting> = {};
|
||||||
resetCacheStrategy: 'close',
|
|
||||||
watermark: {
|
|
||||||
visible: false,
|
|
||||||
text: 'SoybeanAdmin'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
6
src/typings/app.d.ts
vendored
6
src/typings/app.d.ts
vendored
@ -21,7 +21,7 @@ declare namespace App {
|
|||||||
/** Whether info color is followed by the primary color */
|
/** Whether info color is followed by the primary color */
|
||||||
isInfoFollowPrimary: boolean;
|
isInfoFollowPrimary: boolean;
|
||||||
/** Reset cache strategy */
|
/** Reset cache strategy */
|
||||||
resetCacheStrategy?: UnionKey.ResetCacheStrategy;
|
resetCacheStrategy: UnionKey.ResetCacheStrategy;
|
||||||
/** Layout */
|
/** Layout */
|
||||||
layout: {
|
layout: {
|
||||||
/** Layout mode */
|
/** Layout mode */
|
||||||
@ -33,7 +33,7 @@ declare namespace App {
|
|||||||
*
|
*
|
||||||
* if true, the vertical child level menus in left and horizontal first level menus in top
|
* if true, the vertical child level menus in left and horizontal first level menus in top
|
||||||
*/
|
*/
|
||||||
reverseHorizontalMix?: boolean;
|
reverseHorizontalMix: boolean;
|
||||||
};
|
};
|
||||||
/** Page */
|
/** Page */
|
||||||
page: {
|
page: {
|
||||||
@ -98,7 +98,7 @@ declare namespace App {
|
|||||||
right: boolean;
|
right: boolean;
|
||||||
};
|
};
|
||||||
/** Watermark */
|
/** Watermark */
|
||||||
watermark?: {
|
watermark: {
|
||||||
/** Whether to show the watermark */
|
/** Whether to show the watermark */
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
/** Watermark text */
|
/** Watermark text */
|
||||||
|
Loading…
Reference in New Issue
Block a user