@zhangqingcq/vgce 0.1.25 → 0.1.26

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.25",
3
+ "version": "0.1.26",
4
4
  "description": "Vector graphics configure editor. svg组态编辑器。基于vue3.3+ts+element-plus+vite",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -33,14 +33,28 @@
33
33
  import { fileRead, fileWrite } from '@/utils/file-read-write'
34
34
  import { useEditPrivateStore } from '@/stores/system'
35
35
  import { setEditorLoadTime } from '@/utils'
36
+ import { onMounted } from 'vue'
36
37
 
37
38
  setEditorLoadTime()
38
39
 
39
40
  const emits = defineEmits(['onReturn', 'onPreview', 'onSave'])
40
41
  const props = withDefaults(
41
- defineProps<{ customToolbar?: IConfig; vueComp?: Record<string, any>; data?: string; saveFile?: boolean }>(),
42
+ defineProps<{
43
+ customToolbar?: IConfig
44
+ vueComp?: Record<string, any>
45
+ data?: string
46
+ saveFile?: boolean
47
+ mqtt?: { cover: boolean; url: string; user: string; pwd: string; topics: string }
48
+ }>(),
42
49
  {
43
- saveFile: false
50
+ saveFile: false,
51
+ mqtt: () => ({
52
+ cover: false,
53
+ url: '',
54
+ user: '',
55
+ pwd: '',
56
+ topics: ''
57
+ })
44
58
  }
45
59
  )
46
60
  const globalStore = useGlobalStore(pinia)
@@ -126,6 +140,14 @@
126
140
  centerRef.value.onCanvasMouseUp()
127
141
  }
128
142
 
143
+ onMounted(() => {
144
+ configStore.net.mqtt.useGlobalMqtt = Boolean(props.mqtt?.cover)
145
+ configStore.net.mqtt.global.url = props.mqtt?.url || ''
146
+ configStore.net.mqtt.global.user = props.mqtt?.user || ''
147
+ configStore.net.mqtt.global.pwd = props.mqtt?.pwd || ''
148
+ configStore.net.mqtt.global.topics = props.mqtt?.topics || ''
149
+ })
150
+
129
151
  defineExpose({
130
152
  setGraphNodeJson
131
153
  })
@@ -173,16 +173,21 @@
173
173
  <span style="font-weight: bold">MQTT</span>
174
174
  </template>
175
175
  <el-form label-width="60px" label-position="left">
176
- <el-form-item label="URL" size="small">
176
+ <el-form-item label="外部配置" size="small">
177
+ <el-switch v-model="configStore.net.mqtt.useGlobalMqtt" /><span style="color: #999"
178
+ >(开启后这里无需配置)</span
179
+ >
180
+ </el-form-item>
181
+ <el-form-item label="URL" size="small" v-if="!configStore.net.mqtt.useGlobalMqtt">
177
182
  <el-input v-model="configStore.net.mqtt.url" placeholder="如 ws://127.0.0.1:4500" />
178
183
  </el-form-item>
179
- <el-form-item label="用户名" size="small">
184
+ <el-form-item label="用户名" size="small" v-if="!configStore.net.mqtt.useGlobalMqtt">
180
185
  <el-input v-model="configStore.net.mqtt.user" placeholder="username" />
181
186
  </el-form-item>
182
- <el-form-item label="密码" size="small">
187
+ <el-form-item label="密码" size="small" v-if="!configStore.net.mqtt.useGlobalMqtt">
183
188
  <el-input v-model="configStore.net.mqtt.pwd" placeholder="password" />
184
189
  </el-form-item>
185
- <el-form-item label="Topics" size="small">
190
+ <el-form-item label="Topics" size="small" v-if="!configStore.net.mqtt.useGlobalMqtt">
186
191
  <el-input v-model="configStore.net.mqtt.topics" placeholder="topics" />
187
192
  </el-form-item>
188
193
  </el-form>
@@ -31,7 +31,12 @@
31
31
 
32
32
  const emit = defineEmits(['onMessage', 'onEvent'])
33
33
  const props = withDefaults(
34
- defineProps<{ vueComp?: Record<string, any>; data?: IDataModel; canvasDrag?: boolean; showCanvasInfo?: boolean }>(),
34
+ defineProps<{
35
+ vueComp?: Record<string, any>
36
+ data?: IDataModel
37
+ canvasDrag?: boolean
38
+ showCanvasInfo?: boolean
39
+ }>(),
35
40
  {
36
41
  canvasDrag: true,
37
42
  showCanvasInfo: true
@@ -55,10 +60,17 @@
55
60
  },
56
61
  net: {
57
62
  mqtt: {
63
+ useGlobalMqtt: false,
58
64
  url: '',
59
65
  user: '',
60
66
  pwd: '',
61
- topics: ''
67
+ topics: '',
68
+ global: {
69
+ url: '',
70
+ user: '',
71
+ pwd: '',
72
+ topics: ''
73
+ }
62
74
  }
63
75
  }
64
76
  },
@@ -274,7 +286,12 @@
274
286
  }
275
287
 
276
288
  const connectNet = () => {
277
- const m = preview_data.config.net.mqtt
289
+ let m
290
+ if (preview_data.config.net.mqtt.useGlobalMqtt) {
291
+ m = preview_data.config.net.mqtt.global
292
+ } else {
293
+ m = preview_data.config.net.mqtt
294
+ }
278
295
  if (m && m.url && m.user && m.pwd && m.topics) {
279
296
  link.sub(m.url, m.user, m.pwd, m.topics, (topics: string, message: string) => {
280
297
  console.log(topics)
@@ -28,7 +28,16 @@ export const useConfigStore = defineStore('config-store', {
28
28
  return {
29
29
  svg: s,
30
30
  connection_line: t,
31
- net: { mqtt: { url: '', user: '', pwd: '', topics: '' } }
31
+ net: {
32
+ mqtt: {
33
+ useGlobalMqtt: false,
34
+ url: '',
35
+ user: '',
36
+ pwd: '',
37
+ topics: '',
38
+ global: { url: '', user: '', pwd: '', topics: '' }
39
+ }
40
+ }
32
41
  }
33
42
  },
34
43
  getters: {},
@@ -11,9 +11,16 @@ export interface IPositionCenterSvg {
11
11
 
12
12
  export interface INet {
13
13
  mqtt: {
14
+ useGlobalMqtt: boolean
14
15
  url: string
15
16
  user: string
16
17
  pwd: string
17
18
  topics: string
19
+ global: {
20
+ url: string
21
+ user: string
22
+ pwd: string
23
+ topics: string
24
+ }
18
25
  }
19
26
  }
@@ -1,21 +1,22 @@
1
- <script setup lang="ts">
2
- import SvgEditor from '@/components/svg-editor/index.vue'
3
- import { useStore } from '@/stores/main'
4
- import type { IDataModel } from '@/components/svg-editor/types'
5
- import Preview from './Preview.vue'
6
-
7
- const store = useStore()
8
-
9
- const previewShow = ref(false)
10
- function previewHandle(d: IDataModel) {
11
- store.data = d
12
- nextTick(function () {
13
- previewShow.value = true
14
- })
15
- }
16
- </script>
17
-
18
- <template>
19
- <SvgEditor :data="(store.data && JSON.stringify(store.data)) || ''" @onPreview="previewHandle" saveFile />
20
- <Preview v-if="previewShow" @back="previewShow = false" />
21
- </template>
1
+ <script setup lang="ts">
2
+ import SvgEditor from '@/components/svg-editor/index.vue'
3
+ import { useStore } from '@/stores/main'
4
+ import type { IDataModel } from '@/components/svg-editor/types'
5
+ import Preview from './Preview.vue'
6
+
7
+ const store = useStore()
8
+
9
+ const previewShow = ref(false)
10
+
11
+ function previewHandle(d: IDataModel) {
12
+ store.data = d
13
+ nextTick(function () {
14
+ previewShow.value = true
15
+ })
16
+ }
17
+ </script>
18
+
19
+ <template>
20
+ <SvgEditor :data="(store.data && JSON.stringify(store.data)) || ''" saveFile @onPreview="previewHandle" />
21
+ <Preview v-if="previewShow" @back="previewShow = false" />
22
+ </template>