!36 czh-20260612-优化单点登录的url

Merge pull request !36 from 陈志浩/feature/autoLogin
This commit is contained in:
陈志浩
2026-06-12 09:11:47 +00:00
committed by Gitee
9 changed files with 605 additions and 6 deletions
+3
View File
@@ -31,3 +31,6 @@ VITE_APP_SUB_jeecg-app-1 = '//localhost:8092'
# 在线文档编辑版本。可选属性:wps, onlyoffice # 在线文档编辑版本。可选属性:wps, onlyoffice
VITE_GLOB_ONLINE_DOCUMENT_VERSION=wps VITE_GLOB_ONLINE_DOCUMENT_VERSION=wps
# AutoLogin SSO - 指向 demo 网关
VITE_AUTOLOGIN_URL=http://localhost:9100/api/sys/autoLogin
+3
View File
@@ -32,3 +32,6 @@ VITE_GLOB_API_URL_PREFIX=
# 在线文档编辑版本。可选属性:wps, onlyoffice # 在线文档编辑版本。可选属性:wps, onlyoffice
VITE_GLOB_ONLINE_DOCUMENT_VERSION=wps VITE_GLOB_ONLINE_DOCUMENT_VERSION=wps
# AutoLogin SSO - 指向生产网关(地址由运维提供)
VITE_AUTOLOGIN_URL=http://200.100.65.101:9100/api/sys/autoLogin
+16
View File
@@ -0,0 +1,16 @@
import { defHttp } from '/@/utils/http/axios';
enum AutoLoginApi {
AutoLogin = '/sys/autoLogin',
IpAutoLogin = '/sys/ipAutoLogin',
}
/** 自动登录 — 请求网关地址(由 VITE_AUTOLOGIN_URL 控制),form 表单格式 */
export function autoLoginApi() {
const url = import.meta.env.VITE_AUTOLOGIN_URL || AutoLoginApi.AutoLogin;
return defHttp.post({
url,
data: 'username=&password=',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
});
}
+5 -1
View File
@@ -12,5 +12,9 @@ export enum PageEnum {
//文件路由 //文件路由
SYS_FILES_PATH = '/file/share', SYS_FILES_PATH = '/file/share',
// 邮件中的跳转地址 // 邮件中的跳转地址
TOKEN_LOGIN = '/tokenLogin' TOKEN_LOGIN = '/tokenLogin',
// 自动登录路径
AUTOLOGIN_PATH = '/user/autoLogin',
// 登出结果页路径
LOGOUT_RESULT_PATH = '/user/logoutResult',
} }
+3 -3
View File
@@ -28,7 +28,7 @@ const ROOT_PATH = RootRoute.path;
//update-begin---author:wangshuai ---date:20220629 for[issues/I5BG1I]vue3不支持auth2登录------------ //update-begin---author:wangshuai ---date:20220629 for[issues/I5BG1I]vue3不支持auth2登录------------
//update-begin---author:wangshuai ---date:20221111 for: [VUEN-2472]分享免登录------------ //update-begin---author:wangshuai ---date:20221111 for: [VUEN-2472]分享免登录------------
const whitePathList: PageEnum[] = [LOGIN_PATH, OAUTH2_LOGIN_PAGE_PATH,SYS_FILES_PATH, TOKEN_LOGIN ]; const whitePathList: PageEnum[] = [LOGIN_PATH, OAUTH2_LOGIN_PAGE_PATH,SYS_FILES_PATH, TOKEN_LOGIN, PageEnum.AUTOLOGIN_PATH, PageEnum.LOGOUT_RESULT_PATH ];
//update-end---author:wangshuai ---date:20221111 for: [VUEN-2472]分享免登录------------ //update-end---author:wangshuai ---date:20221111 for: [VUEN-2472]分享免登录------------
//update-end---author:wangshuai ---date:20220629 for[issues/I5BG1I]vue3不支持auth2登录------------ //update-end---author:wangshuai ---date:20220629 for[issues/I5BG1I]vue3不支持auth2登录------------
@@ -57,7 +57,7 @@ export function createPermissionGuard(router: Router) {
// Whitelist can be directly entered // Whitelist can be directly entered
if (whitePathList.includes(to.path as PageEnum)) { if (whitePathList.includes(to.path as PageEnum)) {
if (to.path === LOGIN_PATH && token) { if ((to.path === LOGIN_PATH || to.path === PageEnum.AUTOLOGIN_PATH) && token) {
const isSessionTimeout = userStore.getSessionTimeout; const isSessionTimeout = userStore.getSessionTimeout;
//update-begin---author:scott ---date:2023-04-24 for:【QQYUN-4713】登录代码调整逻辑有问题,改造待观察-- //update-begin---author:scott ---date:2023-04-24 for:【QQYUN-4713】登录代码调整逻辑有问题,改造待观察--
@@ -122,7 +122,7 @@ export function createPermissionGuard(router: Router) {
//---------【首次登陆并且是企业微信或者钉钉的情况下才会调用】------------------------------------------------ //---------【首次登陆并且是企业微信或者钉钉的情况下才会调用】------------------------------------------------
//update-end---author:wangshuai ---date:20230302 for:只有首次登陆并且是企业微信或者钉钉的情况下才会调用------------ //update-end---author:wangshuai ---date:20230302 for:只有首次登陆并且是企业微信或者钉钉的情况下才会调用------------
// 如果当前是在OAuth2APP环境,就跳转到OAuth2登录页面,否则跳转到登录页面 // 如果当前是在OAuth2APP环境,就跳转到OAuth2登录页面,否则跳转到登录页面
path = isOAuth2AppEnv() ? OAUTH2_LOGIN_PAGE_PATH : LOGIN_PATH; path = isOAuth2AppEnv() ? OAUTH2_LOGIN_PAGE_PATH : PageEnum.AUTOLOGIN_PATH;
} }
//update-end---author:wangshuai ---date:20220629 for[issues/I5BG1I]vue3 Auth2未实现------------ //update-end---author:wangshuai ---date:20220629 for[issues/I5BG1I]vue3 Auth2未实现------------
// redirect login page // redirect login page
+21 -1
View File
@@ -65,6 +65,26 @@ export const TokenLoginRoute: AppRouteRecordRaw = {
}, },
}; };
// update-begin--author:liaozhiyang---date:20240301---for:【QQYUN-7967】新增、编辑路由访问 // update-begin--author:liaozhiyang---date:20240301---for:【QQYUN-7967】新增、编辑路由访问
export const AutoLoginRoute: AppRouteRecordRaw = {
path: '/user/autoLogin',
name: 'AutoLogin',
component: () => import('/@/views/sys/login/AutoLogin.vue'),
meta: {
title: '自动登录',
ignoreAuth: true,
},
};
export const LogoutResultRoute: AppRouteRecordRaw = {
path: '/user/logoutResult',
name: 'LogoutResult',
component: () => import('/@/views/sys/login/LogoutResult.vue'),
meta: {
title: '退出登录',
ignoreAuth: true,
},
};
export const formUrlDetail = { export const formUrlDetail = {
path: '/online/formUrlDetail/:id/:dataId', path: '/online/formUrlDetail/:id/:dataId',
name: 'formUrlDetail', name: 'formUrlDetail',
@@ -107,4 +127,4 @@ export const formUrlSuccess = {
// update-end--author:liaozhiyang---date:20240301---for:【QQYUN-7967】新增、编辑路由访问 // update-end--author:liaozhiyang---date:20240301---for:【QQYUN-7967】新增、编辑路由访问
// Basic routing without permission // Basic routing without permission
export const basicRoutes = [LoginRoute, RootRoute, ...mainOutRoutes, REDIRECT_ROUTE, PAGE_NOT_FOUND_ROUTE, TokenLoginRoute, Oauth2LoginRoute,formUrlDetail, formUrlAdd, formUrlEdit, formUrlSuccess]; export const basicRoutes = [LoginRoute, RootRoute, ...mainOutRoutes, REDIRECT_ROUTE, PAGE_NOT_FOUND_ROUTE, TokenLoginRoute, Oauth2LoginRoute, AutoLoginRoute, LogoutResultRoute,formUrlDetail, formUrlAdd, formUrlEdit, formUrlSuccess];
+16 -1
View File
@@ -8,6 +8,7 @@ import { ROLES_KEY, TOKEN_KEY, USER_INFO_KEY, LOGIN_INFO_KEY, DB_DICT_DATA_KEY,
import { getAuthCache, setAuthCache, removeAuthCache } from '/@/utils/auth'; import { getAuthCache, setAuthCache, removeAuthCache } from '/@/utils/auth';
import { GetUserInfoModel, LoginParams, ThirdLoginParams } from '/@/api/sys/model/userModel'; import { GetUserInfoModel, LoginParams, ThirdLoginParams } from '/@/api/sys/model/userModel';
import { doLogout, getUserInfo, loginApi, phoneLoginApi, thirdLogin } from '/@/api/sys/user'; import { doLogout, getUserInfo, loginApi, phoneLoginApi, thirdLogin } from '/@/api/sys/user';
import { autoLoginApi } from '/@/api/sys/autologin';
import { useI18n } from '/@/hooks/web/useI18n'; import { useI18n } from '/@/hooks/web/useI18n';
import { useMessage } from '/@/hooks/web/useMessage'; import { useMessage } from '/@/hooks/web/useMessage';
import { router } from '/@/router'; import { router } from '/@/router';
@@ -161,6 +162,20 @@ export const useUserStore = defineStore({
return Promise.reject(error); return Promise.reject(error);
} }
}, },
/**
* 网关自动登录 — 跳过密码,由网关注入身份
*/
async autoLogin(goHome = true): Promise<GetUserInfoModel | null> {
try {
const data = await autoLoginApi();
const { token, userInfo } = data;
this.setToken(token);
this.setTenant(userInfo.loginTenantId);
return this.afterLoginAction(goHome, data);
} catch (error) {
return Promise.reject(error);
}
},
/** /**
* 扫码登录事件 * 扫码登录事件
*/ */
@@ -330,7 +345,7 @@ export const useUserStore = defineStore({
}else{ }else{
// update-begin-author:sunjianlei date:20230306 for: 修复登录成功后,没有正确重定向的问题 // update-begin-author:sunjianlei date:20230306 for: 修复登录成功后,没有正确重定向的问题
goLogin && (await router.push({ goLogin && (await router.push({
path: PageEnum.BASE_LOGIN, path: PageEnum.LOGOUT_RESULT_PATH,
query: { query: {
// 传入当前的路由,登录成功后跳转到当前路由 // 传入当前的路由,登录成功后跳转到当前路由
redirect: router.currentRoute.value.fullPath, redirect: router.currentRoute.value.fullPath,
+287
View File
@@ -0,0 +1,287 @@
<template>
<div class="login-wrapper">
<div class="decorations">
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="line line-1"></span>
<span class="line line-2"></span>
<span class="line line-3"></span>
</div>
<div class="login-main">
<!-- 研究所标识 -->
<div class="institute-logo">
<img src="/resource/img/institute_logo.png" alt="七〇四研究所" />
</div>
<!-- 系统标题 -->
<div class="system-title">
<img class="system-logo" src="/resource/img/logo.png" alt="Logo" />
<span class="system-name">事项督办系统</span>
</div>
<!-- 单点登录卡片 -->
<div class="login-card">
<template v-if="loading">
<div class="loading-spinner"></div>
<div class="card-title">正在单点登录</div>
<div class="card-desc">正在验证身份请稍候...</div>
</template>
<template v-else>
<div class="card-icon error-icon">!</div>
<div class="card-title">登录失败</div>
<div class="card-desc">{{ errorMsg }}</div>
<button class="retry-btn" @click="handleRetry">重试</button>
</template>
</div>
</div>
<!-- 底部版权 -->
<div class="footer-text">
中国船舶集团有限公司第七〇四研究所 数智化中心&copy;2026
</div>
</div>
</template>
<script lang="ts" setup>
import { ref, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { useUserStore } from '/@/store/modules/user';
const router = useRouter();
const userStore = useUserStore();
const loading = ref(true);
const errorMsg = ref('');
async function doAutoLogin() {
loading.value = true;
errorMsg.value = '';
try {
await userStore.autoLogin(true);
} catch (error: any) {
loading.value = false;
errorMsg.value = error?.message || '单点登录失败,请稍后重试';
}
}
function handleRetry() {
doAutoLogin();
}
onMounted(() => {
doAutoLogin();
});
</script>
<style lang="less" scoped>
.login-wrapper {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
background: #fff;
overflow: hidden;
&::before,
&::after {
content: '';
position: absolute;
border-radius: 50%;
opacity: 0.6;
pointer-events: none;
}
&::before {
width: 600px;
height: 600px;
bottom: -280px;
left: -120px;
background: radial-gradient(circle, rgba(59, 130, 246, 0.12), transparent 70%);
}
&::after {
width: 500px;
height: 500px;
bottom: -200px;
right: -100px;
background: radial-gradient(circle, rgba(16, 185, 129, 0.10), transparent 70%);
}
}
.decorations {
position: absolute;
inset: 0;
pointer-events: none;
z-index: 0;
.dot {
position: absolute;
border-radius: 50%;
opacity: 0.55;
}
.dot:nth-child(1) { width: 18px; height: 18px; bottom: 22%; left: 12%; background: #3b82f6; opacity: 0.35; }
.dot:nth-child(2) { width: 12px; height: 12px; bottom: 32%; right: 15%; background: #f59e0b; opacity: 0.45; }
.dot:nth-child(3) { width: 24px; height: 24px; bottom: 15%; left: 30%; background: #10b981; opacity: 0.3; }
.dot:nth-child(4) { width: 10px; height: 10px; bottom: 28%; right: 28%; background: #8b5cf6; opacity: 0.5; }
.dot:nth-child(5) { width: 16px; height: 16px; bottom: 18%; left: 55%; background: #ec4899; opacity: 0.35; }
.dot:nth-child(6) { width: 20px; height: 20px; bottom: 10%; right: 10%; background: #06b6d4; opacity: 0.4; }
.dot:nth-child(7) { width: 8px; height: 8px; bottom: 35%; left: 20%; background: #f97316; opacity: 0.5; }
.dot:nth-child(8) { width: 14px; height: 14px; bottom: 8%; left: 45%; background: #6366f1; opacity: 0.4; }
.dot:nth-child(9) { width: 20px; height: 20px; top: 8%; left: 10%; background: #3b82f6; opacity: 0.25; }
.dot:nth-child(10) { width: 10px; height: 10px; top: 14%; right: 18%; background: #ec4899; opacity: 0.35; }
.dot:nth-child(11) { width: 16px; height: 16px; top: 5%; right: 8%; background: #10b981; opacity: 0.3; }
.dot:nth-child(12) { width: 8px; height: 8px; top: 18%; left: 25%; background: #f59e0b; opacity: 0.4; }
.line {
position: absolute;
pointer-events: none;
border-radius: 2px;
opacity: 0.15;
}
.line-1 { top: 12%; right: 5%; width: 120px; height: 2px; background: #3b82f6; transform: rotate(-15deg); }
.line-2 { top: 20%; left: 8%; width: 80px; height: 2px; background: #ec4899; transform: rotate(10deg); }
.line-3 { top: 6%; right: 15%; width: 60px; height: 2px; background: #10b981; transform: rotate(-8deg); }
}
.login-main {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 40px 24px;
z-index: 1;
}
.institute-logo {
margin-bottom: 48px;
img {
width: 400px;
height: auto;
display: block;
}
}
.system-title {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 48px;
.system-logo {
width: 72px;
height: 72px;
}
.system-name {
font-size: 28px;
font-weight: 600;
color: #1a1a1a;
letter-spacing: 2px;
}
}
.login-card {
width: 100%;
max-width: 360px;
padding: 40px 32px;
background: #fafbfc;
border-radius: 12px;
text-align: center;
}
.loading-spinner {
width: 40px;
height: 40px;
margin: 0 auto 20px;
border: 3px solid #e5e7eb;
border-top-color: #1a6dd4;
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
.card-icon {
width: 48px;
height: 48px;
margin: 0 auto 16px;
border-radius: 50%;
font-size: 24px;
font-weight: 700;
line-height: 48px;
}
.error-icon {
background: #fee2e2;
color: #ef4444;
}
.card-title {
font-size: 18px;
font-weight: 600;
color: #1a1a1a;
margin-bottom: 8px;
}
.card-desc {
font-size: 14px;
color: rgba(0, 0, 0, 0.45);
margin-bottom: 24px;
}
.retry-btn {
width: 100%;
height: 44px;
border: none;
border-radius: 8px;
background: #1a6dd4;
color: #fff;
font-size: 15px;
font-weight: 500;
cursor: pointer;
transition: background 0.2s;
margin-bottom: 12px;
&:hover {
background: #155ab0;
}
}
.login-link {
display: inline-block;
font-size: 14px;
color: #1a6dd4;
cursor: pointer;
&:hover {
color: #155ab0;
text-decoration: underline;
}
}
.footer-text {
position: relative;
z-index: 1;
text-align: center;
font-size: 13px;
color: rgba(0, 0, 0, 0.65);
padding: 16px 0;
}
</style>
+251
View File
@@ -0,0 +1,251 @@
<template>
<div class="login-wrapper">
<div class="decorations">
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="line line-1"></span>
<span class="line line-2"></span>
<span class="line line-3"></span>
</div>
<div class="login-main">
<!-- 研究所标识 -->
<div class="institute-logo">
<img src="/resource/img/institute_logo.png" alt="七〇四研究所" />
</div>
<!-- 系统标题 -->
<div class="system-title">
<img class="system-logo" src="/resource/img/logo.png" alt="Logo" />
<span class="system-name">事项督办系统</span>
</div>
<!-- 退出登录卡片 -->
<div class="login-card">
<div class="card-icon success-icon">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<polyline points="20 6 9 17 4 12"></polyline>
</svg>
</div>
<div class="card-title">已退出登录</div>
<div class="card-desc">您已安全退出系统</div>
<button class="sso-btn" @click="handleAutoLogin">重新单点登录</button>
</div>
</div>
<!-- 底部版权 -->
<div class="footer-text">
中国船舶集团有限公司第七〇四研究所 数智化中心&copy;2026
</div>
</div>
</template>
<script lang="ts" setup>
import { useRouter } from 'vue-router';
const router = useRouter();
function handleAutoLogin() {
router.replace('/user/autoLogin');
}
</script>
<style lang="less" scoped>
.login-wrapper {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
background: #fff;
overflow: hidden;
&::before,
&::after {
content: '';
position: absolute;
border-radius: 50%;
opacity: 0.6;
pointer-events: none;
}
&::before {
width: 600px;
height: 600px;
bottom: -280px;
left: -120px;
background: radial-gradient(circle, rgba(59, 130, 246, 0.12), transparent 70%);
}
&::after {
width: 500px;
height: 500px;
bottom: -200px;
right: -100px;
background: radial-gradient(circle, rgba(16, 185, 129, 0.10), transparent 70%);
}
}
.decorations {
position: absolute;
inset: 0;
pointer-events: none;
z-index: 0;
.dot {
position: absolute;
border-radius: 50%;
opacity: 0.55;
}
.dot:nth-child(1) { width: 18px; height: 18px; bottom: 22%; left: 12%; background: #3b82f6; opacity: 0.35; }
.dot:nth-child(2) { width: 12px; height: 12px; bottom: 32%; right: 15%; background: #f59e0b; opacity: 0.45; }
.dot:nth-child(3) { width: 24px; height: 24px; bottom: 15%; left: 30%; background: #10b981; opacity: 0.3; }
.dot:nth-child(4) { width: 10px; height: 10px; bottom: 28%; right: 28%; background: #8b5cf6; opacity: 0.5; }
.dot:nth-child(5) { width: 16px; height: 16px; bottom: 18%; left: 55%; background: #ec4899; opacity: 0.35; }
.dot:nth-child(6) { width: 20px; height: 20px; bottom: 10%; right: 10%; background: #06b6d4; opacity: 0.4; }
.dot:nth-child(7) { width: 8px; height: 8px; bottom: 35%; left: 20%; background: #f97316; opacity: 0.5; }
.dot:nth-child(8) { width: 14px; height: 14px; bottom: 8%; left: 45%; background: #6366f1; opacity: 0.4; }
.dot:nth-child(9) { width: 20px; height: 20px; top: 8%; left: 10%; background: #3b82f6; opacity: 0.25; }
.dot:nth-child(10) { width: 10px; height: 10px; top: 14%; right: 18%; background: #ec4899; opacity: 0.35; }
.dot:nth-child(11) { width: 16px; height: 16px; top: 5%; right: 8%; background: #10b981; opacity: 0.3; }
.dot:nth-child(12) { width: 8px; height: 8px; top: 18%; left: 25%; background: #f59e0b; opacity: 0.4; }
.line {
position: absolute;
pointer-events: none;
border-radius: 2px;
opacity: 0.15;
}
.line-1 { top: 12%; right: 5%; width: 120px; height: 2px; background: #3b82f6; transform: rotate(-15deg); }
.line-2 { top: 20%; left: 8%; width: 80px; height: 2px; background: #ec4899; transform: rotate(10deg); }
.line-3 { top: 6%; right: 15%; width: 60px; height: 2px; background: #10b981; transform: rotate(-8deg); }
}
.login-main {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 40px 24px;
z-index: 1;
}
.institute-logo {
margin-bottom: 48px;
img {
width: 400px;
height: auto;
display: block;
}
}
.system-title {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 48px;
.system-logo {
width: 72px;
height: 72px;
}
.system-name {
font-size: 28px;
font-weight: 600;
color: #1a1a1a;
letter-spacing: 2px;
}
}
.login-card {
width: 100%;
max-width: 360px;
padding: 40px 32px;
background: #fafbfc;
border-radius: 12px;
text-align: center;
}
.card-icon {
width: 56px;
height: 56px;
margin: 0 auto 16px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
}
.success-icon {
background: #dcfce7;
color: #22c55e;
}
.card-title {
font-size: 18px;
font-weight: 600;
color: #1a1a1a;
margin-bottom: 8px;
}
.card-desc {
font-size: 14px;
color: rgba(0, 0, 0, 0.45);
margin-bottom: 24px;
}
.sso-btn {
width: 100%;
height: 44px;
border: none;
border-radius: 8px;
background: #1a6dd4;
color: #fff;
font-size: 15px;
font-weight: 500;
cursor: pointer;
transition: background 0.2s;
margin-bottom: 12px;
&:hover {
background: #155ab0;
}
}
.login-link {
display: inline-block;
font-size: 14px;
color: #1a6dd4;
cursor: pointer;
&:hover {
color: #155ab0;
text-decoration: underline;
}
}
.footer-text {
position: relative;
z-index: 1;
text-align: center;
font-size: 13px;
color: rgba(0, 0, 0, 0.65);
padding: 16px 0;
}
</style>