openatc-components 0.4.68 → 0.4.71

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.
@@ -1,599 +1,604 @@
1
- /**
2
- * Copyright (c) 2020 kedacom
3
- * OpenATC is licensed under Mulan PSL v2.
4
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
5
- * You may obtain a copy of Mulan PSL v2 at:
6
- * http://license.coscl.org.cn/MulanPSL2
7
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
8
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
9
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
10
- * See the Mulan PSL v2 for more details.
11
- **/
12
- <template>
13
- <div class="app-container" ref="pattern-container">
14
- <el-table :data="newPatternList" :max-height="tableHeight" id="footerBtn" :show-header="isShowTableHeader">
15
- <el-table-column :type="isAllowedExpand ? 'expand' : ''" v-if="isAllowedExpand">
16
- <template slot-scope="scope">
17
- <div v-if="isAllowedExpand && isSingleCrossMode" class="optimizetype">
18
- <span>{{$t('openatccomponents.pattern.optimizetype')}}</span>
19
- <el-select v-model="value" clearable :placeholder="$t('openatccomponents.common.select')">
20
- <el-option
21
- v-for="item in typeOptions"
22
- :key="item.value"
23
- :label="$t('openatccomponents.overview.type' + item.value)"
24
- :value="item.value"
25
- >
26
- </el-option>
27
- </el-select>
28
- <span class="optimiNum">{{$t('openatccomponents.pattern.optimizecycle')}}</span>
29
- <el-input v-model="optimizecycle" clearable :placeholder="$t('openatccomponents.common.enter')"></el-input>
30
- <el-button type="primary" @click="onOptimizeClick(scope.row, scope.$index)">{{$t('openatccomponents.pattern.inoptimize')}}</el-button>
31
- </div>
32
- <div class="components-container board">
33
- <XiaoKanBan v-for="n in scope.row.ringCount"
34
- :key="n"
35
- :isSingleCrossMode="isSingleCrossMode"
36
- class="kanban todo"
37
- :list="scope.row.rings[n-1]"
38
- :header-text="$t('openatccomponents.pattern.ring') +' '+n"
39
- :index="scope.$index"
40
- @fatherMethod="fatherMethod"/>
41
- </div>
42
- </template>
43
- </el-table-column>
44
- <el-table-column align="center" label="No" width="45" minWidth="40" v-if="isShowColumn('no')">
45
- <template slot-scope="scope">
46
- <span>{{scope.$index+1}}</span>
47
- </template>
48
- </el-table-column>
49
- <el-table-column align="center" :label="$t('openatccomponents.greenwaveoptimize.deviceid')" width="100" minWidth="40" v-if="isShowColumn('agentid')">
50
- <template slot-scope="scope">
51
- <span>{{scope.row.agentid}}</span>
52
- </template>
53
- </el-table-column>
54
- <el-table-column align="center" :label="$t('openatccomponents.overview.crossname')" width="120" minWidth="40" v-if="isShowColumn('name')">
55
- <template slot-scope="scope">
56
- <span>{{getDevName(scope.row)}}</span>
57
- </template>
58
- </el-table-column>
59
- <el-table-column align="center" :label="$t('openatccomponents.greenwaveoptimize.period')" width="100" minWidth="40" v-if="isShowColumn('period')">
60
- <template slot-scope="scope">
61
- <span>{{getPeriod(scope.row)}}</span>
62
- </template>
63
- </el-table-column>
64
- <el-table-column property="isValid" :label="$t('openatccomponents.token.isValid')" align="center" width="80" prop="isused" v-if="isShowColumn('isused')">
65
- <template slot-scope="scope">
66
- <el-switch
67
- style="padding-left: 5px;"
68
- v-model="scope.row.isused"
69
- active-color="#299BCC">
70
- </el-switch>
71
- </template>
72
- </el-table-column>
73
- <el-table-column
74
- :label="$t('openatccomponents.greenwaveoptimize.pattern')"
75
- width="120"
76
- align="center"
77
- v-if="isShowColumn('patternid')">
78
- <template slot-scope="scope">
79
- <el-select
80
- v-model="scope.row.patternid"
81
- size="small"
82
- :loading="loading"
83
- @focus="getCurPattern(scope.row.agentid)"
84
- @change="changeCurPattern(scope.row,$event)">
85
- <el-option v-for="option in (scope.row.allPatterns)"
86
- :key="option.patternid"
87
- :label="option.patterndesc"
88
- :value="option.patternid">
89
- <span>{{ option.patterndesc }}</span>
90
- </el-option>
91
- </el-select>
92
- <span></span>
93
- </template>
94
- </el-table-column>
95
- <el-table-column align="center" :label="$t('openatccomponents.greenwaveoptimize.offset')" width="85" prop="offset" v-if="isShowColumn('offset')">
96
- <template slot-scope="scope">
97
- <el-input-number v-if="isAllowedExpand" :controls="false" :min="0" :step="1" v-model.number="scope.row.offset" size="small" style="width:70%;"></el-input-number>
98
- <span v-else>
99
- {{ scope.row.offset }}
100
- </span>
101
- </template>
102
- </el-table-column>
103
- <el-table-column align="center" :label="$t('openatccomponents.greenwaveoptimize.cycle')" width="60" prop="cycle" v-if="isShowColumn('cycle')">
104
- </el-table-column>
105
- <el-table-column align="center" :label="$t('openatccomponents.pattern.plan')" v-if="isShowColumn('pattern')">
106
- <template slot-scope="scope">
107
- <div class="pattern-figure">
108
- <pattern-list
109
- v-if="getControlType(scope.row) === 'ring'"
110
- :patternStatusList="JSON.parse(JSON.stringify(scope.row.rings))"
111
- :cycles="scope.row.cycle"
112
- :phaseList="JSON.parse(JSON.stringify(scope.row.currPhase))"
113
- :contrloType="getControlType(scope.row)"
114
- >
115
- </pattern-list>
116
- <pattern-list
117
- v-else
118
- :patternId="scope.row.patternid"
119
- :contrloType="getControlType(scope.row)"
120
- :index="scope.$index"
121
- :cycleChange="false"
122
- :stagesChange="getSelectedPattern(scope.row).stagesList"
123
- :patternStatusList="getSelectedPattern(scope.row).rings"
124
- :patternList="JSON.parse(JSON.stringify(scope.row.allPatterns))"
125
- :allPatternList="JSON.parse(JSON.stringify(scope.row.allPatterns))"
126
- :cycles="scope.row.cycle"
127
- :phaseList="JSON.parse(JSON.stringify(scope.row.currPhase))"
128
- :agentId="scope.row.agentid"
129
- :showBarrier="false">
130
- </pattern-list>
131
- </div>
132
- </template>
133
- </el-table-column>
134
- </el-table>
135
- </div>
136
- </template>
137
-
138
- <script>
139
- import XiaoKanBan from '../../XiaoKanBan/index.vue'
140
- // import { getPatternList } from '../../../../api/route'
141
- import { getIntersectionInfo } from '../../../../api/template'
142
- import { getMessageByCode } from '../../../../utils/responseMessage'
143
- import { getDuration } from '../../../../api/cross'
144
- // import { getDirName } from '../../../components/SelectCrossPhase/utils.js'
145
- export default {
146
- name: 'PatternTable',
147
- components: {
148
- XiaoKanBan
149
- },
150
- props: {
151
- devicesData: {
152
- type: Array,
153
- default: () => []
154
- },
155
- optList: {
156
- type: Array
157
- },
158
- isSingleCrossMode: {
159
- type: Boolean,
160
- default: false
161
- },
162
- tableColums: {
163
- type: Array,
164
- default: () => []
165
- },
166
- isAllowedExpand: {
167
- type: Boolean,
168
- default: true
169
- },
170
- isShowGenerateButton: {
171
- type: Boolean,
172
- default: true
173
- },
174
- isShowTableHeader: {
175
- type: Boolean,
176
- default: true
177
- },
178
- maxTableHeight: {
179
- type: Number,
180
- default: 200
181
- }
182
- },
183
- data () {
184
- return {
185
- typeOptions: [{
186
- value: 'flow-split-opt'
187
- }, {
188
- value: 'cycle-opt'
189
- }],
190
- value: 'flow-split-opt',
191
- optimizecycle: 0,
192
- controlType: 'stage',
193
- loading: true,
194
- tableHeight: 460,
195
- screenHeight: window.innerHeight, // 屏幕高度
196
- newPatternList: []
197
- }
198
- },
199
- created () {
200
- },
201
- watch: {
202
- maxTableHeight: function () {
203
- this.$nextTick(() => {
204
- this.tableHeight = this.maxTableHeight // 动态更新高度
205
- })
206
- },
207
- optList: {
208
- handler: function (val) {
209
- if (val && val.length > 0) {
210
- // for () {
211
-
212
- // }
213
- }
214
- },
215
- deep: true
216
- },
217
- newPatternList: {
218
- handler: function (val) {
219
- console.log('onNewPatternListChange', val)
220
- this.$emit('onNewPatternListChange', val)
221
- },
222
- deep: true
223
- }
224
- },
225
- mounted: function () {
226
- },
227
- methods: {
228
- onOptimizeClick (row, index) {
229
- let msg = this.$t('openatccomponents.pattern.algorithmEngineOptimization')
230
- const loading = this.$loading({
231
- lock: true,
232
- text: msg,
233
- spinner: 'el-icon-loading',
234
- background: 'rgba(0, 0, 0, 0.7)'
235
- })
236
- setTimeout(() => {
237
- loading.close()
238
- this.handeleOptimizeClick(row, index)
239
- }, 1000)
240
- },
241
- handeleOptimizeClick (row, index) {
242
- let newPha = []
243
- for (let i = 0; i < row.rings.length; i++) {
244
- newPha.push(...row.rings[i])
245
- }
246
- let phaseData = newPha.map(item => {
247
- return {
248
- id: item.id,
249
- flowperhour: item.flowperhour,
250
- saturation: item.saturation
251
- }
252
- })
253
- let patternList = row.allPatterns
254
- if (row.feature && row.feature.patternList && row.feature.patternList.length > 0) {
255
- patternList = row.feature.patternList
256
- }
257
- let pattern = patternList.filter((item) => item.id === row.patternid)[0]
258
- let phaseList = row.currPhase
259
- let reqData = {
260
- 'type': this.value,
261
- 'optcycle': this.optimizecycle ? this.optimizecycle : 0,
262
- 'phaseList': phaseList,
263
- 'pattern': pattern,
264
- 'phases': phaseData
265
- }
266
- let isValidata = []
267
- for (let j = 0; j < newPha.length; j++) {
268
- let comNum = (newPha[j].length / 4) * 1700 * 0.8
269
- isValidata.push(newPha[j].flowperhour > comNum)
270
- }
271
- if (isValidata.includes(true)) {
272
- this.$confirm(this.$t('openatccomponents.overview.maxFlow'),
273
- this.$t('openatccomponents.common.alarm'), {
274
- confirmButtonText: this.$t('openatccomponents.common.confirm'),
275
- cancelButtonText: this.$t('openatccomponents.common.cancel'),
276
- type: 'warning'
277
- }).then(() => {
278
- this.doOptimize(row, index, reqData)
279
- }).catch(() => {})
280
- } else {
281
- this.doOptimize(row, index, reqData)
282
- }
283
- },
284
- doOptimize (row, index, reqData) {
285
- // let _this = this
286
- getDuration(reqData).then(data => {
287
- if (data.data.success) {
288
- this.$message({
289
- type: 'success',
290
- message: this.$t('openatccomponents.pattern.success')
291
- })
292
- // let cycle = 0
293
- for (let i = 0; i < row.rings.length; i++) {
294
- for (let j = 0; j < row.rings[i].length; j++) {
295
- for (let h = 0; h < data.data.data.phase.length; h++) {
296
- if (row.rings[i][j].id === data.data.data.phase[h].id) {
297
- row.rings[i][j].value = data.data.data.phase[h].duration
298
- // cycle = cycle + row.rings[i][j].value
299
- }
300
- }
301
- }
302
- }
303
- }
304
- }).catch(error => {
305
- console.log(error)
306
- })
307
- },
308
- isShowColumn (colum) {
309
- let res = true
310
- if (this.tableColums && this.tableColums.length > 0) {
311
- res = this.tableColums.find(item => item === colum)
312
- }
313
- return res
314
- },
315
- getPeriod (row) {
316
- let period = row.timeperiodrange || row.period
317
- let res = ''
318
- if (period && period.length > 0) {
319
- res = period[0].substring(0, 5) + '-' + period[1].substring(0, 5)
320
- }
321
- return res
322
- },
323
- getDevName (row) {
324
- let res = row.name ? row.name : ''
325
- if (this.devicesData) {
326
- let dev = this.devicesData.find(item => item.agentid === row.agentid)
327
- res = dev ? dev.name : res
328
- }
329
- return res
330
- },
331
- onPatternTable (routeData, patternList, phaseList) {
332
- if (patternList.length === 0) {
333
- // this.$message.error('方案为空!')
334
- return
335
- }
336
- if (phaseList.length === 0) {
337
- // this.$message.error('相位为空!')
338
- return
339
- }
340
- // this.routeData = routeData
341
- // this.patternList = patternList
342
- // this.phaseList = phaseList
343
- this.handlePatternList(routeData, patternList, phaseList)
344
- },
345
- // 依据anengid获取设备信息,同时兼容单路口数据按序index取值
346
- getDevFromDevsOrIndex (devs, agentid, index) {
347
- let res
348
- // check special
349
- let isSingleCrossMode = false
350
- if (devs && devs.length > 1 && devs[0].agentid === devs[1].agentid) {
351
- isSingleCrossMode = true
352
- // check errData
353
- if (index === undefined || index === null) {
354
- console.log('getDevFromDevsOrIndex Err: index is null')
355
- }
356
- }
357
- if (!isSingleCrossMode) {
358
- res = devs.filter(ist => ist.agentid === agentid)[0]
359
- } else {
360
- res = devs[index]
361
- console.log('getDevByIndex:', res)
362
- }
363
- return res
364
- },
365
- handlePatternList (routeData, patternList, phaseList) {
366
- this.newPatternList = []
367
- let devs = routeData.devs
368
- let index = 0
369
- for (let pattern of patternList) {
370
- let obj = {}
371
- let id = pattern.agentid
372
- obj.agentid = id
373
- let count = [] // 计算相位有几个环
374
- if (pattern.feature !== undefined && pattern.feature.patternList.length !== 0) {
375
- let currPatternList = pattern.feature.patternList
376
- // let dev = devs.filter(ist => ist.agentid === id)[0]
377
- let dev = this.getDevFromDevsOrIndex(devs, id, index)
378
- index = index + 1
379
- let patternId = dev.patternid
380
- let currPattern
381
- if (Array.isArray(currPatternList)) {
382
- currPattern = currPatternList.filter(cpl => cpl.id === patternId)[0]
383
- if (!currPattern) {
384
- currPattern = currPatternList[0]
385
- }
386
- } else {
387
- currPattern = currPatternList
388
- }
389
- if (!currPattern) {
390
- currPattern = currPatternList[0]
391
- }
392
- // let currPattern = currPatternList.filter(cpl => cpl.id === patternId)[0]
393
- if (currPattern.desc === '') {
394
- obj.desc = this.$t('openatccomponents.greenwaveoptimize.pattern') + currPattern.id
395
- } else {
396
- obj.desc = currPattern.desc
397
- }
398
- obj = {...obj, ...dev}
399
- obj.id = currPattern.id
400
- obj.offset = currPattern.offset
401
- obj.cycle = currPattern.cycle
402
- obj.patternId = currPattern.id
403
- obj.patternid = currPattern.id
404
- obj.patternDesc = currPattern.desc === '' ? `${this.$t('openatccomponents.greenwaveoptimize.pattern')}${currPattern.id}` : currPattern.desc
405
- obj.allPatterns = currPatternList.map(ele => {
406
- let patterndesc = ele.desc === '' ? `${this.$t('openatccomponents.greenwaveoptimize.pattern')}${currPattern.id}` : ele.desc
407
- return {
408
- patternid: ele.id,
409
- patterndes: ele.desc,
410
- patterndesc: patterndesc,
411
- ...ele
412
- }
413
- })
414
- let rings = currPattern.rings
415
- let currPhase = phaseList.filter(phl => phl.agentid === id)[0].feature.phaseList
416
- obj.currPhase = currPhase
417
- obj.phaseList = currPhase
418
- // 计算有几个环
419
- for (let ring of rings) {
420
- if (ring.length === 0) continue
421
- for (let rr of ring) {
422
- rr.desc = []
423
- let targetPhase = currPhase.filter(curp => curp.id === rr.id)[0]
424
- if (!targetPhase) continue
425
- let direction = targetPhase.direction // 相位方向集合
426
- let phaseRing = currPhase.filter(curp => curp.id === rr.id)[0].ring
427
- count.push(phaseRing)
428
- for (let dir of direction) {
429
- let obj = {}
430
- obj.id = dir
431
- rr.desc.push(obj)
432
- }
433
- }
434
- }
435
- obj.rings = rings
436
- }
437
- let ringCount = Array.from(new Set(count)) // 去除数组重复的元素
438
- ringCount = ringCount.sort(this.sortNumbers) // 把数组中的值按照从小到大的顺序重新排序
439
- obj.ringCount = ringCount
440
- this.newPatternList.push(obj)
441
- }
442
- console.log('handlePatternList newPatternList', this.newPatternList)
443
- },
444
- sortNumbers (a, b) {
445
- return a - b
446
- },
447
- fatherMethod (val) {
448
- let index = val.index
449
- let cycle = val.cycle
450
- this.newPatternList[index].cycle = cycle
451
- },
452
- changeCurPattern (row, curPatternid) {
453
- // 修改当前方案(allPatterns: 所有可选项)
454
- const data = {
455
- agentid: row.agentid,
456
- patternid: curPatternid,
457
- patterndes: row.allPatterns.filter(ele => ele.patternid === curPatternid)[0].patterndes,
458
- allPatterns: row.allPatterns
459
- }
460
- row.desc = data.patternDesc
461
- row.patternId = data.patternid
462
- row.patternid = data.patternid
463
- row.patterndes = data.patterndes
464
- row.allPatterns = data.allPatterns
465
- row.patternid = data.patternid
466
- let selectPattern = row.allPatterns.filter(item => item.patternid === row.patternid)[0]
467
- let res = this.getRings(selectPattern.rings, row.phaseList)
468
- row.rings = res.rings
469
- row.ringCount = res.ringCount
470
- // row.rings = selectPattern.rings
471
- row.cycle = selectPattern.cycle
472
- row.offset = selectPattern.offset
473
- row.currPhase = row.phaseList
474
- },
475
- getRings (ringsList, phaseList) {
476
- let res = {}
477
- let rings = JSON.parse(JSON.stringify(ringsList))
478
- let count = []
479
- // 计算有几个环
480
- for (let ring of rings) {
481
- if (ring.length === 0) continue
482
- for (let rr of ring) {
483
- rr.desc = []
484
- let direction = phaseList.filter(curp => curp.id === rr.id)[0].direction // 相位方向集合
485
- let phaseRing = phaseList.filter(curp => curp.id === rr.id)[0].ring
486
- count.push(phaseRing)
487
- for (let dir of direction) {
488
- let obj = {}
489
- obj.id = dir
490
- rr.desc.push(obj)
491
- }
492
- }
493
- }
494
- let ringCount = Array.from(new Set(count)) // 去除数组重复的元素
495
- ringCount = ringCount.sort(this.sortNumbers) // 把数组中的值按照从小到大的顺序重新排序
496
- res = {
497
- rings: rings,
498
- ringCount: ringCount
499
- }
500
- return res
501
- },
502
- getControlType (row) {
503
- let contrloType = 'ring'
504
- let allPatternList = row.feature && row.feature.patternList ? row.feature.patternList : row.allPatterns
505
- if (
506
- !allPatternList[0].contrloType &&
507
- allPatternList[0].rings.length > 0
508
- ) {
509
- contrloType = 'ring'
510
- } else if (
511
- !allPatternList[0].contrloType &&
512
- allPatternList[0].rings.length === 0
513
- ) {
514
- contrloType = 'stage'
515
- } else {
516
- contrloType = allPatternList[0].contrloType
517
- }
518
- let res = contrloType
519
- return res
520
- },
521
- getSelectedPattern (row) {
522
- let res = []
523
- let patternList = row.feature && row.feature.patternList ? row.feature.patternList : row.allPatterns
524
- let pattern = patternList.find(item => item.id === row.patternid)
525
- if (pattern) {
526
- res = JSON.parse(JSON.stringify(pattern))
527
- }
528
- return res
529
- },
530
- getCurPattern (agentid) {
531
- // 获取当前设备所有可选方案
532
- this.loading = true
533
- let _this = this
534
- getIntersectionInfo(agentid).then(res => {
535
- this.loading = false
536
- if (!res.data.success) {
537
- let commomMsg = this.$t('openatccomponents.overview.signalID') + ' : ' + agentid
538
- let msg = getMessageByCode(res.data.code, this.$i18n.locale)
539
- if (res.data.data) {
540
- // 子类型错误
541
- let childErrorCode = res.data.data.errorCode
542
- if (childErrorCode) {
543
- let childerror = getMessageByCode(res.data.data.errorCode, this.$i18n.locale)
544
- msg = msg + ' - ' + childerror
545
- }
546
- }
547
- msg = msg + ' - ' + commomMsg
548
- this.$message.error(msg)
549
- return
550
- }
551
- let allPatternList = res.data.data.param.patternList
552
- _this.newPatternList.forEach(ele => {
553
- if (ele.agentid === agentid) {
554
- ele.allPatterns = allPatternList.map(ele => {
555
- return {
556
- ...ele,
557
- patternid: ele.id,
558
- patterndes: ele.desc,
559
- patterndesc: ele.desc === '' ? `${_this.$t('openatccomponents.greenwaveoptimize.pattern')}${ele.id}` : ele.desc
560
- }
561
- })
562
- }
563
- })
564
- })
565
- }
566
- }
567
- }
568
- </script>
569
-
570
- <style lang="scss">
571
- .board {
572
- width: 100%;
573
- margin-left: 10PX;
574
- display: flex;
575
- justify-content: flex-start;
576
- gap: 10PX;
577
- align-items: flex-start;
578
- }
579
- .optimizetype{
580
- font-size: 14PX;
581
- display: flex;
582
- justify-content: flex-start;
583
- align-items: center;
584
- gap: 10PX;
585
- padding-left: 20PX;
586
- .el-input {
587
- width: 120PX;
588
- }
589
- // .el-select{
590
- // width: 170PX;
591
- // }
592
- // .el-button {
593
- // margin-left: 10PX;
594
- // }
595
- .optimiNum {
596
- padding-left: 10PX;
597
- }
598
- }
599
- </style>
1
+ /**
2
+ * Copyright (c) 2020 kedacom
3
+ * OpenATC is licensed under Mulan PSL v2.
4
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
5
+ * You may obtain a copy of Mulan PSL v2 at:
6
+ * http://license.coscl.org.cn/MulanPSL2
7
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
8
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
9
+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
10
+ * See the Mulan PSL v2 for more details.
11
+ **/
12
+ <template>
13
+ <div class="app-container" ref="pattern-container">
14
+ <el-table :data="newPatternList" :max-height="tableHeight" id="footerBtn" :show-header="isShowTableHeader">
15
+ <el-table-column :type="isAllowedExpand ? 'expand' : ''" v-if="isAllowedExpand">
16
+ <template slot-scope="scope">
17
+ <div v-if="isAllowedExpand && isSingleCrossMode" class="optimizetype">
18
+ <span>{{$t('openatccomponents.pattern.optimizetype')}}</span>
19
+ <el-select v-model="value" clearable :placeholder="$t('openatccomponents.common.select')">
20
+ <el-option
21
+ v-for="item in typeOptions"
22
+ :key="item.value"
23
+ :label="$t('openatccomponents.overview.type' + item.value)"
24
+ :value="item.value"
25
+ >
26
+ </el-option>
27
+ </el-select>
28
+ <span class="optimiNum">{{$t('openatccomponents.pattern.optimizecycle')}}</span>
29
+ <el-input v-model="optimizecycle" clearable :placeholder="$t('openatccomponents.common.enter')"></el-input>
30
+ <el-button type="primary" @click="onOptimizeClick(scope.row, scope.$index)">{{$t('openatccomponents.pattern.inoptimize')}}</el-button>
31
+ </div>
32
+ <div class="components-container board">
33
+ <XiaoKanBan v-for="n in scope.row.ringCount"
34
+ :key="n"
35
+ :isSingleCrossMode="isSingleCrossMode"
36
+ class="kanban todo"
37
+ :list="scope.row.rings[n-1]"
38
+ :header-text="$t('openatccomponents.pattern.ring') +' '+n"
39
+ :index="scope.$index"
40
+ @fatherMethod="fatherMethod"/>
41
+ </div>
42
+ </template>
43
+ </el-table-column>
44
+ <el-table-column align="center" label="No" width="45" minWidth="40" v-if="isShowColumn('no')">
45
+ <template slot-scope="scope">
46
+ <span>{{scope.$index+1}}</span>
47
+ </template>
48
+ </el-table-column>
49
+ <el-table-column align="center" :label="$t('openatccomponents.greenwaveoptimize.deviceid')" width="100" minWidth="40" v-if="isShowColumn('agentid')">
50
+ <template slot-scope="scope">
51
+ <span>{{scope.row.agentid}}</span>
52
+ </template>
53
+ </el-table-column>
54
+ <el-table-column align="center" :label="$t('openatccomponents.overview.crossname')" width="120" minWidth="40" v-if="isShowColumn('name')">
55
+ <template slot-scope="scope">
56
+ <span>{{getDevName(scope.row)}}</span>
57
+ </template>
58
+ </el-table-column>
59
+ <el-table-column align="center" :label="$t('openatccomponents.greenwaveoptimize.period')" width="100" minWidth="40" v-if="isShowColumn('period')">
60
+ <template slot-scope="scope">
61
+ <span>{{getPeriod(scope.row)}}</span>
62
+ </template>
63
+ </el-table-column>
64
+ <el-table-column property="isValid" :label="$t('openatccomponents.token.isValid')" align="center" width="80" prop="isused" v-if="isShowColumn('isused')">
65
+ <template slot-scope="scope">
66
+ <el-switch
67
+ style="padding-left: 5px;"
68
+ v-model="scope.row.isused"
69
+ active-color="#299BCC">
70
+ </el-switch>
71
+ </template>
72
+ </el-table-column>
73
+ <el-table-column align="center" :label="$t('openatccomponents.greenwaveoptimize.pattern')" width="120" minWidth="40" v-if="isShowColumn('patternName')">
74
+ <template slot-scope="scope">
75
+ <span>{{scope.row.patternDesc}}</span>
76
+ </template>
77
+ </el-table-column>
78
+ <el-table-column
79
+ :label="$t('openatccomponents.greenwaveoptimize.pattern')"
80
+ width="120"
81
+ align="center"
82
+ v-if="isShowColumn('patternid')">
83
+ <template slot-scope="scope">
84
+ <el-select
85
+ v-model="scope.row.patternid"
86
+ size="small"
87
+ :loading="loading"
88
+ @focus="getCurPattern(scope.row.agentid)"
89
+ @change="changeCurPattern(scope.row,$event)">
90
+ <el-option v-for="option in (scope.row.allPatterns)"
91
+ :key="option.patternid"
92
+ :label="option.patterndesc"
93
+ :value="option.patternid">
94
+ <span>{{ option.patterndesc }}</span>
95
+ </el-option>
96
+ </el-select>
97
+ <span></span>
98
+ </template>
99
+ </el-table-column>
100
+ <el-table-column align="center" :label="$t('openatccomponents.greenwaveoptimize.offset')" width="85" prop="offset" v-if="isShowColumn('offset')">
101
+ <template slot-scope="scope">
102
+ <el-input-number v-if="isAllowedExpand" :controls="false" :min="0" :step="1" v-model.number="scope.row.offset" size="small" style="width:70%;"></el-input-number>
103
+ <span v-else>
104
+ {{ scope.row.offset }}
105
+ </span>
106
+ </template>
107
+ </el-table-column>
108
+ <el-table-column align="center" :label="$t('openatccomponents.greenwaveoptimize.cycle')" width="60" prop="cycle" v-if="isShowColumn('cycle')">
109
+ </el-table-column>
110
+ <el-table-column align="center" :label="$t('openatccomponents.pattern.plan')" v-if="isShowColumn('pattern')">
111
+ <template slot-scope="scope">
112
+ <div class="pattern-figure">
113
+ <pattern-list
114
+ v-if="getControlType(scope.row) === 'ring'"
115
+ :patternStatusList="JSON.parse(JSON.stringify(scope.row.rings))"
116
+ :cycles="scope.row.cycle"
117
+ :phaseList="JSON.parse(JSON.stringify(scope.row.currPhase))"
118
+ :contrloType="getControlType(scope.row)"
119
+ >
120
+ </pattern-list>
121
+ <pattern-list
122
+ v-else
123
+ :patternId="scope.row.patternid"
124
+ :contrloType="getControlType(scope.row)"
125
+ :index="scope.$index"
126
+ :cycleChange="false"
127
+ :stagesChange="getSelectedPattern(scope.row).stagesList"
128
+ :patternStatusList="getSelectedPattern(scope.row).rings"
129
+ :patternList="JSON.parse(JSON.stringify(scope.row.allPatterns))"
130
+ :allPatternList="JSON.parse(JSON.stringify(scope.row.allPatterns))"
131
+ :cycles="scope.row.cycle"
132
+ :phaseList="JSON.parse(JSON.stringify(scope.row.currPhase))"
133
+ :agentId="scope.row.agentid"
134
+ :showBarrier="false">
135
+ </pattern-list>
136
+ </div>
137
+ </template>
138
+ </el-table-column>
139
+ </el-table>
140
+ </div>
141
+ </template>
142
+
143
+ <script>
144
+ import XiaoKanBan from '../../XiaoKanBan/index.vue'
145
+ // import { getPatternList } from '../../../../api/route'
146
+ import { getIntersectionInfo } from '../../../../api/template'
147
+ import { getMessageByCode } from '../../../../utils/responseMessage'
148
+ import { getDuration } from '../../../../api/cross'
149
+ // import { getDirName } from '../../../components/SelectCrossPhase/utils.js'
150
+ export default {
151
+ name: 'PatternTable',
152
+ components: {
153
+ XiaoKanBan
154
+ },
155
+ props: {
156
+ devicesData: {
157
+ type: Array,
158
+ default: () => []
159
+ },
160
+ optList: {
161
+ type: Array
162
+ },
163
+ isSingleCrossMode: {
164
+ type: Boolean,
165
+ default: false
166
+ },
167
+ tableColums: {
168
+ type: Array,
169
+ default: () => []
170
+ },
171
+ isAllowedExpand: {
172
+ type: Boolean,
173
+ default: true
174
+ },
175
+ isShowGenerateButton: {
176
+ type: Boolean,
177
+ default: true
178
+ },
179
+ isShowTableHeader: {
180
+ type: Boolean,
181
+ default: true
182
+ },
183
+ maxTableHeight: {
184
+ type: Number,
185
+ default: 200
186
+ }
187
+ },
188
+ data () {
189
+ return {
190
+ typeOptions: [{
191
+ value: 'flow-split-opt'
192
+ }, {
193
+ value: 'cycle-opt'
194
+ }],
195
+ value: 'flow-split-opt',
196
+ optimizecycle: 0,
197
+ controlType: 'stage',
198
+ loading: true,
199
+ tableHeight: 460,
200
+ screenHeight: window.innerHeight, // 屏幕高度
201
+ newPatternList: []
202
+ }
203
+ },
204
+ created () {
205
+ },
206
+ watch: {
207
+ maxTableHeight: function () {
208
+ this.$nextTick(() => {
209
+ this.tableHeight = this.maxTableHeight // 动态更新高度
210
+ })
211
+ },
212
+ optList: {
213
+ handler: function (val) {
214
+ if (val && val.length > 0) {
215
+ // for () {
216
+
217
+ // }
218
+ }
219
+ },
220
+ deep: true
221
+ },
222
+ newPatternList: {
223
+ handler: function (val) {
224
+ console.log('onNewPatternListChange', val)
225
+ this.$emit('onNewPatternListChange', val)
226
+ },
227
+ deep: true
228
+ }
229
+ },
230
+ mounted: function () {
231
+ },
232
+ methods: {
233
+ onOptimizeClick (row, index) {
234
+ let msg = this.$t('openatccomponents.pattern.algorithmEngineOptimization')
235
+ const loading = this.$loading({
236
+ lock: true,
237
+ text: msg,
238
+ spinner: 'el-icon-loading',
239
+ background: 'rgba(0, 0, 0, 0.7)'
240
+ })
241
+ setTimeout(() => {
242
+ loading.close()
243
+ this.handeleOptimizeClick(row, index)
244
+ }, 1000)
245
+ },
246
+ handeleOptimizeClick (row, index) {
247
+ let newPha = []
248
+ for (let i = 0; i < row.rings.length; i++) {
249
+ newPha.push(...row.rings[i])
250
+ }
251
+ let phaseData = newPha.map(item => {
252
+ return {
253
+ id: item.id,
254
+ flowperhour: item.flowperhour,
255
+ saturation: item.saturation
256
+ }
257
+ })
258
+ let patternList = row.allPatterns
259
+ if (row.feature && row.feature.patternList && row.feature.patternList.length > 0) {
260
+ patternList = row.feature.patternList
261
+ }
262
+ let pattern = patternList.filter((item) => item.id === row.patternid)[0]
263
+ let phaseList = row.currPhase
264
+ let reqData = {
265
+ 'type': this.value,
266
+ 'optcycle': this.optimizecycle ? this.optimizecycle : 0,
267
+ 'phaseList': phaseList,
268
+ 'pattern': pattern,
269
+ 'phases': phaseData
270
+ }
271
+ let isValidata = []
272
+ for (let j = 0; j < newPha.length; j++) {
273
+ let comNum = (newPha[j].length / 4) * 1700 * 0.8
274
+ isValidata.push(newPha[j].flowperhour > comNum)
275
+ }
276
+ if (isValidata.includes(true)) {
277
+ this.$confirm(this.$t('openatccomponents.overview.maxFlow'),
278
+ this.$t('openatccomponents.common.alarm'), {
279
+ confirmButtonText: this.$t('openatccomponents.common.confirm'),
280
+ cancelButtonText: this.$t('openatccomponents.common.cancel'),
281
+ type: 'warning'
282
+ }).then(() => {
283
+ this.doOptimize(row, index, reqData)
284
+ }).catch(() => {})
285
+ } else {
286
+ this.doOptimize(row, index, reqData)
287
+ }
288
+ },
289
+ doOptimize (row, index, reqData) {
290
+ // let _this = this
291
+ getDuration(reqData).then(data => {
292
+ if (data.data.success) {
293
+ this.$message({
294
+ type: 'success',
295
+ message: this.$t('openatccomponents.pattern.success')
296
+ })
297
+ // let cycle = 0
298
+ for (let i = 0; i < row.rings.length; i++) {
299
+ for (let j = 0; j < row.rings[i].length; j++) {
300
+ for (let h = 0; h < data.data.data.phase.length; h++) {
301
+ if (row.rings[i][j].id === data.data.data.phase[h].id) {
302
+ row.rings[i][j].value = data.data.data.phase[h].duration
303
+ // cycle = cycle + row.rings[i][j].value
304
+ }
305
+ }
306
+ }
307
+ }
308
+ }
309
+ }).catch(error => {
310
+ console.log(error)
311
+ })
312
+ },
313
+ isShowColumn (colum) {
314
+ let res = true
315
+ if (this.tableColums && this.tableColums.length > 0) {
316
+ res = this.tableColums.find(item => item === colum)
317
+ }
318
+ return res
319
+ },
320
+ getPeriod (row) {
321
+ let period = row.timeperiodrange || row.period
322
+ let res = ''
323
+ if (period && period.length > 0) {
324
+ res = period[0].substring(0, 5) + '-' + period[1].substring(0, 5)
325
+ }
326
+ return res
327
+ },
328
+ getDevName (row) {
329
+ let res = row.name ? row.name : ''
330
+ if (this.devicesData) {
331
+ let dev = this.devicesData.find(item => item.agentid === row.agentid)
332
+ res = dev ? dev.name : res
333
+ }
334
+ return res
335
+ },
336
+ onPatternTable (routeData, patternList, phaseList) {
337
+ if (patternList.length === 0) {
338
+ // this.$message.error('方案为空!')
339
+ return
340
+ }
341
+ if (phaseList.length === 0) {
342
+ // this.$message.error('相位为空!')
343
+ return
344
+ }
345
+ // this.routeData = routeData
346
+ // this.patternList = patternList
347
+ // this.phaseList = phaseList
348
+ this.handlePatternList(routeData, patternList, phaseList)
349
+ },
350
+ // 依据anengid获取设备信息,同时兼容单路口数据按序index取值
351
+ getDevFromDevsOrIndex (devs, agentid, index) {
352
+ let res
353
+ // check special
354
+ let isSingleCrossMode = false
355
+ if (devs && devs.length > 1 && devs[0].agentid === devs[1].agentid) {
356
+ isSingleCrossMode = true
357
+ // check errData
358
+ if (index === undefined || index === null) {
359
+ console.log('getDevFromDevsOrIndex Err: index is null')
360
+ }
361
+ }
362
+ if (!isSingleCrossMode) {
363
+ res = devs.filter(ist => ist.agentid === agentid)[0]
364
+ } else {
365
+ res = devs[index]
366
+ console.log('getDevByIndex:', res)
367
+ }
368
+ return res
369
+ },
370
+ handlePatternList (routeData, patternList, phaseList) {
371
+ this.newPatternList = []
372
+ let devs = routeData.devs
373
+ let index = 0
374
+ for (let pattern of patternList) {
375
+ let obj = {}
376
+ let id = pattern.agentid
377
+ obj.agentid = id
378
+ let count = [] // 计算相位有几个环
379
+ if (pattern.feature !== undefined && pattern.feature.patternList.length !== 0) {
380
+ let currPatternList = pattern.feature.patternList
381
+ // let dev = devs.filter(ist => ist.agentid === id)[0]
382
+ let dev = this.getDevFromDevsOrIndex(devs, id, index)
383
+ index = index + 1
384
+ let patternId = dev.patternid
385
+ let currPattern
386
+ if (Array.isArray(currPatternList)) {
387
+ currPattern = currPatternList.filter(cpl => cpl.id === patternId)[0]
388
+ if (!currPattern) {
389
+ currPattern = currPatternList[0]
390
+ }
391
+ } else {
392
+ currPattern = currPatternList
393
+ }
394
+ if (!currPattern) {
395
+ currPattern = currPatternList[0]
396
+ }
397
+ // let currPattern = currPatternList.filter(cpl => cpl.id === patternId)[0]
398
+ if (currPattern.desc === '') {
399
+ obj.desc = this.$t('openatccomponents.greenwaveoptimize.pattern') + currPattern.id
400
+ } else {
401
+ obj.desc = currPattern.desc
402
+ }
403
+ obj = {...obj, ...dev}
404
+ obj.id = currPattern.id
405
+ obj.offset = currPattern.offset
406
+ obj.cycle = currPattern.cycle
407
+ obj.patternId = currPattern.id
408
+ obj.patternid = currPattern.id
409
+ obj.patternDesc = currPattern.desc === '' ? `${this.$t('openatccomponents.greenwaveoptimize.pattern')}${currPattern.id}` : currPattern.desc
410
+ obj.allPatterns = currPatternList.map(ele => {
411
+ let patterndesc = ele.desc === '' ? `${this.$t('openatccomponents.greenwaveoptimize.pattern')}${currPattern.id}` : ele.desc
412
+ return {
413
+ patternid: ele.id,
414
+ patterndes: ele.desc,
415
+ patterndesc: patterndesc,
416
+ ...ele
417
+ }
418
+ })
419
+ let rings = currPattern.rings
420
+ let currPhase = phaseList.filter(phl => phl.agentid === id)[0].feature.phaseList
421
+ obj.currPhase = currPhase
422
+ obj.phaseList = currPhase
423
+ // 计算有几个环
424
+ for (let ring of rings) {
425
+ if (ring.length === 0) continue
426
+ for (let rr of ring) {
427
+ rr.desc = []
428
+ let targetPhase = currPhase.filter(curp => curp.id === rr.id)[0]
429
+ if (!targetPhase) continue
430
+ let direction = targetPhase.direction // 相位方向集合
431
+ let phaseRing = currPhase.filter(curp => curp.id === rr.id)[0].ring
432
+ count.push(phaseRing)
433
+ for (let dir of direction) {
434
+ let obj = {}
435
+ obj.id = dir
436
+ rr.desc.push(obj)
437
+ }
438
+ }
439
+ }
440
+ obj.rings = rings
441
+ }
442
+ let ringCount = Array.from(new Set(count)) // 去除数组重复的元素
443
+ ringCount = ringCount.sort(this.sortNumbers) // 把数组中的值按照从小到大的顺序重新排序
444
+ obj.ringCount = ringCount
445
+ this.newPatternList.push(obj)
446
+ }
447
+ console.log('handlePatternList newPatternList', this.newPatternList)
448
+ },
449
+ sortNumbers (a, b) {
450
+ return a - b
451
+ },
452
+ fatherMethod (val) {
453
+ let index = val.index
454
+ let cycle = val.cycle
455
+ this.newPatternList[index].cycle = cycle
456
+ },
457
+ changeCurPattern (row, curPatternid) {
458
+ // 修改当前方案(allPatterns 所有可选项)
459
+ const data = {
460
+ agentid: row.agentid,
461
+ patternid: curPatternid,
462
+ patterndes: row.allPatterns.filter(ele => ele.patternid === curPatternid)[0].patterndes,
463
+ allPatterns: row.allPatterns
464
+ }
465
+ row.desc = data.patternDesc
466
+ row.patternId = data.patternid
467
+ row.patternid = data.patternid
468
+ row.patterndes = data.patterndes
469
+ row.allPatterns = data.allPatterns
470
+ row.patternid = data.patternid
471
+ let selectPattern = row.allPatterns.filter(item => item.patternid === row.patternid)[0]
472
+ let res = this.getRings(selectPattern.rings, row.phaseList)
473
+ row.rings = res.rings
474
+ row.ringCount = res.ringCount
475
+ // row.rings = selectPattern.rings
476
+ row.cycle = selectPattern.cycle
477
+ row.offset = selectPattern.offset
478
+ row.currPhase = row.phaseList
479
+ },
480
+ getRings (ringsList, phaseList) {
481
+ let res = {}
482
+ let rings = JSON.parse(JSON.stringify(ringsList))
483
+ let count = []
484
+ // 计算有几个环
485
+ for (let ring of rings) {
486
+ if (ring.length === 0) continue
487
+ for (let rr of ring) {
488
+ rr.desc = []
489
+ let direction = phaseList.filter(curp => curp.id === rr.id)[0].direction // 相位方向集合
490
+ let phaseRing = phaseList.filter(curp => curp.id === rr.id)[0].ring
491
+ count.push(phaseRing)
492
+ for (let dir of direction) {
493
+ let obj = {}
494
+ obj.id = dir
495
+ rr.desc.push(obj)
496
+ }
497
+ }
498
+ }
499
+ let ringCount = Array.from(new Set(count)) // 去除数组重复的元素
500
+ ringCount = ringCount.sort(this.sortNumbers) // 把数组中的值按照从小到大的顺序重新排序
501
+ res = {
502
+ rings: rings,
503
+ ringCount: ringCount
504
+ }
505
+ return res
506
+ },
507
+ getControlType (row) {
508
+ let contrloType = 'ring'
509
+ let allPatternList = row.feature && row.feature.patternList ? row.feature.patternList : row.allPatterns
510
+ if (
511
+ !allPatternList[0].contrloType &&
512
+ allPatternList[0].rings.length > 0
513
+ ) {
514
+ contrloType = 'ring'
515
+ } else if (
516
+ !allPatternList[0].contrloType &&
517
+ allPatternList[0].rings.length === 0
518
+ ) {
519
+ contrloType = 'stage'
520
+ } else {
521
+ contrloType = allPatternList[0].contrloType
522
+ }
523
+ let res = contrloType
524
+ return res
525
+ },
526
+ getSelectedPattern (row) {
527
+ let res = []
528
+ let patternList = row.feature && row.feature.patternList ? row.feature.patternList : row.allPatterns
529
+ let pattern = patternList.find(item => item.id === row.patternid)
530
+ if (pattern) {
531
+ res = JSON.parse(JSON.stringify(pattern))
532
+ }
533
+ return res
534
+ },
535
+ getCurPattern (agentid) {
536
+ // 获取当前设备所有可选方案
537
+ this.loading = true
538
+ let _this = this
539
+ getIntersectionInfo(agentid).then(res => {
540
+ this.loading = false
541
+ if (!res.data.success) {
542
+ let commomMsg = this.$t('openatccomponents.overview.signalID') + ' : ' + agentid
543
+ let msg = getMessageByCode(res.data.code, this.$i18n.locale)
544
+ if (res.data.data) {
545
+ // 子类型错误
546
+ let childErrorCode = res.data.data.errorCode
547
+ if (childErrorCode) {
548
+ let childerror = getMessageByCode(res.data.data.errorCode, this.$i18n.locale)
549
+ msg = msg + ' - ' + childerror
550
+ }
551
+ }
552
+ msg = msg + ' - ' + commomMsg
553
+ this.$message.error(msg)
554
+ return
555
+ }
556
+ let allPatternList = res.data.data.param.patternList
557
+ _this.newPatternList.forEach(ele => {
558
+ if (ele.agentid === agentid) {
559
+ ele.allPatterns = allPatternList.map(ele => {
560
+ return {
561
+ ...ele,
562
+ patternid: ele.id,
563
+ patterndes: ele.desc,
564
+ patterndesc: ele.desc === '' ? `${_this.$t('openatccomponents.greenwaveoptimize.pattern')}${ele.id}` : ele.desc
565
+ }
566
+ })
567
+ }
568
+ })
569
+ })
570
+ }
571
+ }
572
+ }
573
+ </script>
574
+
575
+ <style lang="scss">
576
+ .board {
577
+ width: 100%;
578
+ margin-left: 10PX;
579
+ display: flex;
580
+ justify-content: flex-start;
581
+ gap: 10PX;
582
+ align-items: flex-start;
583
+ }
584
+ .optimizetype{
585
+ font-size: 14PX;
586
+ display: flex;
587
+ justify-content: flex-start;
588
+ align-items: center;
589
+ gap: 10PX;
590
+ padding-left: 20PX;
591
+ .el-input {
592
+ width: 120PX;
593
+ }
594
+ // .el-select{
595
+ // width: 170PX;
596
+ // }
597
+ // .el-button {
598
+ // margin-left: 10PX;
599
+ // }
600
+ .optimiNum {
601
+ padding-left: 10PX;
602
+ }
603
+ }
604
+ </style>