// 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((to, from, next) => {
    // tools.showLoading()
    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){
        // next('/pages/login/index');
        next();
    }else {
        next();
    }

});
// 全局路由后置守卫
router.afterEach((to, from) => {
    // console.log('后置守卫to------', to)
    // tools.hideLoading()
})

export {
    router,
    RouterMount
}
