优化处理

This commit is contained in:
2025-10-26 16:59:50 +08:00
parent fdac026720
commit 2e243c7671
45 changed files with 346 additions and 3757 deletions
+13 -9
View File
@@ -1,5 +1,5 @@
import { defineStore } from 'pinia'
import { ref, computed, watch } from 'vue'
import { ref, computed, watch, nextTick } from 'vue'
import type { ChatMessage, ChatSession } from '@/types'
import { stompWebSocketService, type WebSocketMessage, type ConnectionStatus } from '@/services/stomp-websocket'
import { useAuthStore } from './auth'
@@ -381,31 +381,35 @@ export const useChatStore = defineStore('chat', () => {
}
// 添加AI回复消息(直接显示完整内容)
const addAiReplyMessages = (content: string) => {
const addAiReplyMessages = async (content: string) => {
// 停止输入状态
isTyping.value = false
// 使用 nextTick 确保 DOM 更新的顺序性,避免与定时同步并发
await nextTick()
// 直接添加完整的AI回复
const aiMessage = addMessage({
content: content.trim(),
type: 'ai',
sessionId: currentSession.value?.id
conversationId: currentSession.value?.id
})
// 强制触发响应式更新
console.log('AI消息已添加,当前消息总数:', messages.value.length)
console.log('最新AI消息:', aiMessage)
console.log('AI消息已添加,当前消息总数:', messages.value.length)
console.log('📝 最新AI消息:', aiMessage)
console.log('📊 所有消息:', messages.value)
}
// WebSocket消息处理
let handleWebSocketMessage = (wsMessage: WebSocketMessage) => {
let handleWebSocketMessage = async (wsMessage: WebSocketMessage) => {
console.log('收到WebSocket消息:', wsMessage.type, wsMessage.senderType)
switch (wsMessage.type) {
case 'TEXT':
if (wsMessage.senderType === 'AI') {
// AI回复消息 - 支持分段显示
addAiReplyMessages(wsMessage.content)
await addAiReplyMessages(wsMessage.content)
}
break
@@ -602,8 +606,8 @@ export const useChatStore = defineStore('chat', () => {
onMessage: (callback: (message: any) => void) => {
// 简单的消息监听实现
const originalHandler = handleWebSocketMessage
handleWebSocketMessage = (message: any) => {
originalHandler(message)
handleWebSocketMessage = async (message: any) => {
await originalHandler(message)
callback(message)
}
}