index.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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 articleRouter from '@/router/modules/article'
  8. import atlasRouter from '@/router/modules/atlas'
  9. import bonusRouter from '@/router/modules/bonus'
  10. import configRouter from '@/router/modules/config'
  11. import financeRouter from '@/router/modules/finance'
  12. import profileRouter from '@/router/modules/profile'
  13. import shopRouter from '@/router/modules/shop'
  14. import userRouter from '@/router/modules/user'
  15. import chartsRouter from './modules/charts'
  16. import componentsRouter from './modules/components'
  17. import nestedRouter from './modules/nested'
  18. import tableRouter from './modules/table'
  19. import refactorRouter from '@/router/modules/refactor'
  20. import purchaseRoutes from '@/ui-refactor/views/purchase/routes'
  21. import { guestRoutes } from '@/ui-refactor/views/guest-shop/routes'
  22. /**
  23. * Note: sub-menu only appear when route children.length >= 1
  24. * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
  25. *
  26. * hidden: true if set true, item will not show in the sidebar(default is false)
  27. * alwaysShow: true if set true, will always show the root menu
  28. * if not set alwaysShow, when item has more than one children route,
  29. * it will becomes nested mode, otherwise not show the root menu
  30. * redirect: noRedirect if set noRedirect will no redirect in the breadcrumb
  31. * name:'router-name' the name is used by <keep-alive> (must set!!!)
  32. * meta : {
  33. roles: ['admin','editor'] control the page roles (you can set multiple roles)
  34. title: 'title' the name show in sidebar and breadcrumb (recommend set)
  35. icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
  36. noCache: true if set true, the page will no be cached(default is false)
  37. affix: true if set true, the tag will affix in the tags-view
  38. breadcrumb: false if set false, the item will hidden in breadcrumb(default is true)
  39. activeMenu: '/example/list' if set path, the sidebar will highlight the path you set
  40. }
  41. */
  42. /**
  43. * constantRoutes
  44. * a base page that does not have permission requirements
  45. * all roles can be accessed
  46. */
  47. export const constantRoutes = [
  48. {
  49. path: '/redirect',
  50. component: Layout,
  51. hidden: true,
  52. children: [
  53. {
  54. path: '/redirect/:path(.*)',
  55. component: () => import('@/views/redirect/index')
  56. }
  57. ]
  58. },
  59. {
  60. path: '/login',
  61. component: () => import('@/views/login/index'),
  62. hidden: true,
  63. meta: { title: '会员管理系统' }
  64. },
  65. {
  66. path: '/auth-redirect',
  67. component: () => import('@/views/login/auth-redirect'),
  68. hidden: true
  69. },
  70. {
  71. path: '/login-by-backend',
  72. component: () => import('@/views/login/login-by-backend'),
  73. name: 'login-by-backend'
  74. },
  75. {
  76. path: '/404',
  77. component: () => import('@/views/error-page/404'),
  78. hidden: true
  79. },
  80. {
  81. path: '/401',
  82. component: () => import('@/views/error-page/401'),
  83. hidden: true
  84. },
  85. {
  86. path: '/',
  87. component: () => import('@/ui-refactor/index.vue'),
  88. redirect: '/dashboard/index',
  89. children: [
  90. ...purchaseRoutes,
  91. ...guestRoutes,
  92. {
  93. path: 'dashboard/member-welcome-pack',
  94. component: () => import('@/ui-refactor/views/welcome-pack/MemberWelcomePack.vue'),
  95. name: 'MemberWelcomePack',
  96. meta: {
  97. title: 'Member Welcome Pack',
  98. publicLayout: {
  99. hero: {
  100. breadcrumbs: [
  101. { text: 'My Account', to: '/dashboard/index' },
  102. { text: 'Member Welcome Pack' }
  103. ],
  104. titleParts: [{ text: 'Member ' }, { text: 'Welcome Pack.', accent: true }],
  105. subtitle:
  106. 'Continue your order with your current member info. Referrer fields are pre-filled with your profile, and payment runs through the unified checkout flow.'
  107. }
  108. }
  109. }
  110. },
  111. {
  112. path: 'dashboard/index',
  113. alias: '/dashboard/index/dashboard',
  114. component: () => import('@/ui-refactor/views/account/AccountPage.vue'),
  115. name: 'Dashboard',
  116. meta: { title: 'dashboard', icon: 'dashboard', affix: true }
  117. },
  118. {
  119. path: 'dashboard/team-inquiry',
  120. component: () => import('@/ui-refactor/views/team-inquiry/TeamInquiryPage.vue'),
  121. name: 'MemberTeamInquiry',
  122. meta: {
  123. title: 'Team Inquiry',
  124. publicLayout: {
  125. hero: {
  126. breadcrumbs: [
  127. { text: 'My Account', to: '/dashboard/index' },
  128. { text: 'Team Inquiry' }
  129. ],
  130. titleParts: [{ text: 'Your team, ' }, { text: 'at a glance.', accent: true }],
  131. subtitle:
  132. 'View your personal member summary and your direct team details. Calculations are refreshed at the end of each pay cycle.'
  133. }
  134. }
  135. }
  136. }
  137. ]
  138. },
  139. refactorRouter
  140. ]
  141. /**
  142. * asyncRoutes
  143. * the routes that need to be dynamically loaded based on user roles
  144. */
  145. export const asyncRoutes = [
  146. {
  147. path: '/permission',
  148. component: Layout,
  149. redirect: '/permission/page',
  150. alwaysShow: true, // will always show the root menu
  151. name: 'Permission',
  152. meta: {
  153. title: 'permission',
  154. icon: 'lock',
  155. roles: ['admin', 'editor'] // you can set roles in root nav
  156. },
  157. children: [
  158. {
  159. path: 'page',
  160. component: () => import('@/views/permission/page'),
  161. name: 'PagePermission',
  162. meta: {
  163. title: 'pagePermission',
  164. roles: ['admin'] // or you can only set roles in sub nav
  165. }
  166. },
  167. {
  168. path: 'directive',
  169. component: () => import('@/views/permission/directive'),
  170. name: 'DirectivePermission',
  171. meta: {
  172. title: 'directivePermission'
  173. // if do not set roles, means: this page does not require permission
  174. }
  175. },
  176. {
  177. path: 'role',
  178. component: () => import('@/views/permission/role'),
  179. name: 'RolePermission',
  180. meta: {
  181. title: 'rolePermission',
  182. roles: ['admin']
  183. }
  184. }
  185. ]
  186. },
  187. {
  188. path: '/icon',
  189. component: Layout,
  190. children: [
  191. {
  192. path: 'index',
  193. component: () => import('@/views/icons/index'),
  194. name: 'Icons',
  195. meta: { title: 'icons', icon: 'icon', noCache: true }
  196. }
  197. ]
  198. },
  199. componentsRouter,
  200. chartsRouter,
  201. nestedRouter,
  202. tableRouter,
  203. shopRouter,
  204. profileRouter,
  205. configRouter,
  206. atlasRouter,
  207. articleRouter,
  208. bonusRouter,
  209. financeRouter,
  210. userRouter,
  211. {
  212. path: '/error',
  213. component: Layout,
  214. redirect: 'noRedirect',
  215. name: 'ErrorPages',
  216. meta: {
  217. title: 'errorPages',
  218. icon: '404'
  219. },
  220. children: [
  221. {
  222. path: '401',
  223. component: () => import('@/views/error-page/401'),
  224. name: 'Page401',
  225. meta: { title: 'page401', noCache: true }
  226. },
  227. {
  228. path: '404',
  229. component: () => import('@/views/error-page/404'),
  230. name: 'Page404',
  231. meta: { title: 'page404', noCache: true }
  232. }
  233. ]
  234. },
  235. {
  236. path: '/error-log',
  237. component: Layout,
  238. children: [
  239. {
  240. path: 'log',
  241. component: () => import('@/views/error-log/index'),
  242. name: 'ErrorLog',
  243. meta: { title: 'errorLog', icon: 'bug' }
  244. }
  245. ]
  246. },
  247. // 404 page must be placed at the end !!!
  248. { path: '*', redirect: '/404', hidden: true }
  249. ]
  250. const createRouter = () =>
  251. new Router({
  252. // mode: 'history', // require service support
  253. scrollBehavior: () => ({ y: 0 }),
  254. routes: constantRoutes.concat(asyncRoutes)
  255. // routes: constantRoutes.concat(asyncRoutes)
  256. })
  257. const router = createRouter()
  258. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  259. export function resetRouter() {
  260. const newRouter = createRouter()
  261. router.matcher = newRouter.matcher // reset router
  262. }
  263. export function selfAddRoutes(params) {
  264. const newRouter = createRouter()
  265. router.matcher = newRouter.matcher
  266. router.addRoutes(params)
  267. }
  268. export default router