vue-wiring-diagram 1.0.20 → 1.1.1

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.
@@ -64,7 +64,7 @@
64
64
  </template>
65
65
 
66
66
  <script setup>
67
- import {defineComponent, onMounted, reactive, ref, shallowRef} from "vue";
67
+ import {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";
@@ -1,10 +1,17 @@
1
+ export const LINE = 'line'
2
+ export const PIPE = 'pipe'
3
+ export const ARROW = 'arrow'
4
+
1
5
  // 线类型
2
6
  export const typeList = [{
3
7
  label: '直线',
4
- value: 'line',
8
+ value: LINE,
5
9
  }, {
6
10
  label: '管道',
7
- value: 'pipe',
11
+ value: PIPE,
12
+ }, {
13
+ label: '箭头',
14
+ value: ARROW,
8
15
  }]
9
16
 
10
17
  // 箭头类型
@@ -53,8 +60,21 @@ export const directionList = [{
53
60
  value: STOP,
54
61
  }, {
55
62
  label: '正向',
56
- value: FORWARD_PIPE ,
63
+ value: FORWARD_PIPE,
57
64
  }, {
58
65
  label: '反向',
59
66
  value: REVERSE_PIPE,
60
67
  }]
68
+
69
+ export const FLASHING = 'flashing'
70
+ export const ARROWFORWARD = 'arrowForward'
71
+ export const ARROWBACKWORD = 'arrowBackward'
72
+
73
+ // 箭头方向
74
+ export const arrowDirection = [{
75
+ label: '正向',
76
+ value: ARROWFORWARD,
77
+ }, {
78
+ label: '反向',
79
+ value: ARROWBACKWORD,
80
+ }]
@@ -13,6 +13,8 @@ import {Graph} from "@antv/x6";
13
13
  import {getData, getRealData, showPorts} from "../common.js";
14
14
  import {ElMessage} from "element-plus";
15
15
  import {defaultMatch, defaultText, setPipeDirection} from "packages/components/tools.js";
16
+ import {ARROWFORWARD, FLASHING} from "packages/components/enums.js";
17
+ import {arrowBackward, arrowForward} from "packages/components/settings.js";
16
18
 
17
19
  defineOptions({
18
20
  name: 'wiring-diagram-preview'
@@ -117,10 +119,10 @@ const allFields = ref([])
117
119
  * 刷新数据
118
120
  */
119
121
  const refreshData = () => {
120
- cells.value = graph.value.getCells().filter(cell => cell?.data?.type === 'text' || cell?.data?.type === 'pipe')
122
+ cells.value = graph.value.getCells().filter(cell => cell?.data?.type === 'text' || cell?.data?.type === 'pipe' || cell?.data?.type === 'arrow')
121
123
  cells.value.forEach(item => {
122
124
  if (item?.data?.fields?.length) {
123
- item.data.fields.forEach(field => {
125
+ item?.data.fields.forEach(field => {
124
126
  if (field.field) {
125
127
  allFields.value.push({id: item?.id, fields: item?.data.fields})
126
128
  }
@@ -163,13 +165,17 @@ const setFieldData = async () => {
163
165
 
164
166
  realData?.forEach(item => {
165
167
  const cell = graph.value.getCellById(item.id)
168
+ console.log('122222222',cell)
166
169
  if (cell.data.type === 'text') {
167
170
  cell.label = replaceAllTemplateLiteralsWithArray(cell.data.content, item.fields)
168
171
  }
169
172
  if (cell.data.type === 'pipe') {
170
173
  console.log('管道详情', cell, item.fields?.[0].value)
171
174
  setPipe(cell, item.fields?.[0].value)
172
- // TODO: 暂时不支持管道
175
+ }
176
+
177
+ if (cell.data.type === 'arrow') {
178
+ setArrow(cell, item.fields?.[0].value)
173
179
  }
174
180
  })
175
181
  timer.value = setTimeout(() => {
@@ -185,7 +191,7 @@ const setFieldData = async () => {
185
191
  */
186
192
  const replaceAllTemplateLiteralsWithArray = (str, fields) => {
187
193
  let index = 0
188
- return str.replace(defaultMatch, (match, p1) => {
194
+ return str.replace(defaultMatch, () => {
189
195
  const field = fields.find(item => item.index === index)
190
196
  index++
191
197
  if (field) {
@@ -202,17 +208,37 @@ const replaceAllTemplateLiteralsWithArray = (str, fields) => {
202
208
  * @param value
203
209
  */
204
210
  const setPipe = (cell, value) => {
205
- if(!cell.data.isCondition) {
211
+ if (!cell.data.isCondition) {
206
212
  return false
207
213
  }
208
214
  for (let i = 0; i < cell.data.condition.length; i++) {
209
- if (value > cell.data.condition[i].min && value <= cell.data.condition[i].max) {
215
+ if (Number(value) > cell.data.condition[i].min && Number(value) <= cell.data.condition[i].max) {
210
216
  cell.attr('line2/style/animation', setPipeDirection(cell.data.condition[i].direction))
211
217
  return false
212
218
  }
213
219
  }
214
220
  }
215
221
 
222
+ /**
223
+ * 设置箭头
224
+ * @param cell
225
+ * @param value
226
+ */
227
+ const setArrow = (cell, value) => {
228
+ console.log(cell,value)
229
+ if (!cell.data.isCondition) {
230
+ return false
231
+ }
232
+ for (let i = 0; i < cell.data.condition.length; i++) {
233
+ if (Number(value) > cell.data.condition[i].min && Number(value) <= cell.data.condition[i].max) {
234
+ cell.attr('arrow/style/animation', cell.data.condition[i].animation === FLASHING ? 'flashing 2s infinite linear' : '')
235
+ cell.attr('arrow/d', cell.data.condition[i].direction === ARROWFORWARD ? arrowForward : arrowBackward)
236
+ cell.attr('arrow/display', cell.data.condition[i].display)
237
+ return false
238
+ }
239
+ }
240
+ }
241
+
216
242
  /**
217
243
  * \@description 画布自适应
218
244
  */
@@ -93,36 +93,136 @@ export const textOptions = {
93
93
  },
94
94
  }
95
95
 
96
+ // 默认线配置
97
+ export const defaultLine = {
98
+ markup: [
99
+ {
100
+ tagName: 'path',
101
+ selector: 'line',
102
+ groupSelector: 'lines'
103
+ },
104
+ ],
105
+ attrs: {
106
+ wrap: {
107
+ strokeWidth: 10
108
+ },
109
+ lines: {
110
+ connection: true,
111
+ strokeLinejoin: 'round',
112
+ fill: 'none',
113
+ strokeWidth: 2,
114
+ },
115
+ line: {
116
+ stroke: '#ffffff',
117
+ strokeWidth: 1,
118
+ sourceMarker: {
119
+ args: {
120
+ width: 10,
121
+ height: 10,
122
+ offset: 0,
123
+ },
124
+ name: null
125
+ },
126
+ targetMarker: {
127
+ args: {
128
+ width: 10,
129
+ height: 10,
130
+ offset: 0,
131
+ },
132
+ name: null
133
+ },
134
+ },
135
+ }
136
+ }
96
137
 
97
- // 线配置
98
- export const lineOptions = {
138
+ // 管道线配置
139
+ export const pipeOptions = {
99
140
  markup: [
100
141
  {
101
142
  tagName: 'path',
102
- selector: 'line1',
143
+ selector: 'line',
103
144
  groupSelector: 'lines'
104
145
  },
105
146
  {
106
147
  tagName: 'path',
107
- selector: 'line2',
148
+ selector: 'pipe',
108
149
  groupSelector: 'lines'
109
150
  },
110
151
  ],
111
152
  attrs: {
153
+ wrap: {
154
+ strokeWidth: 10
155
+ },
112
156
  lines: {
113
157
  connection: true,
114
158
  strokeLinejoin: 'round',
115
159
  fill: 'none',
116
160
  strokeWidth: 2,
117
161
  },
118
- line1: {
162
+ line: {
163
+ stroke: '#ffffff',
164
+ strokeWidth: 1,
165
+ targetMarker: null,
166
+ sourceMarker: null
167
+ },
168
+ pipe: {
119
169
  stroke: '#2364DD',
120
170
  strokeWidth: 1,
171
+ strokeDasharray: 5,
172
+ sourceMarker: {
173
+ args: {
174
+ width: 10,
175
+ height: 10,
176
+ offset: 0,
177
+ },
178
+ name: null
179
+ },
180
+ targetMarker: {
181
+ args: {
182
+ width: 10,
183
+ height: 10,
184
+ offset: 0,
185
+ },
186
+ name: null
187
+ },
188
+ },
189
+ }
190
+ }
191
+
192
+ // 正向箭头
193
+ export const arrowForward = 'M 0 -6 8 0 0 6 z'
194
+
195
+ // 逆向箭头
196
+ export const arrowBackward = 'M 0 -6 -8 0 0 6 z'
197
+
198
+
199
+ // 箭头线配置
200
+ export const arrowOptions = {
201
+ attrs: {
202
+ wrap: {
203
+ strokeWidth: 10
204
+ },
205
+ arrow: {
206
+ d: arrowForward,
207
+ fill: '#ED8A19',
208
+ stroke: '#ED8A19',
209
+ style: {
210
+ animation: 'flashing 2s infinite linear'
211
+ },
212
+ display: 'block',
213
+ },
214
+ arrow1: {
215
+ atConnectionRatio: 0.5,
121
216
  },
122
- line2: {
217
+ lines: {
218
+ connection: true,
219
+ strokeLinejoin: 'round',
220
+ fill: 'none',
221
+ strokeWidth: 2,
222
+ },
223
+ line: {
123
224
  stroke: '#ffffff',
124
225
  strokeWidth: 1,
125
- strokeDasharray: 0,
126
226
  sourceMarker: {
127
227
  args: {
128
228
  width: 10,
@@ -140,5 +240,23 @@ export const lineOptions = {
140
240
  name: null
141
241
  },
142
242
  },
143
- }
243
+ },
244
+ markup: [
245
+ {
246
+ tagName: 'path',
247
+ selector: 'line',
248
+ groupSelector: 'lines'
249
+ },
250
+ {
251
+ tagName: 'path',
252
+ groupSelector: 'arrow',
253
+ selector: 'arrow1',
254
+ },
255
+ ]
256
+ }
257
+
258
+ // 线配置
259
+ export const lineOptions = {
260
+ markup: defaultLine.markup,
261
+ attrs: defaultLine.attrs,
144
262
  }
@@ -5,7 +5,7 @@ import {Clipboard} from "@antv/x6-plugin-clipboard";
5
5
  import {History} from "@antv/x6-plugin-history";
6
6
  import {Selection} from "@antv/x6-plugin-selection";
7
7
  import {lineOptions} from "packages/components/settings.js";
8
- import {STOP} from "packages/components/enums.js";
8
+ import {ARROWFORWARD, FLASHING, STOP} from "packages/components/enums.js";
9
9
 
10
10
  /**
11
11
  * 图形变换
@@ -191,10 +191,16 @@ export const addLineTools = (cell) => {
191
191
  }
192
192
 
193
193
  /**
194
- * 判断是直线还是管道
194
+ * 判断当前默认线的类型
195
195
  */
196
196
  export const isLineOrPipe = () => {
197
- return lineOptions.attrs.line2.strokeDasharray === 0 ? 'line' : 'pipe'
197
+ if (lineOptions.attrs?.pipe) {
198
+ return 'pipe'
199
+ }
200
+ if (lineOptions.attrs?.arrow) {
201
+ return 'arrow'
202
+ }
203
+ return 'line'
198
204
  }
199
205
 
200
206
  /**
@@ -223,9 +229,18 @@ export const defaultText = '--'
223
229
  // 默认匹配字符串
224
230
  export const defaultMatch = /\$\{(.*?)\}/g
225
231
 
226
- // 默认条件单挑配置
227
- export const defaultCondition = {
232
+ // 默认条件管道单个配置
233
+ export const defaultPipeCondition = {
228
234
  min: 0,
229
235
  max: 0,
230
236
  direction: STOP,
231
237
  }
238
+
239
+ // 默认条件箭头线配置
240
+ export const defaultArrowCondition = {
241
+ min: 0,
242
+ max: 0,
243
+ animation: FLASHING,
244
+ direction: ARROWFORWARD,
245
+ display: 'block'
246
+ }
@@ -9,3 +9,19 @@
9
9
  stroke-dashoffset: 1000
10
10
  }
11
11
  }
12
+
13
+ // 闪烁箭头
14
+ @keyframes flashing {
15
+ 0% {
16
+ opacity: 0;
17
+ }
18
+ 35% {
19
+ opacity: 1;
20
+ }
21
+ 65% {
22
+ opacity: 1;
23
+ }
24
+ 100% {
25
+ opacity: 0;
26
+ }
27
+ }
@@ -159,4 +159,8 @@
159
159
  display: flex;
160
160
  flex-direction: column;
161
161
  gap: 10px;
162
+
163
+ .row-label{
164
+ font-size: 14px;
165
+ }
162
166
  }
@@ -241,6 +241,10 @@
241
241
  }
242
242
  }
243
243
 
244
+ ::v-deep(.el-switch__label) {
245
+ color: #ffffff;
246
+ }
247
+
244
248
  .el-table {
245
249
  --el-table-border-color: rgba(35, 100, 221, 0.3);
246
250
  --el-table-row-hover-bg-color: rgba(35, 100, 221, 0.3);