router.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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']
  19. router.beforeEach((to, from, next) => {
  20. next();
  21. // let userToken = uni.getStorageSync('token')
  22. // if(userToken){
  23. // next();
  24. // }else{
  25. // let isWeiXin = tools.isWx();
  26. // if(isWeiXin && to.path!=='/pages/login/index'){
  27. // let wx_key = uni.getStorageSync('wx_key')
  28. // if(wx_key && to.path==='/pages/login/register'){
  29. // next()
  30. // }else{
  31. // const href = window.location.href;
  32. // if (href.indexOf('?code=') > -1 || href.indexOf('&code=') > -1){
  33. // const urlArr = href.split('?')
  34. // const rightUrlArr = urlArr[1].split('#/')
  35. // const queryObj = {}
  36. // rightUrlArr[0].split('&').map((item) => {
  37. // const splitStr = item.split('=')
  38. // return {
  39. // key: splitStr[0],
  40. // value: splitStr[1],
  41. // }
  42. // }).forEach((item) => {
  43. // queryObj[item.key] = item.value
  44. // })
  45. // if(urlArr.length>=3){
  46. // rightUrlArr[1]= "?"+urlArr[2]
  47. // }
  48. // let from = {
  49. // code: queryObj.code,
  50. // wx_type:1,
  51. // invite_code:uni.getStorageSync("invite_code"),
  52. // memberCode:uni.getStorageSync("memberCode"),
  53. // }
  54. // // await userWxAppletLogin(from).then((res)=>{
  55. // // if (res.code === 1) {
  56. // // if(res.data.wx_key){
  57. // // uni.setStorageSync('wx_key',res.data.wx_key)
  58. // // next('/pages/login/register')
  59. // // }else{
  60. // // uni.setStorageSync('token',res.data.token)
  61. // // uni.setStorageSync('m_id',res.data.m_id)
  62. // // next(to.path)
  63. // // }
  64. // // } else {
  65. // // tools.error(res.msg);
  66. // // }
  67. // // })
  68. // }else{
  69. // uni.removeStorageSync('token')
  70. // uni.removeStorageSync('m_id')
  71. // tools.wxLogin();
  72. // }
  73. // }
  74. // }else if(whiteList.indexOf(to.path)>-1){
  75. // next()
  76. // }else {
  77. // next('/pages/login/index')
  78. // }
  79. // }
  80. });
  81. // 全局路由后置守卫
  82. router.afterEach((to, from) => {
  83. // console.log('后置守卫to------', to)
  84. })
  85. export {
  86. router,
  87. RouterMount
  88. }