Compare commits

..

2 Commits

Author SHA1 Message Date
Leo_Ding
eee7025a85 Merge branch 'main' of https://gitlab.guxuan.icu/Leo_Ding/JinShan_uniapp 2026-01-21 16:05:56 +08:00
Leo_Ding
7e181b21f2 智能聊天 2026-01-21 16:05:51 +08:00
2 changed files with 30 additions and 22 deletions

View File

@ -6,12 +6,11 @@
</view>
<!-- 聊天消息区域 -->
<scroll-view scroll-y :scroll-top="scrollTop" class="chat-messages" :scroll-with-animation="true"
<scroll-view scroll-y :scroll-top="scrollTrigger" class="chat-messages" :scroll-with-animation="true"
@scroll="onScroll">
<view class="" style="padding: 10px 0;">
<view v-for="(msg, index) in messages" :key="index"
:class="['message', msg.sender === 'me' ? 'sent' : 'received']">
<view v-for="(msg, index) in messages" :key="index" :id="'msg-' + index" :class="['message', msg.sender === 'me' ? 'sent' : 'received']">
<image v-if="msg.sender !== 'me'" :src="botAvatar" class="avatar"></image>
<view :class="['message-bubble', msg.sender === 'me' ? 'me' : '']">
@ -19,7 +18,7 @@
{{ msg.type === 'thinking' ? '思考中' : msg.type === 'answer' ? '回答' : '' }}
</text> -->
<view class="message-text" style="color: #999999;">{{ msg.thinkContent }}</view>
<view class="message-text" v-if="msg.answerType===2">{{ msg.showAnswer}}</view>
<view class="message-text" v-if="msg.answerType===2">{{ msg.answerContent}}</view>
<view class="message-text" v-if="msg.answerType===1">
<view>
穿搭建议:
@ -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,8 +563,11 @@
//
scrollToBottom() {
console.log(2222)
this.$nextTick(() => {
this.scrollTop = 99999; //
// scrollTop scrollTrigger
// Date.now()
this.scrollTrigger = Date.now();
});
},
@ -593,8 +601,8 @@
}
.chat-messages {
flex: 1;
/* padding: 15px; */
/* flex: 1; 注释掉这行 */
height: calc(100vh - 100px); /* 根据顶部提示条和底部输入框的高度估算,或者使用 JS 动态计算 */
background-color: #e5ddd5;
overflow-y: auto;
}

View File

@ -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