diff --git a/pages/chat/ChatMainList.vue b/pages/chat/ChatMainList.vue index a3ed5e4..d72c489 100644 --- a/pages/chat/ChatMainList.vue +++ b/pages/chat/ChatMainList.vue @@ -25,10 +25,8 @@ - @@ -49,17 +47,17 @@ - + - + @@ -99,11 +97,13 @@ const chatMsgList = ref([]) const inputMessage = ref('') - - const activityList = ref([]) /// 从个渠道获取如二维,没有的时候就返回首页的数据 const sceneId = ref('') + /// agentId 首页接口中获取 + const agentId = ref('1') + /// 会话ID 历史数据接口中获取 + const conversationId = ref('1931957498711957505') const mainPageDataModel = ref({}) // 锚点ID(控制滚动位置) @@ -116,41 +116,7 @@ emits('openDrawer') 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 = () => { // #ifdef MP-WEIXIN clearTimeout(timer.value) @@ -164,42 +130,13 @@ // #endif } - // 点击输入框、发送按钮时,不收键盘 const handleNoHideKeyboard = () => { // #ifdef MP-WEIXIN holdKeyboardFlag.value = false // #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 = () => { // 短暂指向最新消息的ID(触发滚动) 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 typeWriterTimer = null; let aiMsgBuffer = ''; // 全局缓冲区 let isTyping = false; // 是否正在打字 - const sendChat = (text) => { - - console.log('=============会话测试') + /// 发送获取AI聊天消息 + const sendChat = (message, isInstruct = false) => { const args = { - conversationId: "1931957498711957505", - agentId: "1", - messageType: 0, - messageContent: text + conversationId: conversationId.value, + agentId: agentId.value, + messageType: isInstruct ? 1 : 0, + messageContent: message } - // 1. 插入AI消息 + // 插入AI消息 const aiMsg = { msgId: `msg_${chatMsgList.value.length}`, msgType: MessageRole.AI, diff --git a/pages/chat/styles/ChatMainList.scss b/pages/chat/styles/ChatMainList.scss index b338e98..a2341db 100644 --- a/pages/chat/styles/ChatMainList.scss +++ b/pages/chat/styles/ChatMainList.scss @@ -71,6 +71,11 @@ } } + .lastMsgId { + + + } + .footer-area { width: 100vw; flex-shrink: 0;