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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-wiring-diagram",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "A Vue 3.x component for wiring diagram",
5
5
  "type": "module",
6
6
  "main": "dist/vue-wiring-diagram.umd.js",
@@ -23,6 +23,34 @@ export const showPorts = (div, show) => {
23
23
  }
24
24
  }
25
25
 
26
+ /**
27
+ * 获取设备列表
28
+ * @returns {Promise<unknown>}
29
+ */
30
+ export const getDeviceList = () => {
31
+ return get('/cny/custom/deviceList').then(res => {
32
+ if(res?.isOk) {
33
+ return res.data
34
+ }
35
+ })
36
+ }
37
+
38
+ /**
39
+ * 获取字段列表
40
+ * @param deviceCode
41
+ * @returns {Promise<*>}
42
+ */
43
+ export const getFieldList = (deviceCode) => {
44
+ return get('/cny/custom/monitorInfo', {
45
+ deviceCode: deviceCode,
46
+ fieldType: 1
47
+ }).then(res => {
48
+ if(res?.isOk) {
49
+ return res.data
50
+ }
51
+ })
52
+ }
53
+
26
54
  /**
27
55
  * 获取数据
28
56
  */
@@ -62,7 +90,7 @@ export const updateData = (id,data) => {
62
90
  * @returns {Promise<*>}
63
91
  */
64
92
  export const getRealData = (fields) => {
65
- return post('/cny/custom/arrRealData', fields).then(res => {
93
+ return post('/cny/custom/arrRealData2', fields).then(res => {
66
94
  if (res?.isOk) {
67
95
  return res.data
68
96
  } else {
@@ -0,0 +1,88 @@
1
+ /**
2
+ * @Author: HuaYJ
3
+ * @Date: 2024/10/24 10:23
4
+ */
5
+ <template>
6
+ <div class="form-container">
7
+ <el-button type="primary" size="small" @click="addItemBtnClick" style="margin-bottom: 10px">添加条件</el-button>
8
+ <el-table :data="items" size="small" border>
9
+ <el-table-column prop="min" label="最小值" width="150" align="center">
10
+ <template #default="scope">
11
+ <el-input-number v-model="scope.row.min" size="small" controls-position="right" ></el-input-number>
12
+ </template>
13
+ </el-table-column>
14
+ <el-table-column prop="max" label="最大值" width="150" align="center">
15
+ <template #default="scope">
16
+ <el-input-number v-model="scope.row.max" size="small" controls-position="right"></el-input-number>
17
+ </template>
18
+ </el-table-column>
19
+ <el-table-column prop="direction" label="流向" align="center">
20
+ <template #default="scope">
21
+ <el-select v-model="scope.row.direction" size="small">
22
+ <el-option v-for="item in directionList" :key="item.value" :label="item.label" :value="item.value"></el-option>
23
+ </el-select>
24
+ </template>
25
+ </el-table-column>
26
+ <el-table-column label="操作" align="center">
27
+ <template #default="scope">
28
+ <el-button type="danger" size="small" @click="deleteItemBtnClick(scope.$index)">删除</el-button>
29
+ </template>
30
+ </el-table-column>
31
+ </el-table>
32
+ <div class="footer" style="margin-top: 10px">
33
+ <el-button type="primary" @click="saveBtnClick">保存</el-button>
34
+ <el-button @click="cancelBtnClick">取消</el-button>
35
+ </div>
36
+ </div>
37
+ </template>
38
+
39
+ <script setup>
40
+ import {ref} from "vue";
41
+ import {directionList} from "packages/components/enums.js";
42
+ import {defaultCondition} from "packages/components/tools.js";
43
+
44
+ const props = defineProps({
45
+ payload: {
46
+ type: Array,
47
+ }
48
+ })
49
+
50
+ const items = ref(props.payload)
51
+
52
+ /**
53
+ * 添加条件
54
+ */
55
+ const addItemBtnClick = () => {
56
+ items.value.push(JSON.parse(JSON.stringify(defaultCondition)))
57
+ }
58
+
59
+ /**
60
+ * 删除条件
61
+ * @param index
62
+ */
63
+ const deleteItemBtnClick = (index) => {
64
+ items.value.splice(index, 1)
65
+ }
66
+
67
+ const emit = defineEmits(['close'])
68
+
69
+ /**
70
+ * 保存
71
+ */
72
+ const saveBtnClick = () => {
73
+ emit('close', items.value)
74
+ }
75
+
76
+ /**
77
+ * 取消
78
+ */
79
+ const cancelBtnClick = () => {
80
+ emit('close', false)
81
+ }
82
+
83
+ </script>
84
+
85
+ <style scoped lang="scss">
86
+ @use '/packages/styles/elPath.scss';
87
+ @use '/packages/styles/dialog.scss';
88
+ </style>
@@ -9,10 +9,84 @@
9
9
  <div class="row-column">
10
10
  <el-row :gutter="20">
11
11
  <el-col :span="12">
12
- <div class="row-label">颜色</div>
12
+ <div class="row-label">类型</div>
13
+ </el-col>
14
+ <el-col :span="12">
15
+ <el-select v-model="type" placeholder="请选择线段类型" clearable size="small" @change="changeType">
16
+ <el-option v-for="item in typeList" :key="item.value" :label="item.label" :value="item.value">
17
+ </el-option>
18
+ </el-select>
19
+ </el-col>
20
+ </el-row>
21
+ <el-row :gutter="20">
22
+ <el-col :span="12">
23
+ <div class="row-label">颜色1</div>
24
+ </el-col>
25
+ <el-col :span="12">
26
+ <el-color-picker v-model="stroke1" :show-alpha="true" size="small" @change="changeLine"/>
27
+ </el-col>
28
+ </el-row>
29
+ <el-row :gutter="20" v-if="type === 'pipe'">
30
+ <el-col :span="12">
31
+ <div class="row-label">颜色2</div>
32
+ </el-col>
33
+ <el-col :span="12">
34
+ <el-color-picker v-model="stroke2" :show-alpha="true" size="small" @change="changeLine"/>
35
+ </el-col>
36
+ </el-row>
37
+ <el-row :gutter="20">
38
+ <el-col :span="12">
39
+ <div class="row-label">粗细</div>
40
+ </el-col>
41
+ <el-col :span="12">
42
+ <el-input-number v-model="strokeWidth" size="small" controls-position="right" @change="changeLine" :min="1" :max="10"
43
+ :step="1"/>
44
+ </el-col>
45
+ </el-row>
46
+ </div>
47
+ </el-collapse-item>
48
+ <el-collapse-item v-if="type === 'pipe'" title="管道设置" name="3">
49
+ <div class="row-column">
50
+ <el-row :gutter="20">
51
+ <el-col :span="12">
52
+ <div class="row-label">管道间隔</div>
53
+ </el-col>
54
+ <el-col :span="12">
55
+ <el-input-number v-model="strokeDasharray" size="small" controls-position="right" @change="changeLine" :min="5" :max="100"
56
+ :step="1"/>
57
+ </el-col>
58
+ </el-row>
59
+ <el-row :gutter="20">
60
+ <el-col :span="12">
61
+ <div class="row-label">默认流动方向</div>
62
+ </el-col>
63
+ <el-col :span="12">
64
+ <el-select v-model="strokeDashoffset" placeholder="请选择管道方向" size="small" @change="changeLine">
65
+ <el-option v-for="item in directionList" :key="item.value" :label="item.label" :value="item.value">
66
+ </el-option>
67
+ </el-select>
68
+ </el-col>
69
+ </el-row>
70
+ <el-row :gutter="20">
71
+ <el-col :span="12">
72
+ <div class="row-label">参数设置</div>
73
+ </el-col>
74
+ <el-col :span="12">
75
+ <el-select v-model="deviceCode" placeholder="请选择设备" @change="checkDevice" size="small" filterable clearable >
76
+ <el-option v-for="item in deviceList" :key="item.deviceCode" :label="item.deviceName" :value="item.deviceCode"/>
77
+ </el-select>
78
+ <el-select v-model="fieldCode" placeholder="请选择字段" @change="checkField" size="small" filterable clearable style="margin-top: 10px">
79
+ <el-option v-for="item in fieldList" :key="item.dataField" :label="item.name" :value="item.dataField"/>
80
+ </el-select>
81
+ </el-col>
82
+ </el-row>
83
+ <el-row :gutter="20">
84
+ <el-col :span="12">
85
+ <div class="row-label">条件配置</div>
13
86
  </el-col>
14
87
  <el-col :span="12">
15
- <el-color-picker v-model="stroke" :show-alpha="true" size="small" @change="changeLine"/>
88
+ <el-switch v-model="isCondition" :active-value="true" :inactive-value="false" size="small" @change="changeCondition"/>
89
+ <el-button type="primary" size="small" @click="showCondition" style="margin-left: 10px">配置</el-button>
16
90
  </el-col>
17
91
  </el-row>
18
92
  </div>
@@ -102,75 +176,178 @@
102
176
  </div>
103
177
  </el-collapse-item>
104
178
  </el-collapse>
179
+ <el-dialog v-model="dialogCondition.show" width="500px" title="条件配置" :show-close="false" :close-on-click-modal="false"
180
+ :close-on-press-escape="false">
181
+ <condition v-if="dialogCondition.show" :payload="dialogCondition.payload" @close="closeCondition"></condition>
182
+ </el-dialog>
105
183
  </div>
106
184
  </template>
107
185
 
108
186
  <script setup>
109
- import {reactive, ref} from "vue";
187
+ import {onMounted, reactive, ref} from "vue";
110
188
  import {lineOptions} from "../settings.js";
189
+ import {setPipeDirection} from "packages/components/tools.js";
190
+ import {arrowList, directionList, STOP, typeList} from "packages/components/enums.js";
191
+ import Condition from "packages/components/edge-control/condition.vue";
192
+ import {getDeviceList, getFieldList} from "packages/components/common.js";
111
193
 
112
194
  const props = defineProps({
113
195
  payload: Object
114
196
  })
115
197
 
116
- const stroke = ref(props.payload.attrs.line.stroke)
198
+ const activeName = ref('0')
199
+
200
+ const type = ref(props.payload.data.type)
201
+ const stroke1 = ref(props.payload.attrs.line2.stroke)
202
+ const stroke2 = ref(props.payload.attrs.line1.stroke)
203
+ const strokeWidth = ref(props.payload.attrs.line1.strokeWidth)
204
+ const strokeDasharray = ref(props.payload.attrs.line2.strokeDasharray)
205
+ const strokeDashoffset = ref(props.payload.attrs.line2?.style?.animation.split(' ')[0] ?? STOP)
117
206
  const sourceMarker = reactive({
118
- name: props.payload.attrs.line.sourceMarker?.name ?? null,
119
- args: props.payload.attrs.line.sourceMarker?.args ?? {}
207
+ name: props.payload.attrs.line2.sourceMarker?.name ?? null,
208
+ args: props.payload.attrs.line2.sourceMarker?.args ?? {}
120
209
  })
121
210
  const targetMarker = reactive({
122
- name: props.payload.attrs.line.targetMarker?.name ?? null,
123
- args: props.payload.attrs.line.targetMarker?.args ?? {}
211
+ name: props.payload.attrs.line2.targetMarker?.name ?? null,
212
+ args: props.payload.attrs.line2.targetMarker?.args ?? {}
124
213
  })
125
214
 
126
- const arrowList = [
127
- {
128
- label: 'Block',
129
- value: 'block'
130
- },
131
- {
132
- label: 'Classic',
133
- value: 'classic'
134
- },
135
- {
136
- label: 'Diamond',
137
- value: 'diamond'
138
- },
139
- {
140
- label: 'Cross',
141
- value: 'cross'
142
- },
143
- {
144
- label: 'Async',
145
- value: 'async'
146
- },
147
- {
148
- label: 'Circle',
149
- value: 'circle'
150
- },
151
- {
152
- label: 'CirclePlus',
153
- value: 'circlePlus'
154
- },
155
- {
156
- label: 'Ellipse',
157
- value: 'ellipse'
158
- },
159
- ]
160
-
161
- const activeName = ref('0')
162
-
163
215
  /**
164
216
  * 线段属性改变
165
217
  */
166
218
  const changeLine = () => {
167
- props.payload.attr('line/stroke', stroke.value)
168
- props.payload.attr('line/sourceMarker/name', sourceMarker.name)
169
- props.payload.attr('line/sourceMarker/args', sourceMarker.args)
170
- props.payload.attr('line/targetMarker/name', targetMarker.name)
171
- props.payload.attr('line/targetMarker/args', targetMarker.args)
172
- lineOptions.line = props.payload.attrs.line
219
+ props.payload.attr('line1/stroke', stroke2.value)
220
+ props.payload.attr('line2/stroke', stroke1.value)
221
+ props.payload.attr('line1/strokeWidth', strokeWidth.value)
222
+ props.payload.attr('line2/strokeWidth', strokeWidth.value)
223
+ props.payload.attr('line2/strokeDasharray', strokeDasharray.value)
224
+ props.payload.attr('line2/sourceMarker/name', sourceMarker.name)
225
+ props.payload.attr('line2/sourceMarker/args', sourceMarker.args)
226
+ props.payload.attr('line2/targetMarker/name', targetMarker.name)
227
+ props.payload.attr('line2/targetMarker/args', targetMarker.args)
228
+ props.payload.attr('line2/style/animation', setPipeDirection(strokeDashoffset.value))
229
+ lineOptions.markup = props.payload.markup
230
+ lineOptions.attrs = props.payload.attrs
231
+ console.log('线-基础配置', lineOptions)
232
+ console.log('线-当前配置', props.payload)
233
+ }
234
+
235
+ /**
236
+ * 线段类型改变
237
+ */
238
+ const changeType = () => {
239
+ if (type.value === 'line') {
240
+ props.payload.attr('line2/strokeDasharray', 0)
241
+ } else if (type.value === 'pipe') {
242
+ props.payload.attr('line2/strokeDasharray', 5)
243
+ }
244
+ props.payload.attr('line2/style/animation', setPipeDirection('none'))
245
+ lineOptions.markup = props.payload.markup
246
+ lineOptions.attrs = props.payload.attrs
247
+ props.payload.data.type = type.value
248
+ console.log('线-基础配置', lineOptions)
249
+ console.log('线-当前配置', props.payload)
173
250
  }
251
+
252
+ // 条件线是否开启
253
+ const isCondition = ref(props.payload.data.isCondition ?? false)
254
+
255
+ /**
256
+ * 条件线改变
257
+ */
258
+ const changeCondition = () => {
259
+ props.payload.data.isCondition = isCondition.value
260
+ }
261
+
262
+ // 条件线配置
263
+ const dialogCondition = reactive({
264
+ show: false,
265
+ payload: null
266
+ })
267
+
268
+ /**
269
+ * 条件线配置显示
270
+ */
271
+ const showCondition = () => {
272
+ dialogCondition.show = true
273
+ dialogCondition.payload = props.payload.data.condition ?? []
274
+ }
275
+
276
+ /**
277
+ * 条件线配置关闭
278
+ * @param condition
279
+ */
280
+ const closeCondition = (condition) => {
281
+ dialogCondition.show = false
282
+ dialogCondition.payload = null
283
+ if (condition) {
284
+ props.payload.data.condition = condition
285
+ }
286
+ console.log('条件线', props.payload.data)
287
+ }
288
+
289
+ const deviceList = ref([]) // 设备列表
290
+ const deviceCode = ref(props.payload.data?.fields?.[0]?.deviceCode ?? '') // 设备编码
291
+ const fieldCode = ref(props.payload.data?.fields?.[0]?.field ?? '') // 字段编码
292
+
293
+ /**
294
+ * 获取设备列表
295
+ */
296
+ const getDevices = async () => {
297
+ deviceList.value = await getDeviceList()
298
+ if (deviceCode.value) {
299
+ checkDevice()
300
+ }
301
+ }
302
+
303
+ let currentDevice = reactive({}) // 当前设备信息
304
+
305
+ /**
306
+ * 监听设备编码变化
307
+ */
308
+ const checkDevice = () => {
309
+ currentDevice = deviceList.value.find(item => item.deviceCode === deviceCode.value)
310
+ if (currentDevice) {
311
+ getFields()
312
+ props.payload.data.fields = [{
313
+ index: 0,
314
+ deviceName: currentDevice.deviceName,
315
+ deviceCode: currentDevice.deviceCode,
316
+ field: fieldCode.value ?? '',
317
+ }]
318
+ fieldCode.value = props.payload.data.fields[0].field
319
+ } else {
320
+ fieldCode.value = ''
321
+ props.payload.data.fields = []
322
+ }
323
+ console.log('管道配置', props.payload)
324
+ }
325
+
326
+ const fieldList = ref([])
327
+
328
+ /**
329
+ * 获取字段列表
330
+ */
331
+ const getFields = async () => {
332
+ fieldList.value = await getFieldList(currentDevice.deviceCode)
333
+ }
334
+
335
+ /**
336
+ * 监听字段编码变化
337
+ */
338
+ const checkField = () => {
339
+ props.payload.data.fields = [{
340
+ index: 0,
341
+ deviceName: currentDevice.deviceName,
342
+ deviceCode: currentDevice.deviceCode,
343
+ field: fieldCode.value ?? '',
344
+ }]
345
+ console.log('管道配置', props.payload)
346
+ }
347
+
348
+ onMounted(() => {
349
+ getDevices()
350
+ })
174
351
  </script>
175
352
 
176
353
  <style scoped lang="scss">