xufenglei
2018-07-24 fd35962de838e033a8964e0959c99572f02b15f0
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
import {environment} from '../../../../environments/environment';
import {Component, OnInit, OnDestroy} from '@angular/core';
import {NzMessageService} from 'ng-zorro-antd';
import {_HttpClient} from '@delon/theme';
import {HttpClient} from '@angular/common/http';
import * as moment from 'moment';
import {DeviceService} from '@business/services/http/device.service';
 
@Component({
  selector: 'pollution-management',
  templateUrl: './management.component.html',
  styleUrls: ['./management.component.less'],
  providers: [DeviceService]
})
export class PollutionManagementComponent implements OnInit, OnDestroy {
 
  constructor(
    private deviceService: DeviceService,
    private http: _HttpClient,
    public msg: NzMessageService,
    private http2: HttpClient) {
  }
 
  _dataSet = [];
 
  sensorKey = 'e1';
  
  ngOnInit() {
    this.changeSensorKey(this.sensorKey);
  }
 
  changeSensorKey(sensorKey) {
    const params = {sensorKey: sensorKey, dimension: 'monitorPoint', areaCode: '320583'};
    this.http2.get(environment.SERVER_BASH_URL + 'demo/pollution', {params: params}).subscribe((res: any) => {
      this._dataSet = res;
    });
  }
 
  ngOnDestroy(): void {
  }
 
  sort(sortName, sortValue) {
    this._dataSet = [
      ...(<any[]>this._dataSet).sort((a, b) => {
        if (a[sortName] > b[sortName]) {
          return (sortValue === 'ascend') ? 1 : -1;
        } else if (a[sortName] < b[sortName]) {
          return (sortValue === 'ascend') ? -1 : 1;
        } else {
          return 0;
        }
      })
    ];
  }
}