12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- // 引入vuex配置
- import store from '../store'
- // 页面白名单
- const whiteList = []
- function hasPermission(url) {
- // 在白名单中或有token,直接跳转
- if (whiteList.indexOf(url) !== -1 || store.state.user.loginInfo) {
- return true
- }
- return false
- }
- uni.addInterceptor('navigateTo', {
- // 页面跳转前进行拦截, invoke根据返回值进行判断是否继续执行跳转
- invoke(e) {
- if (!hasPermission(e.url)) {
- uni.reLaunch({
- url: '/pages/login/login'
- })
- return false
- }
- return true
- },
- success(e) {
- // console.log(e)
- }
- })
- uni.addInterceptor('switchTab', {
- // tabbar页面跳转前进行拦截
- invoke(e) {
- if (!hasPermission(e.url)) {
- uni.reLaunch({
- url: '/pages/login/login'
- })
- return false
- }
- return true
- },
- success(e) {
- // console.log(e)
- }
- })
|