| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import HtProgress from 'nprogress'
- import store from '@/store'
- import {
- recordRoute,
- routesWhiteList,
- progressBar,
- tokenName,
- casTokenName,
- oauthTokenName,
- } from '@/config'
- export default function (to, from, next) {
- // 白名单页面
- if (
- (routesWhiteList.indexOf(to.path) !== -1 ||
- routesWhiteList.indexOf(to.name) !== -1) && window.ssoConfig.mode !== 'oauth'
- ) {
- if(to.query.corpId){
- next({ path: '/matter/approvalForm' })
- }else{
- next()
- }
- } else if (to.query && to.query[tokenName]) {
- // 先跳转到加载中页面
- next({ path: '/loading' })
- store
- .dispatch('user/authentication', to.query)
- .then(() => {
- // 鉴权完成后再跳转回来
- next({ ...to, replace: true })
- })
- .catch(() => {
- next({ path: '/500', replace: true })
- })
- } else if (window.ssoConfig.mode == 'cas') {
- // cas单点登录
- if (to.query && to.query[casTokenName]) {
- const ticket = to.query[casTokenName]
- store
- .dispatch('user/ssoLogin', {
- ticket,
- service: window.location.href.split('?')[0],
- })
- .then(() => {
- next({ ...to, replace: true })
- })
- .catch(() => {
- next({ path: '/500', replace: true })
- })
- } else {
- window.location.href = `${window.ssoConfig.url}?service=${window.location.href}`
- }
- } else if (window.ssoConfig.mode == 'oauth') {
- // oauth单点登录
- if (to.query && to.query[oauthTokenName]) {
- const code = to.query[oauthTokenName]
- store
- .dispatch('user/ssoLogin', {
- code,
- service: window.location.href.split('?')[0],
- })
- .then(() => {
- next({ ...to, replace: true })
- })
- .catch(() => {
- next({ path: '/500', replace: true })
- })
- } else {
- window.location.href = `${window.ssoConfig.url}?response_type=code&client_id=${window.ssoConfig.clientId}&redirect_uri=${window.location.href}`
- }
- } else {
- if (recordRoute) {
- if(to.fullPath=='/matter/approvalForm'){
- next()
- }else{
- next(`/login?redirect=${to.fullPath}`)
- }
- } else {
- next('/login')
- }
- if (progressBar) HtProgress.done()
- }
- }
|