router.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // router.js
  2. import {
  3. RouterMount,
  4. createRouter,
  5. runtimeQuit
  6. } from '@/js_sdk/hhyang-uni-simple-router/uni-simple-router';
  7. import tools from "@/service/tools";
  8. const router = createRouter({
  9. platform: process.env.VUE_APP_PLATFORM,
  10. routerErrorEach: ({
  11. type,
  12. level,
  13. ...args
  14. }) => {
  15. // #ifdef APP-PLUS
  16. if (type === 3) {
  17. router.$lockStatus = false;
  18. tools.onBackPress()
  19. }
  20. // #endif
  21. },
  22. routes: [...ROUTES]
  23. });
  24. //全局路由前置守卫
  25. const whiteList = ['/pages/login/index', '/pages/index/index', '/pages/order/index', '/pages/me/index',
  26. '/pages-address/select-school'
  27. ]
  28. router.beforeEach((to, from, next) => {
  29. let userToken = uni.getStorageSync('token')
  30. let school_id = uni.getStorageSync('school_id');
  31. let operate_id = uni.getStorageSync('operate_id');
  32. if (whiteList.indexOf(to.path) < 0 && !userToken) {
  33. next('/pages/login/index')
  34. } else {
  35. if (!school_id && !operate_id) {
  36. if (whiteList.indexOf(to.path) > 0) {
  37. next()
  38. } else {
  39. next('/pages-address/select-school')
  40. }
  41. } else {
  42. next()
  43. }
  44. }
  45. });
  46. // 全局路由后置守卫
  47. router.afterEach((to, from) => {
  48. // console.log('后置守卫to------', to)
  49. })
  50. export {
  51. router,
  52. RouterMount
  53. }