riku
2023-08-29 71b1532d5a3609f3125e15fbe65e4b34bb6c4e8b
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
<!-- 日均值 -->
<script>
import TimeSelectWithShortCuts from '../../sfc/TimeSelectWithShortCuts.vue';
import InputSearch from '../../sfc/InputSearch.vue';
import AreaAndmonitorType from '../../sfc/AreaAndmonitorType.vue';
import DustRadarChart from '../../sfc/DustRadarChart.vue';
import exceptionApi from '@/api/exceptionApi.js';
 
// 异步组件
const LineChart = defineAsyncComponent(() => import('../../sfc/LineChart.vue'));
 
import dayjs from 'dayjs';
export default {
  components: {
    LineChart,
    TimeSelectWithShortCuts,
    InputSearch,
    AreaAndmonitorType,
    DustRadarChart
  },
  data() {
    return {
      isNoData: false,
      loading: false,
      chartData: [],
      chartData1: {}, //保存查询的结果
      chartData2: {},
      chartData3: {},
      chartData4: {},
      //devId:'',          //设备编号
      begin: '2023-05-01', //开始时间
      end: '2023-05-15', //结束时间
 
      form: {
        // 站点名称
        name: '',
        // 设备编号
        number: '',
        // 开始时间
        beginTime: '',
        // 结束时间
        endTime: ''
      },
      // 折线图配置项
      option: {},
 
      // 复选框组
      radio: 1
    };
  },
  mounted() {
    this.fetch();
  },
  methods: {
    giveTime(val) {
      //将中国标准时间转为指定格式(该组件返回的标准时间的格式,所以必须的加这个函数)
      this.form.beginTime = dayjs(val[0]).format('YYYY-MM-DD HH:mm:ss');
      this.form.endTime = dayjs(val[1]).format('YYYY-MM-DD HH:mm:ss');
    },
 
    fetch() {
      this.fetchData();
      this.exceptiondataCount();
    },
 
    // 点击展示按钮
    fetchData() {
      if (
        this.form.beginTime >= this.form.endTime &&
        (this.form.beginTime != null || this.form.endTime != null) &&
        (this.form.beginTime != '' || tthis.form.endTime != '')
      ) {
        alert('请输入有效的时间段');
        return;
      }
      let params = {};
      if (this.form.name) {
        params['siteName'] = this.form.name;
      }
      if (this.form.beginTime) {
        params['beginTime'] = this.form.beginTime;
      }
      if (this.form.endTime) {
        params['endTime'] = this.form.endTime;
      }
      this.loading = true;
      exceptionApi
        .analysisdata(this.form.name, this.form.beginTime, this.form.endTime)
        .then((response) => {
          this.chartData = response.data.data;
          this.loading = false;
          if (response.data.data.length == 0) {
            this.isNoData = true;
            return;
          }
          // 移除空数据状态
          this.isNoData = false;
          this.setChart();
        });
    },
 
    // 选择其他值类型时
    setChart() {
      if (this.chartData.length) {
        // x轴日期时间
        let dateList = [];
        //颗粒物平均浓度
        let dayAvg = [];
        let dataOnline = [];
        let dataValid = [];
        let dataExceed = [];
        this.chartData.forEach((item) => {
          //x轴日期
          dateList.push(item.lst);
          // 历史油烟浓度
          dayAvg.push(item.dayAvg);
          dataOnline.push(item.dayOnline.slice(0, -1));
          dataValid.push(item.dayValid.slice(0, -1));
          dataExceed.push(item.dayExceeding.slice(0, -1));
        });
 
        this.chartData1 = {
          x: dateList,
          y: dayAvg
        };
        this.chartData2 = {
          x: dateList,
          y: dataOnline
        };
        this.chartData3 = {
          x: dateList,
          y: dataValid
        };
        this.chartData4 = {
          x: dateList,
          y: dataExceed
        };
      }
    },
 
    // 企业异常详情
    exceptiondataCount() {
      exceptionApi
        .exceptiondata1({
          siteName: this.form.name,
          beginTime: this.form.beginTime,
          endTime: this.form.endTime
        })
        .then((res) => {
          // 所有异常
        });
    }
  }
};
</script>
<template>
  <div class="search-container">
    <el-container>
      <el-main>
        <el-form :inline="true" :model="form">
          <el-form-item>
            <AreaAndmonitorType></AreaAndmonitorType>
          </el-form-item>
          <el-form-item>
            <InputSearch
              :isNeedDefaultSite="1"
              @submit-value="(n) => (form.name = n)"
            ></InputSearch>
          </el-form-item>
          <el-form-item>
            <TimeSelectWithShortCuts
              @submit-time="giveTime"
            ></TimeSelectWithShortCuts>
          </el-form-item>
 
          <el-form-item>
            <el-button type="primary" @click="fetch">展示折线图</el-button>
          </el-form-item>
 
          <!-- <div>
            <el-form-item>
              <el-radio-group v-model="radio" @change="setChart">
                <el-radio :label="1">颗粒物浓度平均值</el-radio>
                <el-radio :label="2">数据在线/有效/超标率</el-radio>
              </el-radio-group>
            </el-form-item>
          </div> -->
        </el-form>
 
        <div>数据统计时段:实际获取数据的时段</div>
        <el-card> 异常数量统计 </el-card>
        <el-card> 超标复现率 </el-card>
        <el-card>
          <el-empty v-show="isNoData" :image-size="200" />
          <LineChart
            title="日均值"
            :chartData="chartData1"
            yName="浓度"
            seriesName="日均值"
          >
          </LineChart>
          <LineChart
            title="日在线率"
            :chartData="chartData2"
            yName="百分比"
            seriesName="日在线率"
          >
          </LineChart>
          <LineChart
            title="日有效率"
            :chartData="chartData3"
            yName="百分比"
            seriesName="日有效率"
          >
          </LineChart>
          <LineChart
            title="日超标率"
            :chartData="chartData4"
            yName="百分比"
            seriesName="日超标率"
          >
          </LineChart>
          <DustRadarChart></DustRadarChart>
        </el-card>
      </el-main>
    </el-container>
  </div>
</template>
 
<style scoped>
.el-card {
  margin-top: 40px;
  border-radius: 9px;
}
.chart-container {
  width: 100%;
  height: 600px;
}
.el-header {
  background-color: #010408;
  color: #333;
  line-height: 60px;
}
</style>