zmc
2023-08-29 b77599ace9fc1c68bacd0e37ddb2e83812660ae3
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
<!-- 日均值 -->
<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';
// 异步组件
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: [],     //保存查询的结果
      //devId:'',          //设备编号
      begin:'2023-05-01',         //开始时间
      end:'2023-05-15',           //结束时间
 
      form: {
        // 站点名称
        name: '',
        // 设备编号
        number: '',
        // 开始时间
        beginTime: '',
        // 结束时间
        endTime: ''
      },
      // 折线图配置项
      option:{},
 
      // 复选框组
      radio:1
    }
  },
  mounted(){
  
    this.fetchData()
  },
  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');
    },
 
    // 点击展示按钮
    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
      this.$http.get('/dust/analysisdata',{params:params})
        .then(response => {
          this.chartData = response.data.data
          console.log('分析数据为:',this.chartData);
          this.loading=false
          if(response.data.data.length==0){
          alert('该时段无数据')
          this.isNoData = true
          return
        }
        // 移除空数据状态
        this.isNoData = false
          this.drawChart()
        })
    },
    // 折线图配置项
    drawChart() {
     if(this.chartData.length!=0){
      let xdate=[]
      let ydata=[]
      this.chartData.map(item=>{
        xdate.push(item['lst'])
        ydata.push(item['dayAvg'])
      })
      console.log('配置项为:',xdate,ydata);
      this.option ={
        xAxis: {
            name: '时间',
            data: xdate
          },
          yAxis: {
              type: 'value',
              axisLabel: {
              show: true,
              interval: 'auto'
            },
            name: '颗粒物浓度'
          },
          series: [
            {
              name: 'fume',
              type: 'line',
              data: ydata
            }
          ]
      }
     }
    },
 
    // 选择其他值类型时
    setChart(){
      if(this.chartData.length){
        if (this.radio == 1) {
        // x轴日期时间
        let dateList = [];
        //颗粒物平均浓度
        let dayAvg = [];
        this.chartData.forEach(item => {
          //x轴日期
          dateList.push(item.lst);
          // 历史油烟浓度
          dayAvg.push(item.dayAvg);
        })
        this.option={}
        this.option = {
          xAxis: {
            name: '时间',
            data: dateList,
          },
 
          yAxis: {
          type: 'value',
          axisLabel: {
            show: true,
            interval: 'auto'
          },
          name: 'mg/m³'
        },
          series: [
            {
              name: '颗粒物浓度',
              type: 'line',
              data: dayAvg
            }
          ]
        }
      }
      else if (this.radio == 2) {
         // x轴日期时间
      let dateList = [];
       // 历史风机电
       let dataOnline = [];
       let dataValid = [];
       let dataExceed = [];
       this.chartData.forEach(item => {
          //x轴日期
          dateList.push(item.lst);
           // 历史风机电
          dataOnline.push(item.dayOnline.slice(0,-1));
          dataValid.push(item.dayValid.slice(0,-1));
          dataExceed.push(item.dayExceeding.slice(0,-1));
        })
        this.option={}
        this.option = {
          legend: {
           data: ['日数据在线率','日数据有效率','日数据超标率']
          },
          xAxis: {
          data: dateList,
          name: '时间'
        },
        yAxis: {
          type: 'value',
          axisLabel: {
            show: true,
            interval: 'auto'
          },
          name: '%'
        },
        series: [
          {
            name: '日数据在线率',
            type: 'line',
            data: dataOnline
          },
          {
            name: '日数据有效率',
            type: 'line',
            data: dataValid
          },
          {
            name: '日数据超标率',
            type: 'line',
            data: dataExceed
          },
 
        ]
        }
      }
    }
  }
  }
}
</script>
<template>
  <div class="search-container">
    <el-container>
      <el-main>
 
        <el-form :inline="true" :model="form" class="demo-form-inline">
          <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="fetchData">展示折线图</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>
 
        <el-card>
          <el-empty v-show="isNoData" :image-size="200" />
          <LineChart :chartData="option"> </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>