From 3d17fd4788d1c2fd94a3703f7185b0b70236c75a Mon Sep 17 00:00:00 2001 From: Seven <1530011482@qq.com> Date: Wed, 23 Sep 2026 09:50:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=99=BB=E5=BD=95=E5=92=8C?= =?UTF-8?q?=E6=9C=AA=E8=AF=BB=E6=98=BE=E7=A4=BA=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/index/ChatPage.vue | 19 ++++++++++++------- src/router.js | 7 ++++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/pages/index/ChatPage.vue b/src/pages/index/ChatPage.vue index 2a3d43f..0c04cf4 100644 --- a/src/pages/index/ChatPage.vue +++ b/src/pages/index/ChatPage.vue @@ -432,7 +432,11 @@ export default { }); // 更新最近消息列表 - this.updateRecentChat(this.currentContact.contactName, newMessage); + this.updateRecentChat( + "send", + this.currentContact.contactName, + newMessage + ); // 清空输入框 this.messageText = ""; @@ -449,7 +453,7 @@ export default { }, // 更新最近消息列表 - updateRecentChat(contactName, newMessage) { + updateRecentChat(messageType, contactName, newMessage) { const index = this.recentChats.findIndex( (item) => item.contactName === contactName ); @@ -460,9 +464,10 @@ export default { chat.content = newMessage.content; chat.createdAt = newMessage.createdAt; - // 未读数量 +1 - chat.unreadCount = - (chat.unreadCount || 0) + 1; + // 接收非当前正在聊天的联系人新消息时,未读数量 +1 + if (messageType == "receive" && this.currentContact.contactName != contactName) { + chat.unreadCount = (chat.unreadCount || 0) + 1; + } this.recentChats.splice(index, 1); this.recentChats.unshift(chat); @@ -473,7 +478,7 @@ export default { contactName: contactName, content: newMessage.content, createdAt: newMessage.createdAt, - unreadCount: 1 + unreadCount: 1, }); } }, @@ -508,7 +513,7 @@ export default { this.contactMessages.push(message); } else { // 不是当前联系人,不加入 contactMessages,只更新最近聊天列表、未读数量 - this.updateRecentChat(message); + this.updateRecentChat("receive", senderName, message); } }, diff --git a/src/router.js b/src/router.js index dae795d..0127581 100644 --- a/src/router.js +++ b/src/router.js @@ -43,10 +43,11 @@ const router = new VueRouter({ router.beforeEach((to, from, next) => { const token = store.state.token; if(to.meta.requiresAuth) { - if(token) { - next() - } else { + // 加入/login判断,防止vue-router报错 + if(!token && to.path !== "/login") { next('/login') + } else { + next() } } else { next()