Blame view

src/layouts/page/transition.ts 830 Bytes
1
2
3
4
import type { FunctionalComponent } from 'vue';
import type { RouteLocation } from 'vue-router';

export interface DefaultContext {
Vben authored
5
  Component: FunctionalComponent & { type: Recordable };
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  route: RouteLocation;
}

export function getTransitionName({
  route,
  openCache,
  cacheTabs,
  enableTransition,
  def,
}: Pick<DefaultContext, 'route'> & {
  enableTransition: boolean;
  openCache: boolean;
  def: string;
  cacheTabs: string[];
Vben authored
20
}): string | undefined {
21
  if (!enableTransition) {
Vben authored
22
    return undefined;
23
24
  }
25
26
  const isInCache = cacheTabs.includes(route.name as string);
  const transitionName = 'fade-slide';
Vben authored
27
  let name: string | undefined = transitionName;
28
29

  if (openCache) {
Vben authored
30
    name = isInCache && route.meta.loaded ? transitionName : undefined;
31
  }
Vben authored
32
  return name || (route.meta.transitionName as string) || def;
33
}