diff --git a/dashboard/src/router/ChatBoxRoutes.ts b/dashboard/src/router/ChatBoxRoutes.ts index f19fb204b..393ad8f68 100644 --- a/dashboard/src/router/ChatBoxRoutes.ts +++ b/dashboard/src/router/ChatBoxRoutes.ts @@ -2,13 +2,20 @@ const ChatBoxRoutes = { path: '/chatbox', component: () => import('@/layouts/blank/BlankLayout.vue'), children: [ - { - name: 'ChatBox', - path: '/chatbox', - component: () => import('@/views/ChatBoxPage.vue') - } + { + name: 'ChatBox', + path: '/chatbox', + component: () => import('@/views/ChatBoxPage.vue'), + children: [ + { + path: ':conversationId', + name: 'ChatBoxDetail', + component: () => import('@/views/ChatBoxPage.vue'), + props: true + } + ] + } ] - }; - - export default ChatBoxRoutes; - \ No newline at end of file +}; + +export default ChatBoxRoutes; diff --git a/dashboard/src/router/MainRoutes.ts b/dashboard/src/router/MainRoutes.ts index 80910b8e3..0c2d9cf03 100644 --- a/dashboard/src/router/MainRoutes.ts +++ b/dashboard/src/router/MainRoutes.ts @@ -81,7 +81,15 @@ const MainRoutes = { { name: 'Chat', path: '/chat', - component: () => import('@/views/ChatPage.vue') + component: () => import('@/views/ChatPage.vue'), + children: [ + { + path: ':conversationId', + name: 'ChatDetail', + component: () => import('@/views/ChatPage.vue'), + props: true + } + ] }, { name: 'Settings', diff --git a/dashboard/src/views/ChatPage.vue b/dashboard/src/views/ChatPage.vue index 9656363e6..053b15810 100644 --- a/dashboard/src/views/ChatPage.vue +++ b/dashboard/src/views/ChatPage.vue @@ -111,13 +111,13 @@ const props = defineProps({
-
-
+
+

{{ getCurrentConversation.title || '新对话' }}

{{ formatDate(getCurrentConversation.updated_at) }}
- + mdi-fullscreen
@@ -306,6 +306,8 @@ export default { sidebarHoverTimer: null, sidebarHoverExpanded: false, sidebarHoverDelay: 100, // 悬停延迟,单位毫秒 + + pendingCid: null, // Store pending conversation ID for route handling } }, @@ -317,6 +319,44 @@ export default { } }, + watch: { + // Watch for route changes to handle direct navigation to /chat/ + '$route': { + immediate: true, + handler(to) { + // Check if the route matches /chat/ pattern + if (to.path.startsWith('/chat/')) { + const pathCid = to.path.split('/')[2]; + if (pathCid && pathCid !== this.currCid) { + // If conversations are already loaded + if (this.conversations.length > 0) { + const conversation = this.conversations.find(c => c.cid === pathCid); + if (conversation) { + this.getConversationMessages([pathCid]); + } + } else { + // Store the cid to be used after conversations are loaded + this.pendingCid = pathCid; + } + } + } + } + }, + + // Watch for conversations loaded to handle pending cid + conversations: { + handler(newConversations) { + if (this.pendingCid && newConversations.length > 0) { + const conversation = newConversations.find(c => c.cid === this.pendingCid); + if (conversation) { + this.getConversationMessages([this.pendingCid]); + this.pendingCid = null; + } + } + } + } + }, + mounted() { this.startListeningEvent(); this.checkStatus(); @@ -645,6 +685,15 @@ export default { getConversations() { axios.get('/api/chat/conversations').then(response => { this.conversations = response.data.data; + + // If there's a pending conversation ID from the route + if (this.pendingCid) { + const conversation = this.conversations.find(c => c.cid === this.pendingCid); + if (conversation) { + this.getConversationMessages([this.pendingCid]); + this.pendingCid = null; + } + } }).catch(err => { console.error(err); }); @@ -652,6 +701,17 @@ export default { getConversationMessages(cid) { if (!cid[0]) return; + + // Update the URL to reflect the selected conversation + if (this.$route.path !== `/chat/${cid[0]}` && this.$route.path !== `/chatbox/${cid[0]}`) { + if (this.$route.path.startsWith('/chatbox')) { + router.push(`/chatbox/${cid[0]}`); + } else { + router.push(`/chat/${cid[0]}`); + } + } + + axios.get('/api/chat/get_conversation?conversation_id=' + cid[0]).then(async response => { this.currCid = cid[0]; let message = JSON.parse(response.data.data.history); @@ -684,17 +744,23 @@ export default { }); }, async newConversation() { - await axios.get('/api/chat/new_conversation').then(response => { - this.currCid = response.data.data.conversation_id; + return axios.get('/api/chat/new_conversation').then(response => { + const cid = response.data.data.conversation_id; + this.currCid = cid; + // Update the URL to reflect the new conversation + router.push(`/chat/${cid}`); this.getConversations(); + return cid; }).catch(err => { console.error(err); + throw err; }); }, newC() { this.currCid = ''; this.messages = []; + router.push('/chat'); }, formatDate(timestamp) { @@ -723,7 +789,8 @@ export default { async sendMessage() { if (this.currCid == '') { - await this.newConversation(); + const cid = await this.newConversation(); + // URL is already updated in newConversation method } // Create a message object with actual URLs for display