riku
2023-02-24 110a8520fdf3caacd46750e7b76862df8c7eabd1
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
// pages/mService/pDevicedata/pDevicedata.js
import moment from '../../../utils/moment.min'
import bLoadingStatus from '../../../base/behaviors/bLoadingStatus'
import bLoadingToast from '../../../base/behaviors/bLoadingToast'
 
const echarts = require("../../../component/ec-canvas/echarts")
const deviceservice = require('../../../service/deviceservice')
const app = getApp()
 
function setOption(chart, data) {
  var option = {
    // title: {
    //   text: data.total, //主标题文本
    //   subtext: '注册企业', //副标题文本
    // },
    textStyle: {
      color: 'white'
    },
    color: ['white'],
    grid: {
      containLabel: true
    },
    tooltip: {
      show: true,
      trigger: 'axis'
    },
    xAxis: {
      name: '时间',
      nameLocation: 'end',
      type: 'time',
      boundaryGap: false,
      nameRotate: 90,
      nameTextStyle: {
        fontSize: 10,
      },
      axisLabel: {
        rotate: 45
      }
    },
    yAxis: {
      name: '浓度\n(mg/m³)',
      nameLocation: 'end',
      position: 'left',
      type: 'value',
      splitLine: {
        lineStyle: {
          type: 'dashed'
        }
      },
      // show: false
    },
    grid: {
      x: 38,
      y: 40,
      x2: 30,
      y2: 60
    },
 
    series: [{
      name: '浓度',
      type: 'line',
      smooth: true,
      areaStyle: {
        color: {
          type: 'linear',
          x: 0.5,
          y: 0,
          x2: 0.5,
          y2: 1,
          colorStops: [{
            offset: 0,
            color: '#28db74' // 0% 处的颜色
          }, {
            offset: 1,
            color: '#dcfeea79' // 100% 处的颜色
          }],
          opacity: 0.1,
          global: false // 缺省为 false
        }
      },
      data: data,
    }]
  };
 
  chart.setOption(option);
}
 
Page({
  behaviors: [bLoadingStatus, bLoadingToast],
  /**
   * 页面的初始数据
   */
  data: {
    ec: {
      lazyLoad: true
    },
    //查询日期
    selectDate: '',
    endDay: '',
    //查询时间
    startTime: '',
    endTime: '',
    //监测数据
    dataList: [{
      time: '----',
      value: '--'
    }, ],
    //排口位置
    outfallLocation: undefined,
    //排口所属
    outfallOwner: undefined
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
 
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.ecComponent = this.selectComponent('#mychart-dom-line');
    this.initChart()
  },
 
  initParams() {
    const now = moment()
    const eD = now.format("YYYY-MM-DD")
    this.setData({
      selectDate: eD,
      endDay: eD,
      startTime: '00:00',
      endTime: '23:59'
    })
  },
 
  initChart: function () {
    var data = []
    this.ecComponent.init((canvas, width, height, dpr) => {
      // 获取组件的 canvas、width、height 后的回调函数
      // 在这里初始化图表
      const chart = echarts.init(canvas, null, {
        width: width,
        height: height,
        devicePixelRatio: dpr // new
      });
      canvas.setChart(chart);
      setOption(chart, data);
 
      // 将图表实例绑定到 this 上,可以在其他成员函数(如 dispose)中访问
      this.chart = chart;
      this.getDeviceData()
      this.initParams()
 
      // 注意这里一定要返回 chart 实例,否则会影响事件处理等
      return chart;
    });
  },
 
  getDeviceData() {
    this.setData({
      loading: true
    })
 
    var that = this
    const {
      selectDate,
      startTime,
      endTime
    } = this.data
    let sT = ''
    let eT = ''
    if (selectDate != '') {
      sT = selectDate + ' ' + startTime
      eT = selectDate + ' ' + endTime
    }
    const cb = {
      success(data) {
        that.setData({
          dataList: data.reverse()
        })
        that.parseChart(data)
      },
      fail(err) {
        that.setData({
          dataList: []
        })
      },
      complete() {
        that.setData({
          loading: false
        })
      }
    }
    const sceneType = app.globalData.userInfo.extension2
    switch (sceneType) {
      case '1':
        deviceservice.getJingAnFumeVakue(app.globalData.accessToken.userId, sT, eT, cb)
        break;
      // case '2':
      //   break;
      // case '3':
      //   break;
      // case '4':
      //   break;
      // case '5':
      //   break;
      // case '6':
      //   break;
      // case '7':
      //   break;
      default:
        this.setData({
          dataList: [],
          loading: false
        })
        break;
    }
  },
 
  parseChart(dataList) {
    const xValues = []
    dataList.forEach(d => {
      let t = d.time.replace(' ', 'T')
      t = t + ':00.000'
      xValues.push([t, d.value])
    });
    setOption(this.chart, xValues)
 
    // setOption(this.chart, [
    //   ['2022-11-28T10:05:00.000', 0.02],
    //   ['2022-11-28T10:10:00.000', 0.04],
    //   ['2022-11-28T10:15:00.000', 0.02],
    //   ['2022-11-28T10:20:00.000', 0.02],
    //   ['2022-11-28T10:25:00.000', 0.01],
    //   ['2022-11-28T10:30:00.000', 0.01],
    //   ['2022-11-28T10:35:00.000', 0.01],
    //   ['2022-11-28T10:40:00.000', 0.01],
    //   ['2022-11-28T10:45:00.000', 0.02],
    //   ['2022-11-28T10:50:00.000', 0.03],
    //   ['2022-11-28T10:55:00.000', 0.08],
    //   ['2022-11-28T11:00:00.000', 0.1],
    // ])
  },
 
  bindDateChange(e) {
    let d = e.detail.value
    this.setData({
      selectDate: d,
    })
  },
 
  bindStartTimeChange(e) {
    let d = e.detail.value
    this.setData({
      startTime: d,
    })
  },
 
  bindEndTimeChange(e) {
    let d = e.detail.value
    this.setData({
      endTime: d,
    })
  }
})