fix: 修复继续对话时消息覆盖问题
- 对话完成时正确重置 currentSegmentedMessage - 继续对话时创建新的消息容器 - 删除调试日志代码
This commit is contained in:
@ -1007,28 +1007,27 @@ export function getMessageAreaScript(): string {
|
||||
|
||||
// 实时更新分段消息(按后端返回顺序)
|
||||
function updateSegmentsRealtime(segments, isComplete) {
|
||||
console.log('[WebView] updateSegmentsRealtime 被调用, segments:', segments, 'isComplete:', isComplete);
|
||||
// 如果对话完成且没有新段落,只重置容器
|
||||
if (isComplete && (!segments || segments.length === 0)) {
|
||||
currentSegmentedMessage = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!segments || segments.length === 0) {
|
||||
console.log('[WebView] segments 为空,跳过渲染');
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果没有当前分段消息容器,创建一个
|
||||
if (!currentSegmentedMessage) {
|
||||
console.log('[WebView] 创建新的分段消息容器');
|
||||
// 移除流式消息(如果有)
|
||||
if (currentStreamingMessage) {
|
||||
console.log('[WebView] 移除流式消息');
|
||||
currentStreamingMessage.remove();
|
||||
currentStreamingMessage = null;
|
||||
}
|
||||
|
||||
// 移除所有工具状态消息(因为会在分段中显示)
|
||||
const toolStatuses = messagesEl.querySelectorAll('.tool-status');
|
||||
console.log('[WebView] 找到工具状态消息数量:', toolStatuses.length);
|
||||
toolStatuses.forEach(el => {
|
||||
console.log('[WebView] 移除工具状态消息:', el.className);
|
||||
el.remove();
|
||||
});
|
||||
|
||||
@ -1246,7 +1245,7 @@ export function getMessageAreaScript(): string {
|
||||
currentSegmentedMessage.appendChild(segmentDiv);
|
||||
});
|
||||
|
||||
// 如果对话完成,添加操作按钮
|
||||
// 如果对话完成,添加操作按钮并重置容器
|
||||
if (isComplete) {
|
||||
console.log('[WebView] 对话完成,添加操作按钮');
|
||||
const actionsDiv = document.createElement('div');
|
||||
@ -1281,7 +1280,7 @@ export function getMessageAreaScript(): string {
|
||||
actionsDiv.appendChild(dislikeBtn);
|
||||
currentSegmentedMessage.appendChild(actionsDiv);
|
||||
|
||||
// 重置当前分段消息容器
|
||||
// 重置当前分段消息容器(继续对话时创建新容器)
|
||||
currentSegmentedMessage = null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user