Merge branch 'dev' of https://gitee.com/justop/hxops into dev
This commit is contained in:
commit
5eb36e53ae
6 files changed
+201
-19
No files matched your search
@@ -23,9 +23,10 @@ import GeneralFeedbackDialog from '../components/GeneralFeedbackDialog.vue';
|
||||
import { useMessage } from '../composables/useMessage';
|
||||
import { useIsMobile } from '../composables/useIsMobile';
|
||||
import { useTheme } from '../composables/useTheme';
|
||||
import { getAuthHeaders, getStoredAuthUser, clearAuthUser } from '../utils/auth';
|
||||
import { getAuthHeaders, getStoredAuthUser, logoutAuth } from '../utils/auth';
|
||||
import { copyTextToClipboard } from '../utils/clipboard';
|
||||
import { setLastChatAgentId } from '../utils/lastChatAgent';
|
||||
import { openAgentChatTab, registerOpenAgentId } from '../utils/agentTabs';
|
||||
|
||||
const { t, locale } = useI18n();
|
||||
const { appliedTheme, toggleLightDark } = useTheme();
|
||||
@@ -96,8 +97,13 @@ const handleDocumentPointerDown = (event: MouseEvent | TouchEvent) => {
|
||||
}
|
||||
};
|
||||
|
||||
const onAuthLogout = () => {
|
||||
currentUser.value = null;
|
||||
};
|
||||
|
||||
const handleLogout = () => {
|
||||
clearAuthUser();
|
||||
logoutAuth();
|
||||
onAuthLogout();
|
||||
router.push('/');
|
||||
};
|
||||
|
||||
@@ -1917,11 +1923,21 @@ const switchToAgent = (agent: { id: number; name: string }) => {
|
||||
if (agent.id === agentId) return;
|
||||
setLastChatAgentId(agent.id);
|
||||
const url = router.resolve(`/chat/${agent.id}`).href;
|
||||
window.open(url, '_blank');
|
||||
openAgentChatTab(url, agent.id);
|
||||
};
|
||||
|
||||
const syncOpenAgentRegistration = () => {
|
||||
const id = Number(route.params.agentId);
|
||||
registerOpenAgentId(Number.isFinite(id) && id > 0 ? id : null);
|
||||
};
|
||||
|
||||
const onPageHide = () => {
|
||||
registerOpenAgentId(null);
|
||||
};
|
||||
|
||||
const goToWorkspace = (view?: string) => {
|
||||
setLastChatAgentId(Number(route.params.agentId));
|
||||
registerOpenAgentId(null);
|
||||
const query: Record<string, string> = { no_redirect: '1' };
|
||||
if (view) query.view = view;
|
||||
router.push({ path: '/workspace', query });
|
||||
@@ -1929,6 +1945,9 @@ const goToWorkspace = (view?: string) => {
|
||||
|
||||
// 组件挂载时,如果存在预设问题,则自动触发一次发送
|
||||
onMounted(async () => {
|
||||
syncOpenAgentRegistration();
|
||||
window.addEventListener('pagehide', onPageHide);
|
||||
window.addEventListener('hxops:logout', onAuthLogout);
|
||||
document.addEventListener('mousedown', handleDocumentPointerDown);
|
||||
document.addEventListener('touchstart', handleDocumentPointerDown, { passive: true });
|
||||
document.addEventListener('mousedown', handleMobileAgentPopoverClickOutside);
|
||||
@@ -1960,10 +1979,13 @@ watch(
|
||||
(id) => {
|
||||
const nextId = Number(id);
|
||||
if (Number.isFinite(nextId) && nextId > 0) setLastChatAgentId(nextId);
|
||||
syncOpenAgentRegistration();
|
||||
}
|
||||
);
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener('pagehide', onPageHide);
|
||||
window.removeEventListener('hxops:logout', onAuthLogout);
|
||||
document.removeEventListener('mousedown', handleDocumentPointerDown);
|
||||
document.removeEventListener('touchstart', handleDocumentPointerDown);
|
||||
document.removeEventListener('mousedown', handleMobileAgentPopoverClickOutside);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* 文件用途:用户工作台,支持自定义布局、收藏、嵌入 Agent
|
||||
* 引用文件:vue, vue-router, lucide-vue-next, 后端 /api/user 接口
|
||||
*/
|
||||
import { ref, onMounted, computed, watch, nextTick } from 'vue';
|
||||
import { ref, onMounted, onBeforeUnmount, computed, watch, nextTick } from 'vue';
|
||||
import { useRouter, useRoute } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { config } from '../config';
|
||||
@@ -24,8 +24,9 @@ import {
|
||||
type WecomLoginDialogContent,
|
||||
type WecomMatchField,
|
||||
} from '../utils/wecom';
|
||||
import { getAuthHeaders, getStoredAuthUser, saveAuthUser } from '../utils/auth';
|
||||
import { getAuthHeaders, getStoredAuthUser, saveAuthUser, logoutAuth } from '../utils/auth';
|
||||
import { getLastChatAgentId } from '../utils/lastChatAgent';
|
||||
import { openAgentChatTab } from '../utils/agentTabs';
|
||||
import {
|
||||
Settings,
|
||||
LayoutGrid,
|
||||
@@ -405,7 +406,10 @@ const loadAuthUser = () => {
|
||||
stored = sessionStorage.getItem('hxops_user');
|
||||
}
|
||||
|
||||
if (!stored) return;
|
||||
if (!stored) {
|
||||
currentUser.value = null;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const user = getStoredAuthUser();
|
||||
@@ -847,10 +851,7 @@ const mobileTabTitle = computed(() => {
|
||||
return t('workspace.mobileTabs.applications');
|
||||
});
|
||||
|
||||
const handleLogout = () => {
|
||||
localStorage.removeItem('hxops_user');
|
||||
sessionStorage.removeItem('hxops_user');
|
||||
sessionStorage.removeItem('hxops_wecom_state');
|
||||
const applyLoggedOutState = () => {
|
||||
currentUser.value = null;
|
||||
agents.value = [];
|
||||
quickQuestions.value = [];
|
||||
@@ -858,9 +859,18 @@ const handleLogout = () => {
|
||||
embeddedAgents.value = [];
|
||||
userReport.value = null;
|
||||
fetchPublicAgents();
|
||||
};
|
||||
|
||||
const handleLogout = () => {
|
||||
logoutAuth();
|
||||
applyLoggedOutState();
|
||||
router.push('/');
|
||||
};
|
||||
|
||||
const onAuthLogout = () => {
|
||||
applyLoggedOutState();
|
||||
};
|
||||
|
||||
const captureOriginalProfile = () => {
|
||||
originalProfile.value = { ...profileUser.value };
|
||||
};
|
||||
@@ -1178,7 +1188,7 @@ const navigateToChat = (id: number) => {
|
||||
return;
|
||||
}
|
||||
const url = router.resolve(`/chat/${id}`).href;
|
||||
window.open(url, '_blank');
|
||||
openAgentChatTab(url, id);
|
||||
};
|
||||
|
||||
const navigateWithQuickQuestion = (agentId: number, question: string) => {
|
||||
@@ -1191,7 +1201,7 @@ const navigateWithQuickQuestion = (agentId: number, question: string) => {
|
||||
path: `/chat/${agentId}`,
|
||||
query: { preset: question },
|
||||
}).href;
|
||||
window.open(url, '_blank');
|
||||
openAgentChatTab(url, agentId);
|
||||
};
|
||||
|
||||
const handleWecomDeeplinkContext = async () => {
|
||||
@@ -1224,7 +1234,7 @@ const handleWecomDeeplinkContext = async () => {
|
||||
path: `/chat/${agentId}`,
|
||||
query: preset ? { preset } : {},
|
||||
}).href;
|
||||
window.open(url, '_blank');
|
||||
openAgentChatTab(url, agentId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1362,6 +1372,7 @@ const openAnnouncement = (ann: Announcement) => {
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
window.addEventListener('hxops:logout', onAuthLogout);
|
||||
loadLanguagePreference();
|
||||
fetchAnnouncements();
|
||||
const handledCasdoor = await tryCasdoorCallbackLogin();
|
||||
@@ -1392,6 +1403,10 @@ onMounted(async () => {
|
||||
isLoading.value = false;
|
||||
}
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener('hxops:logout', onAuthLogout);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
Reference in new issue
Block a user