优化发送消息功能

This commit is contained in:
2026-09-22 14:17:54 +08:00
parent 5da8d6df59
commit 4beed1531f
+4 -1
View File
@@ -403,16 +403,18 @@ export default {
this.$set(this.contactMessages, this.currentContact.contactName, []); this.$set(this.contactMessages, this.currentContact.contactName, []);
} }
// 新消息
const newMessage = { const newMessage = {
senderName: this.currentUser.username, senderName: this.currentUser.username,
receiverName: this.currentContact.contactName, receiverName: this.currentContact.contactName,
content: content, content: content,
createdAt: new Date()
}; };
sendMessage(newMessage) sendMessage(newMessage)
.then((response) => { .then((response) => {
console.log("发送消息成功", response.data); console.log("发送消息成功", response.data);
this.contactMessages[this.currentContact.contactName].push({ this.contactMessages.push({
...newMessage, ...newMessage,
from: "me", from: "me",
}); });
@@ -432,6 +434,7 @@ export default {
this.recentChats.splice(index, 1); this.recentChats.splice(index, 1);
this.recentChats.unshift(chat); this.recentChats.unshift(chat);
console.log(this.recentChats)
} else { } else {
// 没有找到这条数据,直接添加到数组最前面 // 没有找到这条数据,直接添加到数组最前面
this.recentChats.unshift({ this.recentChats.unshift({