From ae3855638dba0c927236c1a1b1a85d5b048c40e2 Mon Sep 17 00:00:00 2001 From: Houjie <714924425@qq.com> Date: 星期五, 18 四月 2025 10:31:08 +0800 Subject: [PATCH] 提交 --- common/router/index.js | 61 +++++++++++++++++------------- 1 files changed, 35 insertions(+), 26 deletions(-) diff --git a/common/router/index.js b/common/router/index.js index 4508f1b..25e74d8 100644 --- a/common/router/index.js +++ b/common/router/index.js @@ -1,49 +1,58 @@ import modules from './modules' import Vue from 'vue' import Router from '@/plugin/uni-simple-router/index.js' -import {ACCESS_TOKEN} from '@/common/util/constants.js' -import {isOAuth2AppEnv} from '@/common/util/util.js' +import { + ACCESS_TOKEN +} from '@/common/util/constants.js' +import { + isOAuth2AppEnv +} from '@/common/util/util.js' Vue.use(Router) //鍒濆鍖� const router = new Router({ - encodeURI:true, - routes: [...modules]//璺敱琛� + + encodeURI: true, + routes: [...modules] //璺敱琛� }); -const whiteList = ['/pages/login/login','/pages/login/loginOauth2'] +const whiteList = ['/pages/login/login', '/pages/login/loginOauth2'] //鍏ㄥ眬璺敱鍓嶇疆瀹堝崼 router.beforeEach((to, from, next) => { - if(to.path == '/oauth2-app/login'){ + if (to.path == '/oauth2-app/login') { let temp = location.href; - location.href = temp.replace('/oauth2-app/login','/pages/login/loginOauth2') + location.href = temp.replace('/oauth2-app/login', '/pages/login/loginOauth2') return; } - let token=uni.getStorageSync(ACCESS_TOKEN); - if(token){ - if (to.path === '/pages/login/login' || to.path === '/pages/login/loginOauth2') { - if(from.path ==='/pages/index/index'){ - return; - }else{ - next() - } + let token = uni.getStorageSync(ACCESS_TOKEN); + if (token) { + if (to.path === '/pages/login/login' || to.path === '/pages/login/loginOauth2') { + if (from.path === '/pages/index/index') { + return; + } else { + next() + } } next() - }else{ + } else { if (whiteList.indexOf(to.path) !== -1) { - // 鍦ㄥ厤鐧诲綍鐧藉悕鍗曪紝濡傛灉杩涘叆鐨勯〉闈㈡槸login椤甸潰骞朵笖褰撳墠鏄疧Auth2app鐜锛屽氨杩涘叆OAuth2鐧诲綍椤甸潰 - if (to.path === '/pages/login/login' && isOAuth2AppEnv()) { - next({path: '/pages/login/loginOauth2'}) - } else { - // 鍦ㄥ厤鐧诲綍鐧藉悕鍗曪紝鐩存帴杩涘叆 - next() - } - }else{ + // 鍦ㄥ厤鐧诲綍鐧藉悕鍗曪紝濡傛灉杩涘叆鐨勯〉闈㈡槸login椤甸潰骞朵笖褰撳墠鏄疧Auth2app鐜锛屽氨杩涘叆OAuth2鐧诲綍椤甸潰 + if (to.path === '/pages/login/login' && isOAuth2AppEnv()) { + next({ + path: '/pages/login/loginOauth2' + }) + } else { + // 鍦ㄥ厤鐧诲綍鐧藉悕鍗曪紝鐩存帴杩涘叆 + next() + } + } else { // 濡傛灉褰撳墠鏄湪OAuth2APP鐜锛屽氨璺宠浆鍒癘Auth2鐧诲綍椤甸潰 let path = isOAuth2AppEnv() ? '/pages/login/loginOauth2' : '/pages/login/login'; - next({ path: path }) + next({ + path: path + }) } - } + } }) // 鍏ㄥ眬璺敱鍚庣疆瀹堝崼 router.afterEach((to, from) => { -- Gitblit v1.9.3