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