index.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import type { FunctionalComponent } from 'vue';
  2. import { computed, defineComponent, unref, Transition, KeepAlive } from 'vue';
  3. import { RouterView, RouteLocation } from 'vue-router';
  4. import FrameLayout from '/@/layouts/iframe/index.vue';
  5. import { useRootSetting } from '/@/hooks/setting/useRootSetting';
  6. import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting';
  7. import { useCache } from './useCache';
  8. import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting';
  9. interface DefaultContext {
  10. Component: FunctionalComponent;
  11. route: RouteLocation;
  12. }
  13. export default defineComponent({
  14. name: 'PageLayout',
  15. setup() {
  16. const { getCaches } = useCache(true);
  17. const { getShowMultipleTab } = useMultipleTabSetting();
  18. const { getOpenKeepAlive, getCanEmbedIFramePage } = useRootSetting();
  19. const { getBasicTransition, getEnableTransition } = useTransitionSetting();
  20. const openCache = computed(() => unref(getOpenKeepAlive) && unref(getShowMultipleTab));
  21. return () => {
  22. return (
  23. <>
  24. <RouterView>
  25. {{
  26. default: ({ Component, route }: DefaultContext) => {
  27. // No longer show animations that are already in the tab
  28. const cacheTabs = unref(getCaches);
  29. const isInCache = cacheTabs.includes(route.name as string);
  30. const name =
  31. isInCache && route.meta.loaded && unref(getEnableTransition)
  32. ? 'fade-slide'
  33. : null;
  34. const renderComp = () => <Component key={route.fullPath} />;
  35. const PageContent = unref(openCache) ? (
  36. <KeepAlive>{renderComp()}</KeepAlive>
  37. ) : (
  38. renderComp()
  39. );
  40. return unref(getEnableTransition) ? (
  41. <Transition
  42. name={name || route.meta.transitionName || unref(getBasicTransition)}
  43. mode="out-in"
  44. appear={true}
  45. >
  46. {() => PageContent}
  47. </Transition>
  48. ) : (
  49. PageContent
  50. );
  51. },
  52. }}
  53. </RouterView>
  54. {unref(getCanEmbedIFramePage) && <FrameLayout />}
  55. </>
  56. );
  57. };
  58. },
  59. });