解决登录和未读显示的bug

This commit is contained in:
2026-09-23 09:50:04 +08:00
parent f8625ab36e
commit 3d17fd4788
2 changed files with 16 additions and 10 deletions
+12 -7
View File
@@ -432,7 +432,11 @@ export default {
}); });
// 更新最近消息列表 // 更新最近消息列表
this.updateRecentChat(this.currentContact.contactName, newMessage); this.updateRecentChat(
"send",
this.currentContact.contactName,
newMessage
);
// 清空输入框 // 清空输入框
this.messageText = ""; this.messageText = "";
@@ -449,7 +453,7 @@ export default {
}, },
// 更新最近消息列表 // 更新最近消息列表
updateRecentChat(contactName, newMessage) { updateRecentChat(messageType, contactName, newMessage) {
const index = this.recentChats.findIndex( const index = this.recentChats.findIndex(
(item) => item.contactName === contactName (item) => item.contactName === contactName
); );
@@ -460,9 +464,10 @@ export default {
chat.content = newMessage.content; chat.content = newMessage.content;
chat.createdAt = newMessage.createdAt; chat.createdAt = newMessage.createdAt;
// 未读数量 +1 // 接收非当前正在聊天的联系人新消息时,未读数量 +1
chat.unreadCount = if (messageType == "receive" && this.currentContact.contactName != contactName) {
(chat.unreadCount || 0) + 1; chat.unreadCount = (chat.unreadCount || 0) + 1;
}
this.recentChats.splice(index, 1); this.recentChats.splice(index, 1);
this.recentChats.unshift(chat); this.recentChats.unshift(chat);
@@ -473,7 +478,7 @@ export default {
contactName: contactName, contactName: contactName,
content: newMessage.content, content: newMessage.content,
createdAt: newMessage.createdAt, createdAt: newMessage.createdAt,
unreadCount: 1 unreadCount: 1,
}); });
} }
}, },
@@ -508,7 +513,7 @@ export default {
this.contactMessages.push(message); this.contactMessages.push(message);
} else { } else {
// 不是当前联系人,不加入 contactMessages,只更新最近聊天列表、未读数量 // 不是当前联系人,不加入 contactMessages,只更新最近聊天列表、未读数量
this.updateRecentChat(message); this.updateRecentChat("receive", senderName, message);
} }
}, },
+4 -3
View File
@@ -43,10 +43,11 @@ const router = new VueRouter({
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
const token = store.state.token; const token = store.state.token;
if(to.meta.requiresAuth) { if(to.meta.requiresAuth) {
if(token) { // 加入/login判断,防止vue-router报错
next() if(!token && to.path !== "/login") {
} else {
next('/login') next('/login')
} else {
next()
} }
} else { } else {
next() next()