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 {EmitService} from '../../shared/event/eventEmitter';
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;
//表格信息
loading = false;
selectedValue;
isCheck = false;
allChecked = false;
constructor(private fb: FormBuilder, private overAllSer: OverAllService, private router: Router,
private modalService: NzModalService, private message: NzMessageService,
private emitService: EmitService) {
}
dataSet: any[];
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: object, groupId: string): TreeNodeInterface[] {
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: false, parent: node, gId: groupId, checked: false});
}
}
}
return array;
}
visitNode(node: TreeNodeInterface, hashMap: object, array: TreeNodeInterface[]): void {
array.push(node);
}
}
submitForm(): void {
// for (const i in this.validateForm.controls) {
// this.validateForm.controls[ i ].markAsDirty();
// this.validateForm.controls[ i ].updateValueAndValidity();
// }
}
ngOnInit(): void {
this.selectedValue = 'group';
this.select();
// this.findList();
this.findSize();
}
//添加资源 ,name-分组名称,id-分组id
showBasicCheckModal(hostid) {
this.smartCheck.showCheckModal(hostid);
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.dataSet[i].host = i;
this.dataSet[i].checked = false;
}
console.log(this.dataSet);
this.toTree();
this.expandDataCache[item.host] = this.convertTreeToList(item, item.id);
nzTitle: '删除',
nzContent: '<b style="color: red;">确认删除该资源吗?</b>',
nzOkText: '确定',
nzOkType: 'danger',
nzOnOk: () => {
nzTitle: '删除',
nzContent: '<b style="color: red;">确认删除该分组吗?</b>',
nzOkText: '确定',
nzOkType: 'danger',
nzOnOk: () => {
const data = {params: []};
data.params.push(item.id);
this.overAllSer.deleteGroup(data).subscribe(
'groupids': [item.groupid],
'hostExtend': {
'superiorHostid': null
(res) => {
this.dataSet[item.host].list = res.data;
this.toTree();
}
);
}
const data = {
type:item.equipmentType
}
this.overAllSer.findHostByType(data).subscribe(
(res) => {
this.dataSet[item.host].list = res.data;
this.toTree();
}
);
}
if(item.hostExtend){
if(item.hostExtend.equipmentType == '交换机'){
type = 1;
}
}
this.router.navigate(['app/main/basic-detail'],{
queryParams:{
hostId:item.hostid,
type:type
//临时暂停
showTempStop(item){
this.smartPause.showModal(item.hostid);
}
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
openHost(item){
this.modalService.confirm({
nzTitle: '监控',
nzContent: '确定开启监控设备'+item.name + '?',
nzOkText: '确定',
nzCancelText: '取消',
nzOnOk: () => {
let params1 = 0;
if(item.status == 1){
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')
});
}