Skip to content

Commit 60c615c

Browse files
authored
refactor: adjust layout refresh button and watermark; allow static i18n on language switch (#4579)
* refactor: adjust layout refresh button and watermark; allow static i18n on language switch * chore: typo
1 parent 324cdd8 commit 60c615c

File tree

25 files changed

+142
-125
lines changed

25 files changed

+142
-125
lines changed

apps/web-antd/src/layouts/basic.vue

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<script lang="ts" setup>
22
import type { NotificationItem } from '@vben/layouts';
33
4-
import { computed, ref } from 'vue';
4+
import { computed, ref, watch } from 'vue';
55
66
import { AuthenticationLoginExpiredModal } from '@vben/common-ui';
77
import { VBEN_DOC_URL, VBEN_GITHUB_URL } from '@vben/constants';
8+
import { useWatermark } from '@vben/hooks';
89
import { BookOpenText, CircleHelp, MdiGithub } from '@vben/icons';
910
import {
1011
BasicLayout,
@@ -54,6 +55,7 @@ const notifications = ref<NotificationItem[]>([
5455
const userStore = useUserStore();
5556
const authStore = useAuthStore();
5657
const accessStore = useAccessStore();
58+
const { destroyWatermark, updateWatermark } = useWatermark();
5759
const showDot = computed(() =>
5860
notifications.value.some((item) => !item.isRead),
5961
);
@@ -103,6 +105,21 @@ function handleNoticeClear() {
103105
function handleMakeAll() {
104106
notifications.value.forEach((item) => (item.isRead = true));
105107
}
108+
watch(
109+
() => preferences.app.watermark,
110+
async (enable) => {
111+
if (enable) {
112+
await updateWatermark({
113+
content: `${userStore.userInfo?.username}`,
114+
});
115+
} else {
116+
destroyWatermark();
117+
}
118+
},
119+
{
120+
immediate: true,
121+
},
122+
);
106123
</script>
107124

108125
<template>

apps/web-antd/src/router/guard.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ function setupCommonGuard(router: Router) {
3434
router.afterEach((to) => {
3535
// 记录页面是否加载,如果已经加载,后续的页面切换动画等效果不在重复执行
3636

37-
if (preferences.tabbar.enable) {
38-
loadedPaths.add(to.path);
39-
}
37+
loadedPaths.add(to.path);
4038

4139
// 关闭页面加载进度条
4240
if (preferences.transition.progress) {

apps/web-ele/src/layouts/basic.vue

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<script lang="ts" setup>
22
import type { NotificationItem } from '@vben/layouts';
33
4-
import { computed, ref } from 'vue';
4+
import { computed, ref, watch } from 'vue';
55
66
import { AuthenticationLoginExpiredModal } from '@vben/common-ui';
77
import { VBEN_DOC_URL, VBEN_GITHUB_URL } from '@vben/constants';
8+
import { useWatermark } from '@vben/hooks';
89
import { BookOpenText, CircleHelp, MdiGithub } from '@vben/icons';
910
import {
1011
BasicLayout,
@@ -54,6 +55,7 @@ const notifications = ref<NotificationItem[]>([
5455
const userStore = useUserStore();
5556
const authStore = useAuthStore();
5657
const accessStore = useAccessStore();
58+
const { destroyWatermark, updateWatermark } = useWatermark();
5759
const showDot = computed(() =>
5860
notifications.value.some((item) => !item.isRead),
5961
);
@@ -103,6 +105,21 @@ function handleNoticeClear() {
103105
function handleMakeAll() {
104106
notifications.value.forEach((item) => (item.isRead = true));
105107
}
108+
watch(
109+
() => preferences.app.watermark,
110+
async (enable) => {
111+
if (enable) {
112+
await updateWatermark({
113+
content: `${userStore.userInfo?.username}`,
114+
});
115+
} else {
116+
destroyWatermark();
117+
}
118+
},
119+
{
120+
immediate: true,
121+
},
122+
);
106123
</script>
107124

108125
<template>

apps/web-ele/src/router/guard.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ function setupCommonGuard(router: Router) {
3434
router.afterEach((to) => {
3535
// 记录页面是否加载,如果已经加载,后续的页面切换动画等效果不在重复执行
3636

37-
if (preferences.tabbar.enable) {
38-
loadedPaths.add(to.path);
39-
}
37+
loadedPaths.add(to.path);
4038

4139
// 关闭页面加载进度条
4240
if (preferences.transition.progress) {

apps/web-naive/src/layouts/basic.vue

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<script lang="ts" setup>
22
import type { NotificationItem } from '@vben/layouts';
33
4-
import { computed, ref } from 'vue';
4+
import { computed, ref, watch } from 'vue';
55
66
import { AuthenticationLoginExpiredModal } from '@vben/common-ui';
77
import { VBEN_DOC_URL, VBEN_GITHUB_URL } from '@vben/constants';
8+
import { useWatermark } from '@vben/hooks';
89
import { BookOpenText, CircleHelp, MdiGithub } from '@vben/icons';
910
import {
1011
BasicLayout,
@@ -54,6 +55,7 @@ const notifications = ref<NotificationItem[]>([
5455
const userStore = useUserStore();
5556
const authStore = useAuthStore();
5657
const accessStore = useAccessStore();
58+
const { destroyWatermark, updateWatermark } = useWatermark();
5759
const showDot = computed(() =>
5860
notifications.value.some((item) => !item.isRead),
5961
);
@@ -103,6 +105,22 @@ function handleNoticeClear() {
103105
function handleMakeAll() {
104106
notifications.value.forEach((item) => (item.isRead = true));
105107
}
108+
109+
watch(
110+
() => preferences.app.watermark,
111+
async (enable) => {
112+
if (enable) {
113+
await updateWatermark({
114+
content: `${userStore.userInfo?.username}`,
115+
});
116+
} else {
117+
destroyWatermark();
118+
}
119+
},
120+
{
121+
immediate: true,
122+
},
123+
);
106124
</script>
107125

108126
<template>

apps/web-naive/src/router/guard.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ function setupCommonGuard(router: Router) {
3434
router.afterEach((to) => {
3535
// 记录页面是否加载,如果已经加载,后续的页面切换动画等效果不在重复执行
3636

37-
if (preferences.tabbar.enable) {
38-
loadedPaths.add(to.path);
39-
}
37+
loadedPaths.add(to.path);
4038

4139
// 关闭页面加载进度条
4240
if (preferences.transition.progress) {

docs/src/en/guide/essentials/settings.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ const defaultPreferences: Preferences = {
234234
showIcon: true,
235235
showMaximize: true,
236236
showMore: true,
237-
showRefresh: true,
238237
styleType: 'chrome',
239238
},
240239
theme: {
@@ -262,6 +261,7 @@ const defaultPreferences: Preferences = {
262261
notification: true,
263262
sidebarToggle: true,
264263
themeToggle: true,
264+
refresh: true,
265265
},
266266
};
267267
```
@@ -421,8 +421,6 @@ interface TabbarPreferences {
421421
showMaximize: boolean;
422422
/** Whether to show the more button */
423423
showMore: boolean;
424-
/** Whether to show the refresh button */
425-
showRefresh: boolean;
426424
/** Tab style */
427425
styleType: TabsStyleType;
428426
}
@@ -469,6 +467,8 @@ interface WidgetPreferences {
469467
lockScreen: boolean;
470468
/** Whether notification widget is displayed */
471469
notification: boolean;
470+
/** Whether to show the refresh button */
471+
refresh: boolean;
472472
/** Whether sidebar show/hide widget is displayed */
473473
sidebarToggle: boolean;
474474
/** Whether theme switch widget is displayed */

docs/src/guide/essentials/settings.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ const defaultPreferences: Preferences = {
256256
showIcon: true,
257257
showMaximize: true,
258258
showMore: true,
259-
showRefresh: true,
260259
styleType: 'chrome',
261260
},
262261
theme: {
@@ -282,6 +281,7 @@ const defaultPreferences: Preferences = {
282281
languageToggle: true,
283282
lockScreen: true,
284283
notification: true,
284+
refresh: true,
285285
sidebarToggle: true,
286286
themeToggle: true,
287287
},
@@ -445,8 +445,6 @@ interface TabbarPreferences {
445445
showMaximize: boolean;
446446
/** 显示更多按钮 */
447447
showMore: boolean;
448-
/** 显示刷新按钮 */
449-
showRefresh: boolean;
450448
/** 标签页风格 */
451449
styleType: TabsStyleType;
452450
}
@@ -494,6 +492,8 @@ interface WidgetPreferences {
494492
lockScreen: boolean;
495493
/** 是否显示通知部件 */
496494
notification: boolean;
495+
/** 显示刷新按钮 */
496+
refresh: boolean;
497497
/** 是否显示侧边栏显示/隐藏部件 */
498498
sidebarToggle: boolean;
499499
/** 是否显示主题切换部件 */

packages/@core/preferences/__tests__/__snapshots__/config.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ exports[`defaultPreferences immutability test > should not modify the config obj
8181
"showIcon": true,
8282
"showMaximize": true,
8383
"showMore": true,
84-
"showRefresh": true,
8584
"styleType": "chrome",
8685
},
8786
"theme": {
@@ -107,6 +106,7 @@ exports[`defaultPreferences immutability test > should not modify the config obj
107106
"languageToggle": true,
108107
"lockScreen": true,
109108
"notification": true,
109+
"refresh": true,
110110
"sidebarToggle": true,
111111
"themeToggle": true,
112112
},

packages/@core/preferences/src/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const defaultPreferences: Preferences = {
8181
showIcon: true,
8282
showMaximize: true,
8383
showMore: true,
84-
showRefresh: true,
84+
8585
styleType: 'chrome',
8686
},
8787
theme: {
@@ -107,6 +107,7 @@ const defaultPreferences: Preferences = {
107107
languageToggle: true,
108108
lockScreen: true,
109109
notification: true,
110+
refresh: true,
110111
sidebarToggle: true,
111112
themeToggle: true,
112113
},

0 commit comments

Comments
 (0)