辽宁单点登录

This commit is contained in:
cdf
2026-06-15 17:57:14 +08:00
parent 9224ea17b8
commit 765507398e
4 changed files with 237 additions and 181 deletions

View File

@@ -1,10 +1,11 @@
import type { AxiosRequestConfig, Method } from 'axios'
import axios from 'axios'
import { ElLoading, ElNotification, type LoadingOptions } from 'element-plus'
import { refreshToken } from '@/api/user-boot/user'
import { lnRefreshToken, lnRefreshTokenTo, refreshToken } from '@/api/user-boot/user'
import router from '@/router/index'
import { useAdminInfo } from '@/stores/adminInfo'
import { debounce } from 'lodash-es'
const IS_LN_VERSION = import.meta.env.VITE_NAME === 'LNqr'
let loginExpireTimer: any = null
window.requests = []
window.tokenRefreshing = false
@@ -110,7 +111,8 @@ function createAxios<Data = any, T = ApiPromise<Data>>(
if (
config.url == '/user-boot/user/generateSm2Key' ||
config.url == '/pqs-auth/oauth/token' ||
config.url == '/LNapi/pqs-auth/oauth/lnLogin'
config.url == '/pqs-auth/oauth/lnLogin'||
config.url == '/pqs-auth/oauth/lnRefreshToken'
) {
config.headers.Authorization = 'Basic bmpjbjpuamNucHFz'
}
@@ -146,24 +148,44 @@ function createAxios<Data = any, T = ApiPromise<Data>>(
if (!window.tokenRefreshing) {
window.tokenRefreshing = true
return refreshToken()
.then(res => {
if(IS_LN_VERSION){
//辽宁版本
return lnRefreshTokenTo().then(res => {
adminInfo.setToken(res.data.access_token, 'auth')
adminInfo.setToken(res.data.refresh_token, 'refresh')
window.requests.forEach(cb => cb(res.data.access_token))
window.requests = []
return Axios(response.config)
})
.catch(err => {
window.location.reload()
adminInfo.removeToken()
router.push({ name: 'login' })
}).catch(err => {
// refresh_token + CAS 都过期 → 重新走CAS登录
window.location.href = '/api/pqs-auth/oauth/lnCheck'
return Promise.reject(err)
})
.finally(() => {
window.tokenRefreshing = false
})
}).finally(() => {
window.tokenRefreshing = false
})
}else {
//通用版本
return refreshToken()
.then(res => {
adminInfo.setToken(res.data.access_token, 'auth')
adminInfo.setToken(res.data.refresh_token, 'refresh')
window.requests.forEach(cb => cb(res.data.access_token))
window.requests = []
return Axios(response.config)
})
.catch(err => {
window.location.reload()
adminInfo.removeToken()
router.push({ name: 'login' })
return Promise.reject(err)
})
.finally(() => {
window.tokenRefreshing = false
})
}
} else {
return new Promise(resolve => {
// 用函数形式将 resolve 存入,等待刷新后再执行
@@ -188,6 +210,13 @@ function createAxios<Data = any, T = ApiPromise<Data>>(
router.push({ name: 'login' })
loginExpireTimer = null // 执行后清空定时器
}, 100) // 可根据实际情况调整延迟时间
return Promise.reject(response.data)
} else if (response.data.code == 'A0121') {
//统一认证过期
const casLogoutUrl =
'http://privilege-epri.dcloud.ln.dc.sgcc.com.cn/cas/login?service=http://PQMonitoring.dcloud.ln.dc.sgcc.com.cn'
window.location.href = casLogoutUrl
return Promise.reject(response.data)
} else {
if (options.showCodeMessage) {