Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 340f75f

Browse files
update++
1 parent e9f7a90 commit 340f75f

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

‎src/views/layout/index.vue‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,14 @@ export default {
5151
},
5252
...mapGetters([
5353
'sidebar',
54-
'fullScreen'
54+
'fullScreen',
55+
'userInfo'
5556
])
5657
},
5758
mounted () {
5859
this.initMqtt()
60+
// 添加全局的键盘事件
61+
document.body.addEventListener('keyup', this.handleFullScreen)
5962
},
6063
methods: {
6164
// 全屏显示
@@ -79,23 +82,29 @@ export default {
7982
}
8083
},
8184
initMqtt () {
82-
const URL = '127.0.0.1'
85+
const URL = process.env.VUE_APP_TYPE==='localhost'?'127.0.0.1':'www.lyh.red'
8386
const client = mqtt.connect(`mqtt://${URL}:1212`)
87+
const TopicList = [
88+
`/chat/user/${this.userInfo.id}`,
89+
`/chat/group/#`,
90+
`/message/user/${this.userInfo.id}`,
91+
`/message/audit/#`
92+
]
8493
// 连接
8594
client.on('connect', () => {
8695
console.log('连接' + new Date())
87-
consttopic ='/11123'
88-
client.subscribe(topic, function (err) {
89-
if (!err) {
90-
client.publish(topic, 'Hello mqtt')
91-
}
92-
console.log('订阅成功: '+ topic)
96+
TopicList.forEach(topic => {
97+
client.subscribe(topic, function (err) {
98+
if (!err) {
99+
console.log('订阅成功: '+ topic)
100+
}
101+
})
93102
})
94103
})
95104
// 获取到消息
96105
client.on('message', (topic, message) => {
97106
// message is Buffer
98-
console.log(message.toString())
107+
console.log(topic, message.toString())
99108
})
100109
// 断开自动重连
101110
client.on('close', () => {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /