feat: 消息问答的调整
This commit is contained in:
@@ -15,11 +15,10 @@
|
||||
<view class="area-msg-list-content" v-for="item in chatMsgList" :key="item.msgId" :id="item.msgId">
|
||||
<template v-if="item.msgType === MessageRole.AI">
|
||||
<ChatCardAI class="flex flex-justify-start" :key="`ai-${item.msgId}-${item.msg ? item.msg.length : 0}`"
|
||||
:text="item.finish && item.componentName ? '' : item.msg || ''" :isLoading="item.isLoading">
|
||||
<template #content v-if="item.toolCall || item.componentName">
|
||||
<AnswerComponent v-if="
|
||||
item.componentName === CompName.longTextCard
|
||||
" :text="item.msg" :title="item.title" />
|
||||
:text="item.componentName && item.componentName === CompName.longTextCard ? '' : item.msg || ''" :isLoading="item.isLoading">
|
||||
<template #content v-if="item.toolCall || item.componentName && item.componentName === CompName.longTextCard">
|
||||
<AnswerComponent v-if=" item.componentName === CompName.longTextCard
|
||||
" :text="(item.componentMsg || item.msg)" :title="item.title" :finish="item.finish" />
|
||||
<QuickBookingComponent v-if="
|
||||
item.toolCall && item.toolCall.componentName === CompName.quickBookingCard
|
||||
" />
|
||||
@@ -545,11 +544,29 @@ const handleWebSocketMessage = (data) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 防护:确保 aiMsgIndex 有效
|
||||
if (aiMsgIndex < 0 || aiMsgIndex >= chatMsgList.value.length) {
|
||||
console.error('无效的 aiMsgIndex:', aiMsgIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
// replyMessageId
|
||||
if(data.replyMessageId) {
|
||||
chatMsgList.value[aiMsgIndex].replyMessageId = data.replyMessageId;
|
||||
}
|
||||
|
||||
// 如果服务端在分片中就带来了 componentName,提前记录并将已缓存的 msg 转移到 componentMsg
|
||||
const aiItem = chatMsgList.value[aiMsgIndex];
|
||||
if (data.componentName) {
|
||||
aiItem.componentName = data.componentName;
|
||||
if (data.componentName === CompName.longTextCard) {
|
||||
if (aiItem.msg && aiItem.msg.length > 0) {
|
||||
aiItem.componentMsg = (aiItem.componentMsg || "") + aiItem.msg;
|
||||
aiItem.msg = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 确保消息内容是字符串类型
|
||||
if (data.content && typeof data.content !== "string") {
|
||||
try {
|
||||
@@ -561,13 +578,24 @@ const handleWebSocketMessage = (data) => {
|
||||
|
||||
// 直接拼接内容到对应 AI 消息
|
||||
if (data.content) {
|
||||
if (chatMsgList.value[aiMsgIndex].isLoading) {
|
||||
// 首次收到内容:替换“加载中”文案并取消 loading 状态(恢复原始渲染逻辑)
|
||||
chatMsgList.value[aiMsgIndex].msg = data.content;
|
||||
chatMsgList.value[aiMsgIndex].isLoading = false;
|
||||
// 如果该条消息属于 longTextCard,使用 componentMsg 存储内容并保持 ChatCardAI 的 text 为空
|
||||
const isLongText = aiItem.componentName === CompName.longTextCard || data.componentName === CompName.longTextCard;
|
||||
if (isLongText) {
|
||||
if (aiItem.isLoading) {
|
||||
aiItem.componentMsg = (aiItem.componentMsg || "") + data.content;
|
||||
aiItem.isLoading = false;
|
||||
} else {
|
||||
aiItem.componentMsg = (aiItem.componentMsg || "") + data.content;
|
||||
}
|
||||
} else {
|
||||
// 后续流式内容追加
|
||||
chatMsgList.value[aiMsgIndex].msg += data.content;
|
||||
if (aiItem.isLoading) {
|
||||
// 首次收到内容:替换“加载中”文案并取消 loading 状态(恢复原始渲染逻辑)
|
||||
aiItem.msg = data.content;
|
||||
aiItem.isLoading = false;
|
||||
} else {
|
||||
// 后续流式内容追加
|
||||
aiItem.msg += data.content;
|
||||
}
|
||||
}
|
||||
nextTick(() => scrollToBottom());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user