From 60af83cfee145a64d45f36027eb9dcf69e11c32a Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Thu, 14 Aug 2025 13:53:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E9=80=89=E4=B8=AD=E7=8A=B6=E6=80=81=E7=AE=A1=E7=90=86=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=BB=98=E8=AE=A4=E5=AF=B9=E8=AF=9D=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dashboard/src/views/ChatPage.vue | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/dashboard/src/views/ChatPage.vue b/dashboard/src/views/ChatPage.vue index ca7e660c5..eb0bdf231 100644 --- a/dashboard/src/views/ChatPage.vue +++ b/dashboard/src/views/ChatPage.vue @@ -39,7 +39,7 @@ v-if="!sidebarCollapsed"> + style="background-color: transparent;" v-model:selected="selectedConversations" @update:selected="getConversationMessages"> {{ item.title @@ -351,6 +351,7 @@ export default { prompt: '', messages: [], conversations: [], + selectedConversations: [], // 用于控制左侧列表的选中状态 currCid: '', stagedImagesName: [], // 用于存储图片**文件名**的数组 stagedImagesUrl: [], // 用于存储图片的blob URL数组 @@ -445,9 +446,18 @@ export default { if (this.pendingCid && newConversations.length > 0) { const conversation = newConversations.find(c => c.cid === this.pendingCid); if (conversation) { + // 先设置选中状态,然后加载对话消息 + this.selectedConversations = [this.pendingCid]; this.getConversationMessages([this.pendingCid]); this.pendingCid = null; } + } else { + // 如果没有URL参数指定的对话,且当前没有选中对话,则默认打开第一个对话 + if (!this.currCid && newConversations.length > 0) { + const firstConversation = newConversations[0]; + this.selectedConversations = [firstConversation.cid]; + this.getConversationMessages([firstConversation.cid]); + } } } } @@ -472,12 +482,6 @@ export default { // 添加keyup事件监听 document.addEventListener('keyup', this.handleInputKeyUp); - - // 从 localStorage 获取侧边栏折叠状态 - const savedCollapseState = localStorage.getItem('sidebarCollapsed'); - if (savedCollapseState !== null) { - this.sidebarCollapsed = JSON.parse(savedCollapseState); - } }, beforeUnmount() { @@ -729,6 +733,13 @@ export default { this.getConversationMessages([this.pendingCid]); this.pendingCid = null; } + } else { + // 如果没有URL参数指定的对话,且当前没有选中对话,则默认打开第一个对话 + if (!this.currCid && this.conversations.length > 0) { + const firstConversation = this.conversations[0]; + this.selectedConversations = [firstConversation.cid]; + this.getConversationMessages([firstConversation.cid]); + } } }).catch(err => { if (err.response.status === 401) { @@ -753,6 +764,8 @@ export default { axios.get('/api/chat/get_conversation?conversation_id=' + cid[0]).then(async response => { this.currCid = cid[0]; + // Update the selected conversation in the sidebar + this.selectedConversations = [cid[0]]; let history = response.data.data.history; for (let i = 0; i < history.length; i++) { let content = history[i].content; @@ -810,6 +823,7 @@ export default { newC() { this.currCid = ''; + this.selectedConversations = []; // 清除选中状态 this.messages = []; if (this.$route.path.startsWith('/chatbox')) { this.$router.push('/chatbox'); @@ -838,6 +852,7 @@ export default { axios.get('/api/chat/delete_conversation?conversation_id=' + cid).then(response => { this.getConversations(); this.currCid = ''; + this.selectedConversations = []; // 清除选中状态 this.messages = []; }).catch(err => { console.error(err);