@zhangqingcq/vgce 0.1.18 → 0.1.20

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.18",
3
+ "version": "0.1.20",
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",
@@ -287,6 +287,7 @@
287
287
  }
288
288
  }
289
289
  }
290
+
290
291
  const onSvgMouseEnter = (select_item: IDoneJson, index: number, e: MouseEvent) => {
291
292
  e.preventDefault()
292
293
  e.stopPropagation()
@@ -613,6 +614,7 @@
613
614
  }
614
615
  }
615
616
  }
617
+
616
618
  const onCanvasMouseUp = () => {
617
619
  //如果鼠标不是按下状态
618
620
  if (globalStore.mouse_info.state != EMouseInfoState.Down) {
@@ -666,7 +668,11 @@
666
668
  globalStore.setHandleSvgInfo(null)
667
669
  for (let e of globalStore.done_json) {
668
670
  const t = selectRect.value
669
- e.selected = e.x > t.x && e.x < t.x + t.with && e.y > t.y && e.y < t.y + t.height
671
+ e.selected =
672
+ e.center_position.x > t.x &&
673
+ e.center_position.x < t.x + t.with &&
674
+ e.center_position.y > t.y &&
675
+ e.center_position.y < t.y + t.height
670
676
  }
671
677
  globalStore.intention = EGlobalStoreIntention.None
672
678
  } else if (globalStore.intention != EGlobalStoreIntention.Select) {
@@ -683,6 +689,7 @@
683
689
  }
684
690
  contextMenuStore.display = false
685
691
  }
692
+
686
693
  const onCanvasMouseDown = (e: MouseEvent) => {
687
694
  const { clientX, clientY } = e
688
695
  if (globalStore.intention === EGlobalStoreIntention.Connection) {
@@ -765,6 +772,32 @@
765
772
  }
766
773
  }
767
774
 
775
+ const onLineMouseDown = (e: Record<string, any>) => {
776
+ if (globalStore.intention === EGlobalStoreIntention.Connection && globalStore.handle_svg_info) {
777
+ if (e.button === 0) {
778
+ //鼠标左键创建新线段
779
+ if (globalStore.handle_svg_info.info.props.point_position.val.length !== 2) {
780
+ //鼠标移动后的实时位置(相对于起始点,只在创建第一个点时记录了鼠标原始位置)
781
+ globalStore.handle_svg_info.info.props.point_position.val.push({
782
+ x:
783
+ globalStore.mouse_info.new_position_x -
784
+ globalStore.mouse_info.position_x -
785
+ svgEditLayoutStore.center_offset.x,
786
+ y:
787
+ globalStore.mouse_info.new_position_y -
788
+ globalStore.mouse_info.position_y -
789
+ svgEditLayoutStore.center_offset.y
790
+ })
791
+ }
792
+ } else if (e.button === 2) {
793
+ //鼠标右键结束线段绘制
794
+ globalStore.intention = EGlobalStoreIntention.None
795
+ setSvgActualInfo(globalStore.done_json[globalStore.handle_svg_info.index])
796
+ globalStore.setHandleSvgInfo(null)
797
+ }
798
+ }
799
+ }
800
+
768
801
  function onMousewheel(e: any) {
769
802
  if (e?.wheelDelta) {
770
803
  if (e.wheelDelta > 0) {
@@ -1003,6 +1036,7 @@
1003
1036
  v-if="item.type === EDoneJsonType.ConnectionLine"
1004
1037
  :item-info="item"
1005
1038
  :point-visible="visible_info.connection_line && visible_info.select_item.info?.id == item.id"
1039
+ @mousedown="onLineMouseDown"
1006
1040
  />
1007
1041
  <use
1008
1042
  v-else-if="item.type === EDoneJsonType.File"
@@ -157,7 +157,7 @@
157
157
  <el-scrollbar max-height="60vh">
158
158
  <div class="font-bold mb-10px text-15px guide-title" style="padding-top: 16px">多选</div>
159
159
  <div
160
- >在画布空白区域按住鼠标左键可以框选(图形坐标在框选区域即判定被选中),也可以按住ctrl+鼠标左键点图形进行多选</div
160
+ >在画布空白区域按住鼠标左键可以框选(图形中心点在框选区域即判定被选中),也可以按住ctrl+鼠标左键点图形进行多选</div
161
161
  >
162
162
  <div class="el-divider el-divider--horizontal" role="separator" style="--el-border-style: solid"></div>
163
163
  <div class="font-bold mb-10px text-15px guide-title">拖动画布</div>
@@ -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(
@@ -274,7 +276,7 @@
274
276
  const connectNet = () => {
275
277
  const m = preview_data.config.net.mqtt
276
278
  if (m && m.url && m.user && m.pwd && m.topics) {
277
- 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) => {
278
280
  console.log(topics)
279
281
  console.log(message.toString())
280
282
  //暴露给外部,让用户自己处理消息,message可以用JSON.parse解析成对象(后端推给前端的MQTT消息内容需要是JSON格式)
@@ -310,7 +312,12 @@
310
312
  connectNet()
311
313
  })
312
314
 
313
- onBeforeUnmount(close)
315
+ onBeforeUnmount(() => {
316
+ link.close(() => {
317
+ link.destroy()
318
+ link = null
319
+ })
320
+ })
314
321
 
315
322
  defineExpose({
316
323
  setNodeAttrByID
@@ -6,7 +6,7 @@ const t: IConfigItem = {
6
6
  type: EDoneJsonType.File,
7
7
  config: {
8
8
  can_zoom: true,
9
- have_anchor: true,
9
+ have_anchor: false,
10
10
  actual_rect: true
11
11
  },
12
12
  display: true,
@@ -8,7 +8,7 @@ const t: IConfigItem = {
8
8
  type: EDoneJsonType.CustomSvg,
9
9
  config: {
10
10
  can_zoom: true,
11
- have_anchor: true,
11
+ have_anchor: false,
12
12
  actual_rect: true
13
13
  },
14
14
  display: true,
@@ -8,7 +8,7 @@ const t: IConfigItem = {
8
8
  type: EDoneJsonType.CustomSvg,
9
9
  config: {
10
10
  can_zoom: true,
11
- have_anchor: true,
11
+ have_anchor: false,
12
12
  actual_rect: true
13
13
  },
14
14
  display: true,
@@ -9,7 +9,7 @@ const t: IConfigItem = {
9
9
  display: true,
10
10
  config: {
11
11
  can_zoom: true,
12
- have_anchor: true,
12
+ have_anchor: false,
13
13
  actual_rect: true
14
14
  },
15
15
  props: {
@@ -9,7 +9,7 @@ const t: IConfigItem = {
9
9
  display: true,
10
10
  config: {
11
11
  can_zoom: true,
12
- have_anchor: true,
12
+ have_anchor: false,
13
13
  actual_rect: true
14
14
  },
15
15
  props: {
@@ -7,7 +7,7 @@ const t: IConfigItem = {
7
7
  type: EDoneJsonType.File,
8
8
  config: {
9
9
  can_zoom: true,
10
- have_anchor: true,
10
+ have_anchor: false,
11
11
  actual_rect: true
12
12
  },
13
13
  display: true,
@@ -8,7 +8,7 @@ const t: IConfigItem = {
8
8
  type: EDoneJsonType.Vue,
9
9
  config: {
10
10
  can_zoom: false,
11
- have_anchor: true,
11
+ have_anchor: false,
12
12
  actual_rect: true
13
13
  },
14
14
  display: true,
@@ -8,7 +8,7 @@ const t: IConfigItem = {
8
8
  type: EDoneJsonType.Vue,
9
9
  config: {
10
10
  can_zoom: false,
11
- have_anchor: true,
11
+ have_anchor: false,
12
12
  actual_rect: true
13
13
  },
14
14
  display: true,
@@ -8,7 +8,7 @@ const t: IConfigItem = {
8
8
  type: EDoneJsonType.Vue,
9
9
  config: {
10
10
  can_zoom: false,
11
- have_anchor: true,
11
+ have_anchor: false,
12
12
  actual_rect: true
13
13
  },
14
14
  display: true,
@@ -8,7 +8,7 @@ const t: IConfigItem = {
8
8
  type: EDoneJsonType.Vue,
9
9
  config: {
10
10
  can_zoom: true,
11
- have_anchor: true,
11
+ have_anchor: false,
12
12
  actual_rect: true
13
13
  },
14
14
  display: true,
@@ -8,7 +8,7 @@ const t: IConfigItem = {
8
8
  type: EDoneJsonType.Vue,
9
9
  config: {
10
10
  can_zoom: true,
11
- have_anchor: true,
11
+ have_anchor: false,
12
12
  actual_rect: true
13
13
  },
14
14
  display: true,
@@ -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