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

View File

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

View File

@@ -30,8 +30,19 @@ function agentChatStream(params, onChunk) {
resolve(res.data); resolve(res.data);
}, },
fail(err) { fail(err) {
console.log("====> ", JSON.stringify(err))
reject(err); reject(err);
} },
complete(res) {
if(res.statusCode === 500) {
console.log("====> ", JSON.stringify(res))
if (onChunk) {
onChunk({ error: true, message: '服务器错误', detail: res });
}
reject(res);
}
}
}); });
requestTask.onHeadersReceived(res => { requestTask.onHeadersReceived(res => {

View File

@@ -0,0 +1,7 @@
import request from "../base/request";
function conversationMsgList(args) {
return request.post('/hotelBiz/chat/conversationMessageList', args);
}
export { conversationMsgList }

View File

@@ -0,0 +1,7 @@
import request from "../base/request";
function recentConversation() {
return request.get('/hotelBiz/chat/recentConversation');
}
export{ recentConversation }

View File

@@ -306,7 +306,7 @@ export default {
<style lang="scss"> <style lang="scss">
.zero-markdown-view { .zero-markdown-view {
padding: 15rpx; padding: 0;
position: relative; position: relative;
} }
</style> </style>