4f6550f1
monkeyhouyi
消息提醒弹框页面样式
|
1
2
|
<template>
<div class="News">
|
93186f57
monkeyhouyi
前端整改页面
|
3
4
|
<el-popover placement="left" width="300" trigger="click">
<NewsDialog ref="MessageDialog" @changeMagNum="changeMagNum" />
|
06c7a82f
李宇
最新代码
|
5
|
<div slot="reference" class="news-item" >
|
4f6550f1
monkeyhouyi
消息提醒弹框页面样式
|
6
|
<div class="icon-item">
|
06c7a82f
李宇
最新代码
|
7
8
9
10
|
<div class="red-spot" v-show="isHaveMsg"></div>
<i class="el-icon-message-solid"></i>
</div>
<div class="nav-title">我的消息</div>
|
4f6550f1
monkeyhouyi
消息提醒弹框页面样式
|
11
12
|
</div>
</el-popover>
|
06c7a82f
李宇
最新代码
|
13
14
15
16
17
18
|
<div class="news-item" @click="gopath">
<div class="icon-item">
<i class="el-icon-data-line"></i>
</div>
<div class="nav-title">大屏</div>
</div>
|
4f6550f1
monkeyhouyi
消息提醒弹框页面样式
|
19
20
21
22
23
24
25
26
27
28
29
|
</div>
</template>
<script>
import ReconnectingWebSocket from "reconnecting-websocket";
import NewsDialog from "./NewsDialog";
export default {
name: "News",
components: { NewsDialog },
data() {
return {
|
93186f57
monkeyhouyi
前端整改页面
|
30
31
32
33
|
isHaveMsg: false,
isTwinkle: false,
messageCount: 0,
userList: [],
|
4f6550f1
monkeyhouyi
消息提醒弹框页面样式
|
34
35
36
|
};
},
created() {
|
93186f57
monkeyhouyi
前端整改页面
|
37
|
this.initWebSocket();
|
4f6550f1
monkeyhouyi
消息提醒弹框页面样式
|
38
39
40
|
},
computed: {},
mounted() {},
|
006cc67a
monkeyhouyi
巡查上报
|
41
|
watch: {},
|
4f6550f1
monkeyhouyi
消息提醒弹框页面样式
|
42
43
44
|
destroyed() {
if (this.socket) {
//离开路由之后断开websocket连接
|
006cc67a
monkeyhouyi
巡查上报
|
45
46
47
|
this.socket.close();
this.socket = null;
this.$store.commit("SET_SOCKET", this.socket);
|
4f6550f1
monkeyhouyi
消息提醒弹框页面样式
|
48
49
50
|
}
},
methods: {
|
06c7a82f
李宇
最新代码
|
51
52
53
|
gopath(){
window.location.href = 'http://10.0.0.208:5000/HomePage/index.html';
},
|
006cc67a
monkeyhouyi
巡查上报
|
54
55
|
changeMagNum(val) {
this.isHaveMsg = val ? true : false;
|
5a14192c
monkeyhouyi
1
|
56
|
this.messageCount = val;
|
006cc67a
monkeyhouyi
巡查上报
|
57
|
},
|
4f6550f1
monkeyhouyi
消息提醒弹框页面样式
|
58
|
initWebSocket() {
|
4f6550f1
monkeyhouyi
消息提醒弹框页面样式
|
59
60
61
|
this.socket = this.$store.getters.socket || null;
if ("WebSocket" in window) {
if (!this.socket) {
|
b4af9364
monkeyhouyi
消息管理修改
|
62
|
console.log(this.define.WebSocketUrl, 'this.define.WebSocketUrl');
|
4f6550f1
monkeyhouyi
消息提醒弹框页面样式
|
63
64
65
66
67
68
|
this.socket = new ReconnectingWebSocket(this.define.WebSocketUrl);
this.$store.commit("SET_SOCKET", this.socket);
}
//添加事件监听
let socket = this.socket;
socket.onopen = () => {
|
b4af9364
monkeyhouyi
消息管理修改
|
69
|
console.log('连接成功')
|
4f6550f1
monkeyhouyi
消息提醒弹框页面样式
|
70
71
72
73
74
75
76
77
78
|
var onConnection = {
method: "OnConnection",
token: this.$store.getters.token,
mobileDevice: false,
};
socket.send(JSON.stringify(onConnection));
};
socket.onmessage = (event) => {
let data = JSON.parse(event.data);
|
93186f57
monkeyhouyi
前端整改页面
|
79
|
console.log(data, "event.data");
|
4f6550f1
monkeyhouyi
消息提醒弹框页面样式
|
80
|
if (data.method == "initMessage") {
|
4f6550f1
monkeyhouyi
消息提醒弹框页面样式
|
81
|
this.isTwinkle = !!data.unreadNums.length;
|
93186f57
monkeyhouyi
前端整改页面
|
82
|
this.$refs.MessageDialog.init();
|
4f6550f1
monkeyhouyi
消息提醒弹框页面样式
|
83
84
85
86
87
88
89
90
91
|
}
//用户在线
if (data.method == "Online") {
}
//用户离线
if (data.method == "Offline") {
}
//消息推送(消息公告用的)
if (data.method == "messagePush") {
|
5a14192c
monkeyhouyi
1
|
92
93
94
95
96
97
|
this.$refs.MessageDialog.init();
this.$notify({
title: '消息推送',
message: data.title,
position: 'bottom-right'
});
|
4f6550f1
monkeyhouyi
消息提醒弹框页面样式
|
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
}
//用户过期
if (data.method == "logout") {
this.$message({
message: data.msg || "登录过期,请重新登录",
type: "error",
duration: 1000,
onClose: () => {
this.$store.dispatch("resetToken").then(() => {
location.reload();
});
},
});
}
//接收对方发送的消息
if (data.method == "receiveMessage") {
|
006cc67a
monkeyhouyi
巡查上报
|
114
|
console.log("receiveMessage", "接收对方发送的消息", data);
|
4f6550f1
monkeyhouyi
消息提醒弹框页面样式
|
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
//判断是否打开窗口
if (
this.$refs.UserList &&
this.$refs.UserList.$refs.NCCIm &&
this.$refs.UserList.$refs.NCCIm.visible
) {
if (this.$refs.UserList.$refs.NCCIm.info.id === data.formUserId) {
let messIitem = {
userId: data.formUserId,
messageType: data.messageType,
message: data.formMessage,
dateTime: this.ncc.toDate(data.dateTime),
};
this.$refs.UserList.$refs.NCCIm.addItem(messIitem);
//更新已读
let updateReadMessage = {
method: "UpdateReadMessage",
formUserId: data.formUserId,
token: this.$store.getters.token,
};
socket.send(JSON.stringify(updateReadMessage));
this.$refs.UserList.updateReply(data);
} else {
this.$refs.UserList.updateReply(data, 1);
this.isTwinkle = true;
}
} else {
this.$refs.UserList.updateReply(data, 1);
this.isTwinkle = true;
}
}
//显示自己发送的消息
if (data.method == "sendMessage") {
|
006cc67a
monkeyhouyi
巡查上报
|
148
|
console.log("sendMessage", "显示自己发送的消息", data);
|
4f6550f1
monkeyhouyi
消息提醒弹框页面样式
|
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
if (this.$refs.UserList.$refs.NCCIm.info.id !== data.toUserId)
return;
//添加到客户端
let messIitem = {
userId: data.UserId,
messageType: data.messageType,
message: data.toMessage,
dateTime: this.ncc.toDate(data.dateTime),
};
this.$refs.UserList.updateLatestMessage(data);
this.$refs.UserList.$refs.NCCIm.addItem(messIitem);
}
//消息列表
if (data.method == "messageList") {
|
006cc67a
monkeyhouyi
巡查上报
|
163
|
console.log("messageList", "消息列表", data);
|
4f6550f1
monkeyhouyi
消息提醒弹框页面样式
|
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
this.$refs.UserList.$refs.NCCIm.getList(data);
}
};
}
},
},
};
</script>
<style scoped lang="scss">
.News {
.news-item {
display: flex;
flex-direction: column;
align-items: center;
|
ecc43230
monkeyhouyi
优化首页,应用管理
|
178
|
justify-content: center;
|
4f6550f1
monkeyhouyi
消息提醒弹框页面样式
|
179
180
181
182
183
|
color: #fff;
cursor: pointer;
margin-bottom: 15px;
font-size: 14px;
width: 100%;
|
ecc43230
monkeyhouyi
优化首页,应用管理
|
184
|
height: 80px;
|
4f6550f1
monkeyhouyi
消息提醒弹框页面样式
|
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
&:hover {
background-color: rgba(228, 231, 237, 0.23);
}
&:active {
background-color: #dfdada34;
.nav-title {
color: #1890ff;
}
}
.icon-item {
position: relative;
width: 24px;
height: 18px;
text-align: center;
line-height: 30px;
|
ecc43230
monkeyhouyi
优化首页,应用管理
|
200
|
font-size: 30px;
|
4f6550f1
monkeyhouyi
消息提醒弹框页面样式
|
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
margin: 8px;
.red-spot {
position: absolute;
right: -6px;
top: -6px;
width: 8px;
height: 8px;
background-color: red;
border-radius: 50%;
}
}
.nav-title {
line-height: 30px;
}
}
}
</style>
|