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;
});
}
}
|