router.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // router.js
  2. import { RouterMount, createRouter, runtimeQuit } from '@/js_sdk/hhyang-uni-simple-router/uni-simple-router';
  3. import tools from "@/service/tools";
  4. const router = createRouter({
  5. platform: process.env.VUE_APP_PLATFORM,
  6. routerErrorEach:({type,level,...args})=>{
  7. // console.log({type,level,...args})
  8. // #ifdef APP-PLUS
  9. if(type===3){
  10. router.$lockStatus=false;
  11. tools.onBackPress()
  12. }
  13. // #endif
  14. },
  15. routes: [...ROUTES]
  16. });
  17. //全局路由前置守卫
  18. const whiteList = ['/pages/login/index','/pages/login/register','/pages/login/forget']
  19. router.beforeEach(async (to, from, next) => {
  20. // tools.showLoading()
  21. console.log(to)
  22. console.log(from)
  23. // if(to.path==='/pages/login/index' && from.path!=='/pages/login/index'){
  24. // uni.setStorageSync('pageFullPath',from.fullPath)
  25. // }else if(from.path==='/pages/login/index'){
  26. // let oldFullPath= uni.getStorageSync('pageFullPath')
  27. // if(oldFullPath){
  28. // uni.setStorageSync('pageFullPath','')
  29. // next(oldFullPath);
  30. // }
  31. // }
  32. // let userToken=''
  33. // if (to.query.token ) {
  34. // userToken = to.query.token;
  35. // uni.setStorageSync('token',userToken)
  36. // }else {
  37. // userToken = uni.getStorageSync('token')
  38. // }
  39. // console.log('userToken:'+userToken)
  40. // if(whiteList.indexOf(to.path)<0 && !userToken){
  41. // console.log('----------------------')
  42. // // await tools.weiXinLogin().then(isLogin=>{
  43. // // console.log('-----------isLogin-----------')
  44. // // if(isLogin===-1){
  45. // // next('/pages/login/register');
  46. // // }else if(isLogin){
  47. // // next();
  48. // // }else {
  49. // // next('/pages/login/index');
  50. // // }
  51. // // }).catch(e=>{
  52. // // next('/pages/login/index');
  53. // // })
  54. // next('/pages/login/index');
  55. // // next();
  56. // }else {
  57. // next();
  58. // }
  59. next();
  60. });
  61. // 全局路由后置守卫
  62. router.afterEach((to, from) => {
  63. // console.log('后置守卫to------', to)
  64. // tools.hideLoading()
  65. })
  66. export {
  67. router,
  68. RouterMount
  69. }