@zhangqingcq/vgce 0.0.13 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. package/README.md +16 -2
  2. package/dist/style.css +1 -1
  3. package/dist/vgce.js +28 -34
  4. package/dist/vgce.umd.cjs +5 -5
  5. package/package.json +3 -2
  6. package/src/App.vue +11 -0
  7. package/src/assets/base.less +49 -0
  8. package/src/assets/icons/add.svg +1 -0
  9. package/src/assets/icons/delete.svg +12 -0
  10. package/src/assets/icons/export.svg +1 -0
  11. package/src/assets/icons/group.svg +13 -0
  12. package/src/assets/icons/import.svg +1 -0
  13. package/src/assets/icons/lock.svg +7 -0
  14. package/src/assets/icons/menu-fold.svg +9 -0
  15. package/src/assets/icons/menu-unfold.svg +9 -0
  16. package/src/assets/icons/preview.svg +6 -0
  17. package/src/assets/icons/redo.svg +8 -0
  18. package/src/assets/icons/return.svg +8 -0
  19. package/src/assets/icons/rotate.svg +1 -0
  20. package/src/assets/icons/save.svg +9 -0
  21. package/src/assets/icons/setting.svg +6 -0
  22. package/src/assets/icons/undo.svg +7 -0
  23. package/src/assets/icons/ungroup.svg +16 -0
  24. package/src/assets/icons/unlock.svg +7 -0
  25. package/src/assets/main.less +6 -0
  26. package/src/assets/svgs/alternator.svg +8 -0
  27. package/src/assets/svgs/bot-12.svg +1 -0
  28. package/src/assets/svgs/bot-2.svg +1 -0
  29. package/src/assets/svgs/bot-3.svg +1 -0
  30. package/src/assets/svgs/bot-7.svg +1 -0
  31. package/src/assets/svgs/bot-9.svg +94 -0
  32. package/src/assets/svgs/car.svg +1 -0
  33. package/src/assets/svgs/circuit-breaker.svg +11 -0
  34. package/src/assets/svgs/clock-a.svg +23 -0
  35. package/src/assets/svgs/common-table.svg +7 -0
  36. package/src/assets/svgs/el-button.svg +10 -0
  37. package/src/assets/svgs/el-tag.svg +13 -0
  38. package/src/assets/svgs/hospital.svg +1 -0
  39. package/src/assets/svgs/house.svg +1 -0
  40. package/src/assets/svgs/light.svg +24 -0
  41. package/src/assets/svgs/now-time.svg +9 -0
  42. package/src/assets/svgs/package.svg +1 -0
  43. package/src/assets/svgs/pie-charts.svg +10 -0
  44. package/src/assets/svgs/progress-a.svg +1 -0
  45. package/src/assets/svgs/reservoir.svg +10 -0
  46. package/src/assets/svgs/svg-text.svg +5 -0
  47. package/src/assets/svgs/switch-a.svg +5 -0
  48. package/src/assets/svgs/traction-transformer.svg +11 -0
  49. package/src/components/ace-edit/index.ts +27 -0
  50. package/src/components/config/index.ts +450 -0
  51. package/src/components/config/types.ts +25 -0
  52. package/src/components/svg-analysis/index.vue +11 -0
  53. package/src/components/svg-editor/center-panel/index.vue +867 -0
  54. package/src/components/svg-editor/center-panel/types.ts +11 -0
  55. package/src/components/svg-editor/component-tree/index.vue +33 -0
  56. package/src/components/svg-editor/connection-line/index.vue +125 -0
  57. package/src/components/svg-editor/connection-panel/index.vue +198 -0
  58. package/src/components/svg-editor/export-json/index.vue +37 -0
  59. package/src/components/svg-editor/handle-panel/index.vue +342 -0
  60. package/src/components/svg-editor/import-json/index.vue +37 -0
  61. package/src/components/svg-editor/index.vue +280 -0
  62. package/src/components/svg-editor/left-panel/index.vue +83 -0
  63. package/src/components/svg-editor/right-panel/code-edit-modal.vue +50 -0
  64. package/src/components/svg-editor/right-panel/common-animate.vue +96 -0
  65. package/src/components/svg-editor/right-panel/condition.vue +101 -0
  66. package/src/components/svg-editor/right-panel/dynamic-el-form-item.vue +97 -0
  67. package/src/components/svg-editor/right-panel/index.vue +304 -0
  68. package/src/components/svg-editor/right-panel/list.vue +86 -0
  69. package/src/components/svg-editor/top-panel/index.vue +139 -0
  70. package/src/components/svg-editor/types.ts +22 -0
  71. package/src/components/svg-viewer/index.vue +340 -0
  72. package/src/components/vue3-ruler-tool/index.vue +506 -0
  73. package/src/config/files/clock-a.vue +66 -0
  74. package/src/config/files/common-table.vue +49 -0
  75. package/src/config/files/light-a.vue +72 -0
  76. package/src/config/files/now-time.vue +53 -0
  77. package/src/config/files/pie-charts.vue +72 -0
  78. package/src/config/files/progress.vue +40 -0
  79. package/src/config/files/svg-text.vue +39 -0
  80. package/src/config/files/switch-a.vue +45 -0
  81. package/src/config/index.ts +28 -0
  82. package/src/config/svg/animation/index.ts +8 -0
  83. package/src/config/svg/animation/reservoir.ts +32 -0
  84. package/src/config/svg/custom/clock-a.ts +23 -0
  85. package/src/config/svg/custom/index.ts +11 -0
  86. package/src/config/svg/custom/light.ts +29 -0
  87. package/src/config/svg/custom/svg-text.ts +54 -0
  88. package/src/config/svg/custom/switch-a.ts +29 -0
  89. package/src/config/svg/index.ts +12 -0
  90. package/src/config/svg/stateful/circuit-breaker.ts +38 -0
  91. package/src/config/svg/stateful/index.ts +8 -0
  92. package/src/config/svg/stateless/alternator.ts +28 -0
  93. package/src/config/svg/stateless/bot-12.ts +22 -0
  94. package/src/config/svg/stateless/bot-2.ts +22 -0
  95. package/src/config/svg/stateless/bot-3.ts +22 -0
  96. package/src/config/svg/stateless/bot-7.ts +22 -0
  97. package/src/config/svg/stateless/bot-9.ts +22 -0
  98. package/src/config/svg/stateless/car.ts +22 -0
  99. package/src/config/svg/stateless/hospital.ts +22 -0
  100. package/src/config/svg/stateless/house.ts +22 -0
  101. package/src/config/svg/stateless/index.ts +30 -0
  102. package/src/config/svg/stateless/package.ts +22 -0
  103. package/src/config/svg/stateless/traction-transformer.ts +28 -0
  104. package/src/config/types.ts +126 -0
  105. package/src/config/vue/component/button.ts +57 -0
  106. package/src/config/vue/component/common-table.ts +124 -0
  107. package/src/config/vue/component/index.ts +13 -0
  108. package/src/config/vue/component/now-time.ts +29 -0
  109. package/src/config/vue/component/progress.ts +29 -0
  110. package/src/config/vue/component/tag.ts +46 -0
  111. package/src/config/vue/echarts/index.ts +8 -0
  112. package/src/config/vue/echarts/pie-charts.ts +60 -0
  113. package/src/config/vue/index.ts +5 -0
  114. package/src/hooks.ts +47 -0
  115. package/src/index.ts +14 -0
  116. package/src/main.ts +15 -0
  117. package/src/router.ts +24 -0
  118. package/src/stores/config/index.ts +44 -0
  119. package/src/stores/config/types.ts +27 -0
  120. package/src/stores/global/index.ts +109 -0
  121. package/src/stores/global/types.ts +115 -0
  122. package/src/stores/main.ts +10 -0
  123. package/src/stores/svg-edit-layout/index.ts +17 -0
  124. package/src/stores/svg-edit-layout/types.ts +8 -0
  125. package/src/stores/system/index.ts +174 -0
  126. package/src/stores/system/types.ts +43 -0
  127. package/src/utils/fetch.ts +351 -0
  128. package/src/utils/file-read-write.ts +26 -0
  129. package/src/utils/index.ts +397 -0
  130. package/src/utils/mqtt-net.ts +48 -0
  131. package/src/utils/proxy.ts +7 -0
  132. package/src/utils/scale-core.ts +214 -0
  133. package/src/utils/types.ts +13 -0
  134. package/src/views/EditorS.vue +18 -0
  135. package/src/views/Preview.vue +12 -0
@@ -0,0 +1,340 @@
1
+ <script setup lang="ts">
2
+ import { getCurrentInstance, onMounted, onBeforeUnmount, reactive } from 'vue'
3
+ import { pinia } from '@/hooks'
4
+ import { useGlobalStore } from '@/stores/global'
5
+ import { EGlobalStoreIntention, EMouseInfoState } from '@/stores/global/types'
6
+ import type { IDoneJson } from '@/stores/global/types'
7
+ import { getCommonClass, prosToVBind, setArrItemByID, valFormat } from '@/utils'
8
+
9
+ import { EDoneJsonType, EEventAction, EEventType } from '@/config/types'
10
+ import ConnectionLine from '@/components/svg-editor/connection-line/index.vue'
11
+
12
+ import { vueComp } from '@/config'
13
+ import type { IDataModel } from '@/components/svg-editor/types'
14
+ import 'element-plus/dist/index.css'
15
+ import 'animate.css'
16
+
17
+ import { sub, close } from '@/utils/mqtt-net'
18
+
19
+ //注册所有组件
20
+ const instance = getCurrentInstance()
21
+ Object.keys(vueComp).forEach((key: string) => {
22
+ if (!Object.keys(instance?.appContext?.components as any).includes(key)) {
23
+ // @ts-ignore
24
+ instance?.appContext.app.component(key, vueComp[key])
25
+ }
26
+ })
27
+ const props = withDefaults(defineProps<{ data?: IDataModel; canvasDrag?: boolean }>(), {
28
+ canvasDrag: true
29
+ })
30
+ const preview_data = reactive(
31
+ props.data ?? {
32
+ layout_center: {
33
+ x: 0,
34
+ y: 0
35
+ },
36
+ config: {
37
+ svg: {
38
+ background_color: '#fff',
39
+ scale: 1,
40
+ position_center: {
41
+ x: -333,
42
+ y: -113
43
+ },
44
+ svg_position_center: {
45
+ x: 50,
46
+ y: 50
47
+ }
48
+ },
49
+ net: { mqtt: { url: '', user: '', pwd: '', topics: '' } }
50
+ },
51
+ done_json: []
52
+ }
53
+ )
54
+ const globalStore = useGlobalStore(pinia)
55
+
56
+ const onCanvasMouseMove = (e: MouseEvent) => {
57
+ //如果鼠标不是按下状态 连线除外
58
+ if (
59
+ globalStore.mouse_info.state != EMouseInfoState.Down &&
60
+ globalStore.intention !== EGlobalStoreIntention.Connection
61
+ ) {
62
+ return
63
+ }
64
+ if (!props.canvasDrag) {
65
+ console.log(props.canvasDrag)
66
+ return
67
+ }
68
+ const { clientX, clientY } = e
69
+ globalStore.mouse_info.new_position_x =
70
+ globalStore.mouse_info.now_position_x + clientX - globalStore.mouse_info.position_x
71
+ globalStore.mouse_info.new_position_y =
72
+ globalStore.mouse_info.now_position_y + clientY - globalStore.mouse_info.position_y
73
+ if (globalStore.intention == EGlobalStoreIntention.MoveCanvas) {
74
+ //移动画布
75
+ preview_data.layout_center.x = globalStore.mouse_info.new_position_x
76
+ preview_data.layout_center.y = globalStore.mouse_info.new_position_y
77
+ }
78
+ }
79
+ const onCanvasMouseUp = () => {
80
+ //如果鼠标不是按下状态
81
+ if (globalStore.mouse_info.state != EMouseInfoState.Down) {
82
+ return
83
+ }
84
+ if (globalStore.intention != EGlobalStoreIntention.Select) {
85
+ globalStore.intention = EGlobalStoreIntention.None
86
+ }
87
+ globalStore.setMouseInfo({
88
+ state: EMouseInfoState.Up,
89
+ position_x: 0,
90
+ position_y: 0,
91
+ now_position_x: 0,
92
+ now_position_y: 0,
93
+ new_position_x: 0,
94
+ new_position_y: 0
95
+ })
96
+ }
97
+ const onCanvasMouseDown = (e: MouseEvent) => {
98
+ console.log('onCanvasMouseDown', e)
99
+ const { clientX, clientY } = e
100
+ //点击画布 未选中组件 拖动画布
101
+ globalStore.intention = EGlobalStoreIntention.MoveCanvas
102
+ globalStore.setMouseInfo({
103
+ state: EMouseInfoState.Down,
104
+ position_x: clientX,
105
+ position_y: clientY,
106
+ now_position_x: preview_data.layout_center.x,
107
+ now_position_y: preview_data.layout_center.y,
108
+ new_position_x: preview_data.layout_center.x,
109
+ new_position_y: preview_data.layout_center.y
110
+ })
111
+ }
112
+ const getActualBoundScale = (
113
+ actual_bound: {
114
+ x: number
115
+ y: number
116
+ width: number
117
+ height: number
118
+ },
119
+ scale_x: number,
120
+ scale_y: number
121
+ ) => {
122
+ return {
123
+ x: actual_bound.x - (actual_bound.width / 2) * scale_x + actual_bound.width / 2,
124
+ y: actual_bound.y - (actual_bound.height / 2) * scale_y + actual_bound.height / 2,
125
+ width: actual_bound.width * scale_x,
126
+ height: actual_bound.height * scale_y
127
+ }
128
+ }
129
+ const setNodeAttrByID = (id: string, attr: string, val: any) => {
130
+ return setArrItemByID(id, attr, val, preview_data.done_json)
131
+ }
132
+ const eventHandle = (root: IDoneJson) => {
133
+ if (root.events?.length > 0) {
134
+ for (let e of root.events) {
135
+ if (e.type === EEventType.Click || e.type === EEventType.Change) {
136
+ if (e.condition && e.condition.type !== 'None') {
137
+ if (e.condition.type === 'Relation' && e.condition.Relation && e.condition.Relation.relation) {
138
+ const k = e.condition.Relation.key
139
+ const r = e.condition.Relation.relation
140
+ const v = valFormat(e.condition.Relation.val)
141
+ const v2 = valFormat(e.condition.Relation.val2)
142
+
143
+ if (root.props.hasOwnProperty(k)) {
144
+ const p = root.props[k].val
145
+ if (!relationEval(p, r, v, v2)) {
146
+ continue
147
+ }
148
+ }
149
+ }
150
+ }
151
+ if (e.action === EEventAction.ChangeAttr) {
152
+ if (e.attrs && e.attrs.length > 0) {
153
+ let t
154
+ if (e.target) {
155
+ for (let item of globalStore.done_json) {
156
+ if (item.id === e.target) {
157
+ t = item
158
+ break
159
+ }
160
+ }
161
+ } else {
162
+ t = root
163
+ }
164
+
165
+ if (!t) {
166
+ continue
167
+ }
168
+
169
+ for (let a of e.attrs) {
170
+ if (t.state && t.state.hasOwnProperty(a.key)) {
171
+ t.state[a.key].default = valFormat(a.val)
172
+ } else if (t.props.hasOwnProperty(a.key)) {
173
+ t.props[a.key].val = valFormat(a.val)
174
+ }
175
+ }
176
+ }
177
+ } else if (e.action === EEventAction.JavaScript) {
178
+ const t = new Function(e.scripts)
179
+ t()
180
+ }
181
+ }
182
+ }
183
+ }
184
+ }
185
+ const relationEval = (a: any, r: string, b: any, c: any) => {
186
+ switch (r) {
187
+ case '>':
188
+ return a > b
189
+ case '>=':
190
+ return a >= b
191
+ case '<':
192
+ return a < b
193
+ case '<=':
194
+ return a <= b
195
+ case '==':
196
+ return a == b
197
+ case '!=':
198
+ return a != b
199
+ case '>=,=<':
200
+ return a >= b && a <= c
201
+ case '<,>':
202
+ return a < b || a > c
203
+ }
204
+ }
205
+
206
+ onMounted(() => {
207
+ connectNet()
208
+ })
209
+
210
+ onBeforeUnmount(close)
211
+
212
+ const connectNet = () => {
213
+ const m = preview_data.config.net.mqtt
214
+ if (m && m.url && m.user && m.pwd && m.topics) {
215
+ sub(m.url, m.user, m.pwd, m.topics, (topics: string, message: string) => {
216
+ console.log(topics)
217
+ console.log(message.toString())
218
+ })
219
+ }
220
+ }
221
+
222
+ defineExpose({
223
+ setNodeAttrByID
224
+ })
225
+ </script>
226
+
227
+ <template>
228
+ <div class="canvas" @mousedown="onCanvasMouseDown" @mousemove="onCanvasMouseMove" @mouseup="onCanvasMouseUp">
229
+ <svg
230
+ xmlns="http://www.w3.org/2000/svg"
231
+ :style="{ backgroundColor: preview_data.config.svg.background_color }"
232
+ width="100%"
233
+ height="100%"
234
+ >
235
+ <g
236
+ :transform="`translate(${preview_data.config.svg.position_center.x + preview_data.layout_center.x},${
237
+ preview_data.config.svg.position_center.y + preview_data.layout_center.y
238
+ })rotate(${0})scale(${preview_data.config.svg.scale})`"
239
+ >
240
+ <g
241
+ v-for="item in preview_data.done_json"
242
+ :key="item.id"
243
+ :transform="`translate(${item.x},${item.y})rotate(0)scale(1)`"
244
+ v-show="item.display"
245
+ @click="eventHandle(item)"
246
+ >
247
+ <g :class="`${getCommonClass(item)}`">
248
+ <g
249
+ :transform="`translate(${item.actual_bound.x + item.actual_bound.width / 2},${
250
+ item.actual_bound.y + item.actual_bound.height / 2
251
+ })rotate(${item.rotate}) scale(1) translate(${-(item.actual_bound.x + item.actual_bound.width / 2)},${-(
252
+ item.actual_bound.y +
253
+ item.actual_bound.height / 2
254
+ )})`"
255
+ >
256
+ <connection-line v-if="item.type === EDoneJsonType.ConnectionLine" :item-info="item" />
257
+ <use
258
+ v-else-if="item.type === EDoneJsonType.File"
259
+ :xlink:href="`#svg-${item.name}`"
260
+ v-bind="prosToVBind(item)"
261
+ width="100"
262
+ height="100"
263
+ :id="item.id"
264
+ :transform="`translate(${item.actual_bound.x + item.actual_bound.width / 2},${
265
+ item.actual_bound.y + item.actual_bound.height / 2
266
+ }) scale(${item.scale_x},${item.scale_y}) translate(${-(
267
+ item.actual_bound.x +
268
+ item.actual_bound.width / 2
269
+ )},${-(item.actual_bound.y + item.actual_bound.height / 2)})`"
270
+ />
271
+ <component
272
+ v-else-if="item.type === EDoneJsonType.CustomSvg"
273
+ :is="item.tag"
274
+ v-bind="prosToVBind(item)"
275
+ width="100"
276
+ height="100"
277
+ :id="item.id"
278
+ @on-change="eventHandle(item)"
279
+ :transform="`translate(${item.actual_bound.x + item.actual_bound.width / 2},${
280
+ item.actual_bound.y + item.actual_bound.height / 2
281
+ }) scale(${item.scale_x},${item.scale_y}) translate(${-(
282
+ item.actual_bound.x +
283
+ item.actual_bound.width / 2
284
+ )},${-(item.actual_bound.y + item.actual_bound.height / 2)})`"
285
+ />
286
+ <foreignObject
287
+ v-else-if="item.type === EDoneJsonType.Vue"
288
+ v-bind="getActualBoundScale(item.actual_bound, item.scale_x, item.scale_y)"
289
+ :id="`foreign-object${item.id}`"
290
+ >
291
+ <component
292
+ :is="item.tag"
293
+ v-bind="prosToVBind(item)"
294
+ :id="item.id"
295
+ @on-change="eventHandle(item)"
296
+ :transform="`translate(${item.actual_bound.x + item.actual_bound.width / 2},${
297
+ item.actual_bound.y + item.actual_bound.height / 2
298
+ }) scale(${item.scale_x},${item.scale_y}) translate(${-(
299
+ item.actual_bound.x +
300
+ item.actual_bound.width / 2
301
+ )},${-(item.actual_bound.y + item.actual_bound.height / 2)})`"
302
+ >{{ item.tag_slot }}
303
+ </component>
304
+ </foreignObject>
305
+ </g>
306
+ </g>
307
+ </g>
308
+ </g>
309
+ </svg>
310
+ </div>
311
+ </template>
312
+
313
+ <style lang="less" scoped>
314
+ .canvas {
315
+ width: 100%;
316
+ height: 100vh;
317
+ }
318
+
319
+ .svg-item-none {
320
+ cursor: move;
321
+
322
+ &:hover {
323
+ outline: 1px solid #0cf;
324
+ }
325
+ }
326
+
327
+ .svg-item-move {
328
+ cursor: move;
329
+ outline: 1px dashed rgb(23, 222, 30);
330
+ }
331
+
332
+ .svg-item-select {
333
+ cursor: move;
334
+ outline: 1px solid rgb(23, 222, 30);
335
+ }
336
+
337
+ .common-ani {
338
+ transform-box: fill-box;
339
+ }
340
+ </style>