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 | 7 | export { useLoading } from './src/useLoading'; |
5 | 8 | export { createLoading } from './src/createLoading'; | ... | ... |
src/components/Table/src/hooks/useTable.ts
src/layouts/default/content/index.vue
src/layouts/iframe/index.vue
1 | 1 | <template> |
2 | - <div> | |
2 | + <div v-if="showFrame"> | |
3 | 3 | <template v-for="frame in getFramePages" :key="frame.path"> |
4 | 4 | <FramePage |
5 | 5 | v-if="frame.meta.frameSrc && hasRenderFrame(frame.name)" |
... | ... | @@ -10,7 +10,7 @@ |
10 | 10 | </div> |
11 | 11 | </template> |
12 | 12 | <script lang="ts"> |
13 | - import { defineComponent } from 'vue'; | |
13 | + import { defineComponent, unref, computed } from 'vue'; | |
14 | 14 | import FramePage from '/@/views/sys/iframe/index.vue'; |
15 | 15 | |
16 | 16 | import { useFrameKeepAlive } from './useFrameKeepAlive'; |
... | ... | @@ -19,7 +19,13 @@ |
19 | 19 | name: 'FrameLayout', |
20 | 20 | components: { FramePage }, |
21 | 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 | 31 | </script> | ... | ... |
src/layouts/page/ParentView.vue
... | ... | @@ -5,10 +5,24 @@ |
5 | 5 | <div> |
6 | 6 | <router-view> |
7 | 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 | 26 | </template> |
13 | 27 | </router-view> |
14 | 28 | </div> |
... | ... | @@ -21,6 +35,7 @@ |
21 | 35 | |
22 | 36 | import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting'; |
23 | 37 | import { useCache } from './useCache'; |
38 | + import { getTransitionName } from './transition'; | |
24 | 39 | |
25 | 40 | export default defineComponent({ |
26 | 41 | parentView: true, |
... | ... | @@ -40,6 +55,7 @@ |
40 | 55 | getBasicTransition, |
41 | 56 | openCache, |
42 | 57 | getEnableTransition, |
58 | + getTransitionName, | |
43 | 59 | }; |
44 | 60 | }, |
45 | 61 | }); | ... | ... |
src/layouts/page/index.tsx
1 | 1 | import type { FunctionalComponent } from 'vue'; |
2 | +import type { DefaultContext } from './transition'; | |
2 | 3 | |
3 | 4 | import { computed, defineComponent, unref, Transition, KeepAlive } from 'vue'; |
4 | 5 | import { RouterView, RouteLocation } from 'vue-router'; |
... | ... | @@ -10,6 +11,7 @@ import { useRootSetting } from '/@/hooks/setting/useRootSetting'; |
10 | 11 | import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting'; |
11 | 12 | import { useCache } from './useCache'; |
12 | 13 | import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting'; |
14 | +import { getTransitionName } from './transition'; | |
13 | 15 | // import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent'; |
14 | 16 | |
15 | 17 | interface DefaultContext { |
... | ... | @@ -32,17 +34,20 @@ export default defineComponent({ |
32 | 34 | |
33 | 35 | return () => { |
34 | 36 | return ( |
35 | - <div> | |
37 | + <> | |
36 | 38 | <RouterView> |
37 | 39 | {{ |
38 | 40 | default: ({ Component, route }: DefaultContext) => { |
39 | 41 | // No longer show animations that are already in the tab |
40 | 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 | 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 | 53 | const isParentView = Component?.type.parentView; |
... | ... | @@ -60,11 +65,7 @@ export default defineComponent({ |
60 | 65 | return PageContent; |
61 | 66 | } |
62 | 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 | 69 | {() => PageContent} |
69 | 70 | </Transition> |
70 | 71 | ); |
... | ... | @@ -72,7 +73,7 @@ export default defineComponent({ |
72 | 73 | }} |
73 | 74 | </RouterView> |
74 | 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 | |
12 | 12 | export function createGuard(router: Router) { |
13 | 13 | createPageGuard(router); |
14 | + createPageLoadingGuard(router); | |
14 | 15 | createHttpGuard(router); |
15 | 16 | createScrollGuard(router); |
16 | 17 | createMessageGuard(router); |
17 | 18 | createTitleGuard(router); |
18 | - createPageLoadingGuard(router); | |
19 | 19 | createProgressGuard(router); |
20 | 20 | createPermissionGuard(router); |
21 | 21 | } | ... | ... |