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
<template>
  <div class="params-container">
    <el-row :gutter="layout.gutter">
      <el-col :span="12" class="tbl-wrapper-dialog">
        <flex-box size="mini" title="单体电压差折线图">
          <div slot="tools" class="params-dialog-tools">
            <div class="input-wrapper">
              <el-input v-model="baseTime" size="mini" type="text">
                <template slot="prepend">基准时间</template>
                <template slot="append">分钟</template>
              </el-input>
            </div>
            <el-button type="primary" size="mini" icon="el-icon-refresh" @click="formatData">更新</el-button>
          </div>
          <normal-lines ref="vol" unit="V"></normal-lines>
        </flex-box>
      </el-col>
      <el-col :span="12" class="tbl-wrapper-dialog">
        <flex-box size="mini" title="单体温度差折线图">
          <normal-lines ref="temp" unit="℃"></normal-lines>
        </flex-box>
      </el-col>
    </el-row>
    <div class="form-footer">
      <el-button type="primary" size="mini" @click="success">确定</el-button>
      <el-button type="warning" size="mini" @click="close">取消</el-button>
    </div>
  </div>
</template>
 
<script>
import FlexBox from "@/components/FlexBox";
import NormalLines from "@/components/myCharts/NormalLines";
import formatTime from "@/assets/js/tools/formatTime";
export default {
  name: "DataDiffter",
  components: {NormalLines, FlexBox},
  times: [],
  volSeries: [],
  tempSeries: {},
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    vol: {
      type: Array,
      default() {
        return [];
      }
    },
    temp: {
      type: Array,
      default() {
        return [];
      }
    },
  },
  data() {
    return {
      layout: {
        gutter: 8,
        span: 12
      },
      baseTime: 2,
      timeList: [],
    };
  },
  methods: {
    close() {
      this.$emit("update:visible", false);
    },
    formatData() {
      let vol = this.vol;
      let temp = this.temp;
 
      if(vol.length != 0) {
        let times = [];
 
        let flag = 0;
        let seconds = this.baseTime*60;
        // 获取时间轴(逻辑下方获取值的逻辑要一致)
        vol[0].map((item, key)=>{
          let reTime = seconds*flag;
          let testTime = formatTime(item[0]);
          if(testTime>=reTime) {
            flag++;
            times.push(item[0]);
          }else if(key == (vol[0].length-1)) {
            times.push(item[0]);
          }
        });
        let volSeries = this.getSeries(vol);
        let tempSeries = this.getSeries(temp);
 
        // 配置项
        let volOption = {
          xData: times,
          series: volSeries,
        };
 
        let tempOption = {
          xData: times,
          series: tempSeries,
        };
 
        this.$options.times = times;
        this.$options.volSeries = volSeries;
        this.$options.tempSeries = tempSeries;
 
        this.$refs.vol.setData(volOption);
        this.$refs.temp.setData(tempOption);
      }
    },
    getSeries(data) {
      return data.map((item, key)=>{
        let dataList = this.getItemDataByTime(item, this.baseTime);
        return {
          name: "#"+(key+1),
          type: 'line',
          symbolSize: 0,
          sampling: "average",
          data: dataList,
        }
      });
    },
    getItemDataByTime(data, time) {
      let list = [];
      let seconds = time*60;
      let flag = 0;
      let baseValue = 0;
      data.map((item,key)=>{
        let reTime = seconds*flag;
        let testTime = formatTime(item[0]);
        if(testTime>=reTime) {
          flag++;
          if(flag == 1) {
            baseValue = item[1];
          }
          list.push(item[1]);
        }else if(key == (data.length-1)) {
          list.push(item[1]);
          if(flag == 0) {
            baseValue = data[0][0];
          }
        }
      });
      baseValue = list[0];
      return list.map((item, key)=>{
        if(key == 0) {
          return 0;
        }else {
          return (list[key]-baseValue).toHold(2);
        }
      });
    },
    success() {
      let volList = this.$options.volSeries.map(item=>{
        return item.data;
      });
      let tempList = this.$options.tempSeries.map(item=>{
        return item.data;
      });
      let data = {
        splitTime: this.baseTime,
        mon_vol_compare_pic: this.$refs.vol.getDataURL(),
        mon_temp_compare_pic: this.$refs.temp.getDataURL(),
        time_compare_list: JSON.stringify(this.$options.times),
        mon_vol_compare_list: JSON.stringify(volList),
        mon_tmp_compare_list: JSON.stringify(tempList),
      };
      this.$emit('success', data);
    },
  },
  mounted() {
    this.formatData();
  }
}
</script>
 
<style scoped>
.params-container {
  width: 1300px;
  box-sizing: border-box;
  padding: 8px;
  background-color: #0d43a7;
}
.tbl-wrapper-dialog {
  height: 420px;
}
.input-wrapper {
  display: inline-block;
  width: 230px;
  margin-right: 8px;
}
</style>