1.修复问题同时打开多个标签页,退出登录,其它几个标签页并没有退出登录
2.点击智能体时,若当前已经打开智能体标签,则不会再打开新标签页
This commit is contained in:
1 parent
3642ed8529
commit
63ea9d7ed7
6 files changed
+201
-19
No files matched your search
@@ -0,0 +1,53 @@
|
||||
const agentWindowName = (agentId: number): string => `hxops_agent_${agentId}`;
|
||||
|
||||
const isBlankWindow = (win: Window): boolean => {
|
||||
try {
|
||||
const href = win.location.href;
|
||||
return href === 'about:blank' || href.endsWith('about:blank');
|
||||
} catch {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/** Mark this browser tab as the chat window for an agent (used by window.open target name). */
|
||||
export const registerOpenAgentId = (agentId: number | null): void => {
|
||||
if (agentId && Number.isFinite(agentId) && agentId > 0) {
|
||||
window.name = agentWindowName(agentId);
|
||||
return;
|
||||
}
|
||||
if (window.name.startsWith('hxops_agent_')) {
|
||||
window.name = '';
|
||||
}
|
||||
};
|
||||
|
||||
/** App startup hook (kept for compatibility). */
|
||||
export const initAgentTabSync = (): void => {
|
||||
// Named-window focus does not require background listeners.
|
||||
};
|
||||
|
||||
/**
|
||||
* Focus an existing same-agent tab without reload, or open a new one.
|
||||
*
|
||||
* Per HTML: window.open('', target) focuses an existing named window and
|
||||
* ignores the URL, so the page is not refreshed.
|
||||
*/
|
||||
export const openAgentChatTab = (url: string, agentId: number): void => {
|
||||
const target = agentWindowName(agentId);
|
||||
const existing = window.open('', target);
|
||||
|
||||
if (!existing || existing.closed) {
|
||||
const opened = window.open(url, target);
|
||||
opened?.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
existing.focus();
|
||||
|
||||
if (isBlankWindow(existing)) {
|
||||
try {
|
||||
existing.location.href = url;
|
||||
} catch {
|
||||
window.open(url, target);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user