diff --git a/static/src/app/methods/ui/hostWorkspace.ts b/static/src/app/methods/ui/hostWorkspace.ts index 01e1aeca..eef0c4ce 100644 --- a/static/src/app/methods/ui/hostWorkspace.ts +++ b/static/src/app/methods/ui/hostWorkspace.ts @@ -57,7 +57,11 @@ export const hostWorkspaceMethods = { this.runningWorkspaceTasks = []; } }, - async handleHostWorkspaceSwitch(workspaceId) { + async handleHostWorkspaceSwitch(workspaceId, options = {}) { + // preserveConversationView:跨工作区点选具体对话时使用——保持当前对话视图冻结, + // 不做 /new 跳转与状态清空(否则空对话态会让居中输入栏「先往上再往下」), + // 目标对话由调用方随后立即加载 + const preserveConversationView = Boolean(options && options.preserveConversationView); const targetId = String(workspaceId || '').trim(); if (!targetId || this.hostWorkspaceSwitching) { return; @@ -102,31 +106,39 @@ export const hostWorkspaceMethods = { if (data.default_workspace_id) { this.defaultHostWorkspaceId = String(data.default_workspace_id); } - this.messages = []; - this.currentConversationId = null; - this.resetTokenStatistics?.(); - this.currentConversationTitle = '新对话'; - this.titleReady = true; - this.suppressTitleTyping = false; - try { - const { useTaskStore } = await import('../../../stores/task'); - const taskStore = useTaskStore(); - taskStore.clearTask(); - } catch (_) {} - this.clearLocalTaskUiState?.('switch-host-workspace'); + if (!preserveConversationView) { + this.messages = []; + this.currentConversationId = null; + this.resetTokenStatistics?.(); + this.currentConversationTitle = '新对话'; + this.titleReady = true; + this.suppressTitleTyping = false; + try { + const { useTaskStore } = await import('../../../stores/task'); + const taskStore = useTaskStore(); + taskStore.clearTask(); + } catch (_) {} + this.clearLocalTaskUiState?.('switch-host-workspace'); + } await this.fetchHostWorkspaces(); - const activeStatuses = new Set(['pending', 'running', 'cancel_requested']); - const activeTask = (Array.isArray(this.runningWorkspaceTasks) ? this.runningWorkspaceTasks : []) - .filter((task: any) => String(task?.workspace_id || '') === this.currentHostWorkspaceId) - .find((task: any) => activeStatuses.has(String(task?.status || '')) && task?.conversation_id); - if (activeTask?.conversation_id) { - await this.loadConversation(String(activeTask.conversation_id), { force: true }); + if (preserveConversationView) { + // 不做视图跳转(/new 或自动进入运行中任务对话),仅刷新侧边栏列表 this.conversationsOffset = 0; await this.loadConversationsList(); } else { - this.startTitleTyping('新对话', { animate: false }); - history.replaceState({}, '', '/new'); - await this.loadConversationsList(); + const activeStatuses = new Set(['pending', 'running', 'cancel_requested']); + const activeTask = (Array.isArray(this.runningWorkspaceTasks) ? this.runningWorkspaceTasks : []) + .filter((task: any) => String(task?.workspace_id || '') === this.currentHostWorkspaceId) + .find((task: any) => activeStatuses.has(String(task?.status || '')) && task?.conversation_id); + if (activeTask?.conversation_id) { + await this.loadConversation(String(activeTask.conversation_id), { force: true }); + this.conversationsOffset = 0; + await this.loadConversationsList(); + } else { + this.startTitleTyping('新对话', { animate: false }); + history.replaceState({}, '', '/new'); + await this.loadConversationsList(); + } } const switchedWorkspace = (Array.isArray(this.hostWorkspaces) ? this.hostWorkspaces : []) .find((item: any) => String(item?.workspace_id || '') === this.currentHostWorkspaceId); @@ -338,7 +350,7 @@ export const hostWorkspaceMethods = { const { conversationId, workspaceId } = payload || {}; if (!conversationId || !workspaceId) return; if ((this.versioningHostMode || this.dockerProjectMode) && workspaceId !== this.currentHostWorkspaceId) { - await this.handleHostWorkspaceSwitch(workspaceId); + await this.handleHostWorkspaceSwitch(workspaceId, { preserveConversationView: true }); } await this.loadConversation(conversationId, { force: true, workspaceId }); }, diff --git a/static/src/components/chat/quickdock/QuickDock.vue b/static/src/components/chat/quickdock/QuickDock.vue index e0ef2f4c..5296e171 100644 --- a/static/src/components/chat/quickdock/QuickDock.vue +++ b/static/src/components/chat/quickdock/QuickDock.vue @@ -1,7 +1,10 @@