transition.ts 830 B

123456789101112131415161718192021222324252627282930313233
  1. import type { FunctionalComponent } from 'vue';
  2. import type { RouteLocation } from 'vue-router';
  3. export interface DefaultContext {
  4. Component: FunctionalComponent & { type: Recordable };
  5. route: RouteLocation;
  6. }
  7. export function getTransitionName({
  8. route,
  9. openCache,
  10. cacheTabs,
  11. enableTransition,
  12. def,
  13. }: Pick<DefaultContext, 'route'> & {
  14. enableTransition: boolean;
  15. openCache: boolean;
  16. def: string;
  17. cacheTabs: string[];
  18. }): string | undefined {
  19. if (!enableTransition) {
  20. return undefined;
  21. }
  22. const isInCache = cacheTabs.includes(route.name as string);
  23. const transitionName = 'fade-slide';
  24. let name: string | undefined = transitionName;
  25. if (openCache) {
  26. name = isInCache && route.meta.loaded ? transitionName : undefined;
  27. }
  28. return name || (route.meta.transitionName as string) || def;
  29. }