辽宁单点登录
This commit is contained in:
@@ -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<any> {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
export function lnRefreshTokenTo(): Promise<any> {
|
||||
// 调用useAdminInfo函数获取管理员信息,并将其赋值给adminInfo变量
|
||||
const adminInfo = useAdminInfo()
|
||||
return lnRefreshToken({
|
||||
refreshToken: adminInfo.refresh_token,
|
||||
clientId: "njcn",
|
||||
clientSecret:"njcnpqs"
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取营销用户列表
|
||||
* @returns {AxiosPromise}
|
||||
|
||||
@@ -8,41 +8,17 @@
|
||||
name="el-icon-BellFilled"
|
||||
size="18"
|
||||
/>
|
||||
<span class="nav-menu-text" v-if="globalPopUpRef?.eventList.length != 0">
|
||||
{{ (globalPopUpRef?.eventList.length>99? '99+':globalPopUpRef?.eventList.length) || 0 }}
|
||||
<span
|
||||
class="nav-menu-text"
|
||||
v-if="globalPopUpRef?.eventList?.length > 0"
|
||||
>
|
||||
{{ globalPopUpRef.eventList.length > 99 ? '99+' : globalPopUpRef.eventList.length }}
|
||||
</span>
|
||||
</div>
|
||||
</el-tooltip>
|
||||
<!-- <el-tooltip effect="dark" content="截图" placement="bottom">
|
||||
<div @click="savePng" class="nav-menu-item">
|
||||
<Icon
|
||||
:color="configStore.getColorVal('headerBarTabColor')"
|
||||
class="nav-menu-icon"
|
||||
name="el-icon-Camera"
|
||||
size="18"
|
||||
/>
|
||||
</div>
|
||||
</el-tooltip>
|
||||
<el-tooltip effect="dark" :content="state.isFullScreen ? '缩小' : '放大'" placement="bottom">
|
||||
<div @click="onFullScreen" class="nav-menu-item" :class="state.isFullScreen ? 'hover' : ''">
|
||||
<Icon
|
||||
:color="configStore.getColorVal('headerBarTabColor')"
|
||||
class="nav-menu-icon"
|
||||
v-if="state.isFullScreen"
|
||||
name="fa-solid fa-compress"
|
||||
size="18"
|
||||
/>
|
||||
<Icon
|
||||
:color="configStore.getColorVal('headerBarTabColor')"
|
||||
class="nav-menu-icon"
|
||||
v-else
|
||||
name="fa-solid fa-expand"
|
||||
size="18"
|
||||
/>
|
||||
</div>
|
||||
</el-tooltip> -->
|
||||
|
||||
<el-dropdown style="height: 100%" @command="handleCommand">
|
||||
<div class="admin-info" :class="state.currentNavMenu == 'adminInfo' ? 'hover' : ''">
|
||||
<div class="admin-info" :class="state.currentNavMenu === 'adminInfo' ? 'hover' : ''">
|
||||
<el-avatar :size="25" fit="fill">
|
||||
<img src="@/assets/avatar.png" alt="" />
|
||||
</el-avatar>
|
||||
@@ -52,104 +28,114 @@
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item command="adminInfo">个人资料</el-dropdown-item>
|
||||
<el-dropdown-item command="changePwd">修改密码</el-dropdown-item>
|
||||
<el-dropdown-item command="layout">退出登录</el-dropdown-item>
|
||||
<el-dropdown-item command="logout">退出登录</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
<!-- <div @click="configStore.setLayout('showDrawer', true)" class="nav-menu-item">
|
||||
<Icon
|
||||
:color="configStore.getColorVal('headerBarTabColor')"
|
||||
class="nav-menu-icon"
|
||||
name="fa fa-cogs"
|
||||
size="18"
|
||||
/>
|
||||
</div> -->
|
||||
|
||||
<Config />
|
||||
<PopupPwd ref="popupPwd" />
|
||||
<AdminInfo ref="popupAdminInfo" />
|
||||
<!-- <TerminalVue /> -->
|
||||
<!-- 全局暂降事件 -->
|
||||
<globalPopUp ref="globalPopUpRef" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { reactive, ref } from 'vue'
|
||||
import screenfull from 'screenfull'
|
||||
import { useConfig } from '@/stores/config'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import Config from './config.vue'
|
||||
import { useAdminInfo } from '@/stores/adminInfo'
|
||||
import router from '@/router'
|
||||
import globalPopUp from './globalPopUp.vue'
|
||||
import { routePush } from '@/utils/router'
|
||||
import html2canvas from 'html2canvas'
|
||||
import { useNavTabs } from '@/stores/navTabs'
|
||||
import { logout } from '@/api/user-boot/user'
|
||||
import Config from './config.vue'
|
||||
import PopupPwd from './popup/password.vue'
|
||||
import AdminInfo from './popup/adminInfo.vue'
|
||||
import { useNavTabs } from '@/stores/navTabs'
|
||||
|
||||
// 环境标识
|
||||
const IS_LNQR = import.meta.env.VITE_NAME === 'LNqr'
|
||||
|
||||
const adminInfo = useAdminInfo()
|
||||
const navTabs = useNavTabs()
|
||||
const configStore = useConfig()
|
||||
|
||||
// 引用
|
||||
const popupPwd = ref()
|
||||
const popupAdminInfo = ref()
|
||||
const state = reactive({
|
||||
isFullScreen: false,
|
||||
currentNavMenu: '',
|
||||
showLayoutDrawer: false,
|
||||
showAdminInfoPopover: false
|
||||
})
|
||||
const globalPopUpRef = ref()
|
||||
const savePng = () => {
|
||||
html2canvas(document.body, {
|
||||
scale: 1,
|
||||
useCORS: true
|
||||
}).then(function (canvas) {
|
||||
var link = document.createElement('a')
|
||||
link.href = canvas.toDataURL('image/png')
|
||||
link.download = 'screenshot.png'
|
||||
link.click()
|
||||
})
|
||||
}
|
||||
const onFullScreen = () => {
|
||||
if (!screenfull.isEnabled) {
|
||||
ElMessage.warning('layouts.Full screen is not supported')
|
||||
return false
|
||||
|
||||
// 状态
|
||||
const state = reactive({
|
||||
currentNavMenu: '',
|
||||
})
|
||||
|
||||
// 打开暂降事件
|
||||
const temporaryLandingEvent = () => {
|
||||
if (globalPopUpRef.value) {
|
||||
globalPopUpRef.value.open()
|
||||
}
|
||||
screenfull.toggle()
|
||||
screenfull.onchange(() => {
|
||||
state.isFullScreen = screenfull.isFullscreen
|
||||
})
|
||||
}
|
||||
|
||||
const handleCommand = async(key: string) => {
|
||||
console.log(key)
|
||||
// 下拉菜单命令
|
||||
const handleCommand = async (key: string) => {
|
||||
switch (key) {
|
||||
case 'adminInfo':
|
||||
popupAdminInfo.value.open()
|
||||
popupAdminInfo.value?.open()
|
||||
break
|
||||
case 'changePwd':
|
||||
popupPwd.value.open()
|
||||
popupPwd.value?.open()
|
||||
break
|
||||
case 'layout':
|
||||
await window.location.reload()
|
||||
setTimeout(() => {
|
||||
navTabs.closeTabs()
|
||||
window.localStorage.clear()
|
||||
adminInfo.reset()
|
||||
router.push({ name: 'login' })
|
||||
}, 0)
|
||||
// navTabs.closeTabs()
|
||||
// window.localStorage.clear()
|
||||
// adminInfo.reset()
|
||||
// router.push({ name: 'login' })
|
||||
break
|
||||
default:
|
||||
case 'logout':
|
||||
await handleLogout()
|
||||
break
|
||||
}
|
||||
}
|
||||
const temporaryLandingEvent = () => {
|
||||
globalPopUpRef.value.open()
|
||||
|
||||
// 统一登出逻辑
|
||||
const handleLogout = async () => {
|
||||
try {
|
||||
// 1. 调用后端登出接口
|
||||
await logout()
|
||||
console.log('✅ 后端登出成功')
|
||||
} catch (err) {
|
||||
console.error('❌ 登出接口异常', err)
|
||||
} finally {
|
||||
// 2. 清理本地所有数据
|
||||
clearLocalData()
|
||||
|
||||
// 3. LNqr 环境跳 CAS 登出
|
||||
if (IS_LNQR) {
|
||||
redirectToCasLogout()
|
||||
} else {
|
||||
// 普通环境直接跳登录页
|
||||
window.location.href = '/login'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 清理本地数据
|
||||
const clearLocalData = () => {
|
||||
// 清空 localStorage
|
||||
window.localStorage.clear()
|
||||
|
||||
// 清空用户状态
|
||||
adminInfo.reset()
|
||||
|
||||
// 清空标签页
|
||||
navTabs.closeTabs()
|
||||
|
||||
// 清 Cookie
|
||||
document.cookie.split(';').forEach(cookie => {
|
||||
const name = cookie.split('=')[0].trim()
|
||||
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`
|
||||
})
|
||||
|
||||
console.log('✅ 本地数据已全部清空')
|
||||
}
|
||||
|
||||
// CAS 登出跳转
|
||||
const redirectToCasLogout = () => {
|
||||
const casLogoutUrl =
|
||||
'http://privilege-epri.dcloud.ln.dc.sgcc.com.cn/cas/logout?service=http://privilege-epri.dcloud.ln.dc.sgcc.com.cn/cas/login?service=http://PQMonitoring.dcloud.ln.dc.sgcc.com.cn'
|
||||
window.location.href = casLogoutUrl
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -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); }
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div @keyup.enter="onSubmit(formRef)">
|
||||
<div v-if='!VITE_FLAG' @keyup.enter="onSubmit(formRef)">
|
||||
<div @contextmenu.stop="" id="bubble" class="bubble">
|
||||
<canvas id="bubble-canvas" class="bubble-canvas"></canvas>
|
||||
</div>
|
||||
@@ -67,7 +67,6 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, onBeforeUnmount, reactive, ref, nextTick } from 'vue'
|
||||
import * as pageBubble from '@/utils/pageBubble'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { gongkey, login, getSysConfig, loginLNqr } from '@/api/user-boot/user'
|
||||
import { useAdminInfo } from '@/stores/adminInfo'
|
||||
import type { FormInstance, InputInstance, FormRules } from 'element-plus'
|
||||
@@ -78,6 +77,7 @@ import { getTheme } from '@/api/systerm'
|
||||
import { useConfig } from '@/stores/config'
|
||||
import PopupUpdatePwd from './popupUpdatePwd.vue'
|
||||
const VITE_FLAG = import.meta.env.VITE_NAME == 'LNqr'
|
||||
|
||||
const router = useRouter()
|
||||
let timer: number
|
||||
const configStore = useConfig()
|
||||
@@ -185,33 +185,84 @@ const onSubmit = async (formEl: FormInstance | undefined) => {
|
||||
}
|
||||
})
|
||||
}
|
||||
const LNonSubmit = async () => {
|
||||
/*const LNonSubmit = async () => {
|
||||
state.submitLoading = true
|
||||
loginLNqr()
|
||||
.then(res => {
|
||||
//返回 a
|
||||
|
||||
//拿到token了,可以正常操作页面
|
||||
userInfo.dataFill(res.data)
|
||||
state.submitLoading = false
|
||||
getSysConfig().then(res => {
|
||||
window.localStorage.setItem('sysdata', JSON.stringify(res.data))
|
||||
})
|
||||
router.push({
|
||||
path: '/'
|
||||
})
|
||||
|
||||
})
|
||||
.catch(err => {
|
||||
console.log("---------")
|
||||
console.log(err)
|
||||
//
|
||||
window.location.href = "http://privilege-epri.dcloud.ln.dc.sgcc.com.cn/cas/login"
|
||||
})
|
||||
lnToken().then(res => {
|
||||
console.log(555)
|
||||
loginLNqr().then(res => {
|
||||
//拿到token了,可以正常操作页面
|
||||
userInfo.dataFill(res.data)
|
||||
state.submitLoading = false
|
||||
getSysConfig().then(res => {
|
||||
window.localStorage.setItem('sysdata', JSON.stringify(res.data))
|
||||
})
|
||||
router.push({
|
||||
path: '/'
|
||||
})
|
||||
}).catch(err => {
|
||||
console.log("---------")
|
||||
console.log(err)
|
||||
//
|
||||
//window.location.href = "http://privilege-epri.dcloud.ln.dc.sgcc.com.cn/cas/login"
|
||||
})
|
||||
})
|
||||
setTimeout(() => {
|
||||
state.submitLoading = false
|
||||
}, 500)
|
||||
}*/
|
||||
|
||||
// ========== 修改:CAS 无感登录 ==========
|
||||
const LNonSubmit = async () => {
|
||||
// 先检查是否是 CAS 回调
|
||||
if (handleCasCallback()) {
|
||||
console.log("进入回调")
|
||||
return
|
||||
}
|
||||
// 没有 token,触发 CAS 登录流程
|
||||
console.log('无 token,触发 CAS 登录')
|
||||
// 跳转到后端 CAS 认证入口
|
||||
window.location.href = '/api/pqs-auth/oauth/lnCheck'
|
||||
}
|
||||
// ========== 新增:处理 CAS 回调 ==========
|
||||
const handleCasCallback = () => {
|
||||
const hash = window.location.hash
|
||||
const queryIndex = hash.indexOf('?')
|
||||
if (queryIndex === -1) return false
|
||||
|
||||
console.log(hash)
|
||||
|
||||
const hashParams = new URLSearchParams(hash.substring(queryIndex + 1))
|
||||
if (hashParams.get('flag') !== '1') return false
|
||||
|
||||
// 清理 URL 中的 flag 参数,防止刷新重复触发
|
||||
const cleanHash = hash.substring(0, queryIndex)
|
||||
window.history.replaceState(null, '', cleanHash)
|
||||
if(hashParams && hashParams.get("flag") == 1){
|
||||
state.submitLoading = true
|
||||
let data = {clientId:"njcn",clientSecret:"njcnpqs"}
|
||||
loginLNqr(data).then(res => {
|
||||
//拿到token了,可以正常操作页面
|
||||
userInfo.dataFill(res.data)
|
||||
state.submitLoading = false
|
||||
getSysConfig().then(res => {
|
||||
window.localStorage.setItem('sysdata', JSON.stringify(res.data))
|
||||
})
|
||||
router.push({
|
||||
path: '/'
|
||||
})
|
||||
|
||||
}).catch(err => {
|
||||
console.log("---------")
|
||||
console.log(err)
|
||||
state.submitLoading = false
|
||||
})
|
||||
}else {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
defineExpose({ VITE_FLAG })
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@@ -367,3 +418,5 @@ const LNonSubmit = async () => {
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user