router.d.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // 全局路由类型声明
  2. import { type RouteComponent, type RouteLocationNormalized } from "vue-router";
  3. declare global {
  4. interface ToRouteType extends RouteLocationNormalized {
  5. meta: CustomizeRouteMeta;
  6. }
  7. /**
  8. * @description 完整子路由的`meta`配置表
  9. */
  10. interface CustomizeRouteMeta {
  11. /** 菜单名称(兼容国际化、非国际化,如何用国际化的写法就必须在根目录的`locales`文件夹下对应添加) `必填` */
  12. title: string;
  13. /** 菜单图标 `可选` */
  14. icon?: string | FunctionalComponent | IconifyIcon;
  15. /** 菜单名称右侧的额外图标 */
  16. extraIcon?: string | FunctionalComponent | IconifyIcon;
  17. /** 是否在菜单中显示(默认`true`)`可选` */
  18. showLink?: boolean;
  19. /** 是否显示父级菜单 `可选` */
  20. showParent?: boolean;
  21. /** 页面级别权限设置 `可选` */
  22. roles?: Array<string>;
  23. /** 按钮级别权限设置 `可选` */
  24. auths?: Array<string>;
  25. /** 路由组件缓存(开启 `true`、关闭 `false`)`可选` */
  26. keepAlive?: boolean;
  27. /** 内嵌的`iframe`链接 `可选` */
  28. frameSrc?: string;
  29. /** 是否是内部页面 使用frameSrc来嵌入页面时,当isFrameSrcInternal=true的时候, 前端需要做特殊处理 */
  30. /** 比如链接是 /druid/login.html */
  31. /** 前端需要处理成 http://localhost:8080/druid/login.html */
  32. isFrameSrcInternal?: boolean;
  33. /** `iframe`页是否开启首次加载动画(默认`true`)`可选` */
  34. frameLoading?: boolean;
  35. /** 页面加载动画(有两种形式,一种直接采用vue内置的`transitions`动画,另一种是使用`animate.css`写进、离场动画)`可选` */
  36. transition?: {
  37. /**
  38. * @description 当前路由动画效果
  39. * @see {@link https://next.router.vuejs.org/guide/advanced/transitions.html#transitions}
  40. * @see animate.css {@link https://animate.style}
  41. */
  42. name?: string;
  43. /** 进场动画 */
  44. enterTransition?: string;
  45. /** 离场动画 */
  46. leaveTransition?: string;
  47. };
  48. // 是否不添加信息到标签页,(默认`false`)
  49. hiddenTag?: boolean;
  50. /** 动态路由可打开的最大数量 `可选` */
  51. dynamicLevel?: number;
  52. /** 将某个菜单激活
  53. * (主要用于通过`query`或`params`传参的路由,当它们通过配置`showLink: false`后不在菜单中显示,就不会有任何菜单高亮,
  54. * 而通过设置`activePath`指定激活菜单即可获得高亮,`activePath`为指定激活菜单的`path`)
  55. */
  56. activePath?: string;
  57. }
  58. /**
  59. * @description 完整子路由配置表
  60. */
  61. interface RouteChildrenConfigsTable {
  62. /** 子路由地址 `必填` */
  63. path: string;
  64. /** 路由名字(对应不要重复,和当前组件的`name`保持一致)`必填` */
  65. name?: string;
  66. /** 路由重定向 `可选` */
  67. redirect?: string;
  68. /** 按需加载组件 `可选` */
  69. component?: RouteComponent;
  70. meta?: CustomizeRouteMeta;
  71. /** 子路由配置项 */
  72. children?: Array<RouteChildrenConfigsTable>;
  73. }
  74. /**
  75. * @description 整体路由配置表(包括完整子路由)
  76. */
  77. interface RouteConfigsTable {
  78. /** 路由地址 `必填` */
  79. path: string;
  80. /** 路由名字(保持唯一)`可选` */
  81. name?: string;
  82. /** `Layout`组件 `可选` */
  83. component?: RouteComponent;
  84. /** 路由重定向 `可选` */
  85. redirect?: string;
  86. meta?: {
  87. /** 菜单名称(兼容国际化、非国际化,如何用国际化的写法就必须在根目录的`locales`文件夹下对应添加)`必填` */
  88. title: string;
  89. /** 菜单图标 `可选` */
  90. icon?: string | FunctionalComponent | IconifyIcon;
  91. /** 是否在菜单中显示(默认`true`)`可选` */
  92. showLink?: boolean;
  93. /** 菜单升序排序,值越高排的越后(只针对顶级路由)`可选` */
  94. rank?: number;
  95. };
  96. /** 子路由配置项 */
  97. children?: Array<RouteChildrenConfigsTable>;
  98. }
  99. }
  100. // https://router.vuejs.org/zh/guide/advanced/meta.html#typescript
  101. declare module "vue-router" {
  102. interface RouteMeta extends CustomizeRouteMeta {}
  103. }