// router.js import { RouterMount, createRouter } from 'uni-simple-router'; import tools from '@/common/js/tools' import store from '@/store/index' import { getPlatform } from '@/common/js/utils' const router = createRouter({ platform: process.env.VUE_APP_PLATFORM, routes: [...ROUTES] }); //全局路由前置守卫 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'] router.beforeEach((to, from, next) => { let token = to.query.token; let m_id = to.query.m_id; if (token && m_id) { // store.commit("setCookie", { 'token': token, 'm_id': m_id }); uni.setStorageSync('token',token); uni.setStorageSync('m_id',m_id); next('/pages/index/index'); } const userToken = uni.getStorageSync('token') const userMid = uni.getStorageSync('m_id') console.log('登陆信息-------'+userToken+'--------------'+userMid) if((!userToken || !userMid) && whiteList.indexOf(to.fullPath)<0){ console.log('暂无登陆信息') console.log(to.fullPath ) if(to.fullPath!=='/pages/login/index'){ next('/pages/login/index'); } } console.log('前置守卫to----------', to) next(); // console.log('前置守卫from----------', from) // if (getPlatform() == 'H5') { // console.log('userToken-------', userToken); // console.log('userMid-------', userMid); // if (userToken && userMid) { // if (to.fullPath == '/pages/login/index' || to.fullPath == '/pages/permission/index') { // uni.navigateTo({ // url: '/pages/index/index?value=0' // }); // } else { // next(); // } // } else { // /** // * 当本地缓存查询不到认证信息时,清除所有用户数据 // */ // store.commit('user/removeToken') // const index = whiteList.indexOf(to.fullPath) // if (index > -1) { // next(); // } else { // tools.error('登录失效') // uni.navigateTo({ // url: '/pages/login/index' // }); // } // } // } else { // next(); // } }); // 全局路由后置守卫 router.afterEach((to, from) => { console.log('后置守卫to------', to) }) export { router, RouterMount }