Newer
Older
import {AfterViewInit, Component, ElementRef, OnInit, Renderer2, ViewChild} from '@angular/core';
import {JhiEventManager} from 'ng-jhipster';
import { Principal} from '../shared';
import {AlarmService} from '../alarm/alarm.service';
import {NzMessageService} from 'ng-zorro-antd';
import {LayoutService} from '../layouts/layout.service';
import {SelectGroupComponent} from '../modal/select-group/select-group.component';
@Component({
selector: 'jhi-home',
templateUrl: './home.component.html',
styleUrls: [
'home.css'
]
})
export class HomeComponent implements OnInit,AfterViewInit {
@ViewChild("leftDiv") leftDiv:ElementRef;
@ViewChild("rightDiv") rightDiv:ElementRef;
warnList= [];
totalNum;
groupList;
pageNum = 1;
pageCount = 10;
loading = false;
obj = {
leftGroupId:null,
alarmGroupId:null
};
private overAllSer:OverAllService,private message:NzMessageService,
private alarmSer:AlarmService,private renderer:Renderer2,
private layoutSer:LayoutService,
private principal: Principal,
private eventManager: JhiEventManager,
private router:Router
}
ngAfterViewInit(){
let rightHeight = this.rightDiv.nativeElement.clientHeight;
this.renderer.setStyle(this.leftDiv.nativeElement,"height",rightHeight +"px");
}
//查看详情
goToDetail(item) {
this.router.navigate(['app/main/basic-detail'], {
queryParams: {
hostId: item.hostid,
name: item.hostname,
hostName: item.hostname
}
});
}
//获取分组
getGroup() {
this.overAllSer.findGroup().subscribe(
(res) => {
this.obj.leftGroupId = this.groupList[0].groupid;
this.countGroupItem();
}
//主机组中统计
countGroupItem(){
this.layoutSer.findHostCountByStatusByGroup(this.obj.leftGroupId).subscribe(
(res)=>{
this.setLeftOne(res.data);
}
);
this.layoutSer.findItemStatisticsByGroupid(this.obj.leftGroupId).subscribe(
(res)=>{
this.leftTwoData = res.data;
this.setLeftTwo(res.data);
}
)
}
setLeftOne(data){
if(this.leftOneData.serious > 0){
let a:any = (this.leftOneData.serious / this.leftOneTotal)* 100;
this.leftOneDataPre.seriousPer = a.toFixed(2);
if(this.leftOneData.waring > 0){
let b:any = ( (this.leftOneData.waring / this.leftOneTotal)* 100 );
if(this.leftOneData.normal > 0){
let c:any = ( (this.leftOneData.normal / this.leftOneTotal)* 100);
this.leftOneDataPre.normalPer = c .toFixed(2);
}
if(this.leftOneData.disable > 0){
let d:any = ( (this.leftOneData.disable / this.leftOneTotal)* 100 );
this.leftOneDataPre.disablePer = d .toFixed(2);
fontWeight: 'normal',
},
subtextStyle: {
color: '#de4751',
fontSize: 12
}
},
tooltip: {
trigger: 'item',
formatter: "{a} <br/>{b} : {c} ({d}%)"
},
series: [
{
label: {
normal: {
show: false,
position: 'center'
}
},
labelLine: {
normal: {
show: false
}
},
data: [
],
itemStyle: {
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
};
}
this.leftTwoTotal = data.total;
if(this.leftTwoData.serious > 0){
let w:any = ( (this.leftTwoData.serious / this.leftTwoTotal)*100 );
this.leftTwoDataPre.seriousPer = w.toFixed(2);
if(this.leftTwoData.waring > 0){
let x:any = ( (this.leftTwoData.waring / this.leftTwoTotal)*100 );
this.leftTwoDataPre.warningPer = x .toFixed(2);
}
if(this.leftTwoData.normal > 0){
let y:any = ( (this.leftTwoData.normal / this.leftTwoTotal)*100 );
this.leftTwoDataPre.normalPer = y.toFixed(2);
}
if(this.leftTwoData.disable > 0){
let z:any = ( (this.leftTwoData.disable / this.leftTwoTotal)*100);
this.leftTwoDataPre.disablePer = z.toFixed(2);
fontWeight: 'normal',
},
subtextStyle: {
color: '#de4751',
fontSize: 12
}
},
tooltip: {
trigger: 'item',
formatter: "{a} <br/>{b} : {c} ({d}%)"
},
series: [
{
label: {
normal: {
show: false,
position: 'center'
}
},
labelLine: {
normal: {
show: false
}
},
data: [
],
itemStyle: {
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
};
if(res.data && res.data.length > 0){
this.rightTwoChart = {
tooltip : {
trigger: 'item',
formatter: "{a} <br/>{b} : {c} ({d}%)"
},
type: 'pie',
radius : '55%',
center: ['50%', '60%'],
data:res.data.map(e=>{
const arr = {
name:e.name
}
return arr;
}),
itemStyle: {
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
const data = {
pageNum: this.pageNum,
pageCount: this.pageCount,
obj:{
this.warnList = res.data.data;
this.totalNum = res.data.totalNum;
}
}