Эх сурвалжийг харах

会话结束后请求历史记录

gcz 2 сар өмнө
parent
commit
83f74e34bc

+ 9 - 2
src/layout/index.vue

@@ -58,7 +58,7 @@
                :key="index" 
                class="history-item"
                @click="handleHistoryClick(item)">
-            {{ item.fileName||item.askContent }}
+            {{ item.fileName||item.askContent||'暂无标题' }}
           </div>
           <!-- v-if="hasMore" -->
           <div 
@@ -92,7 +92,7 @@
 </template>
 
 <script setup>
-import { ref, onMounted } from 'vue'
+import { ref, onMounted, onUnmounted } from 'vue'
 import { useRoute, useRouter } from 'vue-router'
 import { useUserStore } from '../stores/user'
 import request from '../utils/request' // 确保引入request
@@ -132,6 +132,13 @@ const getHistoryList = async () => {
 // 组件挂载时获取历史记录
 onMounted(() => {
   getHistoryList()
+  // 添加事件监听器
+  window.addEventListener('updateHistory', getHistoryList)
+})
+
+// 添加组件卸载时的清理
+onUnmounted(() => {
+  window.removeEventListener('updateHistory', getHistoryList)
 })
 
 const handleHistoryClick = async (item) => {

+ 2 - 0
src/views/AIChat.vue

@@ -319,6 +319,8 @@ const simulateStreamResponse = async (question) => {
         }
         
         eventSource.close();
+        // 发送事件通知更新历史记录
+        window.dispatchEvent(new Event('updateHistory'));
         loading.value = false;
         await scrollToBottom();
         return;