Newer
Older
import {Component, OnInit, ViewChild} from '@angular/core';
import {OverAllService} from '../overAll.service';
import {NzModalService} from 'ng-zorro-antd';
import {NzMessageService} from 'ng-zorro-antd';
import {Router} from '@angular/router';
import {
FormBuilder,
FormGroup,
Validators
} from '@angular/forms';
import {BasicEditComponent} from '../../modal/basic-edit/basic-edit.component';
import {BasiCheckComponent} from '../../modal/basi-check/basi-check.component';
import {CreateGroupComponent} from '../../modal/create-group/create-group.component';
import {AlarmModalComponent} from '../../modal/alarm-modal/alarm-modal.component';
export interface TreeNodeInterface {
host: any;
name: string;
age: number;
level: number;
expand: boolean;
address: string;
children?: TreeNodeInterface[];
}
styles: [
`:host ::ng-deep .table-dropdown a{
font-weight: 300;
}`
]
@ViewChild('basicEdit') basicEdit: BasicEditComponent;
@ViewChild('smartCheck') smartCheck: BasiCheckComponent;
@ViewChild('smartCreateGroup') smartCreateGroup: CreateGroupComponent;
constructor(private fb: FormBuilder, private overAllSer: OverAllService, private router: Router,
private modalService: NzModalService, private message: NzMessageService,
collapse(array: TreeNodeInterface[], data: TreeNodeInterface, $event: boolean): void {
if ($event === false) {
if (data.children) {
data.children.forEach(d => {
const target = array.find(a => a.host === d.host);
target.expand = false;
this.collapse(array, target, false);
});
} else {
return;
}
}
}
convertTreeToList(root: any, groupId: string,index): TreeNodeInterface[] {
if(root.host == index){
stack.push({...root, level: 0, expand: true});
}else{
stack.push({...root, level: 0, expand: false});
}
while (stack.length !== 0) {
const node = stack.pop();
this.visitNode(node, hashMap, array);
if (node.list) {
for (let i = node.list.length - 1; i >= 0; i--) {
stack.push({...node.list[i], level: node.level + 1, expand: true, parent: node, gId: groupId, checked: false});
}
}
}
return array;
}
visitNode(node: TreeNodeInterface, hashMap: object, array: TreeNodeInterface[]): void {
array.push(node);
}
}
ngOnInit(): void {
this.selectedValue = 'group';
this.select();
this.findSize();
this.loading = true;
this.searchStatus = true;
this.frontPagination = false;
const data = {
search:{
name:this.searchName
}
}
this.overAllSer.find(data).subscribe(
(res)=>{
if(res.errCode == 10000){
this.searchData = res.data;
}
this.loading = false;
}
)
}
//backList
backList(){
this.searchStatus = false;
this.frontPagination = true;
}
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
//查询设备状态
findOpStatus(){
this.overAllSer.findHostCountByStatus(0).subscribe(
(res)=>{
if(res.errCode == 10000){
this.green = res.data.size;
}else{
this.message.info(res.Msg);
}
}
)
this.overAllSer.findHostCountByStatus(1).subscribe(
(res)=>{
this.gray = res.data.size;
}
)
this.overAllSer.findWarningByAll(1).subscribe(
(res)=>{
if(res.errCode == 10000){
this.yellow = res.data.size;
}else{
this.message.info(res.Msg);
}
}
)
this.overAllSer.findWarningByAll(0).subscribe(
(res)=>{
if(res.errCode == 10000){
this.red = res.data.size;
}else{
this.message.info(res.Msg);
}
}
)
showBasicEditModal(item) {
this.basicEdit.showModal(item.hostId, item.name, item.id);
editBasicModal(item) {
this.basicEdit.editModal(item.hostid, item.name, item.gId);
this.dataSet = res.data;
// this.dataSet = this.dataSet.filter(d => d.list); //过滤无list的
for (let i = 0; i < this.dataSet.length; i++) {
this.dataSet[i].host = i;
this.dataSet[i].checked = false;
this.dataSet = res.data;
// this.dataSet = this.dataSet.filter(d => d.list); //过滤无list的
this.expandDataCache[item.host] = this.convertTreeToList(item, item.id, index);
nzTitle: '删除',
nzContent: '<b style="color: red;">确认删除该资源吗?</b>',
nzOkText: '确定',
nzOkType: 'danger',
nzOnOk: () => {
//批量删除资源
batchDeleteConfirm(){
if(this.batchDelList.length == 0){
this.message.info('请选择需要删除的设备');
return false;
}
this.modalService.confirm({
nzTitle: '删除',
nzContent: '<b style="color: red;">确认要删除所选设备吗?</b>',
nzOkText: '确定',
nzOkType: 'danger',
nzOnOk: () => {
const data = {
}
this.overAllSer.deleteHostPost(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.message.info('删除成功');
this.select();
} else {
this.message.info(res.errMsg);
}
}
);
},
nzCancelText: '取消',
nzOnCancel: () => console.log('Cancel')
});
}
nzTitle: '删除',
nzContent: '<b style="color: red;">确认删除该分组吗?</b>',
nzOkText: '确定',
nzOkType: 'danger',
nzOnOk: () => {
const data = {params: []};
//添加告警
showAlarm(item){
this.smartAlarmModal.showModal(item);
}
if(item.list){
if(item.expand){
item.expand = false;
}else{
item.expand = true;
}
return false;
}
'groupids': [item.groupid],
'hostExtend': {
'superiorHostid': null
if(item.list){
if(item.expand){
item.expand = false;
}else{
item.expand = true;
}
return false;
}
this.loading = true;
if(res.data){
this.dataSet[item.host].list = res.data;
this.toTree(item.host);
}else{
this.message.info('该分组下无资源');
}
this.loading = false;
if(item.hostExtend){
if(item.hostExtend.equipmentType == '交换机'){
type = 1;
}
}
this.router.navigate(['app/main/basic-detail'],{
queryParams:{
hostId:item.hostid,
if(event){
if(item.hostid){
this.batchDelList.push(item.hostid);
}
}else{
if(item.hostid){
const index = this.batchDelList.indexOf(item.hostid);
this.batchDelList.splice(index,1)
}
openHost(item){
this.modalService.confirm({
nzTitle: '监控',
nzContent: '确定开启监控设备'+item.name + '?',
nzOkText: '确定',
nzCancelText: '取消',
nzOnOk: () => {
let params1 = 0;
}
const params2 = item.hostid;
this.overAllSer.stopOrOpen(params1,params2).subscribe(
(res) => {
if (res.errCode == 10000) {
this.message.info('修改成功');
this.select();
} else {
this.message.info(res.errMsg);
}
}
);
},
nzOnCancel: () => console.log('Cancel')
});
}
openBatchHost(status,operation){
if(this.batchDelList.length == 0){
this.message.info('请选择需要'+ operation +'的设备');
return false;
}
this.modalService.confirm({
nzTitle: '监控',
nzContent: '确定批量'+operation+'监控设备?',
nzOkText: '确定',
nzCancelText: '取消',
nzOnOk: () => {
const data = {
status:status,
hostids:this.batchDelList
}
this.overAllSer.batchStopOrOpen(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.message.info('修改成功');
this.batchDelList = [];
this.select();
} else {
this.message.info(res.errMsg);
}
}
);
},
nzOnCancel: () => console.log('Cancel')
});