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.
49 lines
818 B
49 lines
818 B
import { |
|
getAccessToken |
|
} from '@/utils/auth' |
|
|
|
// 登录页面 |
|
const loginPage = "/pages/login" |
|
|
|
const indexPage = "/pages/index" |
|
|
|
// 页面白名单 |
|
const whiteList = [ |
|
'/pages/login', |
|
|
|
] |
|
|
|
// 检查地址白名单 |
|
function checkWhite(url) { |
|
const path = url.split('?')[0] |
|
return whiteList.indexOf(path) !== -1 |
|
} |
|
|
|
// 页面跳转验证拦截器 |
|
let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"] |
|
list.forEach(item => { |
|
uni.addInterceptor(item, { |
|
invoke(to) { |
|
console.log('routeTo', to); |
|
if (getAccessToken()) { |
|
if (to.path === loginPage) { |
|
uni.reLaunch({ |
|
url: "/" |
|
}) |
|
} |
|
return true |
|
} else { |
|
if (checkWhite(to.url)) { |
|
return true |
|
} |
|
uni.reLaunch({ |
|
url: loginPage |
|
}) |
|
return false |
|
} |
|
}, |
|
fail(err) { |
|
console.log(err) |
|
} |
|
}) |
|
}) |