diff --git a/pages/ai/aichat.js b/pages/ai/aichat.js index 0360fac..7822d29 100644 --- a/pages/ai/aichat.js +++ b/pages/ai/aichat.js @@ -282,11 +282,20 @@ Page({ finishAIResponse() { const isClearRequest = this.activeRequestType === 'clear' + // 清空请求的确认语由服务端下发:只保留这条确认,其余历史随清空一起丢弃 + const clearReplyId = isClearRequest ? this.activeServerId : '' this.resetActiveRequest() if (isClearRequest) { - this.setData({ messages: [], isTyping: false }) - wx.removeStorageSync('ai_chat_history') + const messages = clearReplyId + ? this.data.messages.filter(item => item.type === 'ai' && item._serverId === clearReplyId) + : [] + this.setData({ messages, isTyping: false }) + if (messages.length) { + this.saveChatHistory(messages) + } else { + wx.removeStorageSync('ai_chat_history') + } wx.removeStorageSync('ai_session_id') return }