feat: 停止的时候处理

This commit is contained in:
2025-09-09 23:13:33 +08:00
parent 6fc01a1bd5
commit 35abfea922
2 changed files with 62 additions and 35 deletions

View File

@@ -256,8 +256,9 @@ const handleScrollToLower = () => {};
// 滚动到底部 - 优化版本,确保打字机效果始终可见
const scrollToBottom = () => {
nextTick(() => {
// 使用更大的值确保滚动到真正的底部
scrollTop.value = 99999;
// 强制触发滚动更新
// 强制触发滚动更新增加延迟确保DOM更新完成
setTimeout(() => {
scrollTop.value = scrollTop.value + Math.random();
}, 10);
@@ -538,7 +539,6 @@ const initTypewriterManager = () => {
typewriterManager.setCallbacks({
// 每个字符打字时的回调
onCharacterTyped: (displayedContent) => {
// 只有在用户没有滚动时才自动滚动到底部
scrollToBottom();
},
// 内容更新时的回调
@@ -671,30 +671,38 @@ const stopRequest = () => {
// 发送中断消息给服务器 (messageType=2)
sendWebSocketMessage(2, "stop_request", { silent: true });
// 停止打字机效果
// 停止打字机效果并保留当前内容
if (typewriterManager) {
typewriterManager.stopTypewriter();
}
// 获取当前已显示的内容
const currentStatus = typewriterManager.getStatus();
const currentDisplayedContent = currentStatus.displayedContent;
// 重置会话状态和消息状态
isSessionActive.value = false;
resetMessageState();
// 使用新的方法停止并保留当前内容
typewriterManager.stopAndKeepCurrent();
// 更新最后一条AI消息的状态
const aiMsgIndex = chatMsgList.value.length - 1;
if (
chatMsgList.value[aiMsgIndex] &&
chatMsgList.value[aiMsgIndex].msgType === MessageRole.AI
) {
chatMsgList.value[aiMsgIndex].isLoading = false;
// 更新最后一条AI消息的状态
const aiMsgIndex = chatMsgList.value.length - 1;
if (
!chatMsgList.value[aiMsgIndex].msg ||
chatMsgList.value[aiMsgIndex].msg.startsWith("加载中")
chatMsgList.value[aiMsgIndex] &&
chatMsgList.value[aiMsgIndex].msgType === MessageRole.AI
) {
chatMsgList.value[aiMsgIndex].msg = "请求已停止";
chatMsgList.value[aiMsgIndex].isLoading = false;
// 如果有已显示的内容,使用已显示的内容,否则显示停止消息
if (
currentDisplayedContent &&
currentDisplayedContent.trim() &&
!currentDisplayedContent.startsWith("加载中")
) {
chatMsgList.value[aiMsgIndex].msg = currentDisplayedContent;
} else {
chatMsgList.value[aiMsgIndex].msg = "请求已停止";
}
}
}
// 重置会话状态(但不重置消息状态,保留已显示内容)
isSessionActive.value = false;
console.log("请求已停止,状态已重置");
setTimeoutScrollToBottom();