xufenglei
2018-08-02 e97df5aa8edc8e2737d5cb0dab4314871cd3bf71
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
import {environment} from '../../../../environments/environment';
import {Component, OnInit} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {zip} from 'rxjs/observable/zip';
 
@Component({
  selector: 'app-real-time',
  templateUrl: './real-time.component.html',
})
export class RealTimeComponent implements OnInit {
 
  public monitorPointOptions = [];
  public avgs = {};
  public levels = [35, 115, 200];
  public devices = [];
  constructor(
    private http: HttpClient
  ) {}
 
  ngOnInit() {
    this.http.get(environment.SERVER_BASH_URL + 'monitor-point/list/region', {params: {name: 'areaCode', value: '320583'}}).subscribe((res: any) => {
      this.monitorPointOptions = res.data;
    });
  }
 
  monitorPointChange(id) {
    this.avgs = {};
    this.devices = [];
    zip(
      this.http.get(environment.SERVER_BASH_URL + 'demo/avg', {params: {monitorPointId: id}}),
      this.http.get(environment.SERVER_BASH_URL + 'device/professionId', {params: {monitorPointId: id}})
    ).subscribe(
      ([avgs, devices]) => {
        if (!!avgs) {
          this.avgs = avgs;
        }
        if (!!devices['data']) {
          this.devices = devices['data'];
        }
      });
  }
}