feat: 首页消息列表调整

This commit is contained in:
zoujing 2025-07-27 15:11:40 +08:00
parent 7b09a565d8
commit a796d06631
2 changed files with 91 additions and 78 deletions

View File

@ -25,10 +25,8 @@
</ChatTopWelcome> </ChatTopWelcome>
<view class="area-msg-list-content" v-for="item in chatMsgList" :key="item.msgId" :id="item.msgId"> <view class="area-msg-list-content" v-for="item in chatMsgList" :key="item.msgId" :id="item.msgId">
<template v-if="item.msgType === MessageRole.AI"> <template v-if="item.msgType === MessageRole.AI">
<ChatCardAI class="message-item-ai" :text="item.msg"> <ChatCardAI class="message-item-ai" :text="item.msg">
</ChatCardAI> </ChatCardAI>
</template> </template>
@ -49,17 +47,17 @@
</view> </view>
<!-- 底部锚点用于滚动到底部 --> <!-- 底部锚点用于滚动到底部 -->
<view :id="lastMsgId"></view> <view :id="lastMsgId" class="lastMsgId"></view>
</scroll-view> </scroll-view>
<!-- 输入框区域 --> <!-- 输入框区域 -->
<view class="footer-area"> <view class="footer-area">
<ChatMoreTips @replySent="handleReply" :itemList="mainPageDataModel.guideWords"></ChatMoreTips> <ChatMoreTips @replySent="handleReply" :itemList="mainPageDataModel.guideWords"></ChatMoreTips>
<ChatQuickAccess @replySent="handleReply"></ChatQuickAccess> <ChatQuickAccess @replySent="handleReplyInstruct"></ChatQuickAccess>
<ChatInputArea <ChatInputArea
v-model:inputMessage="inputMessage" v-model:inputMessage="inputMessage"
:holdKeyboard="holdKeyboard" :holdKeyboard="holdKeyboard"
@send="sendMessage" @send="sendMessageAction"
@noHideKeyboard="handleNoHideKeyboard" @noHideKeyboard="handleNoHideKeyboard"
/> />
</view> </view>
@ -100,10 +98,12 @@
const chatMsgList = ref([]) const chatMsgList = ref([])
const inputMessage = ref('') const inputMessage = ref('')
const activityList = ref([])
/// ///
const sceneId = ref('') const sceneId = ref('')
/// agentId
const agentId = ref('1')
/// ID
const conversationId = ref('1931957498711957505')
const mainPageDataModel = ref({}) const mainPageDataModel = ref({})
// ID // ID
@ -117,40 +117,6 @@
console.log('=============打开抽屉') console.log('=============打开抽屉')
} }
const handleReply = (text) => {
loadMessage(text)
scrollToBottom()
};
onLoad(() => {
uni.getSystemInfo({
success: (res) => {
statusBarHeight.value = res.statusBarHeight || 20;
}
});
});
onMounted(() => {
getMainPageData()
})
const getMainPageData = async() => {
const res = await mainPageData(sceneId.value)
if(res.code === 0) {
mainPageDataModel.value = res.data
initData()
}
}
const initData = () => {
const msg = {
msgId: `msg_${0}`,
msgType: MessageRole.OTHER,
msg: '',
}
chatMsgList.value.push(msg)
}
const handleTouchEnd = () => { const handleTouchEnd = () => {
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
clearTimeout(timer.value) clearTimeout(timer.value)
@ -164,7 +130,6 @@
// #endif // #endif
} }
// //
const handleNoHideKeyboard = () => { const handleNoHideKeyboard = () => {
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
@ -172,34 +137,6 @@
// #endif // #endif
} }
//
const sendMessage = (message) => {
console.log("inputMessage list:", message)
if (!message.trim()) return;
handleNoHideKeyboard()
//
loadMessage(message)
inputMessage.value = ''
scrollToBottom()
}
const loadMessage = (text) => {
const newMsg = {
msgId: `msg_${chatMsgList.value.length}`,
msgType: MessageRole.ME,
msg: text,
msgContent: {
type: MessageType.TEXT,
text: text
}
}
chatMsgList.value.push(newMsg)
console.log("发送的新消息:",JSON.stringify(newMsg))
sendChat(text)
}
const scrollToBottom = () => { const scrollToBottom = () => {
// ID // ID
lastMsgId.value = `${chatMsgList.value[chatMsgList.value.length - 1].msgId}`; lastMsgId.value = `${chatMsgList.value[chatMsgList.value.length - 1].msgId}`;
@ -211,22 +148,93 @@
}); });
} }
///
const handleReply = (text) => {
sendMessage(text)
scrollToBottom()
};
///
const handleReplyInstruct = (text) => {
sendMessage(text, true)
scrollToBottom()
}
onLoad(() => {
uni.getSystemInfo({
success: (res) => {
statusBarHeight.value = res.statusBarHeight || 20;
}
});
});
onMounted(() => {
getMainPageData()
})
///
const getMainPageData = async() => {
const res = await mainPageData(sceneId.value)
if(res.code === 0) {
mainPageDataModel.value = res.data
agentId.value = res.data.agentId
initData()
}
}
///
const initData = () => {
const msg = {
msgId: `msg_${0}`,
msgType: MessageRole.OTHER,
msg: '',
}
chatMsgList.value.push(msg)
}
///
const sendMessageAction = (inputText) => {
console.log("输入消息:", inputText)
if (!inputText.trim()) return;
handleNoHideKeyboard()
sendMessage(inputText)
inputMessage.value = ''
scrollToBottom()
}
const sendMessage = (message, isInstruct = false) => {
const newMsg = {
msgId: `msg_${chatMsgList.value.length}`,
msgType: MessageRole.ME,
msg: message,
msgContent: {
type: MessageType.TEXT,
text: message
}
}
chatMsgList.value.push(newMsg)
sendChat(message, isInstruct)
console.log("发送的新消息:",JSON.stringify(newMsg))
}
let loadingTimer = null; let loadingTimer = null;
let typeWriterTimer = null; let typeWriterTimer = null;
let aiMsgBuffer = ''; // let aiMsgBuffer = ''; //
let isTyping = false; // let isTyping = false; //
const sendChat = (text) => { /// AI
const sendChat = (message, isInstruct = false) => {
console.log('=============会话测试')
const args = { const args = {
conversationId: "1931957498711957505", conversationId: conversationId.value,
agentId: "1", agentId: agentId.value,
messageType: 0, messageType: isInstruct ? 1 : 0,
messageContent: text messageContent: message
} }
// 1. AI // AI
const aiMsg = { const aiMsg = {
msgId: `msg_${chatMsgList.value.length}`, msgId: `msg_${chatMsgList.value.length}`,
msgType: MessageRole.AI, msgType: MessageRole.AI,

View File

@ -71,6 +71,11 @@
} }
} }
.lastMsgId {
}
.footer-area { .footer-area {
width: 100vw; width: 100vw;
flex-shrink: 0; flex-shrink: 0;