添加中断,修复电脑手机运行时信号

This commit is contained in:
2026-07-11 16:56:48 +08:00
parent 9910269733
commit d6437419b1
8 changed files with 211 additions and 138 deletions

View File

@@ -97,7 +97,7 @@
</view>
<view class="main-chat">
<scroll-view class="chat-messages" direction="vertical" scroll-y :scroll-into-view="scrollToView"
@scrolltoupper="loadMoreMessages" :upper-threshold="0" :scroll-with-animation="true"
:upper-threshold="0" :scroll-with-animation="true"
@scroll="onScroll">
<!-- 与AI的对话内容展示 -->
<template v-for="(message, index) in currentMessages" :key="index">
@@ -235,9 +235,12 @@
<view class="chat-input-container" :class="{ 'input-disabled': isThinking }">
<textarea class="message-input" :placeholder="isThinking ? (isSelfSent ? 'AI 正在回复中...' : '电脑正在运行,请稍后') : '输入消息...'" :disabled="isThinking"
v-model="textMessage" auto-height></textarea>
<view class="input-btn-group send-message-btn" :class="{ disabled: isThinking }" @click="!isThinking && sendMessage()">
<view class="iconfont icon-fasong"></view>
</view>
<view v-if="isThinking && !isSelfSent" class="input-btn-group stop-message-btn" @click="stopConversation">
<view class="iconfont icon-tingzhi"></view>
</view>
<view v-else class="input-btn-group send-message-btn" :class="{ disabled: isThinking }" @click="!isThinking && sendMessage()">
<view class="iconfont icon-fasong"></view>
</view>
</view>
</view>
</view>
@@ -807,7 +810,7 @@
// }
// }
// AI 回复超时定时器
let aiResponseTimer = null
// let aiResponseTimer = null
// 发送AI消息
const sendAIMessage = async () => {
@@ -828,17 +831,17 @@
socketStore.send(data)
isThinking.value = true
isSelfSent.value = true // 标记为当前设备发起
// 10分钟超时
aiResponseTimer = setTimeout(() => {
uni.showToast({
title: 'AI回复超时请重试',
icon: 'none'
})
isThinking.value = false
isSelfSent.value = false
textMessage.value = ''
uploadedFiles.value = []
}, 600000)
// // 10分钟超时
// aiResponseTimer = setTimeout(() => {
// uni.showToast({
// title: 'AI回复超时请重试',
// icon: 'none'
// })
// isThinking.value = false
// isSelfSent.value = false
// textMessage.value = ''
// uploadedFiles.value = []
// }, 600000)
} catch (error) {
isThinking.value = false
uni.showToast({
@@ -861,12 +864,13 @@
console.error('中断指令发送失败:', err)
}
// 立即关闭弹窗,清除超时
clearTimeout(aiResponseTimer)
// clearTimeout(aiResponseTimer)
isThinking.value = false
socketStore.isThinking = false
isSelfSent.value = false
textMessage.value = ''
uploadedFiles.value = []
// socketStore.isThinking 和 takeConversationMessages 由后端中断确认驱动(见 handleBusinessMessage
// takeConversationMessages 由后端中断确认驱动(见 handleBusinessMessage
uni.showToast({ title: '已中断', icon: 'none', duration: 1500 })
}
@@ -881,7 +885,7 @@
}
// true → falseAI 回复结束或中断,解锁输入框并刷新消息列表
if (oldVal && !newVal) {
clearTimeout(aiResponseTimer)
// clearTimeout(aiResponseTimer)
console.log('AI回复结束正常/中断),解锁并刷新消息列表');
takeConversationMessages()
isThinking.value = false
@@ -1064,7 +1068,7 @@
// 当前会话的消息
// const currentMessages = ref([])
const allmessages = ref([])
const pageInfoNumber = 100;
// const pageInfoNumber = 10;
const scrollToView = ref('')
// 加载状态和分页相关变量
@@ -1072,7 +1076,8 @@
const currentPage = ref(1) // 当前页码(如果后端支持分页)
// 计算属性:自动根据 allmessages 和 currentPage 计算显示消息
const currentMessages = computed(() => {
return allmessages.value.slice(-pageInfoNumber);
// return allmessages.value.slice(-pageInfoNumber);
return allmessages.value;
})
@@ -1126,21 +1131,21 @@
})
}
}
// 加载更多消息
const loadMoreMessages = async () => {
console.log('加载更多信息');
if (allmessages.value.length > pageInfoNumber * currentPage.value) {
currentPage.value += 1;
const newMessages = allmessages.value.slice(-pageInfoNumber * currentPage.value);
const addMessage = newMessages.length - currentMessages.value.length
currentMessages.value = newMessages
// 等待DOM更新
await nextTick()
scrollToView.value = 'msg-' + (addMessage + 1);
// // 加载更多消息
// const loadMoreMessages = async () => {
// console.log('加载更多信息');
// if (allmessages.value.length > pageInfoNumber * currentPage.value) {
// currentPage.value += 1;
// const newMessages = allmessages.value.slice(-pageInfoNumber * currentPage.value);
// const addMessage = newMessages.length - currentMessages.value.length
// currentMessages.value = newMessages
// // 等待DOM更新
// await nextTick()
// scrollToView.value = 'msg-' + (addMessage + 1);
}
// currentMessages.value = allmessages.value.slice(-pageInfoNumber);
}
// }
// // currentMessages.value = allmessages.value.slice(-pageInfoNumber);
// }