Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c3a6d2bc5b | ||
|
|
2f15cebc4c |
@@ -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>
|
||||||
@@ -168,7 +180,8 @@
|
|||||||
|
|
||||||
<div class="message-content">
|
<div class="message-content">
|
||||||
<div class="message-time">
|
<div class="message-time">
|
||||||
{{ message.time }}
|
{{ getTime(message.time) }}
|
||||||
|
<!-- {{ message.time }} -->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="message-bubble">
|
<div class="message-bubble">
|
||||||
@@ -231,7 +244,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
connectWebSocket,
|
connectWebSocket,
|
||||||
sendWebSocketMessage,
|
sendWebSocketMessage,
|
||||||
closeWebSocket
|
closeWebSocket,
|
||||||
} from "@/utils/websocket";
|
} from "@/utils/websocket";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -243,6 +256,8 @@ export default {
|
|||||||
currentUser: {},
|
currentUser: {},
|
||||||
// 联系人
|
// 联系人
|
||||||
contactList: [],
|
contactList: [],
|
||||||
|
// 在线用户
|
||||||
|
onlineList: [],
|
||||||
// 当前聊天联系人
|
// 当前聊天联系人
|
||||||
currentContact: null,
|
currentContact: null,
|
||||||
// 最近聊天列表
|
// 最近聊天列表
|
||||||
@@ -454,6 +469,18 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getTime(time) {
|
||||||
|
if (!time) return "";
|
||||||
|
|
||||||
|
const date = new Date(time);
|
||||||
|
return `${date.getFullYear()}年${String(date.getMonth() + 1).padStart(
|
||||||
|
2,
|
||||||
|
"0"
|
||||||
|
)}月${String(date.getDate()).padStart(2, "0")}日 ${String(
|
||||||
|
date.getHours()
|
||||||
|
).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
|
||||||
|
},
|
||||||
|
|
||||||
// 更新最近消息列表
|
// 更新最近消息列表
|
||||||
updateRecentChat(messageType, contactName, newMessage) {
|
updateRecentChat(messageType, contactName, newMessage) {
|
||||||
const index = this.recentChats.findIndex(
|
const index = this.recentChats.findIndex(
|
||||||
@@ -528,7 +555,7 @@ export default {
|
|||||||
// 返回 ACK
|
// 返回 ACK
|
||||||
sendWebSocketMessage({
|
sendWebSocketMessage({
|
||||||
type: "ack",
|
type: "ack",
|
||||||
messageId: message.messageId
|
messageId: message.messageId,
|
||||||
});
|
});
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.scrollToBottom();
|
this.scrollToBottom();
|
||||||
@@ -538,6 +565,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 +931,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 +973,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 +1057,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