index.tsx 2.2 KB
Newer Older
陈文彬 已提交
1
import { computed, defineComponent, unref, Transition, KeepAlive, toRaw } from 'vue';
V
vben 已提交
2
import { RouterView, RouteLocation } from 'vue-router';
陈文彬 已提交
3

V
vben 已提交
4
import FrameLayout from '/@/layouts/iframe/index.vue';
陈文彬 已提交
5 6

import { useTransition } from './useTransition';
V
vben 已提交
7
import { useSetting } from '/@/hooks/core/useSetting';
陈文彬 已提交
8 9

import { tabStore } from '/@/store/modules/tab';
V
vben 已提交
10
import { appStore } from '/@/store/modules/app';
陈文彬 已提交
11 12 13 14 15 16 17 18 19 20 21 22 23 24

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;
    }
25
    const { projectSetting } = useSetting();
陈文彬 已提交
26 27 28 29 30 31 32 33 34 35
    return () => {
      const {
        routerTransition,
        openRouterTransition,
        openKeepAlive,
        multiTabsSetting: { show, max },
      } = unref(getProjectConfigRef);

      const openCache = openKeepAlive && show;
      const cacheTabs = toRaw(tabStore.getKeepAliveTabsState) as string[];
36 37 38 39 40
      return (
        <div>
          <RouterView>
            {{
              default: ({ Component, route }: { Component: any; route: RouteLocation }) => {
V
vben 已提交
41
                // No longer show animations that are already in the tab
V
vben 已提交
42
                const name = route.meta.inTab ? 'fade' : null;
V
vben 已提交
43

44 45
                const Content = openCache ? (
                  <KeepAlive max={max} include={cacheTabs}>
46
                    <Component key={route.fullPath} />
47 48
                  </KeepAlive>
                ) : (
49
                  <Component key={route.fullPath} />
50 51 52 53
                );
                return openRouterTransition ? (
                  <Transition
                    {...on}
N
nebv 已提交
54
                    name={name || route.meta.transitionName || routerTransition}
55
                    mode="out-in"
V
vben 已提交
56
                    appear={true}
57 58 59 60 61 62 63 64 65 66 67 68
                  >
                    {() => Content}
                  </Transition>
                ) : (
                  Content
                );
              },
            }}
          </RouterView>
          {projectSetting.canEmbedIFramePage && <FrameLayout />}
        </div>
      );
陈文彬 已提交
69 70 71
    };
  },
});