feat: 对话功能开发
This commit is contained in:
@@ -43,7 +43,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, onUnmounted, nextTick, watch } from 'vue';
|
||||
import { ref, computed, onMounted, onUnmounted, nextTick, watch } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { ChatDotRound, ArrowRight, ArrowDown } from '@element-plus/icons-vue';
|
||||
@@ -136,6 +136,10 @@ watch(
|
||||
if (newSessionId) {
|
||||
currentSessionId.value = newSessionId;
|
||||
loadHistoryMessages(newSessionId);
|
||||
// 确保 SSE 连接已建立(如果之前断开)
|
||||
if (!eventSource) {
|
||||
connectSSE();
|
||||
}
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
@@ -160,7 +164,11 @@ function upsertAssistantBubble(msgId, text) {
|
||||
}
|
||||
|
||||
function connectSSE() {
|
||||
if (eventSource) eventSource.close();
|
||||
if (eventSource) {
|
||||
eventSource.close();
|
||||
eventSource = null;
|
||||
}
|
||||
console.log('[connectSSE] 建立 SSE 连接...');
|
||||
eventSource = createEventSource();
|
||||
|
||||
eventSource.onmessage = (e) => {
|
||||
@@ -231,6 +239,11 @@ async function send() {
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
// 组件挂载时建立 SSE 连接
|
||||
connectSSE();
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
if (eventSource) eventSource.close();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user