index.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. Vue.use(Router)
  4. /* Layout */
  5. import Layout from '@/layout'
  6. /* Router Modules */
  7. import memberRouter from '@/router/modules/member'
  8. import configRouter from '@/router/modules/config'
  9. /**
  10. * Note: sub-menu only appear when route children.length >= 1
  11. * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
  12. *
  13. * hidden: true if set true, item will not show in the sidebar(default is false)
  14. * alwaysShow: true if set true, will always show the root menu
  15. * if not set alwaysShow, when item has more than one children route,
  16. * it will becomes nested mode, otherwise not show the root menu
  17. * redirect: noRedirect if set noRedirect will no redirect in the breadcrumb
  18. * name:'router-name' the name is used by <keep-alive> (must set!!!)
  19. * meta : {
  20. roles: ['admin','editor'] control the page roles (you can set multiple roles)
  21. title: 'title' the name show in sidebar and breadcrumb (recommend set)
  22. icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
  23. noCache: true if set true, the page will no be cached(default is false)
  24. affix: true if set true, the tag will affix in the tags-view
  25. breadcrumb: false if set false, the item will hidden in breadcrumb(default is true)
  26. activeMenu: '/example/list' if set path, the sidebar will highlight the path you set
  27. }
  28. */
  29. /**
  30. * constantRoutes
  31. * a base page that does not have permission requirements
  32. * all roles can be accessed
  33. */
  34. export const constantRoutes = [
  35. {
  36. path: '/redirect',
  37. component: Layout,
  38. hidden: true,
  39. children: [
  40. {
  41. path: '/redirect/:path(.*)',
  42. component: () => import('@/views/redirect/index')
  43. }
  44. ]
  45. },
  46. {
  47. path: '/admin',
  48. component: Layout,
  49. hidden: true,
  50. children: [
  51. {
  52. path: '/admin/role',
  53. component: () => import('@/views/admin/role') // 管理员角色列表
  54. },
  55. {
  56. path: '/admin/role-add',
  57. component: () => import('@/views/admin/role-add') // 添加角色
  58. },
  59. {
  60. path: '/admin/role-edit/:id',
  61. name: 'admin_role-edit',
  62. component: () => import('@/views/admin/role-add') // 编辑角色
  63. },
  64. {
  65. path: '/admin/role-permission/:id',
  66. name: 'admin_role-permission',
  67. component: () => import('@/views/admin/role-permission') // 角色权限
  68. },
  69. {
  70. path: '/admin/change-password',
  71. name: 'admin_change-password',
  72. component: () => import('@/views/admin/edit') // 重置密码
  73. },
  74. {
  75. path: '/admin/index',
  76. name: 'admin_index',
  77. component: () => import('@/views/admin/index') // 管理员列表
  78. },
  79. {
  80. path: '/admin/add',
  81. name: 'admin_add',
  82. component: () => import('@/views/admin/edit') // 添加管理员
  83. },
  84. {
  85. path: '/admin/edit/:id',
  86. name: 'admin_edit',
  87. component: () => import('@/views/admin/edit') // 编辑管理员
  88. }
  89. ]
  90. },
  91. {
  92. path: '/finance',
  93. component: Layout,
  94. hidden: true,
  95. children: [
  96. {
  97. path: '/finance/balance-audit-list', // 会员余额调整列表
  98. component: () => import('@/views/finance/balance-audit-list'),
  99. name: 'finance_balance-audit-list',
  100. },
  101. {
  102. path: '/finance/change-balance-opt', // 申请调整会员余额
  103. component: () => import('@/views/finance/change-balance-opt'),
  104. name: 'finance_change-balance-opt',
  105. },
  106. {
  107. path: '/finance/transfer-list', // 转账记录列表
  108. component: () => import('@/views/finance/transfer-list'),
  109. name: 'finance_transfer-list',
  110. },
  111. {
  112. path: '/finance/recharge', // 充值管理
  113. component: () => import('@/views/finance/recharge'),
  114. name: 'finance_recharge',
  115. },
  116. {
  117. path: '/finance/recharge-status', // 状态管理
  118. component: () => import('@/views/finance/recharge-status'),
  119. name: 'finance_recharge-status',
  120. },
  121. ]
  122. },
  123. {
  124. path: '/login',
  125. component: () => import('@/views/login/index'),
  126. hidden: true
  127. },
  128. {
  129. path: '/auth-redirect',
  130. component: () => import('@/views/login/auth-redirect'),
  131. hidden: true
  132. },
  133. {
  134. path: '/404',
  135. component: () => import('@/views/error-page/404'),
  136. hidden: true
  137. },
  138. {
  139. path: '/401',
  140. component: () => import('@/views/error-page/401'),
  141. hidden: true
  142. },
  143. {
  144. path: '/',
  145. component: Layout,
  146. redirect: '/dashboard',
  147. children: [
  148. {
  149. path: 'dashboard',
  150. component: () => import('@/views/dashboard/index'),
  151. name: 'Dashboard',
  152. meta: { title: 'dashboard', icon: 'dashboard', affix: true }
  153. }
  154. ]
  155. },
  156. {
  157. path: '/profile',
  158. component: Layout,
  159. redirect: '/profile/index',
  160. hidden: true,
  161. children: [
  162. {
  163. path: 'index',
  164. component: () => import('@/views/profile/index'),
  165. name: 'Profile',
  166. meta: { title: 'profile', icon: 'user', noCache: true }
  167. }
  168. ]
  169. }
  170. ]
  171. /**
  172. * asyncRoutes
  173. * the routes that need to be dynamically loaded based on user roles
  174. */
  175. export const asyncRoutes = [
  176. /** when your routing map is too long, you can split it into small modules **/
  177. // 会员
  178. memberRouter,
  179. // 设置
  180. configRouter,
  181. {
  182. path: '/error',
  183. component: Layout,
  184. redirect: 'noRedirect',
  185. name: 'ErrorPages',
  186. meta: {
  187. title: 'errorPages',
  188. icon: '404'
  189. },
  190. children: [
  191. {
  192. path: '401',
  193. component: () => import('@/views/error-page/401'),
  194. name: 'Page401',
  195. meta: { title: 'page401', noCache: true }
  196. },
  197. {
  198. path: '404',
  199. component: () => import('@/views/error-page/404'),
  200. name: 'Page404',
  201. meta: { title: 'page404', noCache: true }
  202. }
  203. ]
  204. },
  205. {
  206. path: '/error-log',
  207. component: Layout,
  208. children: [
  209. {
  210. path: 'log',
  211. component: () => import('@/views/error-log/index'),
  212. name: 'ErrorLog',
  213. meta: { title: 'errorLog', icon: 'bug' }
  214. }
  215. ]
  216. },
  217. // 404 page must be placed at the end !!!
  218. { path: '*', redirect: '/404', hidden: true }
  219. ]
  220. const createRouter = () => new Router({
  221. // mode: 'history', // require service support
  222. scrollBehavior: () => ({ y: 0 }),
  223. routes: constantRoutes.concat(asyncRoutes)
  224. })
  225. const router = createRouter()
  226. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  227. export function resetRouter() {
  228. const newRouter = createRouter()
  229. router.matcher = newRouter.matcher // reset router
  230. }
  231. export function selfAddRoutes(params) {
  232. const newRouter = createRouter()
  233. router.matcher = newRouter.matcher
  234. router.addRoutes(params)
  235. }
  236. export default router