mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-08-27 19:44:50 +08:00
fix(transition): fix transition not work
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
|
// import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
|
||||||
export const Loading = createAsyncComponent(() => import('./src/index.vue'));
|
// export const Loading = createAsyncComponent(() => import('./src/index.vue'));
|
||||||
|
|
||||||
|
import Loading from './src/index.vue';
|
||||||
|
|
||||||
|
export { Loading };
|
||||||
export { useLoading } from './src/useLoading';
|
export { useLoading } from './src/useLoading';
|
||||||
export { createLoading } from './src/createLoading';
|
export { createLoading } from './src/createLoading';
|
||||||
|
@@ -42,6 +42,7 @@ export function useTable(
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
immediate: true,
|
immediate: true,
|
||||||
|
deep: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -28,7 +28,6 @@
|
|||||||
const { prefixCls } = useDesign('layout-content');
|
const { prefixCls } = useDesign('layout-content');
|
||||||
const { getOpenPageLoading } = useTransitionSetting();
|
const { getOpenPageLoading } = useTransitionSetting();
|
||||||
const { getLayoutContentMode, getPageLoading } = useRootSetting();
|
const { getLayoutContentMode, getPageLoading } = useRootSetting();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
prefixCls,
|
prefixCls,
|
||||||
getOpenPageLoading,
|
getOpenPageLoading,
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div v-if="showFrame">
|
||||||
<template v-for="frame in getFramePages" :key="frame.path">
|
<template v-for="frame in getFramePages" :key="frame.path">
|
||||||
<FramePage
|
<FramePage
|
||||||
v-if="frame.meta.frameSrc && hasRenderFrame(frame.name)"
|
v-if="frame.meta.frameSrc && hasRenderFrame(frame.name)"
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent, unref, computed } from 'vue';
|
||||||
import FramePage from '/@/views/sys/iframe/index.vue';
|
import FramePage from '/@/views/sys/iframe/index.vue';
|
||||||
|
|
||||||
import { useFrameKeepAlive } from './useFrameKeepAlive';
|
import { useFrameKeepAlive } from './useFrameKeepAlive';
|
||||||
@@ -19,7 +19,13 @@
|
|||||||
name: 'FrameLayout',
|
name: 'FrameLayout',
|
||||||
components: { FramePage },
|
components: { FramePage },
|
||||||
setup() {
|
setup() {
|
||||||
return { ...useFrameKeepAlive() };
|
const { getFramePages, hasRenderFrame, showIframe } = useFrameKeepAlive();
|
||||||
|
|
||||||
|
const showFrame = computed(() => {
|
||||||
|
return unref(getFramePages).length > 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
return { getFramePages, hasRenderFrame, showIframe, showFrame };
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@@ -5,10 +5,24 @@
|
|||||||
<div>
|
<div>
|
||||||
<router-view>
|
<router-view>
|
||||||
<template v-slot="{ Component, route }">
|
<template v-slot="{ Component, route }">
|
||||||
<keep-alive v-if="openCache" :include="getCaches">
|
<transition
|
||||||
<component :is="Component" :key="route.fullPath" />
|
:name="
|
||||||
</keep-alive>
|
getTransitionName({
|
||||||
<component v-else :is="Component" :key="route.fullPath" />
|
route,
|
||||||
|
openCache: openCache,
|
||||||
|
enableTransition: getEnableTransition,
|
||||||
|
cacheTabs: getCaches,
|
||||||
|
def: getBasicTransition,
|
||||||
|
})
|
||||||
|
"
|
||||||
|
mode="out-in"
|
||||||
|
appear
|
||||||
|
>
|
||||||
|
<keep-alive v-if="openCache" :include="getCaches">
|
||||||
|
<component :is="Component" :key="route.fullPath" />
|
||||||
|
</keep-alive>
|
||||||
|
<component v-else :is="Component" :key="route.fullPath" />
|
||||||
|
</transition>
|
||||||
</template>
|
</template>
|
||||||
</router-view>
|
</router-view>
|
||||||
</div>
|
</div>
|
||||||
@@ -21,6 +35,7 @@
|
|||||||
|
|
||||||
import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting';
|
import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting';
|
||||||
import { useCache } from './useCache';
|
import { useCache } from './useCache';
|
||||||
|
import { getTransitionName } from './transition';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
parentView: true,
|
parentView: true,
|
||||||
@@ -40,6 +55,7 @@
|
|||||||
getBasicTransition,
|
getBasicTransition,
|
||||||
openCache,
|
openCache,
|
||||||
getEnableTransition,
|
getEnableTransition,
|
||||||
|
getTransitionName,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import type { FunctionalComponent } from 'vue';
|
import type { FunctionalComponent } from 'vue';
|
||||||
|
import type { DefaultContext } from './transition';
|
||||||
|
|
||||||
import { computed, defineComponent, unref, Transition, KeepAlive } from 'vue';
|
import { computed, defineComponent, unref, Transition, KeepAlive } from 'vue';
|
||||||
import { RouterView, RouteLocation } from 'vue-router';
|
import { RouterView, RouteLocation } from 'vue-router';
|
||||||
@@ -10,6 +11,7 @@ import { useRootSetting } from '/@/hooks/setting/useRootSetting';
|
|||||||
import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting';
|
import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting';
|
||||||
import { useCache } from './useCache';
|
import { useCache } from './useCache';
|
||||||
import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting';
|
import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting';
|
||||||
|
import { getTransitionName } from './transition';
|
||||||
// import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
|
// import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
|
||||||
|
|
||||||
interface DefaultContext {
|
interface DefaultContext {
|
||||||
@@ -32,17 +34,20 @@ export default defineComponent({
|
|||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<>
|
||||||
<RouterView>
|
<RouterView>
|
||||||
{{
|
{{
|
||||||
default: ({ Component, route }: DefaultContext) => {
|
default: ({ Component, route }: DefaultContext) => {
|
||||||
// No longer show animations that are already in the tab
|
// No longer show animations that are already in the tab
|
||||||
const cacheTabs = unref(getCaches);
|
const cacheTabs = unref(getCaches);
|
||||||
const isInCache = cacheTabs.includes(route.name as string);
|
|
||||||
const name =
|
const name = getTransitionName({
|
||||||
isInCache && route.meta.loaded && unref(getEnableTransition)
|
route,
|
||||||
? 'fade-slide'
|
openCache: unref(openCache),
|
||||||
: null;
|
enableTransition: unref(getEnableTransition),
|
||||||
|
cacheTabs,
|
||||||
|
def: unref(getBasicTransition),
|
||||||
|
});
|
||||||
|
|
||||||
// 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
|
// 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
|
||||||
const isParentView = Component?.type.parentView;
|
const isParentView = Component?.type.parentView;
|
||||||
@@ -60,11 +65,7 @@ export default defineComponent({
|
|||||||
return PageContent;
|
return PageContent;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<Transition
|
<Transition name={name} mode="out-in" appear={true}>
|
||||||
name={name || route.meta.transitionName || unref(getBasicTransition)}
|
|
||||||
mode="out-in"
|
|
||||||
appear={true}
|
|
||||||
>
|
|
||||||
{() => PageContent}
|
{() => PageContent}
|
||||||
</Transition>
|
</Transition>
|
||||||
);
|
);
|
||||||
@@ -72,7 +73,7 @@ export default defineComponent({
|
|||||||
}}
|
}}
|
||||||
</RouterView>
|
</RouterView>
|
||||||
{unref(getCanEmbedIFramePage) && <FrameLayout />}
|
{unref(getCanEmbedIFramePage) && <FrameLayout />}
|
||||||
</div>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
29
src/layouts/page/transition.ts
Normal file
29
src/layouts/page/transition.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import type { FunctionalComponent } from 'vue';
|
||||||
|
import type { RouteLocation } from 'vue-router';
|
||||||
|
|
||||||
|
export interface DefaultContext {
|
||||||
|
Component: FunctionalComponent & { type: Indexable };
|
||||||
|
route: RouteLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getTransitionName({
|
||||||
|
route,
|
||||||
|
openCache,
|
||||||
|
cacheTabs,
|
||||||
|
enableTransition,
|
||||||
|
def,
|
||||||
|
}: Pick<DefaultContext, 'route'> & {
|
||||||
|
enableTransition: boolean;
|
||||||
|
openCache: boolean;
|
||||||
|
def: string;
|
||||||
|
cacheTabs: string[];
|
||||||
|
}) {
|
||||||
|
const isInCache = cacheTabs.includes(route.name as string);
|
||||||
|
const transitionName = 'fade-slide';
|
||||||
|
let name: string | null = transitionName;
|
||||||
|
|
||||||
|
if (openCache) {
|
||||||
|
name = isInCache && route.meta.loaded && enableTransition ? transitionName : null;
|
||||||
|
}
|
||||||
|
return name || route.meta.transitionName || def;
|
||||||
|
}
|
@@ -11,11 +11,11 @@ import { createPageGuard } from './pageGuard';
|
|||||||
|
|
||||||
export function createGuard(router: Router) {
|
export function createGuard(router: Router) {
|
||||||
createPageGuard(router);
|
createPageGuard(router);
|
||||||
|
createPageLoadingGuard(router);
|
||||||
createHttpGuard(router);
|
createHttpGuard(router);
|
||||||
createScrollGuard(router);
|
createScrollGuard(router);
|
||||||
createMessageGuard(router);
|
createMessageGuard(router);
|
||||||
createTitleGuard(router);
|
createTitleGuard(router);
|
||||||
createPageLoadingGuard(router);
|
|
||||||
createProgressGuard(router);
|
createProgressGuard(router);
|
||||||
createPermissionGuard(router);
|
createPermissionGuard(router);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user