Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: adjust layout refresh button and watermark; allow static i18n on language switch #4579

Merged
merged 2 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion apps/web-antd/src/layouts/basic.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<script lang="ts" setup>
import type { NotificationItem } from '@vben/layouts';

import { computed, ref } from 'vue';
import { computed, ref, watch } from 'vue';

import { AuthenticationLoginExpiredModal } from '@vben/common-ui';
import { VBEN_DOC_URL, VBEN_GITHUB_URL } from '@vben/constants';
import { useWatermark } from '@vben/hooks';
import { BookOpenText, CircleHelp, MdiGithub } from '@vben/icons';
import {
BasicLayout,
Expand Down Expand Up @@ -54,6 +55,7 @@ const notifications = ref<NotificationItem[]>([
const userStore = useUserStore();
const authStore = useAuthStore();
const accessStore = useAccessStore();
const { destroyWatermark, updateWatermark } = useWatermark();
const showDot = computed(() =>
notifications.value.some((item) => !item.isRead),
);
Expand Down Expand Up @@ -103,6 +105,21 @@ function handleNoticeClear() {
function handleMakeAll() {
notifications.value.forEach((item) => (item.isRead = true));
}
watch(
() => preferences.app.watermark,
async (enable) => {
if (enable) {
await updateWatermark({
content: `${userStore.userInfo?.username}`,
});
} else {
destroyWatermark();
}
},
{
immediate: true,
},
);
</script>

<template>
Expand Down
4 changes: 1 addition & 3 deletions apps/web-antd/src/router/guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ function setupCommonGuard(router: Router) {
router.afterEach((to) => {
// 记录页面是否加载,如果已经加载,后续的页面切换动画等效果不在重复执行

if (preferences.tabbar.enable) {
loadedPaths.add(to.path);
}
loadedPaths.add(to.path);

// 关闭页面加载进度条
if (preferences.transition.progress) {
Expand Down
19 changes: 18 additions & 1 deletion apps/web-ele/src/layouts/basic.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<script lang="ts" setup>
import type { NotificationItem } from '@vben/layouts';

import { computed, ref } from 'vue';
import { computed, ref, watch } from 'vue';

import { AuthenticationLoginExpiredModal } from '@vben/common-ui';
import { VBEN_DOC_URL, VBEN_GITHUB_URL } from '@vben/constants';
import { useWatermark } from '@vben/hooks';
import { BookOpenText, CircleHelp, MdiGithub } from '@vben/icons';
import {
BasicLayout,
Expand Down Expand Up @@ -54,6 +55,7 @@ const notifications = ref<NotificationItem[]>([
const userStore = useUserStore();
const authStore = useAuthStore();
const accessStore = useAccessStore();
const { destroyWatermark, updateWatermark } = useWatermark();
const showDot = computed(() =>
notifications.value.some((item) => !item.isRead),
);
Expand Down Expand Up @@ -103,6 +105,21 @@ function handleNoticeClear() {
function handleMakeAll() {
notifications.value.forEach((item) => (item.isRead = true));
}
watch(
() => preferences.app.watermark,
async (enable) => {
if (enable) {
await updateWatermark({
content: `${userStore.userInfo?.username}`,
});
} else {
destroyWatermark();
}
},
{
immediate: true,
},
);
anncwb marked this conversation as resolved.
Show resolved Hide resolved
</script>

<template>
Expand Down
4 changes: 1 addition & 3 deletions apps/web-ele/src/router/guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ function setupCommonGuard(router: Router) {
router.afterEach((to) => {
// 记录页面是否加载,如果已经加载,后续的页面切换动画等效果不在重复执行

if (preferences.tabbar.enable) {
loadedPaths.add(to.path);
}
loadedPaths.add(to.path);

// 关闭页面加载进度条
if (preferences.transition.progress) {
Expand Down
20 changes: 19 additions & 1 deletion apps/web-naive/src/layouts/basic.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<script lang="ts" setup>
import type { NotificationItem } from '@vben/layouts';

import { computed, ref } from 'vue';
import { computed, ref, watch } from 'vue';

import { AuthenticationLoginExpiredModal } from '@vben/common-ui';
import { VBEN_DOC_URL, VBEN_GITHUB_URL } from '@vben/constants';
import { useWatermark } from '@vben/hooks';
import { BookOpenText, CircleHelp, MdiGithub } from '@vben/icons';
import {
BasicLayout,
Expand Down Expand Up @@ -54,6 +55,7 @@ const notifications = ref<NotificationItem[]>([
const userStore = useUserStore();
const authStore = useAuthStore();
const accessStore = useAccessStore();
const { destroyWatermark, updateWatermark } = useWatermark();
anncwb marked this conversation as resolved.
Show resolved Hide resolved
const showDot = computed(() =>
notifications.value.some((item) => !item.isRead),
);
Expand Down Expand Up @@ -103,6 +105,22 @@ function handleNoticeClear() {
function handleMakeAll() {
notifications.value.forEach((item) => (item.isRead = true));
}

watch(
() => preferences.app.watermark,
async (enable) => {
if (enable) {
await updateWatermark({
content: `${userStore.userInfo?.username}`,
});
} else {
destroyWatermark();
}
},
{
immediate: true,
},
);
anncwb marked this conversation as resolved.
Show resolved Hide resolved
</script>

<template>
Expand Down
4 changes: 1 addition & 3 deletions apps/web-naive/src/router/guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ function setupCommonGuard(router: Router) {
router.afterEach((to) => {
// 记录页面是否加载,如果已经加载,后续的页面切换动画等效果不在重复执行

if (preferences.tabbar.enable) {
loadedPaths.add(to.path);
}
loadedPaths.add(to.path);

// 关闭页面加载进度条
if (preferences.transition.progress) {
Expand Down
6 changes: 3 additions & 3 deletions docs/src/en/guide/essentials/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ const defaultPreferences: Preferences = {
showIcon: true,
showMaximize: true,
showMore: true,
showRefresh: true,
styleType: 'chrome',
},
theme: {
Expand Down Expand Up @@ -262,6 +261,7 @@ const defaultPreferences: Preferences = {
notification: true,
sidebarToggle: true,
themeToggle: true,
refresh: true,
},
};
```
Expand Down Expand Up @@ -421,8 +421,6 @@ interface TabbarPreferences {
showMaximize: boolean;
/** Whether to show the more button */
showMore: boolean;
/** Whether to show the refresh button */
showRefresh: boolean;
/** Tab style */
styleType: TabsStyleType;
}
Expand Down Expand Up @@ -469,6 +467,8 @@ interface WidgetPreferences {
lockScreen: boolean;
/** Whether notification widget is displayed */
notification: boolean;
/** Whether to show the refresh button */
refresh: boolean;
/** Whether sidebar show/hide widget is displayed */
sidebarToggle: boolean;
/** Whether theme switch widget is displayed */
Expand Down
6 changes: 3 additions & 3 deletions docs/src/guide/essentials/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ const defaultPreferences: Preferences = {
showIcon: true,
showMaximize: true,
showMore: true,
showRefresh: true,
styleType: 'chrome',
},
theme: {
Expand All @@ -282,6 +281,7 @@ const defaultPreferences: Preferences = {
languageToggle: true,
lockScreen: true,
notification: true,
refresh: true,
sidebarToggle: true,
themeToggle: true,
},
Expand Down Expand Up @@ -445,8 +445,6 @@ interface TabbarPreferences {
showMaximize: boolean;
/** 显示更多按钮 */
showMore: boolean;
/** 显示刷新按钮 */
showRefresh: boolean;
/** 标签页风格 */
styleType: TabsStyleType;
}
Expand Down Expand Up @@ -494,6 +492,8 @@ interface WidgetPreferences {
lockScreen: boolean;
/** 是否显示通知部件 */
notification: boolean;
/** 显示刷新按钮 */
refresh: boolean;
/** 是否显示侧边栏显示/隐藏部件 */
sidebarToggle: boolean;
/** 是否显示主题切换部件 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ exports[`defaultPreferences immutability test > should not modify the config obj
"showIcon": true,
"showMaximize": true,
"showMore": true,
"showRefresh": true,
"styleType": "chrome",
},
"theme": {
Expand All @@ -107,6 +106,7 @@ exports[`defaultPreferences immutability test > should not modify the config obj
"languageToggle": true,
"lockScreen": true,
"notification": true,
"refresh": true,
"sidebarToggle": true,
"themeToggle": true,
},
Expand Down
3 changes: 2 additions & 1 deletion packages/@core/preferences/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const defaultPreferences: Preferences = {
showIcon: true,
showMaximize: true,
showMore: true,
showRefresh: true,

styleType: 'chrome',
},
theme: {
Expand All @@ -107,6 +107,7 @@ const defaultPreferences: Preferences = {
languageToggle: true,
lockScreen: true,
notification: true,
refresh: true,
sidebarToggle: true,
themeToggle: true,
},
Expand Down
4 changes: 2 additions & 2 deletions packages/@core/preferences/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ interface TabbarPreferences {
showMaximize: boolean;
/** 显示更多按钮 */
showMore: boolean;
/** 显示刷新按钮 */
showRefresh: boolean;
/** 标签页风格 */
styleType: TabsStyleType;
}
Expand Down Expand Up @@ -218,6 +216,8 @@ interface WidgetPreferences {
lockScreen: boolean;
/** 是否显示通知部件 */
notification: boolean;
/** 显示刷新按钮 */
refresh: boolean;
/** 是否显示侧边栏显示/隐藏部件 */
sidebarToggle: boolean;
/** 是否显示主题切换部件 */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { default as TabsToolMore } from './tool-more.vue';
export { default as TabsToolRefresh } from './tool-refresh.vue';
export { default as TabsToolScreen } from './tool-screen.vue';

This file was deleted.

13 changes: 1 addition & 12 deletions packages/effects/hooks/src/use-watermark.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type { Watermark, WatermarkOptions } from 'watermark-js-plus';

import { nextTick, onUnmounted, ref, watch } from 'vue';

import { preferences } from '@vben/preferences';
import { nextTick, onUnmounted, ref } from 'vue';

const watermark = ref<Watermark>();
const cachedOptions = ref<Partial<WatermarkOptions>>({
Expand Down Expand Up @@ -67,15 +65,6 @@ export function useWatermark() {
watermark.value?.destroy();
}

watch(
() => preferences.app.watermark,
(enable) => {
if (!enable) {
destroyWatermark();
}
},
);

onUnmounted(() => {
destroyWatermark();
});
Expand Down
4 changes: 2 additions & 2 deletions packages/effects/layouts/src/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
### header

- 支持N个自定义插槽,命名方式:header-right-n,header-left-n
- header-left-n ,排序方式:1-4 ,breadcrumb,6-x
- header-right-n ,排序方式:1-4,global-search,6-9,theme-toggle,11-14,language-toggle,16-19,fullscreen,21-24,notification,26-29,user-dropdown,30-x
- header-left-n ,排序方式:0-19 ,breadcrumb 21-x
- header-right-n ,排序方式:0-49,global-search,51-59,theme-toggle,61-69,language-toggle,71-79,fullscreen,81-89,notification,91-149,user-dropdown,151-x
Loading