测试 用electron + springboot 构建桌面应用
he wei
2022-03-21 c036bed301fcd484e7ba7f7f931efb85831d11fd
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
<template>
  <flex-layout>
    <div class="content_header" slot="header">
      <three-btn @click="goSelect">重选文件</three-btn>
      <three-btn @click="exportExcel">导出</three-btn>
      <div class="">
        记录开始时间:2021-03-21 17:52:05
        测试类型:充电
        绝缘
      </div>
    </div>
    <div class="main">
      <div class="flex-row contain-flex-column">
        <flex-box class="item" size="mini" title="组端电压折线图">
          <normal-lines id="groupVol" ref="groupVol" unit="V"></normal-lines>
        </flex-box>
        <flex-box class="item" size="mini" title="电池电流折线图">
          <normal-lines id="groupCurr" ref="groupCurr" unit="A"></normal-lines>
        </flex-box>
      </div>
      <div class="flex-row contain-flex-column">
        <flex-box class="item" size="mini" title="单体电压折线图">
          <normal-lines id="vol" ref="vol" unit="V"></normal-lines>
        </flex-box>
        <flex-box class="item" size="mini" title="容量折线图">
          <div slot="tools" class="chart-tools-wrapper">
            <el-select
              v-model="chartType"
              size="mini"
              @change="changeChartType"
            >
              <el-option
                v-for="item in chartTypes"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </div>
          <normal-lines id="cap" ref="cap" unit="AH"></normal-lines>
        </flex-box>
      </div>
    </div>
    <!-- 导出用的图表 可变的那组图 -->
    <div class="hideContain">
      <normal-lines id="hideChart" ref="hideChart"></normal-lines>
    </div>
  </flex-layout>
</template>
 
<script>
import NormalLines from "@/components/myCharts/NormalLines";
import FlexBox from "@/components/FlexBox";
import ThreeBtn from "@/components/ThreeBtn";
import axios from "@/assets/js/axios";
const dataType = {
  0xFD: '放电',
  0xFC: '充电',
  0xFB: '普通数据'
};
 
export default {
  name: "",
  components: {
    NormalLines,
    FlexBox,
    ThreeBtn,
  },
  data() {
    let info = this.$route.query.data;
    return {
      info,
      chartType: "testCap",
      chartTypes: [
        {
          label: "测试容量",
          value: "testCap",
          unit: "AH",
          fixed: 0,
        },
        {
          label: "实际容量(预估)",
          value: "actualCap",
          unit: "AH",
          fixed: 0,
        },
        // {
        //   label: "剩余容量",
        //   value: "residualCap",
        //   unit: "AH",
        //   fixed: 0,
        // },
        // {
        //   label: "剩余时间",
        //   value: "residualTime",
        //   unit: "",
        //   fixed: 0,
        // },
      ],
      testCapOption: null,
      actualCapOption: null,
      residualCapOption: null,
      residualTimeOption: null,
      unit: ''
    };
  },
  methods: {
    formatData() {
      let { fboData, fboDataStart, fboDataStop } = this.info;
      console.log(fboData, fboDataStart, fboDataStop, "=====data?");
      let monCount = fboDataStart.BattGroup;
      let times = [],
        groupVol = [],
        groupCurr = [],
        testCap = [],
        actualCap = [],
        residualCap = [],
        residualTime = [],
        PosInsRes = [],
        NegInsRes = [],
        SingleVol = [];
      for (let i = 0, j = monCount; i < j; i++) {
        SingleVol[i] = {
          name: "#" + (i + 1) + "电压",
          type: "line",
          symbolSize: 0,
          sampling: "average",
          data: [],
        };
      }
 
      for (let i = 0, j = fboData.length; i < j; i++) {
        let item = fboData[i];
        let testtime = item.m_TestTime;
        let hour = testtime.hour > 9 ? testtime.hour : "0" + testtime.hour;
        let minute =
          testtime.minute > 9 ? testtime.minute : "0" + testtime.minute;
        let second =
          testtime.second > 9 ? testtime.second : "0" + testtime.second;
        let time = "" + hour + ":" + minute + ":" + second;
        // 时间
        times.push(time);
        // 总电压
        groupVol.push(item.SumVoltage);
        // 总电流
        groupCurr.push(item.SumCurrent);
        // 测试容量
        testCap.push(item.testCap);
        // 实际容量
        actualCap.push(item.actualCap);
        // 剩余容量
        residualCap.push(item.residualCap);
        // 剩余时间
        residualTime.push(item.residualTime);
        // 正极绝缘电阻
        PosInsRes.push(item.PosInsRes);
        // 负极绝缘电阻
        NegInsRes.push(item.NegInsRes);
        // 单体电压
        for (let m = 0, n = monCount; m < n; m++) {
          SingleVol[m].data.push(item.SingleVol[m]);
        }
      }
      let groupVolOption = {
        xData: times,
        series: [
          {
            name: "组端电压",
            type: "line",
            symbolSize: 0,
            sampling: "average",
            data: groupVol,
          },
        ],
      };
      let currOption = {
        xData: times,
        series: [
          {
            name: "电流",
            type: "line",
            symbolSize: 0,
            sampling: "average",
            data: groupCurr,
          },
        ],
      };
      let volOption = {
        xData: times,
        series: SingleVol,
      };
      let testCapOption = {
          unit: 'AH',
          xData: times,
          series: [
            {
              name: "测试容量",
              type: "line",
              symbolSize: 0,
              sampling: "average",
              data: testCap,
            },
          ],
        },
        actualCapOption = {
          unit: 'AH',
          xData: times,
          series: [
            {
              name: "实际容量",
              type: "line",
              symbolSize: 0,
              sampling: "lttb",
              data: actualCap,
            },
          ],
        },
        residualCapOption = {
          unit: 'AH',
          xData: times,
          series: [
            {
              name: "剩余容量",
              type: "line",
              symbolSize: 0,
              sampling: "average",
              data: residualCap,
            },
          ],
        },
        residualTimeOption = {
          unit: '',
          xData: times,
          series: [
            {
              name: "剩余时间",
              type: "line",
              symbolSize: 0,
              sampling: "average",
              data: residualTime,
            },
          ],
        };
      this.testCapOption = testCapOption;
      this.actualCapOption = actualCapOption;
      this.residualCapOption = residualCapOption;
      this.residualTimeOption = residualTimeOption;
 
      this.$refs.groupVol.setData(groupVolOption);
      this.$refs.groupCurr.setData(currOption);
      this.$refs.vol.setData(volOption);
      this.$refs.cap.setData(testCapOption);
      // 建立联动
      this.$G.chartManage.connect(["groupVol", "groupCurr", "vol", "cap"]);
    },
    changeChartType(v) {
      this.$refs.cap.setData(this[v + "Option"]);
    },
    goSelect() {
      this.$router.push("/selectFile");
    },
    // 导出报表
    exportExcel() {
      // 容量折线图
      let arr = ['testCap', 'actualCap'];
      let o_pic = {};
      arr.forEach((v) => {
        let option = this[v + 'Option'];
        this.unit = option.unit;
        this.$refs.hideChart.setData(option);
        o_pic[v] = this.$refs.hideChart.getDataURL();
      });
      let params = {
        filePath: this.info.filePath,
        groupVol_echart: this.$refs.groupVol.getDataURL(),
        curr_echart: this.$refs.groupCurr.getDataURL(),
        vol_echart: this.$refs.vol.getDataURL(),
        cap_echart: o_pic.testCap,
        actualCap_echart: o_pic.actualCap
      };
      let baseURL = axios.defaults.baseURL;
      baseURL = baseURL ? baseURL : "";
      var actionUrl = baseURL + "export";
      this.construtFormSubmit(actionUrl, params);
    },
    construtFormSubmit(actionUrl, parms) {
      var form = document.createElement("form");
      form.id = "specialGraph";
      form.style.display = "none";
      form.action = actionUrl;
      form.enctype = "multipart/form-data";
      form.method = "post";
      document.body.appendChild(form);
 
      for (var key in parms) {
        var input = document.createElement("input");
        input.type = "hidden";
        input.name = key;
        input.value = parms[key];
        form.appendChild(input);
      }
      form.submit();
      document.body.removeChild(form);
    },
  },
 
  mounted() {
    console.log(this.info);
    if (!this.info || !this.info.fboData) {
      this.$router.push("/selectFile");
    } else {
      this.formatData();
    }
  },
};
</script>
 
<style scoped>
.main {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.flex-row {
  flex: 1;
}
.contain-flex-column {
  display: flex;
  flex-direction: row;
}
.item {
  background: #0d43a7;
  flex: 1;
}
.content_header {
  padding: 8px;
}
>>> .three-btn + .three-btn {
  margin-left: 8px;
}
.item + .item {
  margin-left: 8px;
}
.flex-row + .flex-row {
  margin-top: 8px;
}
.hideContain {
  position: absolute;
  width: 0;
  height: 0;
  display: none;
}
</style>