增强消息视图的SSE连接管理

This commit is contained in:
jxxghp
2025-08-21 09:22:57 +08:00
parent eafe63c886
commit c330aee560
3 changed files with 57 additions and 10 deletions

View File

@@ -50,6 +50,9 @@ const sendButtonDisabled = ref(false)
// 消息对话框引用
const messageDialogRef = ref<any>(null)
// 消息视图引用
const messageViewRef = ref<any>(null)
// 滚动容器引用
const messageContentRef = ref<any>()
@@ -115,6 +118,12 @@ async function openMessageDialog() {
setTimeout(() => {
forceScrollToEnd()
}, 600)
// 等待对话框打开后恢复SSE连接
nextTick(() => {
if (messageViewRef.value && typeof messageViewRef.value.resumeSSE === 'function') {
messageViewRef.value.resumeSSE()
}
})
}
// 智能滚动到底部(只有用户在底部附近时才滚动)
@@ -184,6 +193,14 @@ defineExpose({
openMessageDialog: openMessageDialogFromExternal,
})
// 监听消息对话框状态变化
watch(messageDialog, newValue => {
if (!newValue && messageViewRef.value && typeof messageViewRef.value.pauseSSE === 'function') {
// 对话框关闭时暂停SSE连接
messageViewRef.value.pauseSSE()
}
})
onMounted(() => {
const shortcut = getQueryValue('shortcut')
if (shortcut) {