index.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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: "/faceReco",
  19. name: "faceReco",
  20. component: () => import('../pages/face/index.vue'),
  21. meta: {
  22. hideInMenu: true,
  23. onlyWeb: true,
  24. viewport: 'width=device-width, initial-scale=1'
  25. }
  26. },
  27. {
  28. path: "/login",
  29. name: "login",
  30. component: () => import('../pages/login/login.vue'),
  31. meta: {
  32. title: '用户登录',
  33. hideInMenu: true
  34. }
  35. },
  36. {
  37. path: "/proxy",
  38. name: "proxy",
  39. component: DEFAULT_LAYOUT,
  40. meta: {
  41. title: '乐跑登录',
  42. icon: 'icon-command',
  43. onlyElectron: true
  44. },
  45. children: [
  46. {
  47. path: 'openProxy',
  48. name: 'proxy.openProxy',
  49. component: () => import('../pages/openProxy/index.vue'),
  50. meta: {
  51. title: '启动登录器'
  52. }
  53. }
  54. ]
  55. },
  56. {
  57. path: "/htmlView",
  58. name: "htmlView",
  59. component: HTML_VIEW,
  60. meta: {
  61. title: '第三方页面',
  62. hideInMenu: true
  63. },
  64. children: [
  65. {
  66. path: 'view',
  67. name: 'htmlView.view',
  68. component: () => import('../pages/htmlView/index.vue'),
  69. meta: {
  70. title: '第三方页面'
  71. }
  72. }
  73. ]
  74. },
  75. {
  76. path: "/store",
  77. name: 'store',
  78. redirect: '/store/goodsList',
  79. component: DEFAULT_LAYOUT,
  80. meta: {
  81. title: '云商城',
  82. icon: 'icon-gift'
  83. },
  84. children: [
  85. {
  86. path: 'goodsList',
  87. name: 'store.goodsList',
  88. component: () => import('../pages/store/goodsList/index.vue'),
  89. meta: {
  90. title: '商品列表'
  91. }
  92. },
  93. {
  94. path: 'goodsDetail/:id',
  95. name: 'store.goodsDetail',
  96. component: () => import('../pages/store/goodsDetail/index.vue'),
  97. meta: {
  98. title: '商品详情',
  99. hideInMenu: true
  100. }
  101. },
  102. {
  103. path: 'orderDetail/:id',
  104. name: 'store.orderDetail',
  105. component: () => import('../pages/store/orders/orderDetail/index.vue'),
  106. meta: {
  107. title: '订单详情',
  108. hideInMenu: true
  109. }
  110. },
  111. {
  112. path: 'myOrder',
  113. name: 'store.myOrder',
  114. component: () => import('../pages/store/orders/orderList/index.vue'),
  115. meta: {
  116. title: '我的订单'
  117. }
  118. },
  119. {
  120. path: 'sendCountRecords',
  121. name: 'store.sendCountRecords',
  122. component: () => import('../pages/store/sendCountRecords/index.vue'),
  123. meta: {
  124. title: '赠送记录',
  125. hideInMenu: true
  126. },
  127. }
  128. ]
  129. },
  130. {
  131. path: "/lepao",
  132. name: 'lepao',
  133. redirect: '/lepao/accountList',
  134. component: DEFAULT_LAYOUT,
  135. meta: {
  136. title: '校园乐跑',
  137. icon: 'icon-dashboard'
  138. },
  139. children: [
  140. {
  141. path: 'accountList',
  142. name: 'lepao.accountList',
  143. component: () => import('../pages/lepao/accountList/index.vue'),
  144. meta: {
  145. title: '乐跑账号'
  146. }
  147. },
  148. {
  149. path: 'lepaoRecords',
  150. name: 'lepao.lepaoRecords',
  151. component: () => import('../pages/lepao/lepaoRecords/index.vue'),
  152. meta: {
  153. title: '乐跑记录'
  154. }
  155. },
  156. {
  157. path: 'recordDetail/:id',
  158. name: 'lepao.recordDetail',
  159. component: () => import('../pages/lepao/lepaoRecords/recordDetail.vue'),
  160. meta: {
  161. title: '路线详情',
  162. hideInMenu: true
  163. }
  164. }
  165. ]
  166. },
  167. {
  168. path: "/qxs",
  169. name: "qxs",
  170. component: DEFAULT_LAYOUT,
  171. meta: {
  172. title: '趣选书',
  173. icon: 'icon-book'
  174. },
  175. children: [
  176. {
  177. path: 'getBookList',
  178. name: 'qxs.getBookList',
  179. component: () => import('../pages/qxs/getBookList.vue'),
  180. meta: {
  181. title: '书单查询'
  182. }
  183. }
  184. ]
  185. },
  186. {
  187. path: "/power",
  188. name: "power",
  189. component: DEFAULT_LAYOUT,
  190. meta: {
  191. title: '宿舍电费',
  192. icon: 'icon-thunderbolt'
  193. },
  194. children: [
  195. {
  196. path: 'accountList',
  197. name: 'power.accountList',
  198. component: () => import('../pages/power/accountList.vue'),
  199. meta: {
  200. title: '定制电费提醒'
  201. }
  202. }
  203. ]
  204. },
  205. {
  206. path: "/service",
  207. name: 'service',
  208. redirect: '/service/orderList',
  209. component: DEFAULT_LAYOUT,
  210. meta: {
  211. title: '售后服务',
  212. icon: 'icon-customer-service'
  213. },
  214. children: [
  215. {
  216. path: 'createOrder',
  217. name: 'service.createOrder',
  218. component: () => import('../pages/service/createOrder.vue'),
  219. meta: {
  220. title: '提交工单'
  221. }
  222. },
  223. {
  224. path: 'orderList',
  225. name: 'service.orderList',
  226. component: () => import('../pages/service/orderList.vue'),
  227. meta: {
  228. title: '我的工单'
  229. }
  230. },
  231. {
  232. path: 'orderDetail/:id',
  233. name: 'service.orderDetail',
  234. component: () => import('../pages/service/orderDetail.vue'),
  235. meta: {
  236. title: '工单详情',
  237. hideInMenu: true
  238. }
  239. }
  240. ]
  241. },
  242. // {
  243. // path: "/download",
  244. // name: "download",
  245. // component: DEFAULT_LAYOUT,
  246. // meta: {
  247. // title: '下载专区',
  248. // onlyWeb: true,
  249. // icon: 'icon-download'
  250. // },
  251. // children: [
  252. // {
  253. // path: 'down',
  254. // name: 'download.down',
  255. // component: () => import('../pages/download/index.vue'),
  256. // meta: {
  257. // title: '客户端下载'
  258. // }
  259. // }
  260. // ]
  261. // },
  262. {
  263. path: "/admin",
  264. name: 'admin',
  265. redirect: '/admin/service/orderList',
  266. component: DEFAULT_LAYOUT,
  267. meta: {
  268. title: '网站管理',
  269. icon: 'icon-computer',
  270. permission: ['admin', 'service', 'product']
  271. },
  272. children: [
  273. {
  274. path: 'userList',
  275. name: 'admin.userList',
  276. component: () => import('../pages/admin/user/userList.vue'),
  277. meta: {
  278. title: '用户管理',
  279. permission: ['admin', 'userList']
  280. }
  281. },
  282. {
  283. path: 'lepaoAccount',
  284. name: 'admin.lepaoAccount',
  285. component: () => import('../pages/admin/lepaoAccount/accountList.vue'),
  286. meta: {
  287. title: '乐跑账号管理',
  288. permission: ['admin', 'lepaoAccount']
  289. }
  290. },
  291. {
  292. path: 'lepaoRecords',
  293. name: 'admin.lepaoRecords',
  294. component: () => import('../pages/admin/lepaoRecords/lepaoRecords.vue'),
  295. meta: {
  296. title: '乐跑记录',
  297. permission: ['admin', 'service']
  298. }
  299. },
  300. {
  301. path: 'lepaoRecords/:id',
  302. name: 'admin.lepaoRecords.detail',
  303. component: () => import('../pages/admin/lepaoRecords/recordDetail.vue'),
  304. meta: {
  305. title: '乐跑记录详情',
  306. hideInMenu: true,
  307. permission: ['admin', 'service']
  308. }
  309. },
  310. {
  311. path: 'service/orderList',
  312. name: 'admin.service.orderList',
  313. component: () => import('../pages/admin/workOrder/orderList.vue'),
  314. meta: {
  315. title: '工单管理',
  316. permission: ['admin', 'service']
  317. }
  318. },
  319. {
  320. path: 'service/orderDetail/:id',
  321. name: 'admin.service.orderDetail',
  322. component: () => import('../pages/admin/workOrder/orderDetail.vue'),
  323. meta: {
  324. title: '工单详情',
  325. hideInMenu: true,
  326. permission: ['admin', 'service']
  327. }
  328. },
  329. {
  330. path: 'mqQueue',
  331. name: 'admin.mq.queue',
  332. component: () => import('../pages/admin/mqQueue/index.vue'),
  333. meta: {
  334. title: '任务队列',
  335. permission: ['admin', 'service']
  336. }
  337. },
  338. {
  339. path: 'goods/sendCountRequestList',
  340. name: 'admin.goods.sendCountRequestList',
  341. component: () => import('../pages/admin/goods/sendCountRequestList.vue'),
  342. meta: {
  343. title: '赠送审核',
  344. permission: ['admin', 'service']
  345. }
  346. },
  347. {
  348. path: 'reqLog',
  349. name: 'admin.log.reqLog',
  350. component: () => import('../pages/admin/reqLog/index.vue'),
  351. meta: {
  352. title: '请求日志',
  353. permission: ['admin']
  354. }
  355. }
  356. ]
  357. },
  358. {
  359. path: '/goodsManage',
  360. name: 'goodsManage',
  361. component: DEFAULT_LAYOUT,
  362. meta: {
  363. title: '商品管理',
  364. icon: 'icon-apps',
  365. permission: ['admin', 'product']
  366. },
  367. children: [
  368. {
  369. path: 'goods/addGoods',
  370. name: 'admin.goods.addGoods',
  371. component: () => import('../pages/admin/goods/addGoods.vue'),
  372. meta: {
  373. title: '添加商品',
  374. permission: ['admin', 'product']
  375. }
  376. },
  377. {
  378. path: 'goods/addGoods/:id',
  379. name: 'admin.goods.editGoods',
  380. component: () => import('../pages/admin/goods/addGoods.vue'),
  381. meta: {
  382. title: '编辑商品',
  383. hideInMenu: true,
  384. permission: ['admin', 'product']
  385. }
  386. },
  387. {
  388. path: 'goods/goodsList',
  389. name: 'admin.goods.goodsList',
  390. component: () => import('../pages/admin/goods/goodsList.vue'),
  391. meta: {
  392. title: '商品管理',
  393. permission: ['admin', 'product']
  394. }
  395. }
  396. ]
  397. },
  398. {
  399. path: "/path",
  400. name: "path",
  401. redirect: '/path/list',
  402. component: DEFAULT_LAYOUT,
  403. meta: {
  404. title: '路径数据',
  405. icon: 'icon-location',
  406. permission: ['admin', 'path']
  407. },
  408. children: [
  409. {
  410. path: 'list',
  411. name: 'path.list',
  412. component: () => import('../pages/path/pathList.vue'),
  413. meta: {
  414. title: '路径列表'
  415. }
  416. },
  417. {
  418. path: 'detail/:id',
  419. name: 'path.detail',
  420. component: () => import('../pages/path/pathDetail.vue'),
  421. meta: {
  422. title: '路径详情',
  423. hideInMenu: true
  424. }
  425. }
  426. ]
  427. },
  428. {
  429. path: "/user",
  430. name: "user",
  431. redirect: '/user/setting',
  432. component: DEFAULT_LAYOUT,
  433. meta: {
  434. title: '个人中心',
  435. icon: 'icon-user'
  436. },
  437. children: [
  438. {
  439. path: 'setting',
  440. name: 'user.setings',
  441. component: () => import('../pages/user/setting/index.vue'),
  442. meta: {
  443. title: '用户设置'
  444. },
  445. }
  446. ]
  447. }
  448. ]
  449. const router = VueRouter.createRouter({
  450. history: VueRouter.createWebHashHistory(),
  451. routes: routes
  452. })
  453. const allow = ['/', '/login', '/qxs/getBookList', '/htmlView/view', '/download/down', '/faceReco']
  454. router.beforeEach(async (to, from, next) => {
  455. if (!allow.includes(to.path)) {
  456. const userStore = useUserStore()
  457. let user = await userStore.getInfo()
  458. if (!user || !user.uuid || !user.session) {
  459. // Message.error('请先登录')
  460. return router.push(`/login?from=${to.path}`)
  461. }
  462. if (to.meta && to.meta.permission && to.meta.permission.length > 0) {
  463. if (!to.meta.permission.some((perm) => user.roles.includes(perm)))
  464. return next('/')
  465. }
  466. }
  467. if (to.meta.viewport) {
  468. const meta = document.querySelector('meta[name="viewport"]')
  469. meta.setAttribute('content', to.meta.viewport)
  470. }
  471. if (to.meta && (to.meta.onlyWeb || to.meta.onlyElectron)) {
  472. const electronEnv = isElectron()
  473. if (to.meta.onlyWeb && electronEnv) return next('/proxy/openProxy')
  474. if (to.meta.onlyElectron && !electronEnv) return next('/lepao/accountList')
  475. }
  476. if (!to.meta.title) document.title = 'RunForge - 智能校园乐跑平台'
  477. else document.title = to.meta.title + ' - RunForge'
  478. next()
  479. })
  480. export { routes, router }