mirror of
https://github.com/jeecgboot/JeecgBoot.git
synced 2025-12-19 20:16:51 +08:00
前端和后端源码,合并到一个git仓库中,方便用户下载,避免前后端不匹配的问题
This commit is contained in:
45
jeecgboot-vue3/src/hooks/web/useSso.ts
Normal file
45
jeecgboot-vue3/src/hooks/web/useSso.ts
Normal file
@ -0,0 +1,45 @@
|
||||
// 单点登录核心类
|
||||
import { getToken } from '/@/utils/auth';
|
||||
import { getUrlParam } from '/@/utils';
|
||||
import { useGlobSetting } from '/@/hooks/setting';
|
||||
import { validateCasLogin } from '/@/api/sys/user';
|
||||
import { useUserStore } from '/@/store/modules/user';
|
||||
const globSetting = useGlobSetting();
|
||||
const openSso = globSetting.openSso;
|
||||
export function useSso() {
|
||||
//update-begin---author:wangshuai---date:2024-01-03---for:【QQYUN-7805】SSO登录强制用http #957---
|
||||
let locationUrl = document.location.protocol +"//" + window.location.host + '/';
|
||||
//update-end---author:wangshuai---date:2024-01-03---for:【QQYUN-7805】SSO登录强制用http #957---
|
||||
|
||||
/**
|
||||
* 单点登录
|
||||
*/
|
||||
async function ssoLogin() {
|
||||
if (openSso == 'true') {
|
||||
let token = getToken();
|
||||
let ticket = getUrlParam('ticket');
|
||||
if (!token) {
|
||||
if (ticket) {
|
||||
await validateCasLogin({
|
||||
ticket: ticket,
|
||||
service: locationUrl,
|
||||
}).then((res) => {
|
||||
const userStore = useUserStore();
|
||||
userStore.setToken(res.token);
|
||||
return userStore.afterLoginAction(true, {});
|
||||
});
|
||||
} else {
|
||||
window.location.href = globSetting.casBaseUrl + '/login?service=' + encodeURIComponent(locationUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
*/
|
||||
async function ssoLoginOut() {
|
||||
window.location.href = globSetting.casBaseUrl + '/logout?service=' + encodeURIComponent(locationUrl);
|
||||
}
|
||||
return { ssoLogin, ssoLoginOut };
|
||||
}
|
||||
Reference in New Issue
Block a user