切换联系人时的UI优化和消息获取
This commit is contained in:
@@ -148,7 +148,7 @@
|
|||||||
<div
|
<div
|
||||||
ref="messageList"
|
ref="messageList"
|
||||||
class="message-list"
|
class="message-list"
|
||||||
:class="activeMenu === 'messages' ? 'active' : ''"
|
:class="activeMenu === 'settings' ? '' : 'active'"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
v-for="message in currentMessages"
|
v-for="message in currentMessages"
|
||||||
@@ -184,14 +184,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
|
||||||
ref="messageList"
|
|
||||||
class="message-list"
|
|
||||||
:class="activeMenu === 'contacts' ? 'empty' : ''"
|
|
||||||
>
|
|
||||||
<div class="empty-content">💬</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 输入消息区域 -->
|
<!-- 输入消息区域 -->
|
||||||
<div v-if="activeMenu === 'messages'" class="input-panel">
|
<div v-if="activeMenu === 'messages'" class="input-panel">
|
||||||
<div class="toolbar">
|
<div class="toolbar">
|
||||||
@@ -282,7 +274,12 @@ export default {
|
|||||||
// 切换菜单
|
// 切换菜单
|
||||||
changeMenu(menu) {
|
changeMenu(menu) {
|
||||||
this.activeMenu = menu;
|
this.activeMenu = menu;
|
||||||
|
this.currentContact = null;
|
||||||
|
if(menu === "contacts") {
|
||||||
|
this.getContactList();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 退出登录
|
// 退出登录
|
||||||
logout() {
|
logout() {
|
||||||
// 清除 token 和用户信息
|
// 清除 token 和用户信息
|
||||||
@@ -290,6 +287,7 @@ export default {
|
|||||||
this.$store.commit("SET_USERNAME", "");
|
this.$store.commit("SET_USERNAME", "");
|
||||||
this.$router.push("/login");
|
this.$router.push("/login");
|
||||||
},
|
},
|
||||||
|
|
||||||
// 获取当前登录用户信息
|
// 获取当前登录用户信息
|
||||||
getCurrentUser() {
|
getCurrentUser() {
|
||||||
// 获取当前登录用户信息
|
// 获取当前登录用户信息
|
||||||
@@ -303,6 +301,7 @@ export default {
|
|||||||
this.$router.push("/login");
|
this.$router.push("/login");
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// 获取最近消息列表
|
// 获取最近消息列表
|
||||||
getRecentMessageList() {
|
getRecentMessageList() {
|
||||||
getRecentMessages()
|
getRecentMessages()
|
||||||
@@ -315,6 +314,7 @@ export default {
|
|||||||
this.$message.error("获取消息列表失败");
|
this.$message.error("获取消息列表失败");
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// 选择联系人
|
// 选择联系人
|
||||||
selectContact(contact) {
|
selectContact(contact) {
|
||||||
this.currentContact = contact;
|
this.currentContact = contact;
|
||||||
@@ -327,12 +327,14 @@ export default {
|
|||||||
this.scrollToBottom();
|
this.scrollToBottom();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// 选择最近一个联系人
|
// 选择最近一个联系人
|
||||||
selectFirstContact() {
|
selectFirstContact() {
|
||||||
if (!this.currentContact && this.recentChats.length > 0) {
|
if (!this.currentContact && this.recentChats.length > 0) {
|
||||||
this.selectContact(this.recentChats[0]);
|
this.selectContact(this.recentChats[0]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 获取当前联系人的消息列表
|
// 获取当前联系人的消息列表
|
||||||
getContactMessageList(contactName, limit) {
|
getContactMessageList(contactName, limit) {
|
||||||
// 获取当前联系人的消息列表
|
// 获取当前联系人的消息列表
|
||||||
@@ -362,6 +364,8 @@ export default {
|
|||||||
this.$message.error("获取消息列表失败");
|
this.$message.error("获取消息列表失败");
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 获取联系人列表
|
||||||
getContactList() {
|
getContactList() {
|
||||||
getContactInfo()
|
getContactInfo()
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
@@ -369,14 +373,13 @@ export default {
|
|||||||
...contact,
|
...contact,
|
||||||
unread: contact.unread || 0,
|
unread: contact.unread || 0,
|
||||||
}));
|
}));
|
||||||
console.log("contactList", this.contactList);
|
|
||||||
this.selectFirstContact();
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
this.$message.error("获取联系人信息失败");
|
this.$message.error("获取联系人信息失败");
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// 获取最后一条消息
|
// 获取最后一条消息
|
||||||
getLastMessage(contactName) {
|
getLastMessage(contactName) {
|
||||||
const messageList = this.contactMessages[contactName];
|
const messageList = this.contactMessages[contactName];
|
||||||
|
|||||||
Reference in New Issue
Block a user