board.js
11.6 KB
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
// pages/tabbar/board.js
var app = getApp();
import moment from 'moment'
import {
GET_ACTIVE_STATICINFO,
GET_TRACK_ALARMINFO,
GET_FENCE_ALARMINFO,
GET_OFFLINE_ALARMINFO,
GET_POWER_ALARMINFO,
GET_ACTIVE_DEVICEINFO,
GET_PSEUDO_OFFLINE
} from '../../http/board'
import * as echarts from '../../components/ec-canvas/echarts';
Page({
/**
* 页面的初始数据
*/
data: {
active: 0,
pageNumber: 1,
pageSize: 10,
staticInfo: {},
totalPages: 0,
list: [],
ec: {
lazyLoad: true
},
showPopup: false,
shared: app.globalData.shared,
columns: [],
dateRange: {},
showText: '',
startTime: '',
endTime: '',
pickerIndex: 3,
currentYear: '',
currentMonth: ''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
console.log(app)
this.setData({
shared: app.globalData.shared
})
this.getWeeksRange()
if (!app.globalData.shared) {
this.getOffLine()
this.getStatic()
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
if (!app.globalData.shared) {
this.getList()
}
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
if (typeof this.getTabBar === 'function' &&
this.getTabBar()) {
this.getTabBar().setData({
selected: 0
})
}
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
this.getWeeksRange()
if (app.globalData.shared) {
return false;
}
this.setData({
pageNumber: 1,
pageSize: 10,
list: [],
totalPages: 0
})
this.getOffLine()
this.getStatic()
//this.getReport()
this.getList()
wx.stopPullDownRefresh()
},
// 生命周期函数-监听页面触底
onReachBottom() {
let total = this.data.totalPages;
let num = this.data.pageNumber;
// 判断是否有下一页
console.log(total + '---' + num)
if (total > num) {
this.setData({
pageNumber: num + 1
});
this.getList()
}
},
// 获取列表
getList() {
let idx = this.data.active;
// 统计报表
if (idx == 0) {
this.getReport()
}
// 防拆报警
if (idx == 1) {
this.getTrackList()
}
// 围栏报警
if (idx == 2) {
this.getFenceList()
}
// 离线报警
if (idx == 3) {
this.getOfflineList()
}
// 低电量
if (idx == 4) {
this.getPowerList()
}
},
// 监听tabs
onChange(e) {
let idx = e.detail.index
this.setData({
active: idx,
pageNumber: 1,
pageSize: 10,
list: [],
totalPages: 0
})
this.getList()
},
// 获取统计信息
getStatic() {
let _this = this;
GET_ACTIVE_STATICINFO().then(res => {
if (res.code != 200) {
return false;
}
_this.setData({
staticInfo: res.data
})
if(_this.data.pseudoOffLine) {
let sum = _this.addSub(res.data.onlineRate, res.data.fakeOfflineRate);
_this.setData({
sumOnlineRate: sum
})
}
})
},
// 加法计算函数
addSub(arg1, arg2) {
let b = Number(arg1) + Number(arg2)
b = Math.round((b) * 100) / 100
b.toFixed(2)
return b
},
getOffLine() {
let _this = this;
GET_PSEUDO_OFFLINE({permissionTag: 'data_doard_offLine'}).then(res => {
if (res.code != 200) {
return false;
}
_this.setData({
pseudoOffLine: res.data
})
})
},
// 获取防拆报警列表
getTrackList() {
let _this = this
let oParams = {}
oParams.pageNumber = this.data.pageNumber
oParams.pageSize = this.data.pageSize
GET_TRACK_ALARMINFO(oParams).then(res => {
if (res.code != 200) {
return false;
}
let obj = res.data || {}
let olist = _this.data.list || [];
let nlist = obj.list || [];
let clist = olist.concat(nlist);
_this.setData({
list: clist,
totalPages: obj.totalPages
})
})
},
// 获取围栏报警列表
getFenceList() {
let _this = this
let oParams = {}
oParams.pageNumber = this.data.pageNumber
oParams.pageSize = this.data.pageSize
GET_FENCE_ALARMINFO(oParams).then(res => {
if (res.code != 200) {
return false;
}
let obj = res.data || {}
let olist = _this.data.list || [];
let nlist = obj.list || [];
let clist = olist.concat(nlist);
_this.setData({
list: clist,
totalPages: obj.totalPages
})
})
},
// 获取离线报警
getOfflineList() {
let _this = this
let oParams = {}
oParams.pageNumber = this.data.pageNumber
oParams.pageSize = this.data.pageSize
GET_OFFLINE_ALARMINFO(oParams).then(res => {
if (res.code != 200) {
return false;
}
let obj = res.data || {}
let olist = _this.data.list || [];
let nlist = obj.list || [];
let clist = olist.concat(nlist);
_this.setData({
list: clist,
totalPages: obj.totalPages
})
})
},
// 低电量
getPowerList() {
let _this = this
let oParams = {}
oParams.pageNumber = this.data.pageNumber
oParams.pageSize = this.data.pageSize
GET_POWER_ALARMINFO(oParams).then(res => {
if (res.code != 200) {
return false;
}
let obj = res.data || {}
let olist = _this.data.list || [];
let nlist = obj.list || [];
let clist = olist.concat(nlist);
_this.setData({
list: clist,
totalPages: obj.totalPages
})
})
},
// 初始化图表
initCharts(xAxis, data) {
let _this = this;
let ecComponent = this.selectComponent('#mychart-dom-bar');
ecComponent.init((canvas, width, height, dpr) => {
// 获取组件的 canvas、width、height 后的回调函数
// 在这里初始化图表
const chart = echarts.init(canvas, null, {
width: width,
height: height,
devicePixelRatio: dpr // new
});
_this.setOption(chart, xAxis, data);
// 注意这里一定要返回 chart 实例,否则会影响事件处理等
return chart;
});
},
// 设置图表数据
setOption(chart, xAxis, data) {
const option = {
color: ['#0077FF'],
xAxis: {
type: 'category',
axisLine: {
show: false
},
axisTick: {
show: false
},
axisLabel: {
margin: 16
},
data: xAxis
},
yAxis: {
type: 'value',
splitLine: {
show: true,
lineStyle: {
type: 'dashed',
color: '#DFE2E6'
}
}
},
series: [{
data: data,
type: 'line',
smooth: false,
areaStyle: {
color: 'rgba(0, 119, 255, 0.1)'
}
}]
};
chart.setOption(option);
},
// 获取报表统计
getReport() {
let _this = this;
let oParams = {}
oParams.startTime = this.data.startTime;
oParams.endTime = this.data.endTime
GET_ACTIVE_DEVICEINFO(oParams).then(res => {
if (res.code != 200) {
return false;
}
let list = res.data || [];
let yDate = []
let xDate = []
list.map(k => {
yDate.push(k.activeNumber)
xDate.push(k.activeDate.substring(5))
})
_this.initCharts(xDate, yDate)
})
},
// 打开弹框
openDialog() {
this.setData({
showPopup: true
})
},
// 关闭弹框
onClose() {
this.setData({
showPopup: false
})
this.getReport()
},
// 获取当月有几个星期
getWeeksRange() {
let columns = []
const recentWeekSTime = moment().startOf('week').add(1, 'day') //.format('YYYY-MM-DD');
const recentWeekETime = moment().endOf('week').add(1, 'day');
const dateRange = {};
if (new Date().getDay() === 0) {
const _sTime = recentWeekSTime.subtract(1, 'week');
const _eTime = recentWeekETime.subtract(1, 'week');
columns.unshift({
label: `${_sTime.format('YYYY年M月D日')}~${_eTime.format('YYYY年M月D日')}`,
startTime: _sTime.format('YYYY-MM-DD'),
endTime: _eTime.format('YYYY-MM-DD')
})
} else {
columns.unshift({
label: `${recentWeekSTime.format('YYYY年M月D日')}~${recentWeekETime.format('YYYY年M月D日')}`,
text: `${recentWeekSTime.format('YYYY年M月D日')}~${recentWeekETime.format('YYYY年M月D日')}`,
startTime: recentWeekSTime.format('YYYY-MM-DD'),
endTime: recentWeekETime.format('YYYY-MM-DD')
});
}
for (let i = 0; i < 3; i++) {
const _sTime = recentWeekSTime.subtract(1, 'week');
const _eTime = recentWeekETime.subtract(1, 'week');
columns.unshift({
label: `${_sTime.format('YYYY年M月D日')}~${_eTime.format('YYYY年M月D日')}`,
text: `${_sTime.format('YYYY年M月D日')}~${_eTime.format('YYYY年M月D日')}`,
startTime: _sTime.format('YYYY-MM-DD'),
endTime: _eTime.format('YYYY-MM-DD')
});
}
let currentYear = moment().year()
let currentMonth = moment().month() + 1
// let columns = []
// for (let i = 0; i < 4; i++) {
// columns.push(`${currentYear}年${currentMonth}月第${i+1}周`)
// }
this.setData({
startTime: columns[3].startTime,
endTime: columns[3].endTime,
showText: columns[3].text,
currentYear: currentYear,
currentMonth: currentMonth,
columns: columns
})
},
// 切换时间
onConfirm(e) {
console.log(e)
let m = e.detail.value
let idx = e.detail.index;
let columns = this.data.columns;
let o = columns[idx]
this.setData({
startTime: o.startTime,
endTime: o.endTime,
showPopup: false,
showText: m.text,
pickerIndex: idx
})
this.getReport()
}
})