vue-wiring-diagram 1.0.15 → 1.0.17

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.
@@ -146,10 +146,12 @@
146
146
  <script setup>
147
147
  import {onMounted, reactive, ref,} from "vue";
148
148
  import {DeleteFilled} from '@element-plus/icons-vue'
149
- import {showPorts} from "../common.js";
149
+ import {getFieldList, showPorts} from "../common.js";
150
150
  import {get} from '../../http.js'
151
151
  import {ElMessageBox} from "element-plus";
152
152
  import {portOption} from "../settings.js";
153
+ import {defaultMatch, defaultText} from "packages/components/tools.js";
154
+ import {getDeviceList} from "/packages/components/common.js";
153
155
 
154
156
  defineOptions({
155
157
  name: 'text-control'
@@ -168,10 +170,8 @@ const fieldList = ref([])
168
170
  /**
169
171
  * 获取设备列表
170
172
  */
171
- const getDeviceList = () => {
172
- get('/cny/custom/deviceList').then(res => {
173
- deviceList.value = res.data
174
- })
173
+ const getDevices = async () => {
174
+ deviceList.value = await getDeviceList()
175
175
  }
176
176
 
177
177
  const deviceCode = ref() // 设备编码
@@ -190,19 +190,13 @@ const checkDevice = () => {
190
190
  /**
191
191
  * 获取字段列表
192
192
  */
193
- const getFields = () => {
194
- get('/cny/custom/monitorInfo', {
195
- deviceCode: currentDevice.deviceCode,
196
- fieldType: 1
197
- }).then(res => {
198
- fieldList.value = res.data
199
- })
193
+ const getFields = async () => {
194
+ fieldList.value = await getFieldList(currentDevice.deviceCode)
200
195
  }
201
196
 
202
- const regexp = /\$\{(.*?)\}/g // 匹配${}
203
197
 
204
198
  const replace = (str) => {
205
- return str.replace(regexp, '--')
199
+ return str.replace(defaultMatch, defaultText)
206
200
  }
207
201
 
208
202
  /**
@@ -219,16 +213,15 @@ const checkField = (row) => {
219
213
  const content = props.payload.data.content
220
214
  props.payload.data.content = text.value = content + '${' + currentDevice.deviceName + '.' + row.name + '}' + unit
221
215
  // 查找所有${}
222
- const matches = content.match(regexp)
216
+ const matches = content.match(defaultMatch)
223
217
  const index = matches?.length || 0
224
- props.payload.data.field.push({
218
+ props.payload.data.fields.push({
225
219
  index: index,
226
220
  deviceName: currentDevice.deviceName,
227
221
  deviceCode: currentDevice.deviceCode,
228
222
  field: row.dataField,
229
223
  })
230
224
  props.payload.label = replace(props.payload.data.content)
231
- console.log('label:', props.payload.label, 'content:', props.payload.data.content, 'field:', props.payload.data.field)
232
225
  })
233
226
  }
234
227
 
@@ -271,11 +264,11 @@ const changeContent = () => {
271
264
  // 判断是否删除的是}
272
265
  if (props.payload.data.content.endsWith('}')) {
273
266
  // 找出所有的${}
274
- const matches = props.payload.data.content.match(regexp)
267
+ const matches = props.payload.data.content.match(defaultMatch)
275
268
  if (matches) {
276
269
  const index = matches.length - 1
277
270
  // 删除数组中最后一个元素
278
- props.payload.data.field.splice(index, 1)
271
+ props.payload.data.fields.splice(index, 1)
279
272
  // 删除字符串中最后一个${}
280
273
  text.value = props.payload.data.content.substring(0, props.payload.data.content.lastIndexOf('${'))
281
274
  }
@@ -362,7 +355,7 @@ const deletePort = (id) => {
362
355
 
363
356
  onMounted(() => {
364
357
  getPorts()
365
- getDeviceList()
358
+ getDevices()
366
359
  document.addEventListener('selectionchange', () => {
367
360
  // 判断是否在输入框内
368
361
  if (document.activeElement.tagName === 'TEXTAREA') {
@@ -0,0 +1,231 @@
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
+ import {lineOptions} from "packages/components/settings.js";
8
+ import {STOP} from "packages/components/enums.js";
9
+
10
+ /**
11
+ * 图形变换
12
+ * @returns {Transform}
13
+ */
14
+ export const transform = () => {
15
+ return new Transform({
16
+ resizing: {
17
+ enabled: true,
18
+ preserveAspectRatio: false
19
+ },
20
+ rotating: true,
21
+ })
22
+ }
23
+
24
+ /**
25
+ * 快捷键
26
+ * @returns {Keyboard}
27
+ */
28
+ export const keyboard = () => {
29
+ return new Keyboard()
30
+ }
31
+
32
+ /**
33
+ * 吸附线
34
+ * @returns {Snapline}
35
+ */
36
+ export const snapLine = () => {
37
+ return new Snapline()
38
+ }
39
+
40
+ /**
41
+ * 复制粘贴
42
+ * @returns {Clipboard|*}
43
+ */
44
+ export const clipboard = () => {
45
+ return new Clipboard({
46
+ format(key) {
47
+ return key.replace(/\s/g, '').replace('cmd', 'command')
48
+ },
49
+ })
50
+ }
51
+
52
+ // 排除撤销重做的命令
53
+ const excludeHistoryCommand = [
54
+ 'tools',
55
+ 'ports'
56
+ ]
57
+
58
+ /**
59
+ * 撤销重做
60
+ * @returns {History}
61
+ */
62
+ export const history = () => {
63
+ return new History({
64
+ beforeAddCommand: (name, args) => {
65
+ if (excludeHistoryCommand.includes(args.key)) {
66
+ return false
67
+ }
68
+ }
69
+ })
70
+ }
71
+
72
+ /**
73
+ * 框选
74
+ * @returns {Selection}
75
+ */
76
+ export const selection = () => {
77
+ return new Selection({
78
+ enabled: true,
79
+ multiple: true, //多选
80
+ rubberband: true, //框选节点
81
+ modifiers: ['alt'],
82
+ showNodeSelectionBox: true,
83
+ })
84
+ }
85
+
86
+ /**
87
+ * 删除
88
+ * @param graph
89
+ * @returns {boolean}
90
+ */
91
+ export const deleteCell = (graph) => {
92
+ const cells = graph.getSelectedCells()
93
+ if (cells.length) {
94
+ graph.removeCells(cells)
95
+ }
96
+ }
97
+
98
+ /**
99
+ * 复制
100
+ * @param graph
101
+ * @returns {boolean}
102
+ */
103
+ export const copyCell = (graph) => {
104
+ const cells = graph.getSelectedCells()
105
+ if (cells.length) {
106
+ graph.copy(cells)
107
+ }
108
+ }
109
+
110
+ /**
111
+ * 粘贴
112
+ * @param graph
113
+ * @returns {boolean}
114
+ */
115
+ export const pasteCell = (graph) => {
116
+ if (!graph.isClipboardEmpty()) {
117
+ const cells = graph.paste({offset: 32})
118
+ graph.cleanSelection()
119
+ graph.select(cells)
120
+ }
121
+ }
122
+
123
+ /**
124
+ * 撤销
125
+ * @param graph
126
+ * @returns {boolean}
127
+ */
128
+ export const undoCell = (graph) => {
129
+ if (graph.canUndo()) {
130
+ graph.undo()
131
+ }
132
+ }
133
+
134
+ /**
135
+ * 重做
136
+ * @param graph
137
+ * @returns {boolean}
138
+ */
139
+ export const redoCell = (graph) => {
140
+ if (graph.canRedo()) {
141
+ graph.redo()
142
+ }
143
+ }
144
+
145
+ /**
146
+ * 添加线工具
147
+ * @param cell
148
+ */
149
+ export const addLineTools = (cell) => {
150
+ cell.addTools([
151
+ {
152
+ name: 'vertices',
153
+ args: {
154
+ snapRadius: 3,
155
+ attrs: {
156
+ r: 3,
157
+ fill: '#239edd',
158
+ cursor: 'move',
159
+ 'stroke-width': 2
160
+ },
161
+ modifiers: ['shift']
162
+ },
163
+ },
164
+ {
165
+ name: 'segments',
166
+ args: {
167
+ attrs: {
168
+ stroke: '#239edd',
169
+ strokeWidth: 2,
170
+ strokeDasharray: '5 5',
171
+ },
172
+ },
173
+ },
174
+ {
175
+ name: 'source-arrowhead',
176
+ args: {
177
+ attrs: {
178
+ stroke: '#239edd',
179
+ },
180
+ },
181
+ },
182
+ {
183
+ name: 'target-arrowhead',
184
+ args: {
185
+ attrs: {
186
+ stroke: '#239edd',
187
+ },
188
+ },
189
+ },
190
+ ]);
191
+ }
192
+
193
+ /**
194
+ * 判断是直线还是管道
195
+ */
196
+ export const isLineOrPipe = () => {
197
+ return lineOptions.attrs.line2.strokeDasharray === 0 ? 'line' : 'pipe'
198
+ }
199
+
200
+ /**
201
+ * 设置管道方向
202
+ * @param direction none无 forward-pipe正向 reverse-pipe反向
203
+ */
204
+ export const setPipeDirection = (direction) => {
205
+ if (direction !== 'none') {
206
+ return direction + ' 30s infinite linear'
207
+ } else {
208
+ return ''
209
+ }
210
+ }
211
+
212
+ /**
213
+ * 设置随机数
214
+ * @returns {number}
215
+ */
216
+ export const setMathRandom = () => {
217
+ return Math.random()
218
+ }
219
+
220
+ // 默认展示的字符串
221
+ export const defaultText = '--'
222
+
223
+ // 默认匹配字符串
224
+ export const defaultMatch = /\$\{(.*?)\}/g
225
+
226
+ // 默认条件单挑配置
227
+ export const defaultCondition = {
228
+ min: 0,
229
+ max: 0,
230
+ direction: STOP,
231
+ }