All files / src/app/platform platform.component.ts

36.67% Statements 11/30
0% Branches 0/2
11.11% Functions 1/9
37.5% Lines 9/24
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 481x 1x 1x 1x           1x                   1x             1x                             1x         1x  
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute, Params } from '@angular/router';
import { PlatformService } from './platform.service';
import { parseResponse } from '../shared/util';
 
@Component({
  selector: 'plat-form',
  templateUrl: './platform.component.html',
})
export class PlatformComponent implements OnInit {
  systems: any[] = [];
  currentSystem: any;
  systemId: number;
  tables: any[];
 
  constructor(private router: Router,
              private routeInfo: ActivatedRoute,
              private platformServ: PlatformService) { }
 
  ngOnInit() {
    // 监测路由
    this.routeInfo.params.subscribe((params: Params) => {
      this.getSystems();
    });
  }
 
  getSystems() {
    this.platformServ.getSystemList().subscribe(result => {
      this.systems = parseResponse(result).data;
      this.currentSystem = this.systems.find(item => item.id == this.routeInfo.snapshot.params.systemId);
 
      // id不存在就赋值第一项的id
      if (this.currentSystem ===  undefined) {
        this.router.navigate([`/platform/${this.systems[0].id}/0/0`]);
        return;
      }
 
      this.getTables(this.currentSystem.id);
    });
  }
 
  getTables(systemId: number) {
    this.platformServ.getTableList(systemId).subscribe(data => {
      this.tables = parseResponse(data).data;
    });
  }
}