index.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. import * as VueRouter from 'vue-router'
  2. import { useUserStore } from '@/store'
  3. import { isElectron } from '../utils/electron'
  4. const DEFAULT_LAYOUT = () => import('@/layout/default-layout.vue')
  5. const HTML_VIEW = () => import('@/layout/html-view.vue')
  6. // import { Message } from '@arco-design/web-vue'
  7. const routes = [
  8. {
  9. path: "/",
  10. name: "main",
  11. component: () => import('../pages/Main/Main.vue'),
  12. meta: {
  13. hideInMenu: true,
  14. onlyWeb: true
  15. }
  16. },
  17. {
  18. path: "/login",
  19. name: "login",
  20. component: () => import('../pages/login/login.vue'),
  21. meta: {
  22. title: '用户登录',
  23. hideInMenu: true
  24. }
  25. },
  26. {
  27. path: "/htmlView",
  28. name: "htmlView",
  29. component: HTML_VIEW,
  30. meta: {
  31. title: '第三方页面',
  32. hideInMenu: true
  33. },
  34. children: [
  35. {
  36. path: 'view',
  37. name: 'htmlView.view',
  38. component: () => import('../pages/htmlView/index.vue'),
  39. meta: {
  40. title: '第三方页面'
  41. }
  42. }
  43. ]
  44. },
  45. {
  46. path: "/store",
  47. name: 'store',
  48. redirect: '/store/goodsList',
  49. component: DEFAULT_LAYOUT,
  50. meta: {
  51. title: '云商城',
  52. icon: 'icon-gift'
  53. },
  54. children: [
  55. {
  56. path: 'goodsList',
  57. name: 'store.goodsList',
  58. component: () => import('../pages/store/goodsList/index.vue'),
  59. meta: {
  60. title: '商品列表'
  61. }
  62. },
  63. {
  64. path: 'goodsDetail/:id',
  65. name: 'store.goodsDetail',
  66. component: () => import('../pages/store/goodsDetail/index.vue'),
  67. meta: {
  68. title: '商品详情',
  69. hideInMenu: true
  70. }
  71. },
  72. {
  73. path: 'orderDetail/:id',
  74. name: 'store.orderDetail',
  75. component: () => import('../pages/store/orders/orderDetail/index.vue'),
  76. meta: {
  77. title: '订单详情',
  78. hideInMenu: true
  79. }
  80. },
  81. {
  82. path: 'myOrder',
  83. name: 'store.myOrder',
  84. component: () => import('../pages/store/orders/orderList/index.vue'),
  85. meta: {
  86. title: '我的订单'
  87. }
  88. },
  89. ]
  90. },
  91. {
  92. path: "/lepao",
  93. name: 'lepao',
  94. redirect: '/lepao/accountList',
  95. component: DEFAULT_LAYOUT,
  96. meta: {
  97. title: '校园乐跑',
  98. icon: 'icon-robot'
  99. },
  100. children: [
  101. {
  102. path: 'accountList',
  103. name: 'lepao.accountList',
  104. component: () => import('../pages/lepao/accountList/index.vue'),
  105. meta: {
  106. title: '账号管理'
  107. }
  108. },
  109. {
  110. path: 'lepaoRecords',
  111. name: 'lepao.lepaoRecords',
  112. component: () => import('../pages/lepao/lepaoRecords/index.vue'),
  113. meta: {
  114. title: '乐跑记录'
  115. }
  116. },
  117. {
  118. path: 'recordDetail/:id',
  119. name: 'lepao.recordDetail',
  120. component: () => import('../pages/lepao/lepaoRecords/recordDetail.vue'),
  121. meta: {
  122. title: '路线详情',
  123. hideInMenu: true
  124. }
  125. }
  126. ]
  127. },
  128. {
  129. path: "/service",
  130. name: 'service',
  131. redirect: '/service/orderList',
  132. component: DEFAULT_LAYOUT,
  133. meta: {
  134. title: '售后服务',
  135. icon: 'icon-customer-service'
  136. },
  137. children: [
  138. {
  139. path: 'createOrder',
  140. name: 'service.createOrder',
  141. component: () => import('../pages/service/createOrder.vue'),
  142. meta: {
  143. title: '提交工单'
  144. }
  145. },
  146. {
  147. path: 'orderList',
  148. name: 'service.orderList',
  149. component: () => import('../pages/service/orderList.vue'),
  150. meta: {
  151. title: '我的工单'
  152. }
  153. },
  154. {
  155. path: 'orderDetail/:id',
  156. name: 'service.orderDetail',
  157. component: () => import('../pages/service/orderDetail.vue'),
  158. meta: {
  159. title: '工单详情',
  160. hideInMenu: true
  161. }
  162. }
  163. ]
  164. },
  165. {
  166. path: "/admin",
  167. name: 'admin',
  168. redirect: '/admin/service/orderList',
  169. component: DEFAULT_LAYOUT,
  170. meta: {
  171. title: '网站管理',
  172. icon: 'icon-check-square',
  173. permission: ['admin', 'service', 'product']
  174. },
  175. children: [
  176. {
  177. path: 'lepaoRecords',
  178. name: 'admin.lepaoRecords',
  179. component: () => import('../pages/admin/lepaoRecords/lepaoRecords.vue'),
  180. meta: {
  181. title: '乐跑记录',
  182. permission: ['admin', 'service']
  183. }
  184. },
  185. {
  186. path: 'lepaoRecords/:id',
  187. name: 'admin.lepaoRecords.detail',
  188. component: () => import('../pages/admin/lepaoRecords/recordDetail.vue'),
  189. meta: {
  190. title: '乐跑记录详情',
  191. hideInMenu: true,
  192. permission: ['admin', 'service']
  193. }
  194. },
  195. {
  196. path: 'service/orderList',
  197. name: 'admin.service.orderList',
  198. component: () => import('../pages/admin/workOrder/orderList.vue'),
  199. meta: {
  200. title: '工单管理',
  201. permission: ['admin', 'service']
  202. }
  203. },
  204. {
  205. path: 'service/orderDetail/:id',
  206. name: 'admin.service.orderDetail',
  207. component: () => import('../pages/admin/workOrder/orderDetail.vue'),
  208. meta: {
  209. title: '工单详情',
  210. hideInMenu: true,
  211. permission: ['admin', 'service']
  212. }
  213. },
  214. {
  215. path: 'goods/addGoods',
  216. name: 'admin.goods.addGoods',
  217. component: () => import('../pages/admin/goods/addGoods.vue'),
  218. meta: {
  219. title: '添加商品',
  220. permission: ['admin', 'product']
  221. }
  222. },
  223. {
  224. path: 'goods/addGoods/:id',
  225. name: 'admin.goods.editGoods',
  226. component: () => import('../pages/admin/goods/addGoods.vue'),
  227. meta: {
  228. title: '编辑商品',
  229. hideInMenu: true,
  230. permission: ['admin', 'product']
  231. }
  232. },
  233. {
  234. path: 'goods/goodsList',
  235. name: 'admin.goods.goodsList',
  236. component: () => import('../pages/admin/goods/goodsList.vue'),
  237. meta: {
  238. title: '商品管理',
  239. permission: ['admin', 'product']
  240. }
  241. }
  242. ]
  243. },
  244. {
  245. path: "/path",
  246. name: "path",
  247. redirect: '/path/list',
  248. component: DEFAULT_LAYOUT,
  249. meta: {
  250. title: '路径数据',
  251. icon: 'icon-location',
  252. permission: ['admin', 'path']
  253. },
  254. children: [
  255. {
  256. path: 'list',
  257. name: 'path.list',
  258. component: () => import('../pages/path/pathList.vue'),
  259. meta: {
  260. title: '路径列表'
  261. }
  262. },
  263. {
  264. path: 'detail/:id',
  265. name: 'path.detail',
  266. component: () => import('../pages/path/pathDetail.vue'),
  267. meta: {
  268. title: '路径详情',
  269. hideInMenu: true
  270. }
  271. }
  272. ]
  273. },
  274. {
  275. path: "/user",
  276. name: "user",
  277. redirect: '/user/setting',
  278. component: DEFAULT_LAYOUT,
  279. meta: {
  280. title: '个人中心',
  281. icon: 'icon-user'
  282. },
  283. children: [
  284. {
  285. path: 'setting',
  286. name: 'user.setings',
  287. component: () => import('../pages/user/setting/index.vue'),
  288. meta: {
  289. title: '用户设置'
  290. },
  291. }
  292. ]
  293. }
  294. ]
  295. const router = VueRouter.createRouter({
  296. history: VueRouter.createWebHashHistory(),
  297. routes: routes
  298. })
  299. const allow = ['/', '/login', '/htmlView/view']
  300. router.beforeEach(async (to, from, next) => {
  301. if (!allow.includes(to.path)) {
  302. const userStore = useUserStore()
  303. let user = await userStore.getInfo()
  304. if (!user || !user.uuid || !user.session) {
  305. // Message.error('请先登录')
  306. return router.push(`/login?from=${to.path}`)
  307. }
  308. }
  309. if (to.meta && (to.meta.onlyWeb || to.meta.onlyElectron)) {
  310. const electronEnv = isElectron()
  311. if (to.meta.onlyWeb && electronEnv) return next('/lepao/accountList')
  312. if (to.meta.onlyElectron && !electronEnv) return next('/lepao/accountList')
  313. }
  314. if (!to.meta.title) {
  315. document.title = 'RunForge - 让跑步的意义由技术重新定义'
  316. } else {
  317. document.title = to.meta.title + ' - RunForge'
  318. }
  319. next()
  320. })
  321. export { routes, router };