vue-wiring-diagram 1.0.14 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/style.css +1 -1
- package/dist/vue-wiring-diagram.es.js +6441 -6398
- package/dist/vue-wiring-diagram.umd.js +35 -35
- package/package.json +1 -1
- package/packages/components/editor/index.vue +63 -114
- package/packages/components/graph-control/index.vue +0 -1
- package/packages/components/settings.js +4 -10
- package/packages/components/tools.js +196 -0
package/package.json
CHANGED
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
</template>
|
|
65
65
|
|
|
66
66
|
<script setup>
|
|
67
|
-
import {onMounted, reactive, ref, shallowRef} from "vue";
|
|
67
|
+
import {defineComponent, onMounted, reactive, ref, shallowRef} from "vue";
|
|
68
68
|
import moment from 'moment'
|
|
69
69
|
import {ElMessage, ElTooltip} from "element-plus";
|
|
70
70
|
import {getData, showPorts} from "../common.js";
|
|
@@ -75,22 +75,26 @@ import edgeControl from "../edge-control/index.vue";
|
|
|
75
75
|
import Shortcuts from "../Shortcuts.vue";
|
|
76
76
|
import {Graph} from "@antv/x6";
|
|
77
77
|
import {Stencil} from '@antv/x6-plugin-stencil'
|
|
78
|
-
import {Transform} from "@antv/x6-plugin-transform";
|
|
79
|
-
import {Snapline} from "@antv/x6-plugin-snapline";
|
|
80
|
-
import {Clipboard} from '@antv/x6-plugin-clipboard'
|
|
81
|
-
import {Keyboard} from "@antv/x6-plugin-keyboard";
|
|
82
|
-
import {Selection} from '@antv/x6-plugin-selection'
|
|
83
|
-
import {History} from '@antv/x6-plugin-history'
|
|
84
78
|
import {Export} from "@antv/x6-plugin-export";
|
|
85
79
|
import imageControl from "../image-control/index.vue";
|
|
86
|
-
import {imageOptions} from "../image-control/imageOptions.js";
|
|
87
80
|
import {baseShape} from "../baseShape.js";
|
|
88
81
|
import {portsOptions} from "../portsOptions.js";
|
|
89
82
|
import {Document, View, ArrowDown} from "@element-plus/icons-vue";
|
|
90
83
|
import WiringDiagramPreview from "../preview/index.vue";
|
|
91
84
|
import ImageManagement from "../image-control/image-management.vue";
|
|
92
85
|
import {get} from "packages/http.js";
|
|
93
|
-
import
|
|
86
|
+
import {
|
|
87
|
+
clipboard,
|
|
88
|
+
keyboard,
|
|
89
|
+
snapLine,
|
|
90
|
+
transform,
|
|
91
|
+
history,
|
|
92
|
+
selection,
|
|
93
|
+
setMathRandom,
|
|
94
|
+
deleteCell,
|
|
95
|
+
copyCell,
|
|
96
|
+
pasteCell, undoCell, redoCell, addLineTools
|
|
97
|
+
} from "packages/components/tools.js";
|
|
94
98
|
|
|
95
99
|
defineOptions({
|
|
96
100
|
name: 'editor'
|
|
@@ -106,7 +110,7 @@ const props = defineProps({
|
|
|
106
110
|
const graph = ref() // 画布实例
|
|
107
111
|
// 控制器
|
|
108
112
|
const controls = reactive({
|
|
109
|
-
label:
|
|
113
|
+
label: '', // 控制器
|
|
110
114
|
component: shallowRef(null), // 控制器组件
|
|
111
115
|
})
|
|
112
116
|
const controlsKey = ref(null) // 控制器key
|
|
@@ -117,13 +121,15 @@ const payload = ref(null)
|
|
|
117
121
|
*/
|
|
118
122
|
const initGraph = () => {
|
|
119
123
|
const container = document.getElementById('drawing-board')
|
|
120
|
-
window.__x6_instances__ = []
|
|
121
124
|
graph.value = new Graph({
|
|
122
125
|
container: container,
|
|
123
126
|
autoResize: true,
|
|
124
127
|
panning: true,
|
|
125
128
|
mousewheel: true,
|
|
126
129
|
connecting: {
|
|
130
|
+
snap: true,
|
|
131
|
+
allowEdge: true,
|
|
132
|
+
highlight: true,
|
|
127
133
|
router: 'orth',
|
|
128
134
|
connectionPoint: {
|
|
129
135
|
name: 'anchor',
|
|
@@ -138,91 +144,74 @@ const initGraph = () => {
|
|
|
138
144
|
zIndex: 0,
|
|
139
145
|
})
|
|
140
146
|
}
|
|
141
|
-
}
|
|
142
|
-
})
|
|
143
|
-
window.__x6_instances__.push(graph.value)
|
|
144
|
-
|
|
145
|
-
graph.value.use(
|
|
146
|
-
new Transform({
|
|
147
|
-
resizing: {
|
|
148
|
-
enabled: true,
|
|
149
|
-
preserveAspectRatio: false
|
|
150
|
-
},
|
|
151
|
-
rotating: true,
|
|
152
|
-
})
|
|
153
|
-
)
|
|
154
|
-
|
|
155
|
-
graph.value.use(new Keyboard())
|
|
156
|
-
graph.value.use(new Snapline())
|
|
157
|
-
graph.value.use(new Clipboard({
|
|
158
|
-
format(key) {
|
|
159
|
-
return key.replace(/\s/g, '').replace('cmd', 'command')
|
|
160
147
|
},
|
|
161
|
-
})
|
|
162
|
-
graph.value.use(
|
|
163
|
-
graph.value.use(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
showNodeSelectionBox: true,
|
|
169
|
-
}))
|
|
170
|
-
|
|
148
|
+
})
|
|
149
|
+
graph.value.use(transform())
|
|
150
|
+
graph.value.use(keyboard())
|
|
151
|
+
graph.value.use(snapLine())
|
|
152
|
+
graph.value.use(clipboard())
|
|
153
|
+
graph.value.use(history())
|
|
154
|
+
graph.value.use(selection())
|
|
171
155
|
graph.value.bindKey(['delete', 'backspace'], () => {
|
|
172
|
-
|
|
173
|
-
if (cells.length) {
|
|
174
|
-
graph.value.removeCells(cells)
|
|
175
|
-
}
|
|
176
|
-
return false
|
|
156
|
+
deleteCell(graph.value)
|
|
177
157
|
})
|
|
178
|
-
|
|
179
158
|
graph.value.bindKey(['ctrl+c', 'cmd + c'], () => {
|
|
180
|
-
|
|
181
|
-
if (cells.length) {
|
|
182
|
-
graph.value.copy(cells)
|
|
183
|
-
ElMessage.success('复制成功')
|
|
184
|
-
}
|
|
185
|
-
return false
|
|
159
|
+
copyCell(graph.value)
|
|
186
160
|
})
|
|
187
|
-
|
|
188
161
|
graph.value.bindKey(['ctrl+v', 'cmd + v'], () => {
|
|
189
|
-
|
|
190
|
-
const cells = graph.value.paste({offset: 32})
|
|
191
|
-
graph.value.cleanSelection()
|
|
192
|
-
graph.value.select(cells)
|
|
193
|
-
ElMessage.success('粘贴成功')
|
|
194
|
-
}
|
|
195
|
-
return false
|
|
162
|
+
pasteCell(graph.value)
|
|
196
163
|
})
|
|
197
|
-
|
|
198
164
|
graph.value.bindKey(['ctrl+z', 'cmd + z'], () => {
|
|
199
|
-
|
|
200
|
-
graph.value.undo()
|
|
201
|
-
}
|
|
202
|
-
return false
|
|
165
|
+
undoCell(graph.value)
|
|
203
166
|
})
|
|
204
|
-
|
|
205
167
|
graph.value.bindKey(['ctrl+y', 'cmd + y'], () => {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
168
|
+
redoCell(graph.value)
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
let setZIndexTimer = null
|
|
172
|
+
|
|
173
|
+
//给线添加拐点
|
|
174
|
+
graph.value.on('edge:mouseenter', ({cell}) => {
|
|
175
|
+
clearTimeout(setZIndexTimer)
|
|
176
|
+
cell.toFront()
|
|
177
|
+
addLineTools(cell)
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
// 隐藏线段的拐点
|
|
181
|
+
graph.value.on('edge:mouseleave', ({cell}) => {
|
|
182
|
+
setZIndexTimer = setTimeout(() => {
|
|
183
|
+
cell.toBack()
|
|
184
|
+
cell.removeTools()
|
|
185
|
+
}, 300)
|
|
186
|
+
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
//连接桩显示
|
|
190
|
+
graph.value.on('node:mouseenter', () => {
|
|
191
|
+
showPorts('#drawing-board', true)
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
//连接桩隐藏
|
|
195
|
+
graph.value.on('node:mouseleave', () => {
|
|
196
|
+
showPorts("#drawing-board", false)
|
|
210
197
|
})
|
|
211
198
|
|
|
199
|
+
// 导出插件
|
|
200
|
+
graph.value.use(new Export())
|
|
201
|
+
|
|
212
202
|
//选中画布
|
|
213
203
|
graph.value.on('blank:click', ({e, x, y}) => {
|
|
214
204
|
payload.value = graph
|
|
215
205
|
controls.component = GraphControl
|
|
216
206
|
controls.label = '画布属性'
|
|
217
|
-
controlsKey.value =
|
|
207
|
+
controlsKey.value = setMathRandom()
|
|
218
208
|
})
|
|
219
209
|
|
|
220
210
|
|
|
221
211
|
//选中节点
|
|
222
212
|
graph.value.on('cell:click', ({cell}) => {
|
|
223
|
-
console.log('cell:click', cell, cell?.data?.type ?? cell?.shape)
|
|
224
213
|
payload.value = cell
|
|
225
|
-
controlsKey.value =
|
|
214
|
+
controlsKey.value = setMathRandom()
|
|
226
215
|
if (cell.data?.type === 'text') {
|
|
227
216
|
controls.component = textControl
|
|
228
217
|
controls.label = '文本属性'
|
|
@@ -246,43 +235,6 @@ const initGraph = () => {
|
|
|
246
235
|
controls.component = null
|
|
247
236
|
controls.label = null
|
|
248
237
|
})
|
|
249
|
-
|
|
250
|
-
//给线添加拐点
|
|
251
|
-
graph.value.on('edge:mouseenter', ({cell}) => {
|
|
252
|
-
cell.addTools([
|
|
253
|
-
{
|
|
254
|
-
name: 'vertices',
|
|
255
|
-
args: {
|
|
256
|
-
snapRadius: 3,
|
|
257
|
-
attrs: {
|
|
258
|
-
r: 3,
|
|
259
|
-
fill: '#239edd',
|
|
260
|
-
cursor: 'move',
|
|
261
|
-
'stroke-width': 0
|
|
262
|
-
},
|
|
263
|
-
modifiers: ['alt']
|
|
264
|
-
},
|
|
265
|
-
},
|
|
266
|
-
]);
|
|
267
|
-
})
|
|
268
|
-
|
|
269
|
-
// 隐藏线段的拐点
|
|
270
|
-
graph.value.on('edge:mouseleave', ({cell}) => {
|
|
271
|
-
cell.removeTools()
|
|
272
|
-
})
|
|
273
|
-
|
|
274
|
-
//连接桩显示
|
|
275
|
-
graph.value.on('node:mouseenter', () => {
|
|
276
|
-
showPorts('#drawing-board', true)
|
|
277
|
-
})
|
|
278
|
-
|
|
279
|
-
//连接桩隐藏
|
|
280
|
-
graph.value.on('node:mouseleave', () => {
|
|
281
|
-
showPorts("#drawing-board", false)
|
|
282
|
-
})
|
|
283
|
-
|
|
284
|
-
// 导出插件
|
|
285
|
-
graph.value.use(new Export())
|
|
286
238
|
}
|
|
287
239
|
|
|
288
240
|
const stencil = ref()
|
|
@@ -343,7 +295,6 @@ const initStencil = () => {
|
|
|
343
295
|
document.getElementById('stencil').appendChild(stencil.value.container)
|
|
344
296
|
})
|
|
345
297
|
}).finally(() => {
|
|
346
|
-
// 添加 hover 事件监听器
|
|
347
298
|
setTimeout(() => {
|
|
348
299
|
const nodes = stencil.value.container.querySelectorAll('.x6-node');
|
|
349
300
|
nodes.forEach((node, index) => {
|
|
@@ -358,7 +309,6 @@ const initStencil = () => {
|
|
|
358
309
|
text.style.fill = '#ffffff';
|
|
359
310
|
}
|
|
360
311
|
}
|
|
361
|
-
// 添加 hover 事件监听器
|
|
362
312
|
node.addEventListener('mouseenter', (e) => {
|
|
363
313
|
if (index > baseShape.length) {
|
|
364
314
|
const text = node.querySelector('text');
|
|
@@ -376,7 +326,7 @@ const initStencil = () => {
|
|
|
376
326
|
}
|
|
377
327
|
})
|
|
378
328
|
});
|
|
379
|
-
},
|
|
329
|
+
}, 200)
|
|
380
330
|
})
|
|
381
331
|
}
|
|
382
332
|
|
|
@@ -469,7 +419,6 @@ const drawLine = () => {
|
|
|
469
419
|
*/
|
|
470
420
|
const adaptive = () => {
|
|
471
421
|
graph.value.zoomToFit({maxScale: 1, padding: 20})
|
|
472
|
-
// ElMessage.success('自适应成功')
|
|
473
422
|
}
|
|
474
423
|
|
|
475
424
|
const dialog = reactive({show: false}) // 弹窗
|
|
@@ -76,7 +76,6 @@ import {ref} from "vue";
|
|
|
76
76
|
const props = defineProps({
|
|
77
77
|
payload: Object
|
|
78
78
|
})
|
|
79
|
-
console.log(props.payload.value.options.grid)
|
|
80
79
|
const color = ref(props.payload.value.options.background?.color || null) // 画布背景颜色
|
|
81
80
|
const visible = ref(props.payload.value.options?.grid?.visible || null) // 网格是否显示
|
|
82
81
|
const size = ref(props.payload.value.options?.grid?.size || 10) // 网格大小
|
|
@@ -33,6 +33,7 @@ export const stencilOptions = {
|
|
|
33
33
|
},
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
// 连接桩配置
|
|
36
37
|
export const portOption = {
|
|
37
38
|
position: 'absolute',
|
|
38
39
|
args: {
|
|
@@ -93,7 +94,7 @@ export const textOptions = {
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
|
|
96
|
-
//
|
|
97
|
+
// 线配置
|
|
97
98
|
export const lineOptions = {
|
|
98
99
|
line: {
|
|
99
100
|
stroke: '#ffffff',
|
|
@@ -105,7 +106,7 @@ export const lineOptions = {
|
|
|
105
106
|
offset: 0,
|
|
106
107
|
},
|
|
107
108
|
name: null
|
|
108
|
-
},
|
|
109
|
+
},
|
|
109
110
|
targetMarker: {
|
|
110
111
|
args: {
|
|
111
112
|
width: 10,
|
|
@@ -113,13 +114,6 @@ export const lineOptions = {
|
|
|
113
114
|
offset: 0,
|
|
114
115
|
},
|
|
115
116
|
name: null
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
ports: {
|
|
119
|
-
groups: {
|
|
120
|
-
ports: {
|
|
121
|
-
portOption
|
|
122
|
-
},
|
|
123
|
-
}
|
|
117
|
+
},
|
|
124
118
|
},
|
|
125
119
|
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import {Transform} from "@antv/x6-plugin-transform";
|
|
2
|
+
import {Keyboard} from "@antv/x6-plugin-keyboard";
|
|
3
|
+
import {Snapline} from "@antv/x6-plugin-snapline";
|
|
4
|
+
import {Clipboard} from "@antv/x6-plugin-clipboard";
|
|
5
|
+
import {History} from "@antv/x6-plugin-history";
|
|
6
|
+
import {Selection} from "@antv/x6-plugin-selection";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 图形变换
|
|
10
|
+
* @returns {Transform}
|
|
11
|
+
*/
|
|
12
|
+
export const transform = () => {
|
|
13
|
+
return new Transform({
|
|
14
|
+
resizing: {
|
|
15
|
+
enabled: true,
|
|
16
|
+
preserveAspectRatio: false
|
|
17
|
+
},
|
|
18
|
+
rotating: true,
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 快捷键
|
|
24
|
+
* @returns {Keyboard}
|
|
25
|
+
*/
|
|
26
|
+
export const keyboard = () => {
|
|
27
|
+
return new Keyboard()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 吸附线
|
|
32
|
+
* @returns {Snapline}
|
|
33
|
+
*/
|
|
34
|
+
export const snapLine = () => {
|
|
35
|
+
return new Snapline()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 复制粘贴
|
|
40
|
+
* @returns {Clipboard|*}
|
|
41
|
+
*/
|
|
42
|
+
export const clipboard = () => {
|
|
43
|
+
return new Clipboard({
|
|
44
|
+
format(key) {
|
|
45
|
+
return key.replace(/\s/g, '').replace('cmd', 'command')
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 排除撤销重做的命令
|
|
51
|
+
const excludeHistoryCommand = [
|
|
52
|
+
'tools',
|
|
53
|
+
'ports'
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 撤销重做
|
|
58
|
+
* @returns {History}
|
|
59
|
+
*/
|
|
60
|
+
export const history = () => {
|
|
61
|
+
return new History({
|
|
62
|
+
beforeAddCommand: (name, args) => {
|
|
63
|
+
if (excludeHistoryCommand.includes(args.key)) {
|
|
64
|
+
return false
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 框选
|
|
72
|
+
* @returns {Selection}
|
|
73
|
+
*/
|
|
74
|
+
export const selection = () => {
|
|
75
|
+
return new Selection({
|
|
76
|
+
enabled: true,
|
|
77
|
+
multiple: true, //多选
|
|
78
|
+
rubberband: true, //框选节点
|
|
79
|
+
modifiers: ['alt'],
|
|
80
|
+
showNodeSelectionBox: true,
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 删除
|
|
86
|
+
* @param graph
|
|
87
|
+
* @returns {boolean}
|
|
88
|
+
*/
|
|
89
|
+
export const deleteCell = (graph) => {
|
|
90
|
+
const cells = graph.getSelectedCells()
|
|
91
|
+
if (cells.length) {
|
|
92
|
+
graph.removeCells(cells)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 复制
|
|
98
|
+
* @param graph
|
|
99
|
+
* @returns {boolean}
|
|
100
|
+
*/
|
|
101
|
+
export const copyCell = (graph) => {
|
|
102
|
+
const cells = graph.getSelectedCells()
|
|
103
|
+
if (cells.length) {
|
|
104
|
+
graph.copy(cells)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 粘贴
|
|
110
|
+
* @param graph
|
|
111
|
+
* @returns {boolean}
|
|
112
|
+
*/
|
|
113
|
+
export const pasteCell = (graph) => {
|
|
114
|
+
if (!graph.isClipboardEmpty()) {
|
|
115
|
+
const cells = graph.paste({offset: 32})
|
|
116
|
+
graph.cleanSelection()
|
|
117
|
+
graph.select(cells)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 撤销
|
|
123
|
+
* @param graph
|
|
124
|
+
* @returns {boolean}
|
|
125
|
+
*/
|
|
126
|
+
export const undoCell = (graph) => {
|
|
127
|
+
if (graph.canUndo()) {
|
|
128
|
+
graph.undo()
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 重做
|
|
134
|
+
* @param graph
|
|
135
|
+
* @returns {boolean}
|
|
136
|
+
*/
|
|
137
|
+
export const redoCell = (graph) => {
|
|
138
|
+
if (graph.canRedo()) {
|
|
139
|
+
graph.redo()
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 添加线工具
|
|
145
|
+
* @param cell
|
|
146
|
+
*/
|
|
147
|
+
export const addLineTools = (cell) => {
|
|
148
|
+
cell.addTools([
|
|
149
|
+
{
|
|
150
|
+
name: 'vertices',
|
|
151
|
+
args: {
|
|
152
|
+
snapRadius: 3,
|
|
153
|
+
attrs: {
|
|
154
|
+
r: 3,
|
|
155
|
+
fill: '#239edd',
|
|
156
|
+
cursor: 'move',
|
|
157
|
+
'stroke-width': 2
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: 'segments',
|
|
163
|
+
args: {
|
|
164
|
+
attrs: {
|
|
165
|
+
stroke: '#239edd',
|
|
166
|
+
strokeWidth: 2,
|
|
167
|
+
strokeDasharray: '5 5',
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
name: 'source-arrowhead',
|
|
173
|
+
args: {
|
|
174
|
+
attrs: {
|
|
175
|
+
stroke: '#239edd',
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
name: 'target-arrowhead',
|
|
181
|
+
args: {
|
|
182
|
+
attrs: {
|
|
183
|
+
stroke: '#239edd',
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
]);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* 设置随机数
|
|
192
|
+
* @returns {number}
|
|
193
|
+
*/
|
|
194
|
+
export const setMathRandom = () => {
|
|
195
|
+
return Math.random()
|
|
196
|
+
}
|