Commit 979058ad95d9669cb113033f76b5dafb932aad0f
1 parent
3b3a7462
perf: refoctor useTitle
Showing
11 changed files
with
61 additions
and
158 deletions
CHANGELOG.zh_CN.md
src/App.vue
@@ -14,18 +14,21 @@ | @@ -14,18 +14,21 @@ | ||
14 | import { initAppConfigStore } from '/@/logics/initAppConfig'; | 14 | import { initAppConfigStore } from '/@/logics/initAppConfig'; |
15 | 15 | ||
16 | import { useLockPage } from '/@/hooks/web/useLockPage'; | 16 | import { useLockPage } from '/@/hooks/web/useLockPage'; |
17 | + import { useTitle } from '/@/hooks/web/useTitle'; | ||
17 | import { useLocale } from '/@/locales/useLocale'; | 18 | import { useLocale } from '/@/locales/useLocale'; |
18 | 19 | ||
19 | export default defineComponent({ | 20 | export default defineComponent({ |
20 | name: 'App', | 21 | name: 'App', |
21 | components: { ConfigProvider, AppProvider }, | 22 | components: { ConfigProvider, AppProvider }, |
22 | setup() { | 23 | setup() { |
23 | - // support Multi-language | ||
24 | - const { getAntdLocale } = useLocale(); | ||
25 | - | ||
26 | // Initialize vuex internal system configuration | 24 | // Initialize vuex internal system configuration |
27 | initAppConfigStore(); | 25 | initAppConfigStore(); |
28 | 26 | ||
27 | + useTitle(); | ||
28 | + | ||
29 | + // support Multi-language | ||
30 | + const { getAntdLocale } = useLocale(); | ||
31 | + | ||
29 | // Create a lock screen monitor | 32 | // Create a lock screen monitor |
30 | const lockEvent = useLockPage(); | 33 | const lockEvent = useLockPage(); |
31 | 34 |
src/components/Table/src/components/settings/FullScreenSetting.vue
@@ -3,8 +3,8 @@ | @@ -3,8 +3,8 @@ | ||
3 | <template #title> | 3 | <template #title> |
4 | <span>{{ t('component.table.settingFullScreen') }}</span> | 4 | <span>{{ t('component.table.settingFullScreen') }}</span> |
5 | </template> | 5 | </template> |
6 | - <FullscreenOutlined @click="toggleFullscreen" v-if="!isFullscreenRef" /> | ||
7 | - <FullscreenExitOutlined @click="toggleFullscreen" v-else /> | 6 | + <FullscreenOutlined @click="toggle" v-if="!isFullscreen" /> |
7 | + <FullscreenExitOutlined @click="toggle" v-else /> | ||
8 | </Tooltip> | 8 | </Tooltip> |
9 | </template> | 9 | </template> |
10 | <script lang="ts"> | 10 | <script lang="ts"> |
@@ -12,7 +12,8 @@ | @@ -12,7 +12,8 @@ | ||
12 | import { Tooltip } from 'ant-design-vue'; | 12 | import { Tooltip } from 'ant-design-vue'; |
13 | import { FullscreenOutlined, FullscreenExitOutlined } from '@ant-design/icons-vue'; | 13 | import { FullscreenOutlined, FullscreenExitOutlined } from '@ant-design/icons-vue'; |
14 | 14 | ||
15 | - import { useFullscreen } from '/@/hooks/web/useFullScreen'; | 15 | + import { useFullscreen } from '@vueuse/core'; |
16 | + | ||
16 | import { useI18n } from '/@/hooks/web/useI18n'; | 17 | import { useI18n } from '/@/hooks/web/useI18n'; |
17 | import { useTableContext } from '../../hooks/useTableContext'; | 18 | import { useTableContext } from '../../hooks/useTableContext'; |
18 | 19 | ||
@@ -27,11 +28,11 @@ | @@ -27,11 +28,11 @@ | ||
27 | setup() { | 28 | setup() { |
28 | const table = useTableContext(); | 29 | const table = useTableContext(); |
29 | const { t } = useI18n(); | 30 | const { t } = useI18n(); |
30 | - const { toggleFullscreen, isFullscreenRef } = useFullscreen(table.wrapRef); | 31 | + const { toggle, isFullscreen } = useFullscreen(table.wrapRef); |
31 | 32 | ||
32 | return { | 33 | return { |
33 | - toggleFullscreen, | ||
34 | - isFullscreenRef, | 34 | + toggle, |
35 | + isFullscreen, | ||
35 | t, | 36 | t, |
36 | }; | 37 | }; |
37 | }, | 38 | }, |
src/hooks/core/useAttrs.ts
@@ -8,7 +8,7 @@ interface Params { | @@ -8,7 +8,7 @@ interface Params { | ||
8 | const DEFAULT_EXCLUDE_KEYS = ['class', 'style']; | 8 | const DEFAULT_EXCLUDE_KEYS = ['class', 'style']; |
9 | const LISTENER_PREFIX = /^on[A-Z]/; | 9 | const LISTENER_PREFIX = /^on[A-Z]/; |
10 | 10 | ||
11 | -export function entries<T>(obj: Hash<T>): [string, T][] { | 11 | +export function entries<T>(obj: Recordable<T>): [string, T][] { |
12 | return Object.keys(obj).map((key: string) => [key, obj[key]]); | 12 | return Object.keys(obj).map((key: string) => [key, obj[key]]); |
13 | } | 13 | } |
14 | 14 |
src/hooks/web/useFullScreen.ts deleted
100644 → 0
1 | -import { Ref, ref, unref } from 'vue'; | ||
2 | - | ||
3 | -type RFSMethodName = | ||
4 | - | 'webkitRequestFullScreen' | ||
5 | - | 'requestFullscreen' | ||
6 | - | 'msRequestFullscreen' | ||
7 | - | 'mozRequestFullScreen'; | ||
8 | -type EFSMethodName = | ||
9 | - | 'webkitExitFullscreen' | ||
10 | - | 'msExitFullscreen' | ||
11 | - | 'mozCancelFullScreen' | ||
12 | - | 'exitFullscreen'; | ||
13 | -type FSEPropName = | ||
14 | - | 'webkitFullscreenElement' | ||
15 | - | 'msFullscreenElement' | ||
16 | - | 'mozFullScreenElement' | ||
17 | - | 'fullscreenElement'; | ||
18 | - | ||
19 | -export function useFullscreen( | ||
20 | - target: Ref<Nullable<HTMLElement>> | Nullable<HTMLElement> = ref(document.documentElement), | ||
21 | - options?: FullscreenOptions | ||
22 | -) { | ||
23 | - const isFullscreenRef = ref(false); | ||
24 | - const el = document.documentElement; | ||
25 | - let RFC_METHOD_NAME: RFSMethodName = 'requestFullscreen'; | ||
26 | - let EFS_METHOD_NAME: EFSMethodName = 'exitFullscreen'; | ||
27 | - let FSE_PROP_NAME: FSEPropName = 'fullscreenElement'; | ||
28 | - | ||
29 | - if ('webkitRequestFullScreen' in el) { | ||
30 | - RFC_METHOD_NAME = 'webkitRequestFullScreen'; | ||
31 | - EFS_METHOD_NAME = 'webkitExitFullscreen'; | ||
32 | - FSE_PROP_NAME = 'webkitFullscreenElement'; | ||
33 | - } else if ('msRequestFullscreen' in el) { | ||
34 | - RFC_METHOD_NAME = 'msRequestFullscreen'; | ||
35 | - EFS_METHOD_NAME = 'msExitFullscreen'; | ||
36 | - FSE_PROP_NAME = 'msFullscreenElement'; | ||
37 | - } else if ('mozRequestFullScreen' in el) { | ||
38 | - RFC_METHOD_NAME = 'mozRequestFullScreen'; | ||
39 | - EFS_METHOD_NAME = 'mozCancelFullScreen'; | ||
40 | - FSE_PROP_NAME = 'mozFullScreenElement'; | ||
41 | - } else if (!('requestFullscreen' in el)) { | ||
42 | - throw new Error('当前浏览器不支持Fullscreen API !'); | ||
43 | - } | ||
44 | - function enterFullscreen(): Promise<void> { | ||
45 | - isFullscreenRef.value = true; | ||
46 | - return (unref(target) as any)[RFC_METHOD_NAME](options); | ||
47 | - } | ||
48 | - | ||
49 | - function exitFullscreen(): Promise<void> { | ||
50 | - isFullscreenRef.value = false; | ||
51 | - return (document as any)[EFS_METHOD_NAME](); | ||
52 | - } | ||
53 | - | ||
54 | - function isFullscreen(): boolean { | ||
55 | - return unref(target) === (document as any)[FSE_PROP_NAME]; | ||
56 | - } | ||
57 | - | ||
58 | - async function toggleFullscreen(): Promise<void> { | ||
59 | - if (!unref(target)) return; | ||
60 | - return isFullscreen() ? exitFullscreen() : enterFullscreen(); | ||
61 | - } | ||
62 | - | ||
63 | - return { | ||
64 | - // watchFullscreen, | ||
65 | - toggleFullscreen, | ||
66 | - exitFullscreen, | ||
67 | - isFullscreen, | ||
68 | - enterFullscreen, | ||
69 | - isFullscreenRef, | ||
70 | - }; | ||
71 | -} |
src/hooks/web/useTitle.ts
0 → 100644
1 | +import { useI18n } from '/@/hooks/web/useI18n'; | ||
2 | +import { useTitle as usePageTitle } from '@vueuse/core'; | ||
3 | +import { useGlobSetting } from '/@/hooks/setting'; | ||
4 | + | ||
5 | +import { REDIRECT_NAME } from '/@/router/constant'; | ||
6 | +import { listenerLastChangeTab } from '/@/logics/mitt/tabChange'; | ||
7 | + | ||
8 | +export function useTitle() { | ||
9 | + const { title } = useGlobSetting(); | ||
10 | + const { t } = useI18n(); | ||
11 | + | ||
12 | + const pageTitle = usePageTitle(); | ||
13 | + | ||
14 | + listenerLastChangeTab((route) => { | ||
15 | + if (route.name === REDIRECT_NAME) { | ||
16 | + return; | ||
17 | + } | ||
18 | + | ||
19 | + const tTitle = t(route?.meta?.title as string); | ||
20 | + pageTitle.value = tTitle ? ` ${tTitle} - ${title} ` : `${title}`; | ||
21 | + }); | ||
22 | +} |
src/layouts/default/header/components/FullScreen.vue
1 | <template> | 1 | <template> |
2 | <Tooltip :title="getTitle" placement="bottom" :mouseEnterDelay="0.5"> | 2 | <Tooltip :title="getTitle" placement="bottom" :mouseEnterDelay="0.5"> |
3 | - <span @click="toggleFullscreen"> | 3 | + <span @click="toggle"> |
4 | <FullscreenOutlined v-if="!isFullscreen" /> | 4 | <FullscreenOutlined v-if="!isFullscreen" /> |
5 | <FullscreenExitOutlined v-else /> | 5 | <FullscreenExitOutlined v-else /> |
6 | </span> | 6 | </span> |
@@ -10,7 +10,8 @@ | @@ -10,7 +10,8 @@ | ||
10 | import { defineComponent, computed, unref } from 'vue'; | 10 | import { defineComponent, computed, unref } from 'vue'; |
11 | import { Tooltip } from 'ant-design-vue'; | 11 | import { Tooltip } from 'ant-design-vue'; |
12 | import { useI18n } from '/@/hooks/web/useI18n'; | 12 | import { useI18n } from '/@/hooks/web/useI18n'; |
13 | - import { useFullscreen } from '/@/hooks/web/useFullScreen'; | 13 | + import { useFullscreen } from '@vueuse/core'; |
14 | + | ||
14 | import { FullscreenExitOutlined, FullscreenOutlined } from '@ant-design/icons-vue'; | 15 | import { FullscreenExitOutlined, FullscreenOutlined } from '@ant-design/icons-vue'; |
15 | export default defineComponent({ | 16 | export default defineComponent({ |
16 | name: 'FullScreen', | 17 | name: 'FullScreen', |
@@ -18,18 +19,18 @@ | @@ -18,18 +19,18 @@ | ||
18 | 19 | ||
19 | setup() { | 20 | setup() { |
20 | const { t } = useI18n(); | 21 | const { t } = useI18n(); |
21 | - const { toggleFullscreen, isFullscreenRef } = useFullscreen(); | 22 | + const { toggle, isFullscreen } = useFullscreen(); |
22 | 23 | ||
23 | const getTitle = computed(() => { | 24 | const getTitle = computed(() => { |
24 | - return unref(isFullscreenRef) | 25 | + return unref(isFullscreen) |
25 | ? t('layout.header.tooltipExitFull') | 26 | ? t('layout.header.tooltipExitFull') |
26 | : t('layout.header.tooltipEntryFull'); | 27 | : t('layout.header.tooltipEntryFull'); |
27 | }); | 28 | }); |
28 | 29 | ||
29 | return { | 30 | return { |
30 | getTitle, | 31 | getTitle, |
31 | - isFullscreen: isFullscreenRef, | ||
32 | - toggleFullscreen, | 32 | + isFullscreen, |
33 | + toggle, | ||
33 | }; | 34 | }; |
34 | }, | 35 | }, |
35 | }); | 36 | }); |
src/router/guard/index.ts
@@ -3,7 +3,6 @@ import router from '/@/router'; | @@ -3,7 +3,6 @@ import router from '/@/router'; | ||
3 | import { createProgressGuard } from './progressGuard'; | 3 | import { createProgressGuard } from './progressGuard'; |
4 | import { createPermissionGuard } from './permissionGuard'; | 4 | import { createPermissionGuard } from './permissionGuard'; |
5 | import { createPageLoadingGuard } from './pageLoadingGuard'; | 5 | import { createPageLoadingGuard } from './pageLoadingGuard'; |
6 | -import { createTitleGuard } from './titleGuard'; | ||
7 | import { createMessageGuard } from './messageGuard'; | 6 | import { createMessageGuard } from './messageGuard'; |
8 | import { createScrollGuard } from './scrollGuard'; | 7 | import { createScrollGuard } from './scrollGuard'; |
9 | import { createHttpGuard } from './httpGuard'; | 8 | import { createHttpGuard } from './httpGuard'; |
@@ -15,7 +14,6 @@ createPageLoadingGuard(router); | @@ -15,7 +14,6 @@ createPageLoadingGuard(router); | ||
15 | createHttpGuard(router); | 14 | createHttpGuard(router); |
16 | createScrollGuard(router); | 15 | createScrollGuard(router); |
17 | createMessageGuard(router); | 16 | createMessageGuard(router); |
18 | -createTitleGuard(router); | ||
19 | createProgressGuard(router); | 17 | createProgressGuard(router); |
20 | createPermissionGuard(router); | 18 | createPermissionGuard(router); |
21 | createStateGuard(router); | 19 | createStateGuard(router); |
src/router/guard/titleGuard.ts deleted
100644 → 0
1 | -import type { Router } from 'vue-router'; | ||
2 | - | ||
3 | -import { useGlobSetting } from '/@/hooks/setting'; | ||
4 | - | ||
5 | -import { setTitle } from '/@/utils'; | ||
6 | -import { useI18n } from '/@/hooks/web/useI18n'; | ||
7 | - | ||
8 | -import { REDIRECT_NAME } from '/@/router/constant'; | ||
9 | - | ||
10 | -const globSetting = useGlobSetting(); | ||
11 | - | ||
12 | -export function createTitleGuard(router: Router) { | ||
13 | - router.afterEach(async (to) => { | ||
14 | - const { t } = useI18n(); | ||
15 | - to.name !== REDIRECT_NAME && setTitle(t(to.meta.title as string), globSetting.title); | ||
16 | - return true; | ||
17 | - }); | ||
18 | -} |
src/utils/index.ts
@@ -62,35 +62,6 @@ export function getDynamicProps<T, U>(props: T): Partial<U> { | @@ -62,35 +62,6 @@ export function getDynamicProps<T, U>(props: T): Partial<U> { | ||
62 | return ret as Partial<U>; | 62 | return ret as Partial<U>; |
63 | } | 63 | } |
64 | 64 | ||
65 | -/** | ||
66 | - * set page Title | ||
67 | - * @param {*} title :page Title | ||
68 | - */ | ||
69 | -function setDocumentTitle(title: string) { | ||
70 | - document.title = title; | ||
71 | - const ua = navigator.userAgent; | ||
72 | - const regex = /\bMicroMessenger\/([\d.]+)/; | ||
73 | - // 兼容 | ||
74 | - if (regex.test(ua) && /ip(hone|od|ad)/i.test(ua)) { | ||
75 | - const i = document.createElement('iframe'); | ||
76 | - i.src = '/favicon.ico'; | ||
77 | - i.style.display = 'none'; | ||
78 | - i.onload = function () { | ||
79 | - setTimeout(function () { | ||
80 | - i.remove(); | ||
81 | - }, 9); | ||
82 | - }; | ||
83 | - document.body.appendChild(i); | ||
84 | - } | ||
85 | -} | ||
86 | - | ||
87 | -export function setTitle(title: string, appTitle?: string) { | ||
88 | - if (title) { | ||
89 | - const _title = title ? ` ${title} - ${appTitle} ` : `${appTitle}`; | ||
90 | - setDocumentTitle(_title); | ||
91 | - } | ||
92 | -} | ||
93 | - | ||
94 | export function getRawRoute(route: RouteLocationNormalized): RouteLocationNormalized { | 65 | export function getRawRoute(route: RouteLocationNormalized): RouteLocationNormalized { |
95 | if (!route) return route; | 66 | if (!route) return route; |
96 | const { matched, ...opt } = route; | 67 | const { matched, ...opt } = route; |
src/views/demo/feat/full-screen/index.vue
1 | <template> | 1 | <template> |
2 | <PageWrapper title="全屏示例"> | 2 | <PageWrapper title="全屏示例"> |
3 | <CollapseContainer class="w-full h-32 bg-white rounded-md" title="Window Full Screen"> | 3 | <CollapseContainer class="w-full h-32 bg-white rounded-md" title="Window Full Screen"> |
4 | - <a-button type="primary" @click="enterFullscreen" class="mr-2"> | ||
5 | - Enter Window Full Screen | ||
6 | - </a-button> | ||
7 | - <a-button color="success" @click="toggleFullscreen" class="mr-2"> | ||
8 | - Toggle Window Full Screen | ||
9 | - </a-button> | 4 | + <a-button type="primary" @click="enter" class="mr-2"> Enter Window Full Screen </a-button> |
5 | + <a-button color="success" @click="toggle" class="mr-2"> Toggle Window Full Screen </a-button> | ||
10 | 6 | ||
11 | - <a-button color="error" @click="exitFullscreen" class="mr-2"> | ||
12 | - Exit Window Full Screen | ||
13 | - </a-button> | 7 | + <a-button color="error" @click="exit" class="mr-2"> Exit Window Full Screen </a-button> |
14 | 8 | ||
15 | - Current State: {{ isFullscreenRef }} | 9 | + Current State: {{ isFullscreen }} |
16 | </CollapseContainer> | 10 | </CollapseContainer> |
17 | 11 | ||
18 | <CollapseContainer class="w-full mt-5 bg-white rounded-md" title="Dom Full Screen"> | 12 | <CollapseContainer class="w-full mt-5 bg-white rounded-md" title="Dom Full Screen"> |
@@ -30,27 +24,23 @@ | @@ -30,27 +24,23 @@ | ||
30 | <script lang="ts"> | 24 | <script lang="ts"> |
31 | import { defineComponent, ref } from 'vue'; | 25 | import { defineComponent, ref } from 'vue'; |
32 | import { CollapseContainer } from '/@/components/Container/index'; | 26 | import { CollapseContainer } from '/@/components/Container/index'; |
33 | - import { useFullscreen } from '/@/hooks/web/useFullScreen'; | 27 | + import { useFullscreen } from '@vueuse/core'; |
28 | + | ||
34 | import { PageWrapper } from '/@/components/Page'; | 29 | import { PageWrapper } from '/@/components/Page'; |
35 | 30 | ||
36 | export default defineComponent({ | 31 | export default defineComponent({ |
37 | components: { CollapseContainer, PageWrapper }, | 32 | components: { CollapseContainer, PageWrapper }, |
38 | setup() { | 33 | setup() { |
39 | const domRef = ref<Nullable<HTMLElement>>(null); | 34 | const domRef = ref<Nullable<HTMLElement>>(null); |
40 | - const { | ||
41 | - enterFullscreen, | ||
42 | - toggleFullscreen, | ||
43 | - isFullscreenRef, | ||
44 | - exitFullscreen, | ||
45 | - } = useFullscreen(); | 35 | + const { enter, toggle, exit, isFullscreen } = useFullscreen(); |
46 | 36 | ||
47 | - const { toggleFullscreen: toggleDom } = useFullscreen(domRef); | 37 | + const { toggle: toggleDom } = useFullscreen(domRef); |
48 | return { | 38 | return { |
49 | - enterFullscreen, | 39 | + enter, |
50 | toggleDom, | 40 | toggleDom, |
51 | - toggleFullscreen, | ||
52 | - isFullscreenRef, | ||
53 | - exitFullscreen, | 41 | + toggle, |
42 | + isFullscreen, | ||
43 | + exit, | ||
54 | domRef, | 44 | domRef, |
55 | }; | 45 | }; |
56 | }, | 46 | }, |