feat: websocket连接成功

This commit is contained in:
2026-01-21 00:58:02 +08:00
parent b6962e5a19
commit 8137a38060
5 changed files with 50 additions and 21 deletions

View File

@@ -24,12 +24,12 @@
</div>
<!-- AI 标识 -->
<div v-if="msg.messageRole === MessageRole.AI" class="mt-2 text-xs text-gray-400 ">
<div v-if="msg.messageRole === MessageRole.AI && msg.finished" class="mt-2 text-xs text-gray-400 ">
本回答由 AI 生成
</div>
<!-- AI 操作按钮 -->
<div v-if="msg.messageRole === MessageRole.AI"
<div v-if="msg.messageRole === MessageRole.AI && msg.finished"
class="mt-4 text-gray-500 flex items-center justify-between gap-4 ">
<RiFileCopyLine size="16px" @click="copyFileClick(msg)" />
<div class="flex items-center gap-4">
@@ -38,7 +38,6 @@
<RiThumbUpLine size="16px" @click="thumbUpClick(msg)" />
<RiThumbDownLine size="16px" @click="thumbDownClick(msg)" />
</div>
</div>
</div>
@@ -318,6 +317,7 @@ const initWebSocket = async () => {
// 处理WebSocket消息
const handleWebSocketMessage = (data: any) => {
console.log("收到WebSocket消息:", data);
// 验证关键字段(若服务端传回 conversationId/agentId则校验是否属于当前会话
if (data.conversationId && data.conversationId !== conversationId.value) {
console.warn("收到不属于当前会话的消息,忽略", data.conversationId);
@@ -374,6 +374,7 @@ const handleWebSocketMessage = (data: any) => {
// 处理完成状态
if (data.finish) {
chatMsgList.value[aiMsgIndex].finished = data.finish;
const msg = chatMsgList.value[aiMsgIndex].messageContent;
if (!msg || chatMsgList.value[aiMsgIndex].isLoading) {
chatMsgList.value[aiMsgIndex].messageContent = "未获取到内容,请重试";

View File

@@ -3,8 +3,8 @@
<div class="flex h-full w-full flex-col md:flex-row ">
<chat-history class="flex-none w-64" />
<div class="flex-1 mr-2 overflow-hidden bg-white rounded-xl">
<chat-guide />
<!-- <chat-box /> -->
<!-- <chat-guide /> -->
<chat-box />
</div>
<TaskList />
</div>

View File

@@ -18,6 +18,8 @@ export class ChatMessage {
messageContent: string;
// 是否加载中
isLoading?: boolean;
// 是否完成
finished?: boolean;
// 工具调用信息
toolCall?: any;
// 问题信息
@@ -28,13 +30,15 @@ export class ChatMessage {
messageRole: MessageRole,
messageContent: string,
isLoading: boolean = false,
finished: boolean = false,
toolCall?: any,
question?: any
) {
this.messageId = messageId;
this.messageRole = messageRole;
this.messageContent = messageContent;
this.finished = finished;
this.isLoading = isLoading;
this.messageId = messageId;
this.toolCall = toolCall;
this.question = question;
}