You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

207 lines
5.7 KiB

  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. Vue.use(Router)
  4. /* Layout */
  5. import Layout from '@/layout'
  6. /**
  7. * Note: 路由配置项
  8. *
  9. * hidden: true // 当设置 true 的时候该路由不会再侧边栏出现 如401,login等页面,或者如一些编辑页面/edit/1
  10. * alwaysShow: true // 当你一个路由下面的 children 声明的路由大于1个时,自动会变成嵌套的模式--如组件页面
  11. * // 只有一个时,会将那个子路由当做根路由显示在侧边栏--如引导页面
  12. * // 若你想不管路由下面的 children 声明的个数都显示你的根路由
  13. * // 你可以设置 alwaysShow: true,这样它就会忽略之前定义的规则,一直显示根路由
  14. * redirect: noRedirect // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
  15. * name:'router-name' // 设定路由的名字,一定要填写不然使用<keep-alive>时会出现各种问题
  16. * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
  17. * roles: ['admin', 'common'] // 访问路由的角色权限
  18. * permissions: ['a:a:a', 'b:b:b'] // 访问路由的菜单权限
  19. * meta : {
  20. noCache: true // 如果设置为true,则不会被 <keep-alive> 缓存(默认 false)
  21. title: 'title' // 设置该路由在侧边栏和面包屑中展示的名字
  22. icon: 'svg-name' // 设置该路由的图标,对应路径src/assets/icons/svg
  23. breadcrumb: false // 如果设置为false,则不会在breadcrumb面包屑中显示
  24. activeMenu: '/system/user' // 当路由设置了该属性,则会高亮相对应的侧边栏。
  25. }
  26. */
  27. // 公共路由
  28. export const constantRoutes = [
  29. {
  30. path: '/redirect',
  31. component: Layout,
  32. hidden: true,
  33. children: [
  34. {
  35. path: '/redirect/:path(.*)',
  36. component: () => import('@/views/redirect')
  37. }
  38. ]
  39. },
  40. // 管理员登录
  41. {
  42. path: '/loginGld',
  43. component: () => import('@/views/loginGld'),
  44. hidden: true
  45. },
  46. // 兽医端登录
  47. {
  48. path: '/login',
  49. component: () => import('@/views/login'),
  50. hidden: true
  51. },
  52. {
  53. path: '/register',
  54. component: () => import('@/views/register'),
  55. hidden: true
  56. },
  57. {
  58. path: '/404',
  59. component: () => import('@/views/error/404'),
  60. hidden: true
  61. },
  62. {
  63. path: '/401',
  64. component: () => import('@/views/error/401'),
  65. hidden: true
  66. },
  67. // 管理员首页
  68. {
  69. path: '/',
  70. component: Layout,
  71. redirect: 'indexGld',
  72. children: [
  73. {
  74. path: 'indexGld',
  75. component: () => import('@/views/indexGld'),
  76. name: 'IndexGld',
  77. meta: { title: '管理员首页', icon: 'dashboard', affix: true }
  78. }
  79. ]
  80. },
  81. // 兽医首页
  82. {
  83. path: '',
  84. component: Layout,
  85. redirect: 'index',
  86. children: [
  87. {
  88. path: 'index',
  89. component: () => import('@/views/index'),
  90. name: 'Index',
  91. meta: { title: '兽医首页', icon: 'dashboard', affix: true }
  92. }
  93. ]
  94. },
  95. {
  96. path: '/user',
  97. component: Layout,
  98. hidden: true,
  99. redirect: 'noredirect',
  100. children: [
  101. {
  102. path: 'profile',
  103. component: () => import('@/views/system/user/profile/index'),
  104. name: 'Profile',
  105. meta: { title: '个人中心', icon: 'user' }
  106. }
  107. ]
  108. }
  109. ]
  110. // 动态路由,基于用户权限动态去加载
  111. export const dynamicRoutes = [
  112. {
  113. path: '/system/user-auth',
  114. component: Layout,
  115. hidden: true,
  116. permissions: ['system:user:edit'],
  117. children: [
  118. {
  119. path: 'role/:userId(\\d+)',
  120. component: () => import('@/views/system/user/authRole'),
  121. name: 'AuthRole',
  122. meta: { title: '分配角色', activeMenu: '/system/user' }
  123. }
  124. ]
  125. },
  126. {
  127. path: '/system/role-auth',
  128. component: Layout,
  129. hidden: true,
  130. permissions: ['system:role:edit'],
  131. children: [
  132. {
  133. path: 'user/:roleId(\\d+)',
  134. component: () => import('@/views/system/role/authUser'),
  135. name: 'AuthUser',
  136. meta: { title: '分配用户', activeMenu: '/system/role' }
  137. }
  138. ]
  139. },
  140. {
  141. path: '/system/dict-data',
  142. component: Layout,
  143. hidden: true,
  144. permissions: ['system:dict:list'],
  145. children: [
  146. {
  147. path: 'index/:dictId(\\d+)',
  148. component: () => import('@/views/system/dict/data'),
  149. name: 'Data',
  150. meta: { title: '字典数据', activeMenu: '/system/dict' }
  151. }
  152. ]
  153. },
  154. {
  155. path: '/monitor/job-log',
  156. component: Layout,
  157. hidden: true,
  158. permissions: ['monitor:job:list'],
  159. children: [
  160. {
  161. path: 'index/:jobId(\\d+)',
  162. component: () => import('@/views/monitor/job/log'),
  163. name: 'JobLog',
  164. meta: { title: '调度日志', activeMenu: '/monitor/job' }
  165. }
  166. ]
  167. },
  168. {
  169. path: '/tool/gen-edit',
  170. component: Layout,
  171. hidden: true,
  172. permissions: ['tool:gen:edit'],
  173. children: [
  174. {
  175. path: 'index/:tableId(\\d+)',
  176. component: () => import('@/views/tool/gen/editTable'),
  177. name: 'GenEdit',
  178. meta: { title: '修改生成配置', activeMenu: '/tool/gen' }
  179. }
  180. ]
  181. }
  182. ]
  183. // 防止连续点击多次路由报错
  184. let routerPush = Router.prototype.push
  185. let routerReplace = Router.prototype.replace
  186. // push
  187. Router.prototype.push = function push(location) {
  188. return routerPush.call(this, location).catch(err => err)
  189. }
  190. // replace
  191. Router.prototype.replace = function push(location) {
  192. return routerReplace.call(this, location).catch(err => err)
  193. }
  194. export default new Router({
  195. mode: 'history', // 去掉url中的#
  196. scrollBehavior: () => ({ y: 0 }),
  197. routes: constantRoutes
  198. })