router.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // router.js
  2. import { RouterMount, createRouter } from 'uni-simple-router';
  3. import tools from '@/common/js/tools'
  4. import store from '@/store/index'
  5. import { getPlatform } from '@/common/js/utils'
  6. const router = createRouter({
  7. platform: process.env.VUE_APP_PLATFORM,
  8. routes: [...ROUTES]
  9. });
  10. //全局路由前置守卫
  11. const whiteList = ['/','/pages/index/index', '/pages/login/index', '/pages/login/module/login-data/login-data','/pages/home/lawyer-team/lawyer-team','/pages/home/navigation-glory/navigation-glory','/pages/home/navigation-product/navigation-product','/pages/navigation-dynamic/module/dynamic-details/dynamic-details','/pages/home/case-particulars-copy/case-particulars-copy','/components/teamd-etails/teamd-etails']
  12. router.beforeEach((to, from, next) => {
  13. let token = to.query.token;
  14. let m_id = to.query.m_id;
  15. if (token && m_id) {
  16. // store.commit("setCookie", { 'token': token, 'm_id': m_id });
  17. uni.setStorageSync('token',token);
  18. uni.setStorageSync('m_id',m_id);
  19. next('/pages/index/index');
  20. }
  21. const userToken = uni.getStorageSync('token')
  22. const userMid = uni.getStorageSync('m_id')
  23. console.log('登陆信息-------'+userToken+'--------------'+userMid)
  24. if((!userToken || !userMid) && whiteList.indexOf(to.fullPath)<0){
  25. console.log('暂无登陆信息')
  26. console.log(to.fullPath )
  27. if(to.fullPath!=='/pages/login/index'){
  28. next('/pages/login/index');
  29. }
  30. }
  31. console.log('前置守卫to----------', to)
  32. next();
  33. // console.log('前置守卫from----------', from)
  34. // if (getPlatform() == 'H5') {
  35. // console.log('userToken-------', userToken);
  36. // console.log('userMid-------', userMid);
  37. // if (userToken && userMid) {
  38. // if (to.fullPath == '/pages/login/index' || to.fullPath == '/pages/permission/index') {
  39. // uni.navigateTo({
  40. // url: '/pages/index/index?value=0'
  41. // });
  42. // } else {
  43. // next();
  44. // }
  45. // } else {
  46. // /**
  47. // * 当本地缓存查询不到认证信息时,清除所有用户数据
  48. // */
  49. // store.commit('user/removeToken')
  50. // const index = whiteList.indexOf(to.fullPath)
  51. // if (index > -1) {
  52. // next();
  53. // } else {
  54. // tools.error('登录失效')
  55. // uni.navigateTo({
  56. // url: '/pages/login/index'
  57. // });
  58. // }
  59. // }
  60. // } else {
  61. // next();
  62. // }
  63. });
  64. // 全局路由后置守卫
  65. router.afterEach((to, from) => {
  66. console.log('后置守卫to------', to)
  67. })
  68. export {
  69. router,
  70. RouterMount
  71. }