Commit a7a8b894c1062d8eb05a094fdbb7887044d0d973
1 parent
da76f3c7
fix(transition): fix transition not work
Showing
8 changed files
with
78 additions
and
23 deletions
src/components/Loading/index.ts
1 | -import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent'; | ||
2 | -export const Loading = createAsyncComponent(() => import('./src/index.vue')); | 1 | +// import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent'; |
2 | +// export const Loading = createAsyncComponent(() => import('./src/index.vue')); | ||
3 | 3 | ||
4 | +import Loading from './src/index.vue'; | ||
5 | + | ||
6 | +export { Loading }; | ||
4 | export { useLoading } from './src/useLoading'; | 7 | export { useLoading } from './src/useLoading'; |
5 | export { createLoading } from './src/createLoading'; | 8 | export { createLoading } from './src/createLoading'; |
src/components/Table/src/hooks/useTable.ts
src/layouts/default/content/index.vue
@@ -28,7 +28,6 @@ | @@ -28,7 +28,6 @@ | ||
28 | const { prefixCls } = useDesign('layout-content'); | 28 | const { prefixCls } = useDesign('layout-content'); |
29 | const { getOpenPageLoading } = useTransitionSetting(); | 29 | const { getOpenPageLoading } = useTransitionSetting(); |
30 | const { getLayoutContentMode, getPageLoading } = useRootSetting(); | 30 | const { getLayoutContentMode, getPageLoading } = useRootSetting(); |
31 | - | ||
32 | return { | 31 | return { |
33 | prefixCls, | 32 | prefixCls, |
34 | getOpenPageLoading, | 33 | getOpenPageLoading, |
src/layouts/iframe/index.vue
1 | <template> | 1 | <template> |
2 | - <div> | 2 | + <div v-if="showFrame"> |
3 | <template v-for="frame in getFramePages" :key="frame.path"> | 3 | <template v-for="frame in getFramePages" :key="frame.path"> |
4 | <FramePage | 4 | <FramePage |
5 | v-if="frame.meta.frameSrc && hasRenderFrame(frame.name)" | 5 | v-if="frame.meta.frameSrc && hasRenderFrame(frame.name)" |
@@ -10,7 +10,7 @@ | @@ -10,7 +10,7 @@ | ||
10 | </div> | 10 | </div> |
11 | </template> | 11 | </template> |
12 | <script lang="ts"> | 12 | <script lang="ts"> |
13 | - import { defineComponent } from 'vue'; | 13 | + import { defineComponent, unref, computed } from 'vue'; |
14 | import FramePage from '/@/views/sys/iframe/index.vue'; | 14 | import FramePage from '/@/views/sys/iframe/index.vue'; |
15 | 15 | ||
16 | import { useFrameKeepAlive } from './useFrameKeepAlive'; | 16 | import { useFrameKeepAlive } from './useFrameKeepAlive'; |
@@ -19,7 +19,13 @@ | @@ -19,7 +19,13 @@ | ||
19 | name: 'FrameLayout', | 19 | name: 'FrameLayout', |
20 | components: { FramePage }, | 20 | components: { FramePage }, |
21 | setup() { | 21 | setup() { |
22 | - return { ...useFrameKeepAlive() }; | 22 | + const { getFramePages, hasRenderFrame, showIframe } = useFrameKeepAlive(); |
23 | + | ||
24 | + const showFrame = computed(() => { | ||
25 | + return unref(getFramePages).length > 0; | ||
26 | + }); | ||
27 | + | ||
28 | + return { getFramePages, hasRenderFrame, showIframe, showFrame }; | ||
23 | }, | 29 | }, |
24 | }); | 30 | }); |
25 | </script> | 31 | </script> |
src/layouts/page/ParentView.vue
@@ -5,10 +5,24 @@ | @@ -5,10 +5,24 @@ | ||
5 | <div> | 5 | <div> |
6 | <router-view> | 6 | <router-view> |
7 | <template v-slot="{ Component, route }"> | 7 | <template v-slot="{ Component, route }"> |
8 | - <keep-alive v-if="openCache" :include="getCaches"> | ||
9 | - <component :is="Component" :key="route.fullPath" /> | ||
10 | - </keep-alive> | ||
11 | - <component v-else :is="Component" :key="route.fullPath" /> | 8 | + <transition |
9 | + :name=" | ||
10 | + getTransitionName({ | ||
11 | + route, | ||
12 | + openCache: openCache, | ||
13 | + enableTransition: getEnableTransition, | ||
14 | + cacheTabs: getCaches, | ||
15 | + def: getBasicTransition, | ||
16 | + }) | ||
17 | + " | ||
18 | + mode="out-in" | ||
19 | + appear | ||
20 | + > | ||
21 | + <keep-alive v-if="openCache" :include="getCaches"> | ||
22 | + <component :is="Component" :key="route.fullPath" /> | ||
23 | + </keep-alive> | ||
24 | + <component v-else :is="Component" :key="route.fullPath" /> | ||
25 | + </transition> | ||
12 | </template> | 26 | </template> |
13 | </router-view> | 27 | </router-view> |
14 | </div> | 28 | </div> |
@@ -21,6 +35,7 @@ | @@ -21,6 +35,7 @@ | ||
21 | 35 | ||
22 | import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting'; | 36 | import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting'; |
23 | import { useCache } from './useCache'; | 37 | import { useCache } from './useCache'; |
38 | + import { getTransitionName } from './transition'; | ||
24 | 39 | ||
25 | export default defineComponent({ | 40 | export default defineComponent({ |
26 | parentView: true, | 41 | parentView: true, |
@@ -40,6 +55,7 @@ | @@ -40,6 +55,7 @@ | ||
40 | getBasicTransition, | 55 | getBasicTransition, |
41 | openCache, | 56 | openCache, |
42 | getEnableTransition, | 57 | getEnableTransition, |
58 | + getTransitionName, | ||
43 | }; | 59 | }; |
44 | }, | 60 | }, |
45 | }); | 61 | }); |
src/layouts/page/index.tsx
1 | import type { FunctionalComponent } from 'vue'; | 1 | import type { FunctionalComponent } from 'vue'; |
2 | +import type { DefaultContext } from './transition'; | ||
2 | 3 | ||
3 | import { computed, defineComponent, unref, Transition, KeepAlive } from 'vue'; | 4 | import { computed, defineComponent, unref, Transition, KeepAlive } from 'vue'; |
4 | import { RouterView, RouteLocation } from 'vue-router'; | 5 | import { RouterView, RouteLocation } from 'vue-router'; |
@@ -10,6 +11,7 @@ import { useRootSetting } from '/@/hooks/setting/useRootSetting'; | @@ -10,6 +11,7 @@ import { useRootSetting } from '/@/hooks/setting/useRootSetting'; | ||
10 | import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting'; | 11 | import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting'; |
11 | import { useCache } from './useCache'; | 12 | import { useCache } from './useCache'; |
12 | import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting'; | 13 | import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting'; |
14 | +import { getTransitionName } from './transition'; | ||
13 | // import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent'; | 15 | // import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent'; |
14 | 16 | ||
15 | interface DefaultContext { | 17 | interface DefaultContext { |
@@ -32,17 +34,20 @@ export default defineComponent({ | @@ -32,17 +34,20 @@ export default defineComponent({ | ||
32 | 34 | ||
33 | return () => { | 35 | return () => { |
34 | return ( | 36 | return ( |
35 | - <div> | 37 | + <> |
36 | <RouterView> | 38 | <RouterView> |
37 | {{ | 39 | {{ |
38 | default: ({ Component, route }: DefaultContext) => { | 40 | default: ({ Component, route }: DefaultContext) => { |
39 | // No longer show animations that are already in the tab | 41 | // No longer show animations that are already in the tab |
40 | const cacheTabs = unref(getCaches); | 42 | const cacheTabs = unref(getCaches); |
41 | - const isInCache = cacheTabs.includes(route.name as string); | ||
42 | - const name = | ||
43 | - isInCache && route.meta.loaded && unref(getEnableTransition) | ||
44 | - ? 'fade-slide' | ||
45 | - : null; | 43 | + |
44 | + const name = getTransitionName({ | ||
45 | + route, | ||
46 | + openCache: unref(openCache), | ||
47 | + enableTransition: unref(getEnableTransition), | ||
48 | + cacheTabs, | ||
49 | + def: unref(getBasicTransition), | ||
50 | + }); | ||
46 | 51 | ||
47 | // When the child element is the parentView, adding the key will cause the component to be executed multiple times. When it is not parentView, you need to add a key, because it needs to be compatible with the same route carrying different parameters | 52 | // When the child element is the parentView, adding the key will cause the component to be executed multiple times. When it is not parentView, you need to add a key, because it needs to be compatible with the same route carrying different parameters |
48 | const isParentView = Component?.type.parentView; | 53 | const isParentView = Component?.type.parentView; |
@@ -60,11 +65,7 @@ export default defineComponent({ | @@ -60,11 +65,7 @@ export default defineComponent({ | ||
60 | return PageContent; | 65 | return PageContent; |
61 | } | 66 | } |
62 | return ( | 67 | return ( |
63 | - <Transition | ||
64 | - name={name || route.meta.transitionName || unref(getBasicTransition)} | ||
65 | - mode="out-in" | ||
66 | - appear={true} | ||
67 | - > | 68 | + <Transition name={name} mode="out-in" appear={true}> |
68 | {() => PageContent} | 69 | {() => PageContent} |
69 | </Transition> | 70 | </Transition> |
70 | ); | 71 | ); |
@@ -72,7 +73,7 @@ export default defineComponent({ | @@ -72,7 +73,7 @@ export default defineComponent({ | ||
72 | }} | 73 | }} |
73 | </RouterView> | 74 | </RouterView> |
74 | {unref(getCanEmbedIFramePage) && <FrameLayout />} | 75 | {unref(getCanEmbedIFramePage) && <FrameLayout />} |
75 | - </div> | 76 | + </> |
76 | ); | 77 | ); |
77 | }; | 78 | }; |
78 | }, | 79 | }, |
src/layouts/page/transition.ts
0 → 100644
1 | +import type { FunctionalComponent } from 'vue'; | ||
2 | +import type { RouteLocation } from 'vue-router'; | ||
3 | + | ||
4 | +export interface DefaultContext { | ||
5 | + Component: FunctionalComponent & { type: Indexable }; | ||
6 | + route: RouteLocation; | ||
7 | +} | ||
8 | + | ||
9 | +export function getTransitionName({ | ||
10 | + route, | ||
11 | + openCache, | ||
12 | + cacheTabs, | ||
13 | + enableTransition, | ||
14 | + def, | ||
15 | +}: Pick<DefaultContext, 'route'> & { | ||
16 | + enableTransition: boolean; | ||
17 | + openCache: boolean; | ||
18 | + def: string; | ||
19 | + cacheTabs: string[]; | ||
20 | +}) { | ||
21 | + const isInCache = cacheTabs.includes(route.name as string); | ||
22 | + const transitionName = 'fade-slide'; | ||
23 | + let name: string | null = transitionName; | ||
24 | + | ||
25 | + if (openCache) { | ||
26 | + name = isInCache && route.meta.loaded && enableTransition ? transitionName : null; | ||
27 | + } | ||
28 | + return name || route.meta.transitionName || def; | ||
29 | +} |
src/router/guard/index.ts
@@ -11,11 +11,11 @@ import { createPageGuard } from './pageGuard'; | @@ -11,11 +11,11 @@ import { createPageGuard } from './pageGuard'; | ||
11 | 11 | ||
12 | export function createGuard(router: Router) { | 12 | export function createGuard(router: Router) { |
13 | createPageGuard(router); | 13 | createPageGuard(router); |
14 | + createPageLoadingGuard(router); | ||
14 | createHttpGuard(router); | 15 | createHttpGuard(router); |
15 | createScrollGuard(router); | 16 | createScrollGuard(router); |
16 | createMessageGuard(router); | 17 | createMessageGuard(router); |
17 | createTitleGuard(router); | 18 | createTitleGuard(router); |
18 | - createPageLoadingGuard(router); | ||
19 | createProgressGuard(router); | 19 | createProgressGuard(router); |
20 | createPermissionGuard(router); | 20 | createPermissionGuard(router); |
21 | } | 21 | } |