You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
2.7 KiB
117 lines
2.7 KiB
1 year ago
|
//只要是未登录状态,想要跳转到名单内的路径时,直接跳到登录页。
|
||
|
// 页面白名单,不受拦截
|
||
|
import versionTool from '@/libs/versionUpdate.js';
|
||
|
|
||
|
const whiteList = [
|
||
|
'/pages/login/index'
|
||
|
]
|
||
|
let apages = getCurrentPages()
|
||
|
console.log("getCurrentPages",apages)
|
||
|
function hasPermission (url) {
|
||
|
console.log('url',url);
|
||
|
// let islogin = sessionStorage.getItem("isLogin");
|
||
|
let islogin = this.$store.state.hasLogin
|
||
|
islogin = Boolean(Number(islogin));//返回布尔值
|
||
|
// 在白名单中或有登录判断条件可以直接跳转
|
||
|
if(whiteList.indexOf(url) !== -1 || islogin) {
|
||
|
return true
|
||
|
}
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
uni.addInterceptor('navigateTo', {
|
||
|
|
||
|
// 页面跳转前进行拦截, invoke根据返回值进行判断是否继续执行跳转
|
||
|
invoke (e) {
|
||
|
if(!hasPermission(e.url)){
|
||
|
uni.reLaunch({
|
||
|
url: '/pages/login/index'
|
||
|
})
|
||
|
return false
|
||
|
}
|
||
|
return true
|
||
|
},
|
||
|
success (e) {
|
||
|
versionTool.isNewVersion()
|
||
|
}
|
||
|
})
|
||
|
|
||
|
uni.addInterceptor('switchTab', {
|
||
|
// tabbar页面跳转前进行拦截
|
||
|
invoke (e) {
|
||
|
if(!hasPermission(e.url)){
|
||
|
uni.reLaunch({
|
||
|
url: '/pages/login/index'
|
||
|
})
|
||
|
return false
|
||
|
}
|
||
|
return true
|
||
|
},
|
||
|
success (e) {
|
||
|
}
|
||
|
})
|
||
|
|
||
|
// import modules from './modules'
|
||
|
// import Vue from 'vue'
|
||
|
// //这里仅示范npm安装方式的引入,其它方式引入请看最上面【安装】部分
|
||
|
// import Router from 'uni-simple-router'
|
||
|
|
||
|
// Vue.use(Router)
|
||
|
// //初始化
|
||
|
// const router = new Router({
|
||
|
// routes: [...modules]//路由表
|
||
|
// });
|
||
|
|
||
|
// //全局路由前置守卫
|
||
|
// router.beforeEach((to, from, next) => {
|
||
|
// next()
|
||
|
// })
|
||
|
// // 全局路由后置守卫
|
||
|
// router.afterEach((to, from) => {
|
||
|
// })
|
||
|
// export default router;
|
||
|
|
||
|
// import Vue from 'vue'
|
||
|
// import store from '../store/index.js'
|
||
|
// import pages from '../pages.js'
|
||
|
|
||
|
// import Router, {
|
||
|
// RouterMount
|
||
|
// } from 'uni-simple-router'
|
||
|
|
||
|
|
||
|
|
||
|
// Vue.use(Router)
|
||
|
|
||
|
// const myRouter =
|
||
|
// pages().pages.map(item => ({
|
||
|
// path: `/${item.path}`,
|
||
|
// meta: item.meta || {}
|
||
|
// }))
|
||
|
// //初始化
|
||
|
// const router = new Router({
|
||
|
// routes: myRouter
|
||
|
// });
|
||
|
|
||
|
// //全局路由前置守卫
|
||
|
// router.beforeEach((to, from, next) => {
|
||
|
|
||
|
// const isLogin = sessionStorage.getItem("isLogin")
|
||
|
// console.log('路由前置守卫',isLogin)
|
||
|
// // if (!isLogin && to.meta.needLogin) {
|
||
|
// if (!isLogin ) {
|
||
|
// next({
|
||
|
// path: '/pages/login/index',
|
||
|
// query: {
|
||
|
// redirect: to.path
|
||
|
// }
|
||
|
// })
|
||
|
// } else {
|
||
|
// next()
|
||
|
// }
|
||
|
|
||
|
// })
|
||
|
// // 全局路由后置守卫
|
||
|
// router.afterEach((to, from) => {console.log('路由后置守卫')})
|
||
|
// export default router;
|