1.修复问题同时打开多个标签页,退出登录,其它几个标签页并没有退出登录
2.点击智能体时,若当前已经打开智能体标签,则不会再打开新标签页
This commit is contained in:
1 parent
3642ed8529
commit
63ea9d7ed7
6 files changed
+201
-19
No files matched your search
+19
-4
@@ -5,7 +5,12 @@ import { watch, onMounted, onBeforeUnmount } from 'vue';
|
||||
import { useTheme } from './composables/useTheme';
|
||||
import LevelMessageDialog from './components/LevelMessageDialog.vue';
|
||||
import { useGlobalMessageDialog } from './composables/useGlobalMessageDialog';
|
||||
import { getAuthHeaders, clearAuthUser } from './utils/auth';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { getAuthHeaders, logoutAuth } from './utils/auth';
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const PUBLIC_PATHS = ['/', '/workspace', '/casdoor-callback', '/reset-password'];
|
||||
|
||||
const { locale } = useI18n();
|
||||
const { themePreference, initTheme, setThemePreference } = useTheme();
|
||||
@@ -58,14 +63,23 @@ watch(themePreference, (newTheme) => {
|
||||
|
||||
const onUnauthorized = () => {
|
||||
showMessageDialog('error', '认证已过期或无效,请重新登录');
|
||||
clearAuthUser();
|
||||
if (window.location.pathname !== '/') {
|
||||
window.location.href = '/';
|
||||
logoutAuth();
|
||||
};
|
||||
|
||||
const onLogout = (event: Event) => {
|
||||
const detail = (event as CustomEvent<{ remote?: boolean }>).detail;
|
||||
if (detail?.remote) {
|
||||
showMessageDialog('info', '您已在其他标签页退出登录');
|
||||
}
|
||||
const path = router.currentRoute.value.path;
|
||||
if (!PUBLIC_PATHS.includes(path)) {
|
||||
router.push('/workspace');
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
window.addEventListener('hxops:unauthorized', onUnauthorized as EventListener);
|
||||
window.addEventListener('hxops:logout', onLogout as EventListener);
|
||||
|
||||
initTheme();
|
||||
|
||||
@@ -90,6 +104,7 @@ onMounted(async () => {
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener('hxops:unauthorized', onUnauthorized as EventListener);
|
||||
window.removeEventListener('hxops:logout', onLogout as EventListener);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Reference in new issue
Block a user