添加联系人的在线状态显示
This commit is contained in:
@@ -113,6 +113,15 @@
|
|||||||
<div class="contact-name">
|
<div class="contact-name">
|
||||||
{{ contact.contactName }}
|
{{ contact.contactName }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="contact-user-status"
|
||||||
|
:class="
|
||||||
|
onlineList.includes(contact.contactName) ? 'online' : 'offline'
|
||||||
|
"
|
||||||
|
>
|
||||||
|
{{ onlineList.includes(contact.contactName) ? "在线" : "离线" }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -140,7 +149,10 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="chat-user-status">
|
<div class="chat-user-status">
|
||||||
{{ currentContact.online ? "在线" : "离线" }}
|
<span v-if="onlineList.includes(currentContact.contactName)">
|
||||||
|
在线
|
||||||
|
</span>
|
||||||
|
<span v-else> 离线 </span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -231,7 +243,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
connectWebSocket,
|
connectWebSocket,
|
||||||
sendWebSocketMessage,
|
sendWebSocketMessage,
|
||||||
closeWebSocket
|
closeWebSocket,
|
||||||
} from "@/utils/websocket";
|
} from "@/utils/websocket";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -243,6 +255,8 @@ export default {
|
|||||||
currentUser: {},
|
currentUser: {},
|
||||||
// 联系人
|
// 联系人
|
||||||
contactList: [],
|
contactList: [],
|
||||||
|
// 在线用户
|
||||||
|
onlineList: [],
|
||||||
// 当前聊天联系人
|
// 当前聊天联系人
|
||||||
currentContact: null,
|
currentContact: null,
|
||||||
// 最近聊天列表
|
// 最近聊天列表
|
||||||
@@ -524,11 +538,11 @@ export default {
|
|||||||
// 不是当前联系人,不加入 contactMessages,只更新最近聊天列表、未读数量
|
// 不是当前联系人,不加入 contactMessages,只更新最近聊天列表、未读数量
|
||||||
this.updateRecentChat("receive", senderName, message);
|
this.updateRecentChat("receive", senderName, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 返回 ACK
|
// 返回 ACK
|
||||||
sendWebSocketMessage({
|
sendWebSocketMessage({
|
||||||
type: "ack",
|
type: "ack",
|
||||||
messageId: message.messageId
|
messageId: message.messageId,
|
||||||
});
|
});
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.scrollToBottom();
|
this.scrollToBottom();
|
||||||
@@ -538,6 +552,9 @@ export default {
|
|||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.scrollToBottom();
|
this.scrollToBottom();
|
||||||
});
|
});
|
||||||
|
} else if (data.type == "userOnline") {
|
||||||
|
// 获取所有在线用户
|
||||||
|
this.onlineList = data.userList;
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -901,10 +918,18 @@ export default {
|
|||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.message-other .message-bubble {
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
|
||||||
.message-me {
|
.message-me {
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.message-me .message-bubble {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
.message-avatar {
|
.message-avatar {
|
||||||
width: 38px;
|
width: 38px;
|
||||||
height: 38px;
|
height: 38px;
|
||||||
@@ -935,7 +960,6 @@ export default {
|
|||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
||||||
float: right;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.message-me .message-bubble {
|
.message-me .message-bubble {
|
||||||
@@ -1020,4 +1044,17 @@ export default {
|
|||||||
background: #ddd;
|
background: #ddd;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.contact-user-status {
|
||||||
|
margin-top: 5px;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-user-status.online {
|
||||||
|
color: #67c23a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-user-status.offline {
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user