diff --git a/src/api/user-boot/user.ts b/src/api/user-boot/user.ts index 63ccd014..f63c5a80 100644 --- a/src/api/user-boot/user.ts +++ b/src/api/user-boot/user.ts @@ -44,13 +44,30 @@ export async function login(params: any) { }) } //辽宁嵌入登录获取token -export async function loginLNqr() { +export async function loginLNqr(data: any) { return request({ url: '/pqs-auth/oauth/lnLogin', method: 'get', + params: data }) } +export async function lnRefreshToken(data: any) { + return request({ + url: '/pqs-auth/oauth/lnRefreshToken', + method: 'get', + params: data + }) +} + +export async function logout() { + return request({ + url: '/pqs-auth/oauth/logout', + method: 'DELETE', + }) +} + + //获取用户信息 export function getUserById() { const adminInfo = useAdminInfo() @@ -77,6 +94,17 @@ export function refreshToken(): Promise { }) } + +export function lnRefreshTokenTo(): Promise { + // 调用useAdminInfo函数获取管理员信息,并将其赋值给adminInfo变量 + const adminInfo = useAdminInfo() + return lnRefreshToken({ + refreshToken: adminInfo.refresh_token, + clientId: "njcn", + clientSecret:"njcnpqs" + }) +} + /** * 获取营销用户列表 * @returns {AxiosPromise} diff --git a/src/layouts/admin/components/navMenus.vue b/src/layouts/admin/components/navMenus.vue index 364b7d65..a07db93b 100644 --- a/src/layouts/admin/components/navMenus.vue +++ b/src/layouts/admin/components/navMenus.vue @@ -8,41 +8,17 @@ name="el-icon-BellFilled" size="18" /> - - {{ (globalPopUpRef?.eventList.length>99? '99+':globalPopUpRef?.eventList.length) || 0 }} + + {{ globalPopUpRef.eventList.length > 99 ? '99+' : globalPopUpRef.eventList.length }} - + -
+
@@ -52,104 +28,114 @@ 个人资料 修改密码 - 退出登录 + 退出登录 - + - -
@@ -163,7 +149,6 @@ const temporaryLandingEvent = () => { height: 60px; display: flex; align-items: center; - // height: 100%; margin-left: auto; background-color: v-bind('configStore.getColorVal("headerBarBackground")'); @@ -219,59 +204,20 @@ const temporaryLandingEvent = () => { } } -.dropdown-menu-box :deep(.el-dropdown-menu__item) { - justify-content: center; -} - -.admin-info-base { - display: flex; - justify-content: center; - flex-wrap: wrap; - padding-top: 10px; - - .admin-info-other { - display: block; - width: 100%; - text-align: center; - padding: 10px 0; - - .admin-info-name { - font-size: var(--el-font-size-large); - } - } -} - -.admin-info-footer { - padding: 10px 0; - margin: 0 -12px -12px -12px; - display: flex; - justify-content: space-around; -} - -.pt2 { - padding-top: 2px; -} - -@keyframes twinkle { - 0% { - transform: scale(0); - } - 80% { - transform: scale(1.2); - } - 100% { - transform: scale(1); - } -} .nav-menu-text { position: absolute; top: 13px; - left: 20px; + left: 20px; font-size: 12px; - display: inline-block; - background-color: #ff0000; + background: #ff0000; color: #fff; border-radius: 5px; padding: 0 3px; } + +@keyframes twinkle { + 0% { transform: scale(0); } + 80% { transform: scale(1.2); } + 100% { transform: scale(1); } +} diff --git a/src/utils/request.ts b/src/utils/request.ts index 99e898de..5e0613fb 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -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>( 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>( 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>( 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) { diff --git a/src/views/user/login.vue b/src/views/user/login.vue index 59ff4ee3..77589c8a 100644 --- a/src/views/user/login.vue +++ b/src/views/user/login.vue @@ -1,5 +1,5 @@