longyvfengyun
2023-12-25 d8d792a6842832e8f6af6604274c438b25053afe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
<template>
    <div class="history-realtime-data">
        <flex-layout>
            <div class="ele-filter-container" slot="header">
                <div class="ele-filter-radio-group">
                    <el-radio-group
                        v-model="filter.timeType"
                        @change="radioChange"
                        size="mini"
                        style="margin-right: 8px;">
                        <el-radio :label="365" >近一年</el-radio>
                        <el-radio :label="90">近三个月</el-radio>
                        <el-radio :label="30">近一个月</el-radio>
                        <el-radio :label="7">近7天</el-radio>
                        <el-radio :label="1">近24小时</el-radio>
                    </el-radio-group>
                    <el-popover
                        placement="top-start"
                        trigger="click">
                        <div class="time-group">
                            <el-date-picker
                                v-model="timeRange"
                                type="datetimerange"
                                @change="timeRangeChange"
                                range-separator="至"
                                start-placeholder="开始日期"
                                end-placeholder="结束日期"
                                :default-time="['00:00:00', '23:59:59']"
                                :clearable="false"
                                :editable="false"></el-date-picker>
                        </div>
                        <el-button size="mini" slot="reference">{{filter.txt}} <i class="el-icon-date"></i></el-button>
                    </el-popover>
                    <span style="color: #FFFFFF">当前显示单体:</span>
                    <el-select
                        v-model="monSelect"
                        filterable placeholder="请选择查看的单体"
                        @change="monSelectChange"
                        size="mini">
                        <el-option
                            v-for="item in monOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                        </el-option>
                    </el-select>
                </div>
            </div>
            <div class="page-content">
                <el-tabs v-model="acTabs" type="border-card" class="flex-layout noborder" @tab-click="tabClick">
                    <el-tab-pane label="在线电压" name="onlineVolGraph">
                      <line-chart-plus ref="onlineVolGraph" id="onlineVolGraph" unit="V"></line-chart-plus>
                    </el-tab-pane>
                    <el-tab-pane label="组端电压" name="groupVolGraph">
                        <line-chart-plus ref="groupVolGraph" id="groupVolGraph" unit="V"></line-chart-plus>
                    </el-tab-pane>
                    <el-tab-pane label="组端电流" name="groupCurrGraph">
                        <line-chart-plus ref="groupCurrGraph" id="groupCurrGraph" unit="A"></line-chart-plus>
                    </el-tab-pane>
                    <el-tab-pane label="单体电压" name="monVolGraph">
                        <line-chart-plus ref="monVolGraph" id="monVolGraph" unit="V"></line-chart-plus>
                    </el-tab-pane>
                    <el-tab-pane label="单体温度" name="monTmpGraph">
                        <line-chart-plus ref="monTmpGraph" id="monTmpGraph" unit="℃"></line-chart-plus>
                    </el-tab-pane>
                    <el-tab-pane label="单体内阻" name="monResGraph">
                        <line-chart-plus ref="monResGraph" id="monResGraph" unit="mΩ"></line-chart-plus>
                    </el-tab-pane>
                </el-tabs>
            </div>
        </flex-layout>
        <div class="progress-container" v-if="progress.show">
            <div class="progress-content">
                <div class="progress">
                    <el-progress type="circle" :percentage="progress.value"></el-progress>
                </div>
            </div>
        </div>
    </div>
</template>
 
<script>
import LineChartPlus from "@/components/chart/LineChartPlus";
import {searchHistoryRealtimeData} from "@/assets/js/realTime";
 
let options = {
    groupVolGraph: {
        title: {
            text: '组端电压折线图',
            x: 'center'
        },
        xAxis: [{
            type: 'category',
        }],
        yAxis: {
            type: 'value',
        },
        series: []
    },
    groupCurrGraph: {
        title: {
            text: '组端电流折线图',
            x: 'center'
        },
        xAxis: [{
            type: 'category',
        }],
        series: []
    },
    onlineVolGraph: {
      title: {
        text: '在线电压折线图',
        x: 'center'
      },
      xAxis: [{
        type: 'category',
      }],
      series: []
    },
    monVolGraph: {
        title: {
            text: '单体电压折线图',
            x: 'center'
        },
        legend: {
            show: true,
            data: [],
        },
        xAxis: [{
            type: 'category',
        }],
        series: []
    },
    monTmpGraph: {
        title: {
            text: '单体温度折线图',
            x: 'center'
        },
        legend: {
            show: true,
            data: [],
        },
        xAxis: [{
            type: 'category',
        }],
        series: []
    },
    monResGraph: {
        title: {
            text: '单体内阻折线图',
            x: 'center'
        },
        legend: {
            show: true,
            data: [],
        },
        xAxis: [{
            type: 'category',
        }],
        series: []
    },
};
export default {
    name: "HistoryRealtimeData",
    components: {
        LineChartPlus,
    },
    props: {
        batt: {
            type: Object,
            default() {
                return {}
            }
        }
    },
    data() {
        return {
            loading: false,
            acTabs: 'onlineVolGraph',
            filter: {
                timeType: 1,
                startTime: '',
                endTime: '',
                txt: '选择日期'
            },
            timeRange: [],
            searchParams: {
                BattGroupId: '',
                recrod_time: '',
                recrod_time1: '',
                mon_num: 0,
                note: 0
            },
            progress: {
                show: false,
                value: 0,
            },
            monCount: 0,
            monSelect: '#1',
        }
    },
    methods: {
        tabClick(params) {
            this.$nextTick(()=>{
                this.$refs[params.name].resize();
            });
        },
        resize() {
            this.$refs[this.acTabs].resize();
        },
        timeRangeChange: function() {
            // 消除单选
            if(!this.filter.timeType != -1) {
                this.filter.timeType = -1;
            }
            // 获取时间段
            const startTime = this.timeRange[1].format("yyyy-MM-dd hh:mm:ss");
            const endTime = this.timeRange[0].format("yyyy-MM-dd hh:mm:ss");
            this.filter.txt = endTime+'至'+startTime;
            // 设置时间段
            this.setRangeTime(startTime, endTime);
            // 根据查询条件获取数据
            this.loopSearch();
        },
        radioChange: function() {
            // 消除日期时间段
            if(this.timeRange.length != 0) {
                this.filter.txt = '选择日期';
                this.timeRange = [];
            }
            let date = new Date();
            // 获取选中日期
            date.setTime(date.getTime() - 3600 * 1000 * 24 * this.filter.timeType);
            // 获取时间段
            const startTime = new Date().format("yyyy-MM-dd hh:mm:ss");
            const endTime = date.format("yyyy-MM-dd hh:mm:ss");
            // 设置时间段
            this.setRangeTime(startTime, endTime);
            // 根据查询条件获取数据
            this.loopSearch();
        },
        setRangeTime: function(startTime, endTime) {
            this.searchParams.recrod_time1 = startTime;
            this.searchParams.recrod_time = endTime;
        },
        loopSearch() {
            let BattGroupId = this.searchParams.BattGroupId;
            let monNum = this.searchParams.note;    // 单体的个数
            let monFlag = this.monSelect.replace("#", "");    // 单体的编号
 
            let start = new Date(this.searchParams.recrod_time).getTime();
            let end = new Date(this.searchParams.recrod_time1).getTime();
            let times = [];
            while(start<end) {
                let recrod_time1 = start+3600*12*1000*30;
                recrod_time1 = recrod_time1>end?end:recrod_time1;
                let tmp = {
                    BattGroupId: BattGroupId,
                    note: monNum,
                    mon_num: monFlag,
                    recrod_time: new Date(start).format("yyyy-MM-dd hh:mm:ss"),
                    recrod_time1: new Date(recrod_time1).format("yyyy-MM-dd hh:mm:ss"),
                };
                times.push(tmp);
                start = recrod_time1+1000;
            }
            this.progress.value = 0;
            this.progress.show = true;
            // 开始查询
            this.search(times, 0);
        },
        search: function(times, index) {
            // 结束标识
            if(!times[index]) {
                this.progress.value = 100;
                this.resize();
                setTimeout(()=>{
                    this.progress.show=false;
                }, 1000);
                return;
            }
 
            // 设置进度值
            this.progress.value = Math.floor(index/times.length*100);
            // 查询历史实时数据
            searchHistoryRealtimeData(times[index]).then(res=>{
                let rs = JSON.parse(res.data.result);
                let data = [];
                if(rs.code == 1) {
                    data = rs.data;
                }
                // 初始化加载加载
                if(index == 0 || options.monTmpGraph.series.length == 0) {
                    // 格式化数据
                    this.formatData(data);
                }else {
                    // 格式化添加的数据
                    this.formatAppendData(data);
                }
                this.search(times, ++index);
            }).catch(error=>{
                console.log(error);
                this.search(times, ++index);
            });
        },
        formatData(data) {
            let dates = [];        // 日期
            let groupVol = [{
                name: '组端电压',
                type: 'line',
                smooth: true,
                symbolSize: 0,
                sampling: 'average',
                data: []
            }];
            let groupCurr = [{
                name: '组端电流',
                type: 'line',
                smooth: true,
                symbolSize: 0,
                sampling: 'average',
                data: []
            }];
            let onlineVol = [{
              name: '在线电压',
              type: 'line',
              smooth: true,
              symbolSize: 0,
              sampling: 'average',
              data: []
            }];
            let monVol = [];    // 单体电压
            let monTmp = [];    // 单体温度
            let monRes = [];    // 单体内阻
            let flag = '-1';
            // 遍历data
            for(let i=0; i<data.length; i++) {
                let _data = data[i];
                if(_data.recrod_time != flag) {
                    flag = _data.recrod_time;
                    groupVol[0].data.push([_data.recrod_time, _data.group_vol]);
                    groupCurr[0].data.push([_data.recrod_time,_data.group_curr]);
                    onlineVol[0].data.push([_data.recrod_time,_data.online_vol]);
                }
                // 设置单体信息
                if(typeof monVol[_data.mon_num - 1] != 'object') {
                    // 单体电压
                    monVol[_data.mon_num - 1] = {
                        name: '#'+_data.mon_num,
                        type: 'line',
                        smooth: true,
                        symbolSize: 0,
                        sampling: 'average',
                        data: []
                    };
                    // 单体温度
                    monTmp[_data.mon_num - 1] = {
                        name: '#'+_data.mon_num,
                        type: 'line',
                        showSymbol: false,
                        data: []
                    };
                    // 单体内阻
                    monRes[_data.mon_num - 1] = {
                        name: '#'+_data.mon_num,
                        type: 'line',
                        smooth: true,
                        symbolSize: 0,
                        sampling: 'average',
                        data: []
                    };
                }
                // 单体电压
                monVol[_data.mon_num - 1].data.push([_data.recrod_time, _data.mon_vol]);
                // 单体温度
                monTmp[_data.mon_num - 1].data.push([_data.recrod_time, _data.mon_tmp]);
                // 单体内阻
                monRes[_data.mon_num - 1].data.push([_data.recrod_time, _data.mon_res]);
            }
            // 设置组端电压
            options.groupVolGraph.series = groupVol;
            // 设置组端电流
            options.groupCurrGraph.series = groupCurr;
            // 设置在线电压
            options.onlineVolGraph.series = onlineVol;
 
            // 设置单体电压
            options.monVolGraph.series = monVol;
            // 设置单体温度
            options.monTmpGraph.series = monTmp;
            // 设置单体内阻
            options.monResGraph.series = monRes;
            // 设置图表的配置项
            this.setOptions();
        },
        formatAppendData(data){
            let groupVol = [[]];    // 组端电压
            let groupCurr = [[]];    // 组端电流
            let onlineVol = [[]];
            let monVol = [];    // 单体电压
            let monTmp = [];    // 单体温度
            let monRes = [];    // 单体内阻
            let flag = '-1';
            // 遍历data
            for(let i=0; i<data.length; i++) {
                let _data = data[i];
                if(_data.recrod_time != flag) {
                    flag = _data.recrod_time;
                    groupVol[0].push([_data.recrod_time, _data.group_vol]);
                    groupCurr[0].push([_data.recrod_time,_data.group_curr]);
                    onlineVol[0].push([_data.recrod_time,_data.online_vol]);
                }
                // 设置单体信息
                if(typeof monVol[_data.mon_num - 1] != 'object') {
                    // 单体电压
                    monVol[_data.mon_num - 1] = [];
                    // 单体温度
                    monTmp[_data.mon_num - 1] = [];
                    // 单体内阻
                    monRes[_data.mon_num - 1] = [];
                }
                // 单体电压
                monVol[_data.mon_num - 1].push([_data.recrod_time, _data.mon_vol]);
                // 单体温度
                monTmp[_data.mon_num - 1].push([_data.recrod_time, _data.mon_tmp]);
                // 单体内阻
                monRes[_data.mon_num - 1].push([_data.recrod_time, _data.mon_res]);
            }
 
            // 添加数据
            this.$refs.groupVolGraph.appendData(groupVol);
            this.$refs.groupCurrGraph.appendData(groupCurr);
            this.$refs.onlineVolGraph.appendData(onlineVol);
            this.$refs.monVolGraph.appendData(monVol);
            this.$refs.monTmpGraph.appendData(monTmp);
            this.$refs.monResGraph.appendData(monRes);
        },
        setOptions() {
            // 设置数据
            this.$refs.groupVolGraph.setOption(options.groupVolGraph);
            this.$refs.groupCurrGraph.setOption(options.groupCurrGraph);
            this.$refs.onlineVolGraph.setOption(options.onlineVolGraph);
            this.$refs.monVolGraph.setOption(options.monVolGraph);
            this.$refs.monTmpGraph.setOption(options.monTmpGraph);
            this.$refs.monResGraph.setOption(options.monResGraph);
            this.setLegends();
        },
        setLegends() {
            this.$refs.monVolGraph.setLegend(this.monSelect);
            this.$refs.monTmpGraph.setLegend(this.monSelect);
            this.$refs.monResGraph.setLegend(this.monSelect);
        },
        monSelectChange: function() {
            //this.setLegends();
            this.loopSearch();
        }
    },
    computed: {
        monOptions: function() {
            var result = [];
            for(var i=0; i<this.monCount; i++) {
                var text = '#'+(i+1);
                result.push({
                    label: text,
                    value: text,
                });
            }
            return result;
        },
    },
    mounted() {
        // 初始化echarts的高度
        this.$nextTick(()=>{
            this.$refs[this.acTabs].resize();
        });
        // 设置电池组id
        this.searchParams.BattGroupId = this.batt.BattGroupId;
        this.searchParams.note = this.batt.MonCount;
        // 设置单体的个数
        this.monCount = this.batt.MonCount;
 
        // 初始化内容
        this.setOptions();
        // 初始化查询
        this.radioChange();
    }
}
</script>
 
<style scoped>
.history-realtime-data {
    height: 600px;
}
.ele-filter-container {
    padding-left: 8px;
    background-color: #052272;
}
.page-content {
    position: relative;
    box-sizing: border-box;
    height: 100%;
    border-radius: 8px;
}
.progress-container {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 99;
    background-color: rgba(155, 152, 152, 0.1);
}
.progress-content {
    display: flex;
    height: 100%;
    flex-direction: row;     /* 子元素横向排列 */
    justify-content: center; /* 相对父元素水平居中 */
    align-items: center; /*  子元素相对父元素垂直居中 */
}
.progress-content .progress {
    display: inline-block;
}
</style>