Skip to content

Commit

Permalink
fix(transition): fix transition not work
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Jan 4, 2021
1 parent da76f3c commit a7a8b89
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 23 deletions.
7 changes: 5 additions & 2 deletions src/components/Loading/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
export const Loading = createAsyncComponent(() => import('./src/index.vue'));
// import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
// export const Loading = createAsyncComponent(() => import('./src/index.vue'));

import Loading from './src/index.vue';

export { Loading };
export { useLoading } from './src/useLoading';
export { createLoading } from './src/createLoading';
1 change: 1 addition & 0 deletions src/components/Table/src/hooks/useTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function useTable(
},
{
immediate: true,
deep: true,
}
);
}
Expand Down
1 change: 0 additions & 1 deletion src/layouts/default/content/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
const { prefixCls } = useDesign('layout-content');
const { getOpenPageLoading } = useTransitionSetting();
const { getLayoutContentMode, getPageLoading } = useRootSetting();
return {
prefixCls,
getOpenPageLoading,
Expand Down
12 changes: 9 additions & 3 deletions src/layouts/iframe/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div>
<div v-if="showFrame">
<template v-for="frame in getFramePages" :key="frame.path">
<FramePage
v-if="frame.meta.frameSrc && hasRenderFrame(frame.name)"
Expand All @@ -10,7 +10,7 @@
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { defineComponent, unref, computed } from 'vue';
import FramePage from '/@/views/sys/iframe/index.vue';
import { useFrameKeepAlive } from './useFrameKeepAlive';
Expand All @@ -19,7 +19,13 @@
name: 'FrameLayout',
components: { FramePage },
setup() {
return { ...useFrameKeepAlive() };
const { getFramePages, hasRenderFrame, showIframe } = useFrameKeepAlive();
const showFrame = computed(() => {
return unref(getFramePages).length > 0;
});
return { getFramePages, hasRenderFrame, showIframe, showFrame };
},
});
</script>
24 changes: 20 additions & 4 deletions src/layouts/page/ParentView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,24 @@
<div>
<router-view>
<template v-slot="{ Component, route }">
<keep-alive v-if="openCache" :include="getCaches">
<component :is="Component" :key="route.fullPath" />
</keep-alive>
<component v-else :is="Component" :key="route.fullPath" />
<transition
:name="
getTransitionName({
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>
</router-view>
</div>
Expand All @@ -21,6 +35,7 @@
import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting';
import { useCache } from './useCache';
import { getTransitionName } from './transition';
export default defineComponent({
parentView: true,
Expand All @@ -40,6 +55,7 @@
getBasicTransition,
openCache,
getEnableTransition,
getTransitionName,
};
},
});
Expand Down
25 changes: 13 additions & 12 deletions src/layouts/page/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { FunctionalComponent } from 'vue';
import type { DefaultContext } from './transition';

import { computed, defineComponent, unref, Transition, KeepAlive } from 'vue';
import { RouterView, RouteLocation } from 'vue-router';
Expand All @@ -10,6 +11,7 @@ import { useRootSetting } from '/@/hooks/setting/useRootSetting';
import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting';
import { useCache } from './useCache';
import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting';
import { getTransitionName } from './transition';
// import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';

interface DefaultContext {
Expand All @@ -32,17 +34,20 @@ export default defineComponent({

return () => {
return (
<div>
<>
<RouterView>
{{
default: ({ Component, route }: DefaultContext) => {
// No longer show animations that are already in the tab
const cacheTabs = unref(getCaches);
const isInCache = cacheTabs.includes(route.name as string);
const name =
isInCache && route.meta.loaded && unref(getEnableTransition)
? 'fade-slide'
: null;

const name = getTransitionName({
route,
openCache: unref(openCache),
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
const isParentView = Component?.type.parentView;
Expand All @@ -60,19 +65,15 @@ export default defineComponent({
return PageContent;
}
return (
<Transition
name={name || route.meta.transitionName || unref(getBasicTransition)}
mode="out-in"
appear={true}
>
<Transition name={name} mode="out-in" appear={true}>
{() => PageContent}
</Transition>
);
},
}}
</RouterView>
{unref(getCanEmbedIFramePage) && <FrameLayout />}
</div>
</>
);
};
},
Expand Down
29 changes: 29 additions & 0 deletions src/layouts/page/transition.ts
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion src/router/guard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import { createPageGuard } from './pageGuard';

export function createGuard(router: Router) {
createPageGuard(router);
createPageLoadingGuard(router);
createHttpGuard(router);
createScrollGuard(router);
createMessageGuard(router);
createTitleGuard(router);
createPageLoadingGuard(router);
createProgressGuard(router);
createPermissionGuard(router);
}

0 comments on commit a7a8b89

Please sign in to comment.