fix: 增加重新登录意社区
This commit is contained in:
@@ -5,7 +5,11 @@ import { useRouter } from 'vue-router';
|
||||
import { getUserInfo } from '@/api';
|
||||
import logoPng from '@/assets/images/logo.png';
|
||||
import SvgIcon from '@/components/SvgIcon/index.vue';
|
||||
import { SSO_CLIENT_ID, SSO_SEVER_URL } from '@/config/sso.ts';
|
||||
import {
|
||||
SSO_CLIENT_LOGIN,
|
||||
SSO_CLIENT_LOGIN_AGAIN,
|
||||
SSO_SEVER_URL,
|
||||
} from '@/config/sso.ts';
|
||||
import { useUserStore } from '@/stores';
|
||||
import { useLoginFormStore } from '@/stores/modules/loginForm';
|
||||
import { useSessionStore } from '@/stores/modules/session.ts';
|
||||
@@ -56,10 +60,11 @@ function onAfterLeave() {
|
||||
}
|
||||
}
|
||||
|
||||
function handleThirdPartyLogin() {
|
||||
function handleThirdPartyLogin(type: any) {
|
||||
const redirectUri = encodeURIComponent(`${window.location.origin}/chat`);
|
||||
console.log('cccc', type);
|
||||
const popup = window.open(
|
||||
`${SSO_SEVER_URL}/login?client_id=${SSO_CLIENT_ID}&redirect_uri=${redirectUri}`,
|
||||
`${SSO_SEVER_URL}/login?client_id=${type}&redirect_uri=${redirectUri}`,
|
||||
'SSOLogin',
|
||||
'width=1000,height=800',
|
||||
);
|
||||
@@ -110,14 +115,67 @@ function handleThirdPartyLogin() {
|
||||
}, 60 * 1000); // 60分钟超时关闭
|
||||
}
|
||||
|
||||
// 让意社区重新登录,先让意社区退出登录,再重新登录
|
||||
function handleLoginAgainYi() {
|
||||
const redirectUri = encodeURIComponent(`${window.location.origin}/chat`);
|
||||
const popup = window.open(
|
||||
`http://localhost:18001/login?client_id=${SSO_CLIENT_LOGIN_AGAIN}&redirect_uri=${redirectUri}`,
|
||||
'SSOLogin',
|
||||
'width=1000,height=800',
|
||||
);
|
||||
|
||||
// 使用标志位防止重复执行
|
||||
let isHandled = false;
|
||||
|
||||
const messageHandler = async (event: any) => {
|
||||
if (event.origin === new URL(SSO_SEVER_URL).origin
|
||||
&& event.data.type === 'SSO_LOGIN_SUCCESS'
|
||||
&& !isHandled) {
|
||||
isHandled = true;
|
||||
console.log('111');
|
||||
try {
|
||||
// 清理监听
|
||||
window.removeEventListener('message', messageHandler);
|
||||
const { token, refreshToken } = event.data;
|
||||
userStore.setToken(token, refreshToken);
|
||||
const resUserInfo = await getUserInfo();
|
||||
userStore.setUserInfo(resUserInfo.data);
|
||||
// 关闭弹窗
|
||||
if (popup && !popup.closed)
|
||||
popup.close();
|
||||
// 后续逻辑
|
||||
ElMessage.success('登录成功');
|
||||
userStore.closeLoginDialog();
|
||||
await sessionStore.requestSessionList(1, true);
|
||||
await router.replace('/');
|
||||
}
|
||||
catch (error) {
|
||||
console.error('登录处理失败:', error);
|
||||
ElMessage.error('登录失败');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 先移除旧监听,再添加新监听
|
||||
window.removeEventListener('message', messageHandler);
|
||||
window.addEventListener('message', messageHandler);
|
||||
|
||||
// 超时自动清理
|
||||
setTimeout(() => {
|
||||
if (!isHandled) {
|
||||
window.removeEventListener('message', messageHandler);
|
||||
if (popup && !popup.closed)
|
||||
popup.close();
|
||||
ElMessage.warning('登录超时');
|
||||
}
|
||||
}, 60 * 1000); // 60分钟超时关闭
|
||||
}
|
||||
|
||||
const wxSrc = computed(
|
||||
() => `${import.meta.env.VITE_WEB_BASE_API}/wwwroot/aihub/wx.png`,
|
||||
);
|
||||
// 微信群二维码
|
||||
const wxGroupQD = `${import.meta.env.VITE_WEB_BASE_API}/wwwroot/aihub/jlq.png`;
|
||||
const srcList = [
|
||||
wxGroupQD,
|
||||
];
|
||||
function openContact() {
|
||||
ElMessageBox.alert(
|
||||
`
|
||||
@@ -251,11 +309,24 @@ function openContact() {
|
||||
</el-divider>
|
||||
<div class="third-party-buttons">
|
||||
<el-tooltip content="使用意社区账号登录" placement="top">
|
||||
<div class="third-party-btn" @click="handleThirdPartyLogin">
|
||||
<div class="third-party-btn" @click="handleThirdPartyLogin(SSO_CLIENT_LOGIN)">
|
||||
<img :src="logoPng" class="third-party-icon" alt="">
|
||||
</div>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
<el-divider content-position="center">
|
||||
<p class="w-max">
|
||||
开通Vip后,点击下方重新登录意社区
|
||||
</p>
|
||||
</el-divider>
|
||||
<el-button
|
||||
class="w-full"
|
||||
type="primary"
|
||||
size="large"
|
||||
@click="handleThirdPartyLogin(SSO_CLIENT_LOGIN_AGAIN)"
|
||||
>
|
||||
意社区重新登录
|
||||
</el-button>
|
||||
<el-divider class="w-max">
|
||||
<p class="w-max">
|
||||
如遇问题,请联系我们
|
||||
|
||||
Reference in New Issue
Block a user