index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import * as VueRouter from 'vue-router'
  2. import { useUserStore } from '@/store'
  3. const DEFAULT_LAYOUT = () => import('@/layout/default-layout.vue')
  4. import { Message } from '@arco-design/web-vue'
  5. const routes = [
  6. {
  7. path: "/",
  8. name: "main",
  9. component: () => import('../pages/Main/Main.vue'),
  10. meta: {
  11. hideInMenu: true
  12. }
  13. },
  14. {
  15. path: "/login",
  16. name: "login",
  17. component: () => import('../pages/login/login.vue'),
  18. meta: {
  19. title: '用户登录',
  20. hideInMenu: true
  21. }
  22. },
  23. {
  24. path: "/store",
  25. name: 'store',
  26. redirect: '/store/goodsList',
  27. component: DEFAULT_LAYOUT,
  28. meta: {
  29. title: 'Forge商城',
  30. icon: 'icon-gift'
  31. },
  32. children: [
  33. {
  34. path: 'goodsList',
  35. name: 'store.goodsList',
  36. component: () => import('../pages/store/goodsList/index.vue'),
  37. meta: {
  38. title: '商品列表'
  39. }
  40. },
  41. {
  42. path: 'goodsDetail/:id',
  43. name: 'store.goodsDetail',
  44. component: () => import('../pages/store/goodsDetail/index.vue'),
  45. meta: {
  46. title: '商品详情',
  47. hideInMenu: true
  48. }
  49. },
  50. {
  51. path: 'orderDetail/:id',
  52. name: 'store.orderDetail',
  53. component: () => import('../pages/store/orders/orderDetail/index.vue'),
  54. meta: {
  55. title: '订单详情',
  56. hideInMenu: true
  57. }
  58. },
  59. {
  60. path: 'myOrder',
  61. name: 'store.myOrder',
  62. component: () => import('../pages/store/orders/orderList/index.vue'),
  63. meta: {
  64. title: '我的订单'
  65. }
  66. },
  67. ]
  68. },
  69. {
  70. path: "/lepao",
  71. name: 'lepao',
  72. redirect: '/lepao/accountList',
  73. component: DEFAULT_LAYOUT,
  74. meta: {
  75. title: '校园乐跑',
  76. icon: 'icon-robot'
  77. },
  78. children: [
  79. {
  80. path: 'accountList',
  81. name: 'lepao.accountList',
  82. component: () => import('../pages/lepao/accountList/index.vue'),
  83. meta: {
  84. title: '账号管理'
  85. }
  86. },
  87. {
  88. path: 'lepaoRecords',
  89. name: 'lepao.lepaoRecords',
  90. component: () => import('../pages/lepao/lepaoRecords/index.vue'),
  91. meta: {
  92. title: '乐跑记录'
  93. }
  94. },
  95. {
  96. path: 'recordDetail/:id',
  97. name: 'lepao.recordDetail',
  98. component: () => import('../pages/lepao/lepaoRecords/recordDetail.vue'),
  99. meta: {
  100. title: '路线详情',
  101. hideInMenu: true
  102. }
  103. }
  104. ]
  105. },
  106. {
  107. path: "/user",
  108. name: "user",
  109. redirect: '/user/setting',
  110. component: DEFAULT_LAYOUT,
  111. meta: {
  112. title: '个人中心',
  113. icon: 'icon-user'
  114. },
  115. children: [
  116. {
  117. path: 'setting',
  118. name: 'user.setings',
  119. component: () => import('../pages/user/setting/index.vue'),
  120. meta: {
  121. title: '用户设置'
  122. },
  123. }
  124. ]
  125. },
  126. {
  127. path: "/path",
  128. name: "path",
  129. redirect: '/path/list',
  130. component: DEFAULT_LAYOUT,
  131. meta: {
  132. title: '路径数据',
  133. icon: 'icon-location',
  134. permission: ['admin', 'path']
  135. },
  136. children: [
  137. {
  138. path: 'list',
  139. name: 'path.list',
  140. component: () => import('../pages/path/pathList.vue'),
  141. meta: {
  142. title: '路径列表'
  143. }
  144. },
  145. {
  146. path: 'detail/:id',
  147. name: 'path.detail',
  148. component: () => import('../pages/path/pathDetail.vue'),
  149. meta: {
  150. title: '路径详情',
  151. hideInMenu: true
  152. }
  153. }
  154. ]
  155. },
  156. ]
  157. const router = VueRouter.createRouter({
  158. history: VueRouter.createWebHashHistory(),
  159. routes: routes
  160. })
  161. const allow = ['/', '/login']
  162. router.beforeEach(async (to, from, next) => {
  163. if (!allow.includes(to.path)) {
  164. const userStore = useUserStore()
  165. let user = await userStore.getInfo()
  166. if (!user || !user.uuid || !user.session) {
  167. // Message.error('请先登录')
  168. return router.push(`/login?from=${to.path}`)
  169. }
  170. }
  171. if (!to.meta.title) {
  172. document.title = 'RunForge - 让跑步的意义由技术重新定义'
  173. } else {
  174. document.title = to.meta.title + ' - RunForge'
  175. }
  176. next()
  177. })
  178. export { routes, router };