Skip to content

Commit 7c3dac4

Browse files
wenyuanwhonghuangdc
authored andcommitted
feat(projects): add configurable user name watermark option
1 parent 39b89a1 commit 7c3dac4

File tree

6 files changed

+21
-5
lines changed

6 files changed

+21
-5
lines changed

src/App.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { NConfigProvider, darkTheme } from 'naive-ui';
44
import type { WatermarkProps } from 'naive-ui';
55
import { useAppStore } from './store/modules/app';
66
import { useThemeStore } from './store/modules/theme';
7+
import { useAuthStore } from './store/modules/auth';
78
import { naiveDateLocales, naiveLocales } from './locales/naive';
89
910
defineOptions({
@@ -12,6 +13,7 @@ defineOptions({
1213
1314
const appStore = useAppStore();
1415
const themeStore = useThemeStore();
16+
const authStore = useAuthStore();
1517
1618
const naiveDarkTheme = computed(() => (themeStore.darkMode ? darkTheme : undefined));
1719
@@ -24,8 +26,13 @@ const naiveDateLocale = computed(() => {
2426
});
2527
2628
const watermarkProps = computed<WatermarkProps>(() => {
29+
const content =
30+
themeStore.watermark.enableUserName && authStore.userInfo.userName
31+
? authStore.userInfo.userName
32+
: themeStore.watermark.text;
33+
2734
return {
28-
content: themeStore.watermark.text,
35+
content,
2936
cross: true,
3037
fullscreen: true,
3138
fontSize: 16,

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ const isWrapperScrollMode = computed(() => themeStore.layout.scrollMode === 'wra
117117
<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.enableUserName')">
121+
<NSwitch v-model:value="themeStore.watermark.enableUserName" />
122+
</SettingItem>
123+
<SettingItem v-if="themeStore.watermark.visible" key="8-2" :label="$t('theme.watermark.text')">
121124
<NInput
122125
v-model:value="themeStore.watermark.text"
123126
autosize

src/locales/langs/en-us.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ const local: App.I18n.Schema = {
143143
},
144144
watermark: {
145145
visible: 'Watermark Full Screen Visible',
146-
text: 'Watermark Text'
146+
text: 'Watermark Text',
147+
enableUserName: 'Enable User Name Watermark'
147148
},
148149
themeDrawerTitle: 'Theme Configuration',
149150
pageFunTitle: 'Page Function',

src/locales/langs/zh-cn.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ const local: App.I18n.Schema = {
143143
},
144144
watermark: {
145145
visible: '显示全屏水印',
146-
text: '水印文本'
146+
text: '水印文本',
147+
enableUserName: '启用用户名水印'
147148
},
148149
themeDrawerTitle: '主题配置',
149150
pageFunTitle: '页面功能',

src/theme/settings.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ export const themeSettings: App.Theme.ThemeSetting = {
5858
},
5959
watermark: {
6060
visible: false,
61-
text: 'SoybeanAdmin'
61+
text: 'SoybeanAdmin',
62+
enableUserName: false
6263
},
6364
tokens: {
6465
light: {

src/typings/app.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ declare namespace App {
112112
visible: boolean;
113113
/** Watermark text */
114114
text: string;
115+
/** Whether to use user name as watermark text */
116+
enableUserName: boolean;
115117
};
116118
/** define some theme settings tokens, will transform to css variables */
117119
tokens: {
@@ -408,6 +410,7 @@ declare namespace App {
408410
watermark: {
409411
visible: string;
410412
text: string;
413+
enableUserName: string;
411414
};
412415
themeDrawerTitle: string;
413416
pageFunTitle: string;

0 commit comments

Comments
 (0)