Skip to content

Commit c9014d0

Browse files
authored
perf: 优化关闭页面切换动画的tab切换性能 (vbenjs#5883)
1 parent ed26dca commit c9014d0

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

packages/effects/layouts/src/basic/content/content.vue

+35-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
RouteLocationNormalizedLoadedGeneric,
66
} from 'vue-router';
77
8+
import { computed } from 'vue';
89
import { RouterView } from 'vue-router';
910
1011
import { preferences, usePreferences } from '@vben/preferences';
@@ -20,6 +21,15 @@ const { keepAlive } = usePreferences();
2021
const { getCachedTabs, getExcludeCachedTabs, renderRouteView } =
2122
storeToRefs(tabbarStore);
2223
24+
/**
25+
* 是否使用动画
26+
*/
27+
const getEnabledTransition = computed(() => {
28+
const { transition } = preferences;
29+
const transitionName = transition.name;
30+
return transitionName && transition.enable;
31+
});
32+
2333
// 页面切换动画
2434
function getTransitionName(_route: RouteLocationNormalizedLoaded) {
2535
// 如果偏好设置未设置,则不使用动画
@@ -90,7 +100,12 @@ function transformComponent(
90100
<div class="relative h-full">
91101
<IFrameRouterView />
92102
<RouterView v-slot="{ Component, route }">
93-
<Transition :name="getTransitionName(route)" appear mode="out-in">
103+
<Transition
104+
v-if="getEnabledTransition"
105+
:name="getTransitionName(route)"
106+
appear
107+
mode="out-in"
108+
>
94109
<KeepAlive
95110
v-if="keepAlive"
96111
:exclude="getExcludeCachedTabs"
@@ -109,6 +124,25 @@ function transformComponent(
109124
:key="route.fullPath"
110125
/>
111126
</Transition>
127+
<template v-else>
128+
<KeepAlive
129+
v-if="keepAlive"
130+
:exclude="getExcludeCachedTabs"
131+
:include="getCachedTabs"
132+
>
133+
<component
134+
:is="transformComponent(Component, route)"
135+
v-if="renderRouteView"
136+
v-show="!route.meta.iframeSrc"
137+
:key="route.fullPath"
138+
/>
139+
</KeepAlive>
140+
<component
141+
:is="Component"
142+
v-else-if="renderRouteView"
143+
:key="route.fullPath"
144+
/>
145+
</template>
112146
</RouterView>
113147
</div>
114148
</template>

0 commit comments

Comments
 (0)