Skip to content

Commit 8b47c5d

Browse files
author
puhui999
committed
websocket:分号补全保持风格统一
1 parent 64e13e6 commit 8b47c5d

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/views/infra/webSocket/index.vue

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,35 +83,35 @@ export default {
8383
// 监听 message 事件
8484
this.ws.onmessage = (event) => {
8585
try {
86-
const data = event.data
86+
const data = event.data;
8787
// 1. 收到心跳
8888
if (data === 'pong') {
89-
return
89+
return;
9090
}
9191
// 2.1 解析 type 消息类型
9292
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);
9595
if (!type) {
96-
this.$modal.msgError('未知的消息类型:' + data)
97-
return
96+
this.$modal.msgError('未知的消息类型:' + data);
97+
return;
9898
}
9999
// 2.2 消息类型:demo-message-receive
100100
if (type === 'demo-message-receive') {
101-
const single = content.single
101+
const single = content.single;
102102
this.content = this.content + "接收时间:" + getNowDateTime() + "\n" +
103103
`${single ? '单发' : '群发'}】用户编号(${content.fromUserId}):${content.text}` + "\n";
104-
return
104+
return;
105105
}
106106
// 2.3 消息类型:notice-push
107107
if (type === 'notice-push') {
108108
this.content = this.content + "接收时间:" + getNowDateTime() + "\n" + `【系统通知】:${content.title}` + "\n";
109-
return
109+
return;
110110
}
111-
this.$modal.msgError('未处理消息:' + data)
111+
this.$modal.msgError('未处理消息:' + data);
112112
} catch (error) {
113-
this.$modal.msgError('处理消息发生异常:' + event.data)
114-
console.error(error)
113+
this.$modal.msgError('处理消息发生异常:' + event.data);
114+
console.error(error);
115115
}
116116
};
117117
// 监听 close 事件
@@ -145,15 +145,15 @@ export default {
145145
const messageContent = JSON.stringify({
146146
text: this.sendText,
147147
toUserId: this.sendUserId
148-
})
148+
});
149149
// 1.2 再 JSON 化整个消息
150150
const jsonMessage = JSON.stringify({
151151
type: 'demo-message-send',
152152
content: messageContent
153-
})
153+
});
154154
// 2. 最后发送消息
155-
this.ws.send(jsonMessage)
156-
this.sendText = ''
155+
this.ws.send(jsonMessage);
156+
this.sendText = '';
157157
}
158158
},
159159
};

0 commit comments

Comments
 (0)