diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue index 0559b21..58ad7cc 100644 --- a/src/views/chat/index.vue +++ b/src/views/chat/index.vue @@ -5,12 +5,9 @@ @change="onSelectUser" />
-
+
加载中...
@@ -215,13 +212,13 @@ const sortMessagesByTime = (messages) => { }) // 调试信息:显示排序后的消息时间 - console.log('消息排序结果:', sorted.map(m => ({ - id: m.id || m._id || m.message_id, - send_time: m.send_time, - content: typeof m.content === 'object' ? - (m.content.message || JSON.stringify(m.content)) : - String(m.content).slice(0, 20) + '...' - }))) + // console.log('消息排序结果:', sorted.map(m => ({ + // id: m.id || m._id || m.message_id, + // send_time: m.send_time, + // content: typeof m.content === 'object' ? + // (m.content.message || JSON.stringify(m.content)) : + // String(m.content).slice(0, 20) + '...' + // }))) return sorted } @@ -252,7 +249,7 @@ const getMessages = async (isHistory = true, pageOverride = null) => { msgTotal = res.total || 0 const list = res.list || [] - console.log(`获取消息 - isHistory: ${isHistory}, page: ${queryPage}, 返回消息数: ${list.length}`) + // console.log(`获取消息 - isHistory: ${isHistory}, page: ${queryPage}, 返回消息数: ${list.length}`) if (list.length > 0) { const newMessages = list.map(item => { @@ -333,10 +330,10 @@ const getMessages = async (isHistory = true, pageOverride = null) => { if (tempMsgIndex !== -1) { // 找到匹配的临时消息,替换它 - console.log('找到匹配的临时消息,进行替换:', { - tempId: currentMessages[tempMsgIndex]._id, - realId: newMsg.id || newMsg._id || newMsg.message_id - }) + // console.log('找到匹配的临时消息,进行替换:', { + // tempId: currentMessages[tempMsgIndex]._id, + // realId: newMsg.id || newMsg._id || newMsg.message_id + // }) currentMessages[tempMsgIndex] = { ...newMsg, _isTemp: false // 标记为非临时消息 @@ -374,17 +371,17 @@ const getMessages = async (isHistory = true, pageOverride = null) => { if (existingMsgIndex === -1) { // 3. 真正的新消息,添加到列表 - console.log('发现新消息:', { - id: newMsg.id || newMsg._id || newMsg.message_id, - content: typeof newMsg.content === 'object' ? newMsg.content.message : newMsg.content - }) + // console.log('发现新消息:', { + // id: newMsg.id || newMsg._id || newMsg.message_id, + // content: typeof newMsg.content === 'object' ? newMsg.content.message : newMsg.content + // }) currentMessages.push(newMsg) hasUpdates = true isProcessed = true } else { - console.log('消息已存在,跳过:', { - id: newMsg.id || newMsg._id || newMsg.message_id - }) + // console.log('消息已存在,跳过:', { + // id: newMsg.id || newMsg._id || newMsg.message_id + // }) } } } @@ -392,9 +389,9 @@ const getMessages = async (isHistory = true, pageOverride = null) => { if (hasUpdates) { // 重新排序并更新消息列表 messages.value = sortMessagesByTime(currentMessages) - console.log('消息列表已更新,当前消息数:', messages.value.length) + // console.log('消息列表已更新,当前消息数:', messages.value.length) } else { - console.log('没有新消息需要处理') + // console.log('没有新消息需要处理') } } @@ -484,7 +481,7 @@ const send = async () => { // 防抖检查 const now = Date.now() if (now - lastSendTime.value < 500) { - console.log('发送过于频繁,已忽略') + // console.log('发送过于频繁,已忽略') return } @@ -499,7 +496,7 @@ const send = async () => { ) if (hasSendingMessage) { - console.log('存在相同内容的发送中消息,已忽略') + // console.log('存在相同内容的发送中消息,已忽略') return } @@ -540,7 +537,7 @@ const send = async () => { }).then((response) => { msg._sending = false msg._failed = false - console.log('消息发送成功', response) + // console.log('消息发送成功', response) // 发送成功后,立即轮询获取最新消息以获取真实ID setTimeout(() => { @@ -549,7 +546,7 @@ const send = async () => { }).catch((error) => { msg._sending = false msg._failed = true - console.error('消息发送失败:', error) + // console.error('消息发送失败:', error) ElMessage({ type: 'error', message: '消息发送失败' }) }).finally(() => { // 重置发送状态 @@ -585,7 +582,7 @@ const uploadImageFile = (file) => { // 防止重复上传 if (isUploading.value) { - console.log('图片正在上传中,请稍候') + // console.log('图片正在上传中,请稍候') return } @@ -661,13 +658,13 @@ const uploadImageFile = (file) => { // 发送失败,更新临时消息状态 msg._sending = false msg._failed = true - console.error('发送图片消息失败:', sendError) + // console.error('发送图片消息失败:', sendError) ElMessage({ type: 'error', message: '发送图片失败' }) }) }).catch((error) => { msg._sending = false msg._failed = true - console.error('图片上传失败:', error) + // console.error('图片上传失败:', error) ElMessage({ type: 'error', message: '图片上传失败' }) }).finally(() => { isUploading.value = false @@ -731,14 +728,14 @@ const handleDrop = (e) => { // 获取拖拽的文件 const files = Array.from(e.dataTransfer.files) - + if (files.length === 0) { return } - + // 过滤出图片文件 const imageFiles = files.filter(file => file.type.startsWith('image/')) - + if (imageFiles.length === 0) { ElMessage({ type: 'warning', message: '请拖拽图片文件' }) return @@ -847,7 +844,7 @@ const startMessageTimer = () => { messageTimer.value = setInterval(() => { if (!msgQuery.user_id) return // 获取最新消息(第一页),用于追加新消息 - console.log('定时器轮询消息,用户ID:', msgQuery.user_id) + // console.log('定时器轮询消息,用户ID:', msgQuery.user_id) getMessages(false, 1) }, 1000) } @@ -939,32 +936,26 @@ const restartMessageTimer = () => { } } -const sendTemplateMessage = async (templateId) => { +const sendTemplateMessage = (templateId) => { if (!activeUser.value.sender_id) return + send_template_message({ + "app_id": route.query.app_id, + "app_secret": route.query.app_secret, + "template_id": route.query.template_id, + "touser": activeUser.value.sender_id + }).then((res) => { + if (res.success == true) { + ElMessage({ type: 'success', message: '模板消息发送成功' }) + // 发送成功后,立即轮询获取最新消息以获取真实ID + setTimeout(() => { + getMessages(false, 1) // 轮询最新消息 + }, 500) + } else { + ElMessage({ type: 'error', message: '推送失败,对方没有订阅!' }) + } - try { - await send_template_message({ - "app_id": route.query.app_id, - "app_secret": route.query.app_secret, - "template_id": route.query.template_id, - "touser": activeUser.value.sender_id - }).then((res) => { - if (res.success == true) { - ElMessage({ type: 'success', message: '模板消息发送成功' }) - // 发送成功后,立即轮询获取最新消息以获取真实ID - setTimeout(() => { - getMessages(false, 1) // 轮询最新消息 - }, 500) - } else { - ElMessage({ type: 'error', message: '推送失败,对方没有订阅!' }) - } + }) - }) - - } catch (error) { - console.error('模板消息发送失败:', error) - ElMessage({ type: 'error', message: '模板消息发送失败' }) - } } @@ -982,7 +973,7 @@ const getAppStaus = async () => { if (appInfoStore && appInfoStore.appDetail) { appInfoStore.appDetail.check_status_text = '' } - console.error('获取应用状态失败:', error) + // console.error('获取应用状态失败:', error) return null } }