diff --git a/Yi.Ai.Vue3/.env.development b/Yi.Ai.Vue3/.env.development index fd80b18c..04164444 100644 --- a/Yi.Ai.Vue3/.env.development +++ b/Yi.Ai.Vue3/.env.development @@ -16,10 +16,8 @@ VITE_WEB_BASE_API = '/dev-api' VITE_API_URL=http://data.ccnetcore.com:19001/api/app # SSO单点登录url -VITE_SSO_SEVER_URL='http://localhost:18001' +VITE_SSO_SEVER_URL=http://localhost:18001 # SSO_SEVER_URL='http://ccnetcore.com' -# SSO单点登录项目标识 -VITE_SSO_CLIENT_ID='YiXin-Ai'; # 版本号 -VITE_APP_VERSION='1.0.0'; +VITE_APP_VERSION='1.0.0' diff --git a/Yi.Ai.Vue3/.env.production b/Yi.Ai.Vue3/.env.production index 10f4606f..b2929308 100644 --- a/Yi.Ai.Vue3/.env.production +++ b/Yi.Ai.Vue3/.env.production @@ -17,10 +17,8 @@ VITE_API_URL = http://data.ccnetcore.com:19001/api/app VITE_BUILD_COMPRESS = gzip # SSO单点登录url -VITE_SSO_SEVER_URL='https://ccnetcore.com' -# SSO单点登录项目标识 -VITE_SSO_CLIENT_ID='YiXin-Ai'; +VITE_SSO_SEVER_URL=https://ccnetcore.com # 版本号 -VITE_APP_VERSION='1.0.6'; +VITE_APP_VERSION='1.0.7' diff --git a/Yi.Ai.Vue3/.eslintrc-auto-import.json b/Yi.Ai.Vue3/.eslintrc-auto-import.json index af1083b7..313e6711 100644 --- a/Yi.Ai.Vue3/.eslintrc-auto-import.json +++ b/Yi.Ai.Vue3/.eslintrc-auto-import.json @@ -5,6 +5,8 @@ "ComputedRef": true, "DirectiveBinding": true, "EffectScope": true, + "ElMessage": true, + "ElMessageBox": true, "ExtractDefaultPropTypes": true, "ExtractPropTypes": true, "ExtractPublicPropTypes": true, diff --git a/Yi.Ai.Vue3/src/components/LoginDialog/index.vue b/Yi.Ai.Vue3/src/components/LoginDialog/index.vue index 0864a526..18358c61 100644 --- a/Yi.Ai.Vue3/src/components/LoginDialog/index.vue +++ b/Yi.Ai.Vue3/src/components/LoginDialog/index.vue @@ -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() {