12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- import { getToken,isLoginSso,removeToken,getSsoAdminToken } from '@/utils/auth'
- // 登录页面
- const loginPage = "/pages/login"
-
- // 页面白名单
- const whiteList = [
- '/pages/login', '/pages/register', '/pages/common/webview/index', '/pages/loginSso',
- ]
- // 检查地址白名单
- 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(isLoginSso,'isLoginSso')
- // 启用单点登录后没有ssoToken清除当前token
- if (!getSsoAdminToken() && isLoginSso) {
- removeToken()
- };
- if (getToken()) {
- if (to.url === loginPage) {
- uni.reLaunch({ url: "/" })
- }
- return true
- } else if(isLoginSso){
- console.log(777)
- uni.reLaunch({ url: '/pages/loginSso'})
- return false
- }else {
- if (checkWhite(to.url)) {
- console.log(6666)
- return true
- }
- console.log(8888)
- uni.reLaunch({ url: loginPage })
- return false
- }
- },
- fail(err) {
- console.log(err)
- }
- })
- })
|