From 7675e8e04dcefba3b5bd5799486ef05106d15b58 Mon Sep 17 00:00:00 2001 From: jinhhanhan <1683105490@qq.com> Date: Mon, 20 Apr 2026 09:52:27 +0800 Subject: [PATCH] =?UTF-8?q?chore=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages_tool/ai-chat/ai-chat-message.vue | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/pages_tool/ai-chat/ai-chat-message.vue b/pages_tool/ai-chat/ai-chat-message.vue index 629241d..91dff58 100644 --- a/pages_tool/ai-chat/ai-chat-message.vue +++ b/pages_tool/ai-chat/ai-chat-message.vue @@ -417,15 +417,11 @@ export default { localUserAvatar: '', // 默认头像路径 defaultAvatar: '/static/images/user-avatar.png', - // 头像选择弹窗控制 showAvatarSelector: false, // 头像选择弹窗控制 - // 新增:用户昵称相关 localUserNickname: '', // 当前用户昵称 defaultNickname: '我', // 默认昵称 showNicknameEditor: false, // 昵称编辑弹窗控制 tempNickname: '', // 昵称编辑临时值 - // AI头像配置(可配置,方便后续更换) - // 支持两种方式: // 1. 使用图片URL:设置为图片链接字符串 // 2. 使用emoji:设置为空字符串或null,将显示默认的🤖 aiAvatarUrl: '/static/images/image_680328925892268.png', @@ -436,7 +432,7 @@ export default { currentConversationId: null, isAIServiceAvailable: true, aiServiceError: null, - isLoadingHistory: false, // 新增:标记历史加载状态 + isLoadingHistory: false, shouldScrollToBottom: false, scrollTimer: null, lastScrollTop: 0, @@ -451,7 +447,7 @@ export default { setTimeout(() => { uni.navigateBack({ delta: 1 }); // 或 redirectTo 首页 }, 1000); - return; // ⚠️ 关键:阻止后续初始化 + return; // 关键:阻止后续初始化 } // 优先读取本地缓存的会话 ID const localConvId = this.getConversationIdFromLocal(); @@ -466,7 +462,6 @@ export default { // 初始历史条数作为偏移量 this.historyOffset = this.messages.length; }); - // 移除:this.historyOffset = 0;(避免覆盖初始历史的偏移量) }, // 新增:组件销毁时清除防抖定时器 beforeDestroy() { @@ -553,13 +548,12 @@ export default { this.localUserAvatar = this.defaultAvatar } }, - // 👇 新增:加载历史记录 -// 👇 修正:加载历史记录 + // 新增:加载历史记录 async loadChatHistoryIfExist() { const convId = aiService.getConversationId(); if (convId) { try { - // ✅ 调用正确的方法,并传入会话ID + // 调用正确的方法,并传入会话ID const response = await aiService.getConversationHistory({ conversation_id: convId }); @@ -568,8 +562,6 @@ async loadChatHistoryIfExist() { console.warn('历史记录为空或格式无效'); return; } - - // 注意:getConversationHistory 返回的数据结构与 getChatHistory 预期的不同 // 需要根据实际返回的 response.data.messages 来映射 console.log('【调试】后端返回的历史消息数据:', response.messages); this.messages = response.messages.map(msg => { @@ -888,8 +880,6 @@ async loadChatHistoryIfExist() { this.messages.push(aiMessage) this.$emit('ai-response', aiMessage) }, - - // 发送流式消息 // 发送流式消息(自动适配 H5 / 微信小程序) async sendStreamMessage(userMessage) { // 创建流式消息对象 @@ -901,10 +891,8 @@ async loadChatHistoryIfExist() { timestamp: Date.now(), isStreaming: true }; - // 标记正在流式响应 this.isStreaming = true; - // 移除加载状态,添加流式消息 this.messages = this.messages.filter(msg => msg.type !== 'loading'); this.shouldScrollToBottom = true; @@ -917,7 +905,6 @@ async loadChatHistoryIfExist() { try { // #ifdef H5 - // ===== H5: 使用 POST + 流式 (fetch readable stream) ===== await aiService.sendHttpStream( userMessage, (chunk) => {