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 e426fa2

Browse files
mqtt添加,订阅主题管理完成
1 parent 6eaec18 commit e426fa2

File tree

6 files changed

+480
-29
lines changed

6 files changed

+480
-29
lines changed

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"vue-router": "~3.0.1",
2626
"vuex": "~3.0.1",
2727
"mavon-editor": "~2.6.17",
28-
"marked": "~0.6.2"
28+
"marked": "~0.6.2",
29+
"mqtt": "^2.18.8"
2930
},
3031
"devDependencies": {
3132
"@vue/cli-plugin-babel": "^3.6.0",

‎src/api/sysMan/topicMan.js‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import request from '@/common/js/request'
2+
3+
// 创建
4+
export function createApi (data) {
5+
return request({
6+
url: '/api/topic/create',
7+
method: 'post',
8+
data
9+
})
10+
}
11+
12+
// 编辑
13+
export function updateApi (data) {
14+
return request({
15+
url: '/api/topic/update',
16+
method: 'put',
17+
data
18+
})
19+
}
20+
21+
// 删除
22+
export function deleteApi (id) {
23+
return request({
24+
url: `/api/topic/delete/${id}`,
25+
method: 'delete'
26+
})
27+
}
28+
29+
// 得到单条数据
30+
export function getRowApi (id) {
31+
return request({
32+
url: `/api/topic/getRow/${id}`,
33+
method: 'get'
34+
})
35+
}
36+
37+
// 获取列表
38+
export function getListApi (params) {
39+
return request({
40+
url: '/api/topic/getList',
41+
method: 'get',
42+
params
43+
})
44+
}
45+
46+
// 获取全部
47+
export function getAllApi (params) {
48+
return request({
49+
url: '/api/topic/getAll',
50+
method: 'get',
51+
params
52+
})
53+
}

‎src/components/PageTree/index.vue‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ export default {
192192
}
193193
},
194194
watch: {
195+
defaultChecked (val) {
196+
// 将节点选中的状态初始化
197+
this.$refs.TreeComponent.setCheckedNodes([])
198+
// const result = [];
199+
for (let i = 0; i < val.length; i++) {
200+
// result.push(data.data[i].id);
201+
// 得到选中的节点,这个方法ojbk
202+
this.$refs.TreeComponent.setChecked(val[i], true)
203+
}
204+
},
195205
'rightMenu.show' (val) {
196206
if (val) {
197207
document.body.addEventListener('click', this.handlecCloseMenu)

‎src/views/layout/index.vue‎

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
</template>
2626

2727
<script>
28+
import mqtt from 'mqtt'
2829
import { mapGetters } from 'vuex'
2930
import { AppMain, Sidebar, Navbar, TagsView } from './components'
3031
@@ -54,21 +55,7 @@ export default {
5455
])
5556
},
5657
mounted () {
57-
// 添加全局的键盘事件
58-
document.body.addEventListener('keyup', this.handleFullScreen)
59-
60-
const html = `<ul>
61-
<li style="list-style: inherit; padding: 2px;">页面上的树使用右键点击</li>
62-
<li style="list-style: inherit; padding: 2px;">shift+f11页面全屏</li>
63-
<li style="list-style: inherit; padding: 2px;">图片点击会放大显示</li>
64-
<li style="list-style: inherit; padding: 2px;"><a style="color: red; text-decoration: underline" href="/#/HOWTOUSE/PAGE">更多</a></li>
65-
</ul>`
66-
this.$notify({
67-
title: '小提示',
68-
dangerouslyUseHTMLString: true,
69-
message: html,
70-
duration: 0
71-
})
58+
this.initMqtt()
7259
},
7360
methods: {
7461
// 全屏显示
@@ -90,6 +77,30 @@ export default {
9077
if (this.fullScreen && e.keyCode === 27) {
9178
this.$store.commit('app/TOGGLE_FULLSCREEN', !this.fullScreen)
9279
}
80+
},
81+
initMqtt () {
82+
const URL = process.env.VUE_APP_TYPE === 'localhost' ? '10.61.0.69' : 'www.lyh.red'
83+
const client = mqtt.connect(`mqtt://${URL}:1212`)
84+
// 连接
85+
client.on('connect', () => {
86+
console.log('连接' + new Date())
87+
const topic = '/11123'
88+
client.subscribe(topic, function (err) {
89+
if (!err) {
90+
client.publish(topic, 'Hello mqtt')
91+
}
92+
console.log('订阅成功: ' + topic)
93+
})
94+
})
95+
// 获取到消息
96+
client.on('message', (topic, message) => {
97+
// message is Buffer
98+
console.log(message.toString())
99+
})
100+
// 断开自动重连
101+
client.on('close', () => {
102+
console.log('close重新连接' + new Date())
103+
})
93104
}
94105
}
95106
}

‎src/views/sysMan/subTopicMan/index.vue‎

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
(0)

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