@zhangqingcq/vgce 0.1.17 → 0.1.19

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhangqingcq/vgce",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "description": "Vector graphics configure editor. svg组态编辑器。基于vue3.3+ts+element-plus+vite",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -58,7 +58,7 @@
58
58
  "animate.css": "^4.1.1",
59
59
  "axios": "^1.4.0",
60
60
  "echarts": "^5.4.1",
61
- "element-plus": "2.8.0",
61
+ "element-plus": "2.8.6",
62
62
  "lodash-es": "^4.17.21",
63
63
  "mqtt": "5.1.3",
64
64
  "pinia": "^2.1.3",
@@ -25,7 +25,7 @@
25
25
  import 'element-plus/dist/index.css'
26
26
  import 'animate.css'
27
27
 
28
- import { sub, close } from '@/utils/mqtt-net'
28
+ import Link from '@/utils/mqtt-net'
29
29
 
30
30
  setEditorLoadTime()
31
31
 
@@ -37,6 +37,8 @@
37
37
  showCanvasInfo: true
38
38
  }
39
39
  )
40
+
41
+ let link: any = Link()
40
42
  const globalStore = useGlobalStore(pinia)
41
43
  componentsRegister(props.vueComp)
42
44
  const preview_data = reactive(
@@ -206,6 +208,8 @@
206
208
  for (let a of e.attrs) {
207
209
  if (a.key === 'state') {
208
210
  t.defaultState = valFormat(a.val)
211
+ } else if (a.key === 'display') {
212
+ t.display = valFormat(a.val)
209
213
  } else if (t.props.hasOwnProperty(a.key)) {
210
214
  t.props[a.key].val = valFormat(a.val)
211
215
  }
@@ -272,7 +276,7 @@
272
276
  const connectNet = () => {
273
277
  const m = preview_data.config.net.mqtt
274
278
  if (m && m.url && m.user && m.pwd && m.topics) {
275
- sub(m.url, m.user, m.pwd, m.topics, (topics: string, message: string) => {
279
+ link.sub(m.url, m.user, m.pwd, m.topics, (topics: string, message: string) => {
276
280
  console.log(topics)
277
281
  console.log(message.toString())
278
282
  //暴露给外部,让用户自己处理消息,message可以用JSON.parse解析成对象(后端推给前端的MQTT消息内容需要是JSON格式)
@@ -308,7 +312,12 @@
308
312
  connectNet()
309
313
  })
310
314
 
311
- onBeforeUnmount(close)
315
+ onBeforeUnmount(() => {
316
+ link.close(() => {
317
+ link.destroy()
318
+ link = null
319
+ })
320
+ })
312
321
 
313
322
  defineExpose({
314
323
  setNodeAttrByID
@@ -1,59 +1,74 @@
1
1
  import { connect } from 'mqtt/dist/mqtt'
2
2
  import type { MqttClient, PacketCallback } from 'mqtt'
3
3
 
4
- let client: MqttClient
4
+ class Link {
5
+ client: MqttClient | null
5
6
 
6
- export const sub = (url: string, user: string, pwd: string, topics: string, callback: any) => {
7
- const _url = url.trim()
8
- if (!/^wss?:\/\/.*$/.test(_url)) {
9
- console.error('编辑器MQTT通信只支持ws协议 (url必须以"ws://"开头)')
10
- return
7
+ constructor() {
8
+ this.client = null
11
9
  }
12
- client = connect(_url, {
13
- username: user.trim(),
14
- password: pwd.trim(),
15
- reconnectPeriod: 600000 /*如果连不上,10分钟后重试*/
16
- })
17
-
18
- client.on('connect', () => {
19
- console.log('MQTT服务器连接成功')
20
- console.log(client.options.clientId)
21
- client.subscribe(topics, { qos: 1 })
22
- })
23
-
24
- client.on('message', callback)
25
- }
26
10
 
27
- export const pub = (url: string, user: string, pwd: string, topics: string, data: any, callback: PacketCallback) => {
28
- const _url = url.trim()
29
- if (!/^wss?:\/\/.*$/.test(_url)) {
30
- console.error('编辑器MQTT通信只支持ws协议 (url必须以"ws://"开头)')
31
- return
11
+ sub(url: string, user: string, pwd: string, topics: string, callback: any) {
12
+ const _url = url.trim()
13
+ if (!/^wss?:\/\/.*$/.test(_url)) {
14
+ console.error('编辑器MQTT通信只支持ws协议 (url必须以"ws://"开头)')
15
+ return false
16
+ }
17
+ this.client = connect(_url, {
18
+ username: user.trim(),
19
+ password: pwd.trim(),
20
+ reconnectPeriod: 600000 /*如果连不上,10分钟后重试*/
21
+ })
22
+
23
+ this.client?.on('connect', () => {
24
+ console.log('MQTT服务器连接成功')
25
+ console.log(this.client?.options.clientId)
26
+ this.client?.subscribe(topics, { qos: 1 })
27
+ })
28
+
29
+ this.client?.on('message', callback)
32
30
  }
33
- client = connect(_url, {
34
- username: user.trim(),
35
- password: pwd.trim()
36
- })
37
-
38
- client.on('connect', () => {
39
- console.log('MQTT服务器连接成功')
40
- console.log(client.options.clientId)
41
- client.publish(
42
- topics,
43
- JSON.stringify(data),
44
- {
45
- qos: 0,
46
- retain: true
47
- },
48
- callback
49
- )
50
- })
51
- }
52
31
 
53
- export const close = () => {
54
- if (client && client.end) {
55
- client.end(true, {}, () => {
32
+ pub(url: string, user: string, pwd: string, topics: string, data: any, callback: PacketCallback) {
33
+ const _url = url.trim()
34
+ if (!/^wss?:\/\/.*$/.test(_url)) {
35
+ console.error('编辑器MQTT通信只支持ws协议 (url必须以"ws://"开头)')
36
+ return false
37
+ }
38
+ this.client = connect(_url, {
39
+ username: user.trim(),
40
+ password: pwd.trim()
41
+ })
42
+
43
+ this.client?.on('connect', () => {
44
+ console.log('MQTT服务器连接成功')
45
+ console.log(this.client?.options.clientId)
46
+ this.client?.publish(
47
+ topics,
48
+ JSON.stringify(data),
49
+ {
50
+ qos: 0,
51
+ retain: true
52
+ },
53
+ callback
54
+ )
55
+ })
56
+ }
57
+
58
+ close(callback?: () => void) {
59
+ this.client?.end?.(true, {}, () => {
56
60
  console.log('MQTT服务连接关闭')
61
+ callback?.()
57
62
  })
58
63
  }
64
+
65
+ destroy() {
66
+ this.client = null
67
+ }
68
+ }
69
+
70
+ const t = function () {
71
+ return new Link()
59
72
  }
73
+
74
+ export default t
@@ -15,7 +15,7 @@
15
15
  <template>
16
16
  <div class="previewPage">
17
17
  <svg-viewer :data="store.data" />
18
- <el-button type="text" @click="back" class="backBtn" :icon="ArrowLeftBold">返回</el-button>
18
+ <el-button link @click="back" class="backBtn" :icon="ArrowLeftBold">返回</el-button>
19
19
  </div>
20
20
  </template>
21
21