Blame view

src/layouts/page/index.vue 2.15 KB
vben authored
1
2
<template>
  <div>
vben authored
3
    <RouterView>
4
      <template #default="{ Component, route }">
vben authored
5
6
7
8
9
10
11
12
13
14
15
16
17
18
        <transition
          :name="
            getTransitionName({
              route,
              openCache,
              enableTransition: getEnableTransition,
              cacheTabs: getCaches,
              def: getBasicTransition,
            })
          "
          mode="out-in"
          appear
        >
          <keep-alive v-if="openCache" :include="getCaches">
19
            <component :is="Component" :key="route.fullPath" />
vben authored
20
          </keep-alive>
21
          <component v-else :is="Component" :key="route.fullPath" />
vben authored
22
23
        </transition>
      </template>
vben authored
24
    </RouterView>
vben authored
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
    <FrameLayout v-if="getCanEmbedIFramePage" />
  </div>
</template>

<script lang="ts">
  import { computed, defineComponent, unref } from 'vue';

  import FrameLayout from '/@/layouts/iframe/index.vue';

  import { useRootSetting } from '/@/hooks/setting/useRootSetting';

  import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting';
  import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting';
  import { getTransitionName } from './transition';
40
41
  import { useStore } from 'vuex';
vben authored
42
43
44
45
46
47
48
49
50
51
52
53
  export default defineComponent({
    name: 'PageLayout',
    components: { FrameLayout },
    setup() {
      const { getShowMultipleTab } = useMultipleTabSetting();

      const { getOpenKeepAlive, getCanEmbedIFramePage } = useRootSetting();

      const { getBasicTransition, getEnableTransition } = useTransitionSetting();

      const openCache = computed(() => unref(getOpenKeepAlive) && unref(getShowMultipleTab));
54
55
56
57
58
59
60
61
62
63
64
      const { getters } = useStore();

      const getCaches = computed((): string[] => {
        if (!unref(getOpenKeepAlive)) {
          return [];
        }
        // TODO The useStore is used here mainly to solve the problem of circular dependency hot update
        const cacheTabs = getters['app-tab/getCachedTabsState'];
        return cacheTabs;
      });
vben authored
65
66
67
68
69
70
71
72
73
74
75
      return {
        getTransitionName,
        openCache,
        getEnableTransition,
        getBasicTransition,
        getCaches,
        getCanEmbedIFramePage,
      };
    },
  });
</script>