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