index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <div>
  3. <router-view>
  4. <template v-slot="{ Component, route }">
  5. <transition
  6. :name="
  7. getTransitionName({
  8. route,
  9. openCache,
  10. enableTransition: getEnableTransition,
  11. cacheTabs: getCaches,
  12. def: getBasicTransition,
  13. })
  14. "
  15. mode="out-in"
  16. appear
  17. >
  18. <keep-alive v-if="openCache" :include="getCaches">
  19. <component :is="Component" v-bind="getKey(Component, route)" />
  20. </keep-alive>
  21. <component v-else :is="Component" v-bind="getKey(Component, route)" />
  22. </transition>
  23. </template>
  24. </router-view>
  25. <FrameLayout v-if="getCanEmbedIFramePage" />
  26. </div>
  27. </template>
  28. <script lang="ts">
  29. import type { FunctionalComponent } from 'vue';
  30. import type { RouteLocation } from 'vue-router';
  31. import { computed, defineComponent, unref } from 'vue';
  32. import FrameLayout from '/@/layouts/iframe/index.vue';
  33. import { useRootSetting } from '/@/hooks/setting/useRootSetting';
  34. import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting';
  35. import { useCache } from './useCache';
  36. import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting';
  37. import { getTransitionName } from './transition';
  38. export default defineComponent({
  39. name: 'PageLayout',
  40. components: { FrameLayout },
  41. setup() {
  42. const { getCaches } = useCache(true);
  43. const { getShowMultipleTab } = useMultipleTabSetting();
  44. const { getOpenKeepAlive, getCanEmbedIFramePage } = useRootSetting();
  45. const { getBasicTransition, getEnableTransition } = useTransitionSetting();
  46. const openCache = computed(() => unref(getOpenKeepAlive) && unref(getShowMultipleTab));
  47. function getKey(component: FunctionalComponent & { type: Indexable }, route: RouteLocation) {
  48. return !!component?.type.parentView ? {} : { key: route.fullPath };
  49. }
  50. return {
  51. getTransitionName,
  52. openCache,
  53. getEnableTransition,
  54. getBasicTransition,
  55. getCaches,
  56. getCanEmbedIFramePage,
  57. getKey,
  58. };
  59. },
  60. });
  61. </script>