| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- // router.js
- import { RouterMount, createRouter, runtimeQuit } from '@/js_sdk/hhyang-uni-simple-router/uni-simple-router';
- import tools from "@/service/tools";
- const router = createRouter({
- platform: process.env.VUE_APP_PLATFORM,
- routerErrorEach:({type,level,...args})=>{
- // console.log({type,level,...args})
- // #ifdef APP-PLUS
- if(type===3){
- router.$lockStatus=false;
- tools.onBackPress()
- }
- // #endif
- },
- routes: [...ROUTES]
- });
- //全局路由前置守卫
- const whiteList = ['/pages/login/index','/pages/login/register']
- router.beforeEach(async (to, from, next) => {
- // tools.showLoading()
- console.log(to)
- console.log(from)
- if(to.path==='/pages/login/index'){
- uni.setStorageSync('pageFullPath',from.fullPath)
- }else if(from.path==='/pages/login/index'){
- let oldFullPath= uni.getStorageSync('pageFullPath')
- if(oldFullPath){
- uni.setStorageSync('pageFullPath','')
- next(oldFullPath);
- }
- }
- let userToken=''
- if (to.query.token ) {
- userToken = to.query.token;
- uni.setStorageSync('token',userToken)
- }else {
- userToken = uni.getStorageSync('token')
- }
- console.log('userToken:'+userToken)
- if(whiteList.indexOf(to.path)<0 && !userToken){
- console.log('----------------------')
- await tools.weiXinLogin().then(isLogin=>{
- console.log('-----------isLogin-----------')
- if(isLogin){
- // next();
- next('/pages/login/index');
- }else {
- next('/pages/login/index');
- }
- }).catch(e=>{
- next('/pages/login/index');
- })
- // next();
- }else {
- next();
- }
- });
- // 全局路由后置守卫
- router.afterEach((to, from) => {
- // console.log('后置守卫to------', to)
- // tools.hideLoading()
- })
- export {
- router,
- RouterMount
- }
|