index.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { computed, defineComponent, unref, Transition, KeepAlive, toRaw } from 'vue';
  2. import { appStore } from '/@/store/modules/app';
  3. import { useTransition } from './useTransition';
  4. import { RouterView, RouteLocation } from 'vue-router';
  5. import { tabStore } from '/@/store/modules/tab';
  6. import FrameLayout from '/@/layouts/iframe/index.vue';
  7. import { useSetting } from '/@/hooks/core/useSetting';
  8. // import { useRouter } from 'vue-router';
  9. export default defineComponent({
  10. name: 'PageLayout',
  11. setup() {
  12. // const { currentRoute } = useRouter();
  13. const getProjectConfigRef = computed(() => {
  14. return appStore.getProjectConfig;
  15. });
  16. const { openPageLoading } = unref(getProjectConfigRef);
  17. let on = {};
  18. if (openPageLoading) {
  19. const { on: transitionOn } = useTransition();
  20. on = transitionOn;
  21. }
  22. const { projectSetting } = useSetting();
  23. return () => {
  24. const {
  25. routerTransition,
  26. openRouterTransition,
  27. openKeepAlive,
  28. multiTabsSetting: { show, max },
  29. } = unref(getProjectConfigRef);
  30. const openCache = openKeepAlive && show;
  31. const cacheTabs = toRaw(tabStore.getKeepAliveTabsState) as string[];
  32. return (
  33. <div>
  34. <RouterView>
  35. {{
  36. default: ({ Component, route }: { Component: any; route: RouteLocation }) => {
  37. const name = route.meta.inTab ? ' ' : null;
  38. const Content = openCache ? (
  39. <KeepAlive max={max} include={cacheTabs}>
  40. <Component {...route.params} />
  41. </KeepAlive>
  42. ) : (
  43. <Component {...route.params} />
  44. );
  45. return openRouterTransition ? (
  46. <Transition
  47. {...on}
  48. name={name || route.meta.transitionName || routerTransition}
  49. mode="out-in"
  50. >
  51. {() => Content}
  52. </Transition>
  53. ) : (
  54. Content
  55. );
  56. },
  57. }}
  58. </RouterView>
  59. {projectSetting.canEmbedIFramePage && <FrameLayout />}
  60. </div>
  61. );
  62. };
  63. },
  64. });