he wei
2024-09-21 70edda3b00f2528a473c28ec5a50b739ed160f0f
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
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
<template>
  <content-box
    style="margin-left: 4px; margin-right: 4px"
    :title="battFullName"
  >
    <div slot="box-tools" class="box-tools">
      <el-tooltip
        class="item"
        effect="dark"
        content="历史数据"
        placement="bottom"
      >
        <i class="iconfont el-icon-jinru" @click="syncPage"></i>
      </el-tooltip>
    </div>
    <div slot="box-tools" class="box-tools" style="right: 40px">
      <el-tooltip
        class="item"
        effect="dark"
        content="历史实时数据"
        placement="bottom"
      >
        <i
          class="el-iconfont el-icon-s-marketing"
          @click="historyRealTimeDataDialog.show = true"
        ></i>
      </el-tooltip>
    </div>
    <flex-layout :no-bg="true">
      <div class="content-header" slot="header">
        <div class="table-layout">
          <div class="table-row">
            <div class="table-cell text-right w80">环境温度:</div>
            <div class="table-cell">
              <el-input
                size="small"
                :disabled="true"
                :value="headers.envirTmp"
              ></el-input>
            </div>
            <div class="table-cell text-right w80">电池电压:</div>
            <div class="table-cell">
              <el-input
                size="small"
                :disabled="true"
                :value="backInputs.group_online_vol"
              ></el-input>
            </div>
            <div class="table-cell text-right w80">剩余容量:</div>
            <div class="table-cell">
              <el-input
                size="small"
                :disabled="true"
                :value="headers.restCap"
              ></el-input>
            </div>
            <div class="table-cell text-right w80">遥测量数量:</div>
            <div class="table-cell">
              <el-input
                size="small"
                :disabled="true"
                :value="headers.remoteControlCount"
              ></el-input>
            </div>
          </div>
          <div class="table-row">
            <div class="table-cell text-right w80">功率温度:</div>
            <div class="table-cell">
              <el-input
                size="small"
                :disabled="true"
                :value="headers.powerTmp"
              ></el-input>
            </div>
            <div class="table-cell text-right w80">电池电流:</div>
            <div class="table-cell">
              <el-input
                size="small"
                :disabled="true"
                :value="backInputs.groupCurr"
              ></el-input>
            </div>
            <div class="table-cell text-right w80">总容量:</div>
            <div class="table-cell">
              <el-input
                size="small"
                :disabled="true"
                :value="headers.battTotalCap"
              ></el-input>
            </div>
            <div class="table-cell text-right w80">循环次数:</div>
            <div class="table-cell">
              <el-input
                size="small"
                :disabled="true"
                :value="headers.battCycles"
              ></el-input>
            </div>
          </div>
        </div>
      </div>
      <div class="page-content">
        <flex-layout :no-bg="true">
          <el-row :gutter="16" class="full-height">
            <el-col :span="12" class="full-height">
              <div class="full-height padding0080 box-sizing">
                <flex-box title="单体电池电压">
                  <bar-chart
                    ref="monVol"
                    id="monVol"
                    unit="V"
                    :show-tools="true"
                  ></bar-chart>
                </flex-box>
              </div>
            </el-col>
            <el-col :span="12" class="full-height">
              <div class="full-height padding8080 box-sizing">
                <flex-box title="电芯温度">
                  <bar-chart
                    ref="monTemp"
                    id="monTemp"
                    unit="℃"
                    :show-tools="true"
                    max-color="red"
                    min-color="green"
                  ></bar-chart>
                </flex-box>
              </div>
            </el-col>
          </el-row>
          <div class="flex-layout-footer" slot="footer" v-if="false">
            <div class="flex-layout-wrap">
              <flex-box
                class="wrap-item"
                v-for="item in events"
                :key="item.title"
                :title="item.title"
              >
                <el-table
                  :data="item.data"
                  stripe
                  :show-header="false"
                  size="small"
                >
                  <el-table-column
                    prop="name"
                    label="名称"
                    align="center"
                    min-width="120"
                  >
                  </el-table-column>
                  <el-table-column
                    prop="value"
                    label="值"
                    align="center"
                    min-width="80"
                  >
                    <template slot-scope="scope">
                      <hdw-light :type="scope.row.value"></hdw-light>
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="name1"
                    label="名称"
                    align="center"
                    min-width="120"
                  ></el-table-column>
                  <el-table-column
                    prop="value1"
                    label="值"
                    align="center"
                    min-width="80"
                  >
                    <template slot-scope="scope">
                      <hdw-light
                        v-if="scope.row.name1"
                        :type="scope.row.value1"
                      ></hdw-light>
                    </template>
                  </el-table-column>
                </el-table>
              </flex-box>
            </div>
          </div>
        </flex-layout>
      </div>
    </flex-layout>
    <!-- 实时历史数据 -->
    <el-dialog
      :title="historyDataTitle"
      width="1200px"
      :visible.sync="historyRealTimeDataDialog.show"
      :close-on-click-modal="false"
      top="0"
      class="dialog-center no-bg"
      :modal-append-to-body="false"
    >
      <history-lithium-real-time
        :visible="historyRealTimeDataDialog.show"
      ></history-lithium-real-time>
    </el-dialog>
  </content-box>
</template>
 
<script>
import ContentBox from "@/components/ContentBox";
import { getBarNum, regEquipType, Timeout } from "@/assets/js/tools";
import FlexBox from "@/components/FlexBox";
import BarChart from "@/components/chart/BarChart";
import lithium from "./js/lithium";
import HdwLight from "@/components/HdwLight";
import { realTimeGroup, realTimeSearch, lithiumBattery } from "./js/realTime";
import HistoryLithiumRealTime from "./components/historyLithiumRealTime";
import { getBattGroupInfo } from "../dataMager/js/battGroupMager";
import createWs from "@/assets/js/websocket";
const WSMixin = createWs("RealTime");
 
import const_digit from "@/assets/js/const/const_digit";
const {
  cap: CAP,
  vol: VOL,
  curr: CURR,
  res: RES,
  conduct: CONDUCT,
  temp: TEMP,
  hum: HUM,
} = const_digit;
 
let monVolOption, monTempOption;
export default {
  name: "lithiumBattery",
  mixins: [WSMixin],
  components: {
    HistoryLithiumRealTime,
    BarChart,
    FlexBox,
    ContentBox,
    HdwLight,
  },
  data() {
    return {
      batt: {},
      tblData: lithium.tblData(),
      events: [
        {
          title: "均衡事件",
          data: [
            {
              name: "均衡模块开启",
              value: -1,
              name1: "静态均衡指示",
              value1: -1,
            },
            {
              name: "静态均衡超时",
              value: -1,
              name1: "超温禁止均衡",
              value1: -1,
            },
            {
              name: "超温禁止均衡",
              value: -1,
              name1: false,
              value1: -1,
            },
          ],
        },
        {
          title: "电压事件",
          data: [
            {
              name: "单体过压告警",
              value: -1,
              name1: "单体过压保护",
              value1: -1,
            },
            {
              name: "单体欠压告警",
              value: -1,
              name1: "单体欠压保护",
              value1: -1,
            },
            {
              name: "总压过压告警",
              value: -1,
              name1: "总压过压保护",
              value1: -1,
            },
            {
              name: "总压欠压告警",
              value: -1,
              name1: "总压欠压保护",
              value1: -1,
            },
          ],
        },
      ],
      infos: {
        battCycles: 0,
        battTotalCap: 771,
        battTotalvolAlmState: 2048,
        currEventCode: 256,
        customAlmCount: 0,
        dischargeCurrAlmState: 0,
        envirTmp: 31.9,
        evirTmpAlmState: 0,
        fetStateCode: 0,
        junhengEventCode: 0,
        junhengStateCode: 0,
        powerTmp: 31.1,
        powerTmpAlmState: 0,
        recordTime: "2021-05-13 00:00:00",
        remoteControlCount: 59394,
        restCap: 1.3,
        sysStateCode: 0,
        tmpEventCode: 0,
        volEventCode: 0,
      },
      inputs: {
        groupVol: 0,
        onlineVol: 0,
        groupCurr: 0,
      },
      historyRealTimeDataDialog: {
        show: false,
      },
    };
  },
  watch: {
    "$route.params.battGroupId"(battGroupId) {
      this.$nextTick(() => {
        this.getBattGroupInfo(battGroupId);
      });
    },
    "$store.state.theme.collapse"() {
      this.$nextTick(() => {
        this.resize();
      });
    },
  },
  methods: {
    initChart() {
      monVolOption = {
        title: {
          show: true,
          text: "最大值=0V;最小值=0V;平均值=0V",
          x: "center",
          textStyle: {
            fontSize: "14",
          },
        },
        series: [
          {
            name: "单体电压",
            type: "bar",
            data: [],
          },
        ],
      };
      monTempOption = {
        title: {
          show: true,
          text: "最大值=0℃;最小值=0℃;平均值=0℃",
          x: "center",
          textStyle: {
            fontSize: "14",
          },
        },
        series: [
          {
            name: "电芯温度",
            type: "bar",
            data: [],
          },
        ],
      };
 
      // 设置配置项
      this.setChart();
    },
    getBattGroupInfo(battGroupId) {
      let loading = this.$layer.loading();
      getBattGroupInfo(battGroupId)
        .then((res) => {
          // 关闭等待框
          this.$layer.close(loading);
          res = res.data;
          if (res.code) {
            this.leafClick(res.data[0]);
          } else {
            this.$layer.msg("未获取到电池组的信息");
          }
        })
        .catch((error) => {
          // 关闭等待框
          this.$layer.close(loading);
          console.log(error);
        });
    },
    leafClick(data) {
      this.batt = data;
      this.sendMessage();
    },
    onWSOpen() {
      this.sendMessage();
    },
    sendMessage() {
      let batt = this.batt;
      // console.log(batt, '=====batt');
      if (!batt.battGroupId || !this.isWSOpen) {
        return false;
      }
      let params = {
        battGroupId: batt.battGroupId,
        devId: batt.fbsdeviceId,
        powerDeviceId: 0,
        pageType: "btssreen",
      };
      // console.log("====", params, JSON.stringify(params));
      this.SOCKET.send(JSON.stringify(params));
    },
    onWSMessage(res) {
      res = JSON.parse(res.data);
      let data = res.data.data;
      // console.log(data, "=====data");
      this.realTimeSearch(data.rtdata);
      this.searchLithiumBattery(data.lithium);
      this.realTimeGroupss(data.rtstate);
    },
    setChart() {
      // 设置单体电压图表配置项
      this.$refs.monVol.setOption(monVolOption);
      // 设置电芯温度图表配置项
      this.$refs.monTemp.setOption(monTempOption);
    },
    setChartData(vols, temps) {
      // 单体电压
      let volBarNum = getBarNum(vols);
      monVolOption.title.text =
        "最大值=" +
        volBarNum.max.toHold(VOL) +
        "V;最小值=" +
        volBarNum.min.toHold(VOL) +
        "V;平均值=" +
        volBarNum.avg.toHold(VOL) +
        "V";
      monVolOption.series[0].data = vols;
 
      // 电芯温度
      let tempBarNum = getBarNum(temps);
      monTempOption.title.text =
        "最大值=" +
        tempBarNum.max.toHold(TEMP) +
        "℃;最小值=" +
        tempBarNum.min.toHold(TEMP) +
        "℃;平均值=" +
        tempBarNum.avg.toHold(TEMP) +
        "℃";
      monTempOption.series[0].data = temps;
 
      this.setChart();
    },
    resize() {
      // 设置单体电压图表配置项
      this.$refs.monVol.resize();
      // 设置电芯温度图表配置项
      this.$refs.monTemp.resize();
    },
    searchLithiumBattery(res) {
      if (res) {
        if (res.code && res.data) {
          this.infos = res.data2.list[0];
        }
      }
    },
    realTimeSearch(res) {
      if (res) {
        // 电压值
        let vols = [];
        let temps = [];
        if (res.code && res.data) {
          let data = res.data2;
          vols = data.map((item) => {
            return ["#" + item.monNum, item.monVol];
          });
 
          temps.push(["电芯温度1", data[0].monTmp]);
          temps.push(["电芯温度2", data[1].monTmp]);
          temps.push(["电芯温度3", data[2].monTmp]);
          temps.push(["电芯温度4", data[3].monTmp]);
        }
 
        // 设置图表的数据
        this.setChartData(vols, temps);
      }
    },
    /* 实时组端信息 */
    realTimeGroupss(res) {
      if (res) {
        if (res.code && res.data) {
          this.inputs = res.data2;
        }
      }
    },
    // 向父级发送同步页面的指令
    syncPage() {
      let batt = this.batt;
      let search =
        "?province=" +
        batt.stationName1 +
        "&city=" +
        batt.stationName2 +
        "&county=" +
        batt.stationName5 +
        "&home=" +
        batt.stationName3 +
        "&batt=" +
        batt.battGroupId;
      this.$router.push("/dataTest/history" + search);
    },
  },
  computed: {
    battFullName() {
      let batt = this.batt;
      if (batt.stationName && batt.battGroupName) {
        return batt.stationName + "-" + batt.battGroupName;
      }
      return "电池组全称";
    },
    headers() {
      let infos = this.infos;
      return {
        envirTmp: infos.envirTmp.toHold(TEMP) + "℃", // 环境温度
        powerTmp: infos.powerTmp.toHold(TEMP) + "℃", // 功率温度
        restCap: infos.restCap.toHold(CAP) + "AH", // 剩余容量
        battTotalCap: infos.battTotalCap.toHold(CAP) + "AH", // 总容量
        battCycles: infos.battCycles, //   循环次数
        remoteControlCount: infos.remoteControlCount,
      };
    },
    backInputs() {
      let batt = this.batt;
      let list = {
        group_online_vol: "在线:0.00V;组端:0.00V",
        groupCurr: "0.00A",
      };
 
      if (regEquipType(batt.FBSDeviceId, "BTS9605")) {
        list.group_online_vol = `组端:${this.inputs.groupVol.toHold(VOL)}V`;
      } else {
        list.group_online_vol = `在线:${this.inputs.onlineVol.toHold(
          VOL
        )}V;组端:${this.inputs.groupVol.toHold(VOL)}V`;
      }
 
      list.groupCurr = this.inputs.groupCurr.toHold(CURR) + "A";
 
      return list;
    },
    historyDataTitle() {
      return this.batt.stationName + "-历史实时数据";
    },
  },
  mounted() {
    let battGroupId = this.$route.params.battGroupId;
    if (battGroupId) {
      this.getBattGroupInfo(battGroupId);
    }
 
    // 初始化图表
    this.initChart();
 
    this.$nextTick(() => {
      this.resize();
    });
 
    // 屏幕缩放时触发
    window.addEventListener("resize", this.resize);
  },
  destroyed() {
    window.removeEventListener("resize", this.resize);
    // 关闭计时器
  },
};
</script>
 
<style scoped>
.content-header {
  box-sizing: border-box;
  padding-right: 8px;
}
 
.table-cell.text-right {
  font-size: 14px;
}
 
.table-cell.text-right .iconfont {
  margin-right: 4px;
}
 
.table-row .table-cell {
  padding-top: 12px;
}
 
.page-content {
  position: relative;
  padding: 8px 8px 2px 8px;
  box-sizing: border-box;
  height: 100%;
}
 
.flex-center {
  height: 100%;
}
 
.flex-layout-footer {
  padding-top: 8px;
  padding-bottom: 8px;
  box-sizing: border-box;
}
 
.flex-layout-wrap {
  display: flex;
  flex-wrap: wrap;
}
 
.wrap-item {
  margin-right: 16px;
}
 
.box-tools {
  line-height: 32px;
}
 
.box-tools .iconfont,
.box-tools .el-iconfont {
  font-size: 24px;
}
 
.box-tools .iconfont:hover,
.box-tools .el-iconfont:hover {
  cursor: pointer;
  color: #cfcfcf;
}
 
.box-tools .iconfont:active,
.box-tools .el-iconfont:active {
  color: #ff0000;
}
</style>