+ 历史消息
data[j].CreatedAt) {
- let temp = data[i];
- data[i] = data[j];
- data[j] = temp;
- }
- }
- }
+ // for (let i = 0; i < data.length; i++) {
+ // for (let j = i + 1; j < data.length; j++) {
+ // if (data[i].CreatedAt > data[j].CreatedAt) {
+ // let temp = data[i];
+ // data[i] = data[j];
+ // data[j] = temp;
+ // }
+ // }
+ // }
+ data.sort((a, b) => {
+ const dateA = new Date(a.CreatedAt);
+ const dateB = new Date(b.CreatedAt);
+
+ // 返回时间差,用于排序
+ return dateA - dateB;
+ });
this.MsgList=data;
- this.scrollToBottom();
+ if(this.history_cnt <=2){
+ this.scrollToBottom();
+ }
},
formatTime(time){
let date = new Date(time);
@@ -276,7 +306,14 @@ export default {
if (data.type == "msg") { // 如果是消息类型,解密消息内容
// console.log("收到数据====" + JSON.stringify(msg.data));
console.log("msg_:", data.data);
- _this.MsgList.push(JSON.parse(data.data));
+ let msg_data=JSON.parse(data.data)
+ _this.MsgList.push(msg_data);
+ if(_this.cur_user_id != msg_data.FromUserID){
+ _this.hasUnreadMsg[msg_data.FromUserID] = true;
+ }else{
+ _this.scrollToBottom();
+ }
+
//console.log("msglist:", _this.MsgList);
// 构建消息内容
}else if (data.type == "check") {
@@ -479,4 +516,14 @@ export default {
margin-top: 20px;
color: white;
}
+.unread-dot {
+ position: absolute;
+ top: 0;
+ right: 0;
+ width: 8px;
+ height: 8px;
+ background-color: red;
+ border-radius: 50%;
+ transform: translate(50%, -50%);
+}
\ No newline at end of file
diff --git a/src/views/DeviceRealVP.vue b/src/views/DeviceRealVP.vue
index 51af3fc..afce332 100644
--- a/src/views/DeviceRealVP.vue
+++ b/src/views/DeviceRealVP.vue
@@ -13,6 +13,7 @@