feat: 对家列表的调整

This commit is contained in:
2025-07-28 21:34:23 +08:00
parent 15200ce3b8
commit 0efc7fe6a0
6 changed files with 108 additions and 27 deletions

View File

@@ -85,15 +85,24 @@
import OneFeelMK002 from '../module/OneFeelMK002.vue';
import { agentChatStream } from '../../request/api/AgentChatStream';
import { mainPageData } from '../../request/api/MainPageData';
import { conversationMsgList } from '../../request/api/ConversationMsgList';
import { recentConversation } from '../../request/api/RecentConversation';
// 导航栏相关
/// 导航栏相关
const statusBarHeight = ref(20);
const timer = ref(null)
const holdKeyboard = ref(false) // focus时点击页面的时候不收起键盘
const holdKeyboardFlag = ref(true) // 是否在键盘弹出,点击界面时关闭键盘
/// focus时点击页面的时候不收起键盘
const holdKeyboard = ref(false)
/// 是否在键盘弹出,点击界面时关闭键盘
const holdKeyboardFlag = ref(true)
///(控制滚动位置)
const scrollTop = ref(99999);
/// 会话列表
const chatMsgList = ref([])
/// 输入口的输入消息
const inputMessage = ref('')
/// 从个渠道获取如二维,没有的时候就返回首页的数据
@@ -101,11 +110,12 @@
/// agentId 首页接口中获取
const agentId = ref('1')
/// 会话ID 历史数据接口中获取
const conversationId = ref('1931957498711957505')
const conversationId = ref('')
/// 首页的数据
const mainPageDataModel = ref({})
//(控制滚动位置)
const scrollTop = ref(99999);
// 会话进行中标志
let isSessionActive = false;
// 打开抽屉
@@ -135,6 +145,7 @@
// #endif
}
/// 滚动到底部
const scrollToBottom = () => {
nextTick(() => {
nextTick(() => {
@@ -142,19 +153,35 @@
});
});
}
/// 延迟在滚到底
const setTimeoutScrollToBottom = () => {
setTimeout(() => {
scrollToBottom()
}, 100)
}
/// 发送普通消息
const handleReply = (text) => {
sendMessage(text)
setTimeout(() => {
scrollToBottom()
}, 100)
setTimeoutScrollToBottom()
};
/// 是发送指令
const handleReplyInstruct = (text) => {
sendMessage(text, true)
scrollToBottom()
setTimeoutScrollToBottom()
}
/// 输入区的发送消息事件
const sendMessageAction = (inputText) => {
console.log("输入消息:", inputText)
if (!inputText.trim()) return;
handleNoHideKeyboard()
sendMessage(inputText)
if(!isSessionActive) {
inputMessage.value = ''
}
setTimeoutScrollToBottom()
}
onLoad(() => {
@@ -165,10 +192,26 @@
});
});
onMounted(() => {
onMounted( async() => {
getMainPageData()
await loadRecentConversation()
loadConversationMsgList()
})
/// 获取最近一次的会话id
const loadRecentConversation = async() => {
const res = await recentConversation()
if(res.code === 0) {
conversationId.value = res.data.conversationId
}
}
/// 加载历史消息的数据
let historyCurrentPageNum = 1
const loadConversationMsgList = async() => {
const args = { pageNum: historyCurrentPageNum++, pageSize : 10, conversationId: conversationId.value }
const res = await conversationMsgList(args)
}
/// 获取首页数据
const getMainPageData = async() => {
@@ -181,7 +224,7 @@
}
}
/// 初始化数据
/// 初始化数据 首次数据加载的时候
const initData = () => {
const msg = {
msgId: `msg_${0}`,
@@ -192,17 +235,16 @@
}
/// 输入区的发送消息事件
const sendMessageAction = (inputText) => {
console.log("输入消息:", inputText)
if (!inputText.trim()) return;
handleNoHideKeyboard()
sendMessage(inputText)
inputMessage.value = ''
scrollToBottom()
}
/// 发送消息的参数拼接
const sendMessage = (message, isInstruct = false) => {
if (isSessionActive) {
uni.showToast({
title: '请等待当前回复完成',
icon: 'none'
});
return;
}
isSessionActive = true;
const newMsg = {
msgId: `msg_${chatMsgList.value.length}`,
msgType: MessageRole.ME,
@@ -217,7 +259,7 @@
console.log("发送的新消息:",JSON.stringify(newMsg))
}
/// 打字机效果实现的变量
let loadingTimer = null;
let typeWriterTimer = null;
let aiMsgBuffer = ''; // 全局缓冲区
@@ -260,9 +302,19 @@
typeWriterTimer = null;
}
// 2. 流式接收内容
// 流式接收内容
agentChatStream(args, (chunk) => {
console.log('分段内容:', chunk)
if (chunk.error) {
chatMsgList.value[aiMsgIndex].msg = '请求错误,请重试';
clearInterval(finishInterval);
isTyping = false;
typeWriterTimer = null;
isSessionActive = false; // 出错也允许再次发送
console.error('流式错误:', chunk.message, chunk.detail);
return;
}
if (chunk && chunk.content) {
// 收到内容,停止动画
if (loadingTimer) {
@@ -285,10 +337,14 @@
if (aiMsgBuffer.length === 0) {
clearInterval(finishInterval);
isTyping = false;
isSessionActive = false; // 会话结束,允许再次发送
scrollToBottom();
}
}, 50);
}
}).catch(e => {
isSessionActive = false; // 出错也允许再次发送
console.log('error:', e)
});
// 打字机函数

View File

@@ -4,7 +4,7 @@
<!-- :style="backgroundStyle" -->
<view class="top-item1-left">
<image :src="initPageImages.welcomeImageUrl"></image>
<text>{{ currentDate }} 多云 -36 </text>
<text>{{ currentDate }} 多云 -36 gg </text>
</view>
<view class="top-item1-right">
<image :src="initPageImages.logoImageUrl"></image>