This commit is contained in:
@zuopngfei 2025-11-10 14:13:23 +08:00
parent b1c7e3343b
commit 7db5eee419

View File

@ -5,12 +5,9 @@
@change="onSelectUser" />
</div>
<div class="right-panel">
<div :class="['chat-body', { 'chat-body--loading': isLoadingMessages, 'chat-body--dragging': isDragging }]" ref="chatBody"
@scroll="handleScroll"
@dragover.prevent="handleDragOver"
@dragenter.prevent="handleDragEnter"
@dragleave.prevent="handleDragLeave"
@drop.prevent="handleDrop">
<div :class="['chat-body', { 'chat-body--loading': isLoadingMessages, 'chat-body--dragging': isDragging }]"
ref="chatBody" @scroll="handleScroll" @dragover.prevent="handleDragOver"
@dragenter.prevent="handleDragEnter" @dragleave.prevent="handleDragLeave" @drop.prevent="handleDrop">
<!-- 加载更多提示 -->
<div v-if="loadingMore" class="loading-more">加载中...</div>
<!-- 拖拽提示 -->
@ -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
}
}