index.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import {createWebHistory, createRouter, RouteRecordRaw} from 'vue-router';
  2. /* Layout */
  3. import Layout from '@/layout/index.vue';
  4. import homeRoutes from './modules/home';
  5. import otrRoutes from './modules/otr';
  6. import salesRoutes from './modules/sales';
  7. import placeholderRoutes from './modules/placeholder';
  8. /**
  9. * Note: 路由配置项
  10. *
  11. * hidden: true // 当设置 true 的时候该路由不会再侧边栏出现 如401,login等页面,或者如一些编辑页面/edit/1
  12. * alwaysShow: true // 当你一个路由下面的 children 声明的路由大于1个时,自动会变成嵌套的模式--如组件页面
  13. * // 只有一个时,会将那个子路由当做根路由显示在侧边栏--如引导页面
  14. * // 若你想不管路由下面的 children 声明的个数都显示你的根路由
  15. * // 你可以设置 alwaysShow: true,这样它就会忽略之前定义的规则,一直显示根路由
  16. * redirect: noRedirect // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
  17. * name:'router-name' // 设定路由的名字,一定要填写不然使用<keep-alive>时会出现各种问题
  18. * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
  19. * roles: ['admin', 'common'] // 访问路由的角色权限
  20. * permissions: ['a:a:a', 'b:b:b'] // 访问路由的菜单权限
  21. * meta : {
  22. noCache: true // 如果设置为true,则不会被 <keep-alive> 缓存(默认 false)
  23. title: 'title' // 设置该路由在侧边栏和面包屑中展示的名字
  24. icon: 'svg-name' // 设置该路由的图标,对应路径src/assets/icons/svg
  25. breadcrumb: false // 如果设置为false,则不会在breadcrumb面包屑中显示
  26. activeMenu: '/system/user' // 当路由设置了该属性,则会高亮相对应的侧边栏。
  27. }
  28. */
  29. // 公共路由
  30. export const constantRoutes: RouteRecordRaw[] = [
  31. {
  32. path: '/',
  33. redirect: '/home'
  34. },
  35. {
  36. path: '/redirect',
  37. component: Layout,
  38. hidden: true,
  39. children: [
  40. {
  41. path: '/redirect/:path(.*)',
  42. component: () => import('@/views/redirect/index.vue')
  43. }
  44. ]
  45. },
  46. {
  47. path: '/login',
  48. component: () => import('@/views/login.vue'),
  49. hidden: true
  50. },
  51. // SSO / 三方登录回调(不属于任何业务模块)
  52. {
  53. path: '/social-callback',
  54. hidden: true,
  55. component: () => import('@/layout/components/SocialCallback/index.vue')
  56. },
  57. {
  58. path: '/authredirect',
  59. component: () => import('@/modules/sales/views/redirect/authredirect.vue'),
  60. hidden: true
  61. },
  62. {
  63. path: '/ssoredirect',
  64. component: () => import('@/modules/sales/views/redirect/ssoredirect.vue'),
  65. hidden: true
  66. },
  67. {
  68. path: '/401',
  69. component: () => import('@/modules/sales/views/error/401.vue'),
  70. hidden: true
  71. },
  72. {
  73. path: '/iconEdit',
  74. component: () => import('@/views/iconEdit.vue'),
  75. hidden: true
  76. },
  77. // 顶部大模块路由(按 module 拆分,便于后续业务迁移时各自维护)
  78. ...homeRoutes,
  79. ...otrRoutes,
  80. ...salesRoutes,
  81. ...placeholderRoutes,
  82. {
  83. path: '/:pathMatch(.*)*',
  84. component: () => import('@/views/error/404.vue'),
  85. hidden: true
  86. },
  87. ];
  88. // 动态路由,基于用户权限动态去加载
  89. export const dynamicRoutes: RouteRecordRaw[] = [
  90. // {
  91. // path: '/system/user-auth',
  92. // component: Layout,
  93. // hidden: true,
  94. // permissions: ['system:user:edit'],
  95. // children: [
  96. // {
  97. // path: 'role/:userId(\\d+)',
  98. // component: () => import('@/views/system/user/authRole.vue'),
  99. // name: 'AuthRole',
  100. // meta: { title: '分配角色', activeMenu: '/system/user', icon: '' }
  101. // }
  102. // ]
  103. // },
  104. // {
  105. // path: '/system/role-auth',
  106. // component: Layout,
  107. // hidden: true,
  108. // permissions: ['system:role:edit'],
  109. // children: [
  110. // {
  111. // path: 'user/:roleId(\\d+)',
  112. // component: () => import('@/views/system/role/authUser.vue'),
  113. // name: 'AuthUser',
  114. // meta: { title: '分配用户', activeMenu: '/system/role', icon: '' }
  115. // }
  116. // ]
  117. // },
  118. // {
  119. // path: '/system/dict-data',
  120. // component: Layout,
  121. // hidden: true,
  122. // permissions: ['system:dict:list'],
  123. // children: [
  124. // {
  125. // path: 'index/:dictId(\\d+)',
  126. // component: () => import('@/views/system/dict/data.vue'),
  127. // name: 'Data',
  128. // meta: { title: '字典数据', activeMenu: '/system/dict', icon: '' }
  129. // }
  130. // ]
  131. // },
  132. // {
  133. // path: '/system/oss-config',
  134. // component: Layout,
  135. // hidden: true,
  136. // permissions: ['system:ossConfig:list'],
  137. // children: [
  138. // {
  139. // path: 'index',
  140. // component: () => import('@/views/system/oss/config.vue'),
  141. // name: 'OssConfig',
  142. // meta: { title: '配置管理', activeMenu: '/system/oss', icon: '' }
  143. // }
  144. // ]
  145. // },
  146. // {
  147. // path: '/tool/gen-edit',
  148. // component: Layout,
  149. // hidden: true,
  150. // permissions: ['tool:gen:edit'],
  151. // children: [
  152. // {
  153. // path: 'index/:tableId(\\d+)',
  154. // component: () => import('@/views/tool/gen/editTable.vue'),
  155. // name: 'GenEdit',
  156. // meta: { title: '修改生成配置', activeMenu: '/tool/gen', icon: '' }
  157. // }
  158. // ]
  159. // }
  160. ];
  161. /**
  162. * 创建路由
  163. */
  164. const router = createRouter({
  165. history: createWebHistory(import.meta.env.VITE_APP_CONTEXT_PATH),
  166. routes: constantRoutes,
  167. // 刷新时,滚动条位置还原
  168. scrollBehavior(to, from, savedPosition) {
  169. if (savedPosition) {
  170. return savedPosition;
  171. } else {
  172. return {top: 0};
  173. }
  174. }
  175. });
  176. // 添加自定义方法 pushTarget
  177. router.pushTarget = (url: string, query: Record<string, any> = {}) => {
  178. const origin = location.origin
  179. // 构造 query 字符串
  180. const queryStr = new URLSearchParams(query).toString()
  181. const fullUrl = origin + url + (queryStr ? '?' + queryStr : '')
  182. window.open(fullUrl, '_blank')
  183. }
  184. export default router;