feat : 测试sso单点登录之后的重定向路径3

This commit is contained in:
clay
2024-04-29 11:27:56 +08:00
parent eee3c3852e
commit 929228974a
2 changed files with 89 additions and 86 deletions

View File

@@ -189,7 +189,8 @@ router.beforeEach(async (to, form, next) => {
NProgress.done()
} else {
sessionStorage.setItem('toView', JSON.stringify(to))
next({path: '/api/auth/cas/login'})
window.location.href = `${window.location.origin}/api/auth/cas/login`
// next({path: '/api/auth/cas/login'})
}
} else {
if (to.path === '/login'|| to.path === '/cas/login') {

View File

@@ -1,96 +1,98 @@
import axios from "axios";
import { AxiosCanceler } from "./axiosCanceler";
import { ElMessageBox, ElNotification } from "element-plus";
import { getToken, removeToken } from "./auth";
import {AxiosCanceler} from "./axiosCanceler";
import {ElMessageBox, ElNotification} from "element-plus";
import {getToken, removeToken} from "./auth";
axios.defaults.headers['Content-Type']='application/json'
axios.defaults.headers['Content-Type'] = 'application/json'
const serveice = axios.create({
baseURL: import.meta.env.VITE_BASE_URL,
timeout: 6000
baseURL: import.meta.env.VITE_BASE_URL,
timeout: 6000
})
const axiosCanceler = new AxiosCanceler()
serveice.interceptors.request.use(config=>{
const ACCESS_TOKEN = getToken() || ''
if(ACCESS_TOKEN!==undefined && ACCESS_TOKEN!=='') {
config.headers['Authorization']=ACCESS_TOKEN
}
// 检查是否有重复请求, 有则取消掉
axiosCanceler.removePendingRequest(config)
// 将请求加入pendingMap
axiosCanceler.addPendingRequest(config)
return config
},error=>{
Promise.reject(error)
serveice.interceptors.request.use(config => {
const ACCESS_TOKEN = getToken() || ''
if (ACCESS_TOKEN !== undefined && ACCESS_TOKEN !== '') {
config.headers['Authorization'] = ACCESS_TOKEN
}
// 检查是否有重复请求, 有则取消掉
axiosCanceler.removePendingRequest(config)
// 将请求加入pendingMap
axiosCanceler.addPendingRequest(config)
return config
}, error => {
Promise.reject(error)
})
serveice.interceptors.response.use(response=>{
axiosCanceler.removePendingRequest(response.config)
//二进制数据直接返回
if(response.request.responseType === 'blob' || response.request.responseType === 'arraybuffer') {
return response.data
}
return response.data
},error=>{
let response = error.response
const status = response.status;
switch(status) {
case 401:
ElMessageBox.confirm('登录状态已过期,请重新登录','系统提示',{
confirmButtonText: '重新登录',
cancelButtonText: '取消',
type: 'warning',
closeOnClickModal: false
}).then(()=>{
removeToken()
window.location = '/api/auth/cas/login'
})
return Promise.reject('会话已过期,请重新登录')
case 402:
break;
case 403:
console.log(response)
ElNotification({
title: '系统提示',
message: response.data.msg,
type: 'warning'
})
break;
case 404:
ElNotification({
title: '系统提示',
message: '不存在的地址',
type: 'error'
})
break;
case 405:
ElNotification({
title: '系统提示',
message: '传输格式错误,请检查',
type: 'error'
})
break;
case 511:
ElNotification({
title: '系统提示',
message: '禁止访问',
type: 'error'
})
removeToken()
window.location = '/forbidden'
break;
case 500:
if (response.data){
serveice.interceptors.response.use(response => {
axiosCanceler.removePendingRequest(response.config)
//二进制数据直接返回
if (response.request.responseType === 'blob' || response.request.responseType === 'arraybuffer') {
return response.data
}else {
ElNotification({
title: '系统提示',
message: '系统未知错误',
type: 'error'
})
break;
}
}
return Promise.reject(error)
}
console.log("windows", window.location.pathname)
return response.data
}, error => {
let response = error.response
const status = response.status;
switch (status) {
case 401:
ElMessageBox.confirm('登录状态已过期,请重新登录', '系统提示', {
confirmButtonText: '重新登录',
cancelButtonText: '取消',
type: 'warning',
closeOnClickModal: false
}).then(() => {
removeToken()
sessionStorage.setItem('toView', window.location.pathname)
window.location = '/api/auth/cas/login'
})
return Promise.reject('会话已过期,请重新登录')
case 402:
break;
case 403:
console.log(response)
ElNotification({
title: '系统提示',
message: response.data.msg,
type: 'warning'
})
break;
case 404:
ElNotification({
title: '系统提示',
message: '不存在的地址',
type: 'error'
})
break;
case 405:
ElNotification({
title: '系统提示',
message: '传输格式错误,请检查',
type: 'error'
})
break;
case 511:
ElNotification({
title: '系统提示',
message: '禁止访问',
type: 'error'
})
removeToken()
window.location = '/forbidden'
break;
case 500:
if (response.data) {
return response.data
} else {
ElNotification({
title: '系统提示',
message: '系统未知错误',
type: 'error'
})
break;
}
}
return Promise.reject(error)
})
export default serveice