@@ -83,35 +83,35 @@ export default {
83
83
// 监听 message 事件
84
84
this .ws .onmessage = (event ) => {
85
85
try {
86
- const data = event .data
86
+ const data = event .data ;
87
87
// 1. 收到心跳
88
88
if (data === ' pong' ) {
89
- return
89
+ return ;
90
90
}
91
91
// 2.1 解析 type 消息类型
92
92
const jsonMessage = JSON .parse (data)
93
- const type = jsonMessage .type
94
- const content = JSON .parse (jsonMessage .content )
93
+ const type = jsonMessage .type ;
94
+ const content = JSON .parse (jsonMessage .content );
95
95
if (! type) {
96
- this .$modal .msgError (' 未知的消息类型:' + data)
97
- return
96
+ this .$modal .msgError (' 未知的消息类型:' + data);
97
+ return ;
98
98
}
99
99
// 2.2 消息类型:demo-message-receive
100
100
if (type === ' demo-message-receive' ) {
101
- const single = content .single
101
+ const single = content .single ;
102
102
this .content = this .content + " 接收时间:" + getNowDateTime () + " \n " +
103
103
` 【${ single ? ' 单发' : ' 群发' } 】用户编号(${ content .fromUserId } ):${ content .text } ` + " \n " ;
104
- return
104
+ return ;
105
105
}
106
106
// 2.3 消息类型:notice-push
107
107
if (type === ' notice-push' ) {
108
108
this .content = this .content + " 接收时间:" + getNowDateTime () + " \n " + ` 【系统通知】:${ content .title } ` + " \n " ;
109
- return
109
+ return ;
110
110
}
111
- this .$modal .msgError (' 未处理消息:' + data)
111
+ this .$modal .msgError (' 未处理消息:' + data);
112
112
} catch (error) {
113
- this .$modal .msgError (' 处理消息发生异常:' + event .data )
114
- console .error (error)
113
+ this .$modal .msgError (' 处理消息发生异常:' + event .data );
114
+ console .error (error);
115
115
}
116
116
};
117
117
// 监听 close 事件
@@ -145,15 +145,15 @@ export default {
145
145
const messageContent = JSON .stringify ({
146
146
text: this .sendText ,
147
147
toUserId: this .sendUserId
148
- })
148
+ });
149
149
// 1.2 再 JSON 化整个消息
150
150
const jsonMessage = JSON .stringify ({
151
151
type: ' demo-message-send' ,
152
152
content: messageContent
153
- })
153
+ });
154
154
// 2. 最后发送消息
155
- this .ws .send (jsonMessage)
156
- this .sendText = ' '
155
+ this .ws .send (jsonMessage);
156
+ this .sendText = ' ' ;
157
157
}
158
158
},
159
159
};
0 commit comments