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
<template>
  <div class="module-wrapper"
       v-loading="loading"
       element-loading-text="拼命加载中"
       element-loading-spinner="el-icon-loading"
       element-loading-background="rgba(0, 0, 0, 0.2)">
    <div class="module-content-item">
      <layout-box>
        <div class="layout-content">
          <div class="mon-vol-bar">
            <flex-box title="锂电池包电压" size="mini">
              <divide-gradient-bar ref="packVol" name="锂电池包电压" unit="V"></divide-gradient-bar>
            </flex-box>
          </div>
          <div class="mon-temp-bar">
            <flex-box title="锂电池包电流" size="mini">
              <divide-dot-bar ref="packCurr" name="锂电池包电流" unit="A" :max="1"></divide-dot-bar>
            </flex-box>
          </div>
        </div>
      </layout-box>
    </div>
    <div class="module-content-item">
      <layout-box>
        <div class="layout-content">
          <div class="mon-vol-bar">
            <flex-box :title="monVolText" size="mini">
              <divide-gradient-bar ref="monVol" name="单体电压" unit="V"></divide-gradient-bar>
            </flex-box>
          </div>
          <div class="mon-temp-bar">
            <flex-box :title="monTempText" size="mini">
              <divide-cube-bar ref="monTemp" name="单体温度" unit="℃" :max="100"></divide-cube-bar>
            </flex-box>
          </div>
        </div>
      </layout-box>
    </div>
  </div>
</template>
 
<script>
import LayoutBox from "@/pages/dataTest/components/layout-box";
import FlexBox from "@/components/FlexBox";
import DivideBar from "@/components/myCharts/DivideBar";
import DivideCubeBar from "@/components/myCharts/DivideCubeBar";
import MonLithiumPack from "@/pages/dataTest/components/monLithiumPack";
import DivideGradientBar from "@/components/myCharts/DivideGradientBar";
import DivideDotBar from "@/components/myCharts/DivideDotBar";
export default {
  name: "lithiumPackTab",
  components: {
    MonLithiumPack,
    DivideBar,
    DivideCubeBar,
    DivideGradientBar,
    DivideDotBar,
    LayoutBox,
    FlexBox
  },
  props: {
    // 数据有变化
    changeFlag: {
      type: Number,
      default: 0,
    },
    // 数据是否更新 仅查看时才更新
    update: {
      type: Boolean,
      default: false,
    },
    monVols: {
      type: Array,
      default() {
        return []
      }
    },
    monTemps: {
      type: Array,
      default() {
        return []
      },
    },
    packVols: {
      type: Array,
      default() {
        return []
      },
    },
    packCurrs: {
      type: Array,
      default() {
        return []
      },
    }
  },
  data() {
    return {
      loading: false,
      list: [],
      monNum: 16,
      packNum: 20
    }
  },
  watch: {
    changeFlag() {
      this.setMonData();
      this.changeListInfo();
    },
    update() {
      this.setMonData();
    }
  },
  methods: {
    resize() {
      this.$nextTick(()=>{
        // 锂电池包电压
        if(this.$refs.packVol) {
          this.$refs.packVol.resize();
        }
 
        // 锂电池包电流
        if(this.$refs.packCurr) {
          this.$refs.packCurr.resize();
        }
 
        // 单体电压图表
        if(this.$refs.monVol) {
          this.$refs.monVol.resize();
        }
 
        // 单体温度图表
        if (this.$refs.monTemp) {
          this.$refs.monTemp.resize();
        }
      });
    },
    /**
     * 切换锂电池包
     * @param item
     */
    changPack(index) {
      this.clearActivePack();
      this.$nextTick(()=>{
        //item.active = true;
        this.list[index].active = true;
      });
      this.loading = true;
      setTimeout(()=>{
        this.loading = false;
        this.setMonData();
      }, 1000)
    },
    clearActivePack() {
      for(let i=0; i<this.list.length; i++) {
        this.list[i].active = false;
      }
    },
    setMonPackData() {
      // 设置锂电池包
      for(let i=0; i<this.packNum; i++) {
        this.list.push({
          num: (i+1),
          active: false,
          vol: 0,
          curr: 0
        });
      }
      this.list[0].active = true;
 
      // 包电压
      let packVol = {
        xLabel: [],
        sData: []
      };
 
      // 包电流
      let packCurr = {
        xLabel: [],
        sData: []
      };
      for(let i=0; i<this.packNum; i++) {
        let label = "包"+(i+1);
        packVol.xLabel.push(label);
        packVol.sData.push(0);
 
        packCurr.xLabel.push(label);
        packCurr.sData.push(0);
      }
 
      if(this.$refs.packVol) {
        this.$refs.packVol.setData(packVol);
      }
 
      if(this.$refs.packCurr) {
        this.$refs.packCurr.setData(packCurr);
      }
    },
    changeListInfo() {
      if(!this.update) {
        return;
      }
      let packVols = this.packVols;
      let packCurrs = this.packCurrs;
      for(let i=0; i<this.list.length; i++) {
        let packVol = packVols[i];
        let packCurr = packCurrs[i];
        this.list[i].vol = packVol?packVol:0;
        this.list[i].curr = packCurr?packCurr:0;
      }
 
      // 包电压
      let packVol = {
        xLabel: [],
        sData: []
      };
 
      // 包电流
      let packCurr = {
        xLabel: [],
        sData: []
      };
      for(let i=0; i<this.packNum; i++) {
        let vol = packVols[i];
        let curr = packCurrs[i];
        let label = "包"+(i+1);
        packVol.xLabel.push(label);
        packVol.sData.push(vol?vol:0);
 
        packCurr.xLabel.push(label);
        packCurr.sData.push(curr?curr:0);
      }
 
      if(this.$refs.packVol) {
        this.$refs.packVol.setData(packVol);
      }
 
      if(this.$refs.packCurr) {
        this.$refs.packCurr.setData(packCurr);
      }
    },
    setMonData() {
      if(!this.update && !this.loading) {
        return;
      }
 
      let activeNum = this.getActiveNum();
      let monNum = this.monNum;
      let monVols = [];
      for(let i=1; i<321; i++) {
        monVols.push(i);
      }
 
      // 单体电压
      let monVolValues = this.getValues(this.monVols, activeNum, monNum);
      let monVol = {
        xLabel: [],
        sData: []
      };
      for(let i=0; i<monVolValues.length; i++) {
        monVol.xLabel.push("#"+(i+1));
        monVol.sData.push(monVolValues[i]);
      }
      if(this.$refs.monVol) {
        this.$refs.monVol.setData(monVol);
      }
 
      let monTemps = [];
      for(let i=1; i<321; i++) {
        monTemps.push(i);
      }
      // 单体温度
      let monTempValues = this.getValues(this.monTemps, activeNum, monNum);
      let monTemp = {
        xLabel: [],
        sData: []
      };
      for(let i=0; i<monTempValues.length; i++) {
        monTemp.xLabel.push("#"+(i+1));
        monTemp.sData.push(monTempValues[i]);
      }
      if(this.$refs.monTemp) {
        this.$refs.monTemp.setData(monTemp);
      }
    },
    /**
     * 获取激活的电池包
     * @returns {number}
     */
    getActiveNum() {
      let list = this.list;
      let num = 0;
      for(let i=0; i<list.length; i++) {
        if(list[i].active) {
          num = list[i].num;
          break;
        }
      }
      return num-1;
    },
    getValues(list, activeNum, monNum) {
      let values = [];
      for(let i=activeNum*monNum; i<activeNum*monNum+monNum; i++) {
        values.push(list[i]?list[i]:0);
      }
      return values;
    }
  },
  computed: {
    activePack() {
      let list = this.list;
      let index = 1;
      for(let i=0; i<list.length; i++) {
        let item = list[i];
        if(item.active) {
          index = item.num;
        }
      }
      return index+"";
    },
    monVolText() {
      return "包"+this.activePack+"-单体电压";
    },
    monTempText() {
      return "包"+this.activePack+"-单体温度";
    }
  },
  mounted() {
    this.setMonPackData();
    this.setMonData();
 
    // 锂电池包点击事件
    let packVolChart = this.$refs.packVol.getChart();
    packVolChart.getZr().on('click', params=>{
      const points = [params.offsetX, params.offsetY];
      if(packVolChart.containPixel('grid', points)) {
        let dataIndex = packVolChart.convertFromPixel({seriesIndex: 0}, [params.offsetX, params.offsetY])[0];
        this.changPack(dataIndex);
      }
    });
    // 锂电池包点击事件
    let packCurrChart = this.$refs.packCurr.getChart();
    packCurrChart.getZr().on('click', params=>{
      const points = [params.offsetX, params.offsetY];
      if(packCurrChart.containPixel('grid', points)) {
        let dataIndex = packCurrChart.convertFromPixel({seriesIndex: 0}, [params.offsetX, params.offsetY])[0];
        this.changPack(dataIndex);
      }
    });
  }
}
</script>
 
<style scoped>
.module-wrapper {
  display: flex;
  width: 100%;
  height: 100%;
  flex-direction: row;
  box-sizing: border-box;
}
.module-content-item{
  flex: 1;
  height: 100%;
  overflow-x: hidden;
  margin-right: 8px;
}
.layout-content {
  box-sizing: border-box;
  padding: 12px 16px 16px 16px;
  height: 100%;
}
.mon-vol-bar,
.mon-temp-bar {
  box-sizing: border-box;
  height: 50%;
}
.mon-vol-bar {
  padding-bottom: 8px;
}
.mon-temp-bar {
  padding-top: 8px;
}
.ele-mon-pack {
  box-sizing: border-box;
  padding: 12px 16px 16px 16px;
  height: 100%;
}
</style>