vue-vben-admin/src/layouts/page/index.tsx

73 lines
2.2 KiB
TypeScript
Raw Normal View History

2020-09-28 20:19:10 +08:00
import { computed, defineComponent, unref, Transition, KeepAlive, toRaw } from 'vue';
2020-10-30 21:32:05 +08:00
import { RouterView, RouteLocation } from 'vue-router';
2020-09-28 20:19:10 +08:00
2020-10-30 21:32:05 +08:00
import FrameLayout from '/@/layouts/iframe/index.vue';
2020-09-28 20:19:10 +08:00
import { useTransition } from './useTransition';
2020-10-30 21:32:05 +08:00
import { useSetting } from '/@/hooks/core/useSetting';
2020-09-28 20:19:10 +08:00
import { tabStore } from '/@/store/modules/tab';
2020-10-30 21:32:05 +08:00
import { appStore } from '/@/store/modules/app';
2020-09-28 20:19:10 +08:00
export default defineComponent({
name: 'PageLayout',
setup() {
const getProjectConfigRef = computed(() => {
return appStore.getProjectConfig;
});
const { openPageLoading } = unref(getProjectConfigRef);
let on = {};
if (openPageLoading) {
const { on: transitionOn } = useTransition();
on = transitionOn;
}
const { projectSetting } = useSetting();
2020-09-28 20:19:10 +08:00
return () => {
const {
routerTransition,
openRouterTransition,
openKeepAlive,
multiTabsSetting: { show, max },
} = unref(getProjectConfigRef);
const openCache = openKeepAlive && show;
const cacheTabs = toRaw(tabStore.getKeepAliveTabsState) as string[];
return (
<div>
<RouterView>
{{
default: ({ Component, route }: { Component: any; route: RouteLocation }) => {
2020-11-02 23:04:25 +08:00
// No longer show animations that are already in the tab
2020-10-14 21:08:07 +08:00
const name = route.meta.inTab ? 'fade' : null;
2020-11-02 23:04:25 +08:00
// TODO add key?
const Content = openCache ? (
<KeepAlive max={max} include={cacheTabs}>
<Component key={route.path} />
</KeepAlive>
) : (
<Component key={route.path} />
);
return openRouterTransition ? (
<Transition
{...on}
2020-10-11 01:13:27 +08:00
name={name || route.meta.transitionName || routerTransition}
mode="out-in"
2020-10-18 21:55:21 +08:00
appear={true}
>
{() => Content}
</Transition>
) : (
Content
);
},
}}
</RouterView>
{projectSetting.canEmbedIFramePage && <FrameLayout />}
</div>
);
2020-09-28 20:19:10 +08:00
};
},
});