fix(auth): 重构登录认证,并支持跳转到关联服务如图纸标注
This commit is contained in:
1 parent
ce1fd59f61
commit
affe139bf9
51 files changed
+1939
-132
No files matched your search
@@ -2,6 +2,8 @@
|
||||
/**
|
||||
* App.vue
|
||||
* 根组件:主题初始化、全局消息弹窗、401 登出监听、html lang 与 i18n locale 同步。
|
||||
* 依赖:useTheme、useGlobalMessageDialog、auth、linked-nav.store。
|
||||
* 逻辑:已登录时预取关联服务侧栏入口,避免页面切换后入口后闪现。
|
||||
*/
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { watch, onMounted, onBeforeUnmount } from 'vue';
|
||||
@@ -11,6 +13,7 @@ import { useGlobalMessageDialog } from '@/shared/composables/useGlobalMessageDia
|
||||
import { useRouter } from 'vue-router';
|
||||
import { getAuthHeaders, logoutAuth } from '@/shared/utils/auth';
|
||||
import { isPublicPath } from '@/shared/constants/routes';
|
||||
import { useLinkedNavStore } from '@/features/sso/stores/linked-nav.store';
|
||||
|
||||
const router = useRouter();
|
||||
const { locale, t } = useI18n();
|
||||
@@ -64,18 +67,20 @@ watch(themePreference, (newTheme) => {
|
||||
|
||||
/**
|
||||
* 处理接口返回未登录状态,提示用户重新登录并清理失效的本地登录信息。
|
||||
* 核心逻辑:忽略可选的 SSO 应用目录请求;其余未授权请求统一展示易懂提示,再执行登出。
|
||||
* 核心逻辑:忽略可选的关联服务/SSO 目录请求;其余未授权请求统一展示易懂提示,再执行登出。
|
||||
* @param event - 包含请求地址和状态码的全局未授权事件。
|
||||
*/
|
||||
const onUnauthorized = (event: Event) => {
|
||||
const url = String((event as CustomEvent<{ url?: string }>).detail?.url || '');
|
||||
// 外部应用目录是可选导航能力,加载失败只能隐藏入口,不能清除有效 HXOPS 登录态。
|
||||
// 侧栏入口目录是可选导航能力,加载失败只能隐藏入口,不能清除有效 HXOPS 登录态。
|
||||
if (/\/api\/sso\/apps(?:\?|$)/.test(url)) return;
|
||||
if (/\/api\/linked-services(?:\?|$)/.test(url)) return;
|
||||
showMessageDialog('error', t('login.sessionExpiredHint'), t('login.sessionExpired'));
|
||||
logoutAuth();
|
||||
};
|
||||
|
||||
const onLogout = (event: Event) => {
|
||||
useLinkedNavStore().reset();
|
||||
const detail = (event as CustomEvent<{ remote?: boolean }>).detail;
|
||||
if (detail?.remote) {
|
||||
showMessageDialog('info', '您已在其他标签页退出登录');
|
||||
@@ -94,6 +99,8 @@ onMounted(async () => {
|
||||
|
||||
const headers = getAuthHeaders();
|
||||
if (Object.keys(headers).length > 0) {
|
||||
// 尽早预取侧栏关联服务,避免进入 Chat/工作台后入口后加载闪现。
|
||||
void useLinkedNavStore().ensureLoaded();
|
||||
try {
|
||||
const res = await fetch('/api/user/home', { headers });
|
||||
if (res.ok) {
|
||||
|
||||
Reference in new issue
Block a user