3 Commits

Author SHA1 Message Date
33e04802dd Merge branch 'main' of https://git.nianxx.cn/zoujing/YGChatCS
# Conflicts:
#	src/pages/index/components/chat/ChatMainList/index.vue
2026-04-05 11:45:51 +08:00
f90625c125 feat: 消息类型 2026-04-05 11:44:09 +08:00
e565e967fc feat: 房间号的文案改 2026-04-05 11:43:43 +08:00
5 changed files with 51 additions and 14 deletions

View File

@@ -50,7 +50,7 @@
}
},
"tianmu": {
"clientId": "4",
"clientId": "9",
"appId": "wx0be424e1d22065a9",
"name": "沐沐",
"placeholder": "快告诉沐沐您在想什么~",

View File

@@ -19,8 +19,8 @@
<view
class="bg-F5F7FA border-box flex flex-items-center p-12 rounded-10 font-size-14 color-171717 mb-12"
>
<text class="font-500 line-height-22 mr-20">房间号</text>
<input placeholder="请填写房间号" v-model="roomId" />
<text class="font-500 line-height-22 mr-20">所在位置</text>
<input placeholder="请填写所在位置" v-model="roomId" />
</view>
<view
@@ -90,7 +90,7 @@
<view v-else class="border-box card-content flex flex-items-center p-12">
<view class="border-box left flex-full pr-20">
<view class="font-size-12 color-525866 line-height-20 mb-4"
>房间号{{ roomId }}</view
>所在位置{{ roomId }}</view
>
<view class="font-size-12 color-525866 line-height-20 mb-4"
>联系方式: {{ contactPhone }}</view
@@ -210,7 +210,7 @@ const handleCall = async () => {
}
if (!roomId.value.trim()) {
uni.showToast({ title: "请填写房间号", icon: "none" });
uni.showToast({ title: "请填写所在位置", icon: "none" });
return;
}

View File

@@ -7,6 +7,20 @@ export const MessageRole = {
OTHER: "OTHER",
};
/// 消息类型 0-对话 1-指令 2-中断停止 3-心跳检测 4-通知
export const MessageType = {
// 对话消息
dialog: 0,
// 指令消息
command: 1,
// 中断停止
stop: 2,
// 心跳检测
heartbeat: 3,
// 通知消息
notice: 4,
};
/// 组件的名称
export const CompName = {
// 快速预定卡片
@@ -28,11 +42,13 @@ export const CompName = {
// 回答卡片
longTextCard: "longTextCard",
// 生成合成图片
generatorPhotoCard: "generatorPhotoCard",
aigcPhotoGeneratorCard: "aigcPhotoGeneratorCard",
};
/// 发送的指令类型
export const Command = {
// 通知消息
welcome: "Command.welcome",
// 快速预定
quickBooking: "Command.quickBooking",
// 探索发现
@@ -47,4 +63,6 @@ export const Command = {
myWorkOrder: "Command.myWorkOrder",
// 反馈意见
feedbackCard: "Command.feedbackCard",
// 生成合成图片
aigcPhotoGenerator: "Command.aigcPhotoGenerator",
};

View File

@@ -15,7 +15,7 @@
<view class="border-box card-content flex flex-items-center pb-12">
<view class="border-box left flex-full pr-20">
<view class="font-size-12 color-525866 line-height-20 mb-4"
>房间号{{ orderData.roomNo }}</view
>所在位置{{ orderData.roomNo }}</view
>
<view class="font-size-12 color-525866 line-height-20 mb-4"
>联系方式: {{ orderData.userPhone }}</view

View File

@@ -10,8 +10,7 @@
:scroll-with-animation="true" @scroll="handleScroll" @scrolltolower="handleScrollToLower">
<!-- welcome栏 -->
<ChatTopWelcome ref="welcomeRef" :mainPageDataModel="mainPageDataModel" />
<!-- <NoticeMessage></NoticeMessage> -->
<NoticeMessage v-if="notitceConent"></NoticeMessage>
<view class="area-msg-list-content" v-for="item in chatMsgList" :key="item.msgId" :id="item.msgId">
<template v-if="item.msgType === MessageRole.AI">
@@ -33,7 +32,7 @@
item.toolCall && item.toolCall.componentName === CompName.mapCard
" />
<GeneratorPhotoComponent v-else-if="
item.toolCall && item.toolCall.componentName === CompName.generateMessageId
item.toolCall && item.toolCall.componentName === CompName.aigcPhotoGeneratorCard
" />
<Feedback v-else-if="
item.toolCall && item.toolCall.componentName === CompName.feedbackCard
@@ -96,7 +95,7 @@ import {
NOTICE_EVENT_LOGOUT,
NOTICE_EVENT_LOGIN_SUCCESS,
} from "@/constant/constant";
import { MessageRole, CompName } from "@/model/ChatModel";
import { MessageRole, MessageType, CompName, Command } from "@/model/ChatModel";
import ChatTopWelcome from "../ChatTopWelcome/index.vue";
import NoticeMessage from "../NoticeMessage/index.vue";
import ChatTopNavBar from "../ChatTopNavBar/index.vue";
@@ -136,6 +135,7 @@ const statusBarHeight = ref(20);
const inputAreaRef = ref(null);
const topNavBarRef = ref();
const welcomeRef = ref();
const notitceConent = ref("");
const holdKeyboardTimer = ref(null);
/// focus时点击页面的时候不收起键盘
@@ -420,6 +420,16 @@ const initWebSocket = async () => {
console.log("WebSocket连接成功");
// 重置会话状态
isSessionActive.value = false; // 连接成功时重置会话状态,避免影响新消息发送
// 连接成功后发送 welcome 消息 (messageType=4)
try {
// fire-and-forget, sendWebSocketMessage 会处理重连与队列
sendWebSocketMessage(MessageType.notice, Command.welcome, { tryReconnect: true, messageId:IdUtils.generateMessageId() }).catch((e) => {
console.warn('发送 Command.welcome 消息失败:', e);
});
} catch (e) {
console.warn('发送 Command.welcome 消息时异常:', e);
}
},
// 连接断开回调
@@ -476,6 +486,15 @@ const handleWebSocketMessage = (data) => {
return;
}
// Welcome 消息 (messageType=4):用于更新顶部欢迎栏内容
if (data.messageType && data.messageType === 'broadcast') {
console.log("收到 welcome 类型消息:", data);
if (data.content) {
notitceConent.value = data.content;
}
return;
}
let aiMsgIndex = -1;
// Prefer matching by replyMessageId if provided
if (data.replyMessageId) {
@@ -733,7 +752,7 @@ const sendWebSocketMessage = async (messageType, messageContent, options = {}) =
const args = {
conversationId: conversationId.value,
agentId: agentId.value,
messageType: String(messageType), // 消息类型 0-对话 1-指令 2-中断停止 3-心跳检测
messageType: String(messageType), // 消息类型 0-对话 1-指令 2-中断停止 3-心跳检测 4-消息
messageContent: messageContent,
messageId: options.messageId || currentSessionMessageId,
};
@@ -840,7 +859,7 @@ const sendChat = async (message, isInstruct = false) => {
return;
}
const messageType = isInstruct ? 1 : 0;
const messageType = isInstruct ? MessageType.command : MessageType.dialog;
const messageContent = isInstruct ? messageCommonType : message;
// 生成 messageId 并保存到当前会话变量stopRequest 可能使用)
currentSessionMessageId = IdUtils.generateMessageId();
@@ -903,7 +922,7 @@ const stopRequest = async () => {
// 发送中断消息给服务器 (messageType=2),带上当前 messageId
try {
await sendWebSocketMessage(2, "stop_request", { messageId: currentSessionMessageId, silent: true });
await sendWebSocketMessage(MessageType.stop, "stop_request", { messageId: currentSessionMessageId, silent: true });
} catch (e) {
console.warn("stopRequest send failed:", e);
}