diff --git a/pages/chat/chatPage.vue b/pages/chat/chatPage.vue index 80e9509..383787a 100644 --- a/pages/chat/chatPage.vue +++ b/pages/chat/chatPage.vue @@ -6,12 +6,11 @@ - - + @@ -19,7 +18,7 @@ {{ msg.type === 'thinking' ? '思考中' : msg.type === 'answer' ? '回答' : '' }} --> {{ msg.thinkContent }} - {{ msg.showAnswer}} + {{ msg.answerContent}} 【穿搭建议】: @@ -130,6 +129,7 @@ return { inputMsg: '', scrollTop: 0, + scrollTrigger: 0, // <<< 新增:这就是我们的强制触发器 userAvatar: require('../../static/imgs/index/nav.png'), botAvatar: require('../../static/imgs/ai/chuandaguwen.png'), messages: [], @@ -147,6 +147,7 @@ isHandleClose: false, connectNum: 0, aiName: '', + scrollBottom: 0, // 新增一个计数器 aiDefaultList: [ '最近雨季来了,家里总是很潮湿,有什么简单有效的除湿防霉小妙招吗?', '我下周要参加一个商务休闲风格的客户午餐会(夏天,户外庭院),男,身高175cm,体型偏瘦,肤色偏白,有什么搭配建议吗?', @@ -158,7 +159,9 @@ onLoad(options) { this.serviceUrl = options.serviceUrl || ''; this.apiKey = options.apiKey || ''; - this.botAvatar = options.icon || this.botAvatar; + // this.botAvatar = options.icon || this.botAvatar; + this.botAvatar =this.botAvatar; + console.log(this.botAvatar) this.aiName = options.name const userInfo = wx.getStorageSync('userInfo') || {}; this.userId = userInfo.id || Date.now().toString(); @@ -205,7 +208,7 @@ answerContent: '', type: 'normal', isTyping: false, - showAnswer: '已连接,请输入您的问题', + answerContent: '已连接,请输入您的问题', answerType: 2 } this.addMessage(params); @@ -251,7 +254,7 @@ if (messageData.event === 'text_chunk') { // 处理分块文本 this.handleTextChunk(messageData); - } else if (messageData.event === 'workflow_finished') { + } else if (messageData.event === 'text_chunk_end') { this.currentAnswer = '' // 处理完整节点完成 this.handleNodeFinished(messageData); @@ -325,7 +328,7 @@ // 提取回答内容,去除标签 const answerContent = text.replace(/<\/?think>/g, ''); if (!answerContent) return; - + console.log(1111) // 查找最后一条回答消息 // const lastAnswerMsgIndex = this.messages.findLastIndex( // msg => msg.type === 'answer' || msg.type === 'normal' @@ -341,6 +344,7 @@ // this.addMessage('bot', answerContent, 'answer'); // } this.messages[this.messages.length - 1].answerContent += answerContent + console.log(this.messages) // this.$forceUpdate(); this.scrollToBottom(); }, @@ -427,17 +431,18 @@ const params = { sender: 'me', thinkContent: '', - answerContent: '', type: 'normal', isTyping: false, - showAnswer: content, + answerContent: content, answerType: 2 } this.addMessage(params); this.isAnswering = true + const mid = 'user-' + Date.now() // 微信小程序中使用 socketTask.send this.socketTask.send({ - data: content, + // data: content, + data:JSON.stringify({ event: 'user_message', data: { id: mid, content: content } }), success: () => { console.log('消息发送成功'); const params = { @@ -558,9 +563,12 @@ // 滚动到底部 scrollToBottom() { + console.log(2222) this.$nextTick(() => { - this.scrollTop = 99999; // 足够大的值确保滚动到底部 - }); + // 核心:不管 scrollTop 原本是多少,我们给 scrollTrigger 一个新数字 + // Date.now() 保证每次调用这个函数时,数值都绝对不一样 + this.scrollTrigger = Date.now(); + }); }, onScroll(e) { @@ -593,10 +601,10 @@ } .chat-messages { - flex: 1; - /* padding: 15px; */ - background-color: #e5ddd5; - overflow-y: auto; +/* flex: 1; 注释掉这行 */ + height: calc(100vh - 100px); /* 根据顶部提示条和底部输入框的高度估算,或者使用 JS 动态计算 */ + background-color: #e5ddd5; + overflow-y: auto; } .message { diff --git a/utils/config.js b/utils/config.js index 7f0d2d6..744349d 100644 --- a/utils/config.js +++ b/utils/config.js @@ -1,9 +1,9 @@ -export const BASE_URL = 'http://10.10.1.6:8071'; -export const IMAGE_BASE_URL = `http://10.10.1.6:8071`; -// export const BASE_URL = 'https://jinshan.nantong.info'; -// export const IMAGE_BASE_URL = `https://jinshan.nantong.info`; +// export const BASE_URL = 'http://10.10.1.11:8071'; +// export const IMAGE_BASE_URL = `http://10.10.1.6:8071`; +export const BASE_URL = 'https://jinshan.nantong.info'; +export const IMAGE_BASE_URL = `https://jinshan.nantong.info`; export const WS_BASE_URL = `wss://jinshan.nantong.info`; -// export const WS_BASE_URL = 'ws://10.10.1.6:8071'; +// export const WS_BASE_URL = 'ws://10.10.1.11:8071'; // http://36.212.197.253:8071