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';
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;
//表格信息
loading = false;
selectedValue;
isCheck = false;
allChecked = false;
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: 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: 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.findList();
this.findSize();
}
//添加资源 ,name-分组名称,id-分组id
showBasicEditModal(item) {
this.basicEdit.showModal(item.hostId, item.name, item.id);
editBasicModal(item) {
this.basicEdit.editModal(item.hostid, item.name, item.gId);
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;
}
this.toTree();
this.expandDataCache[item.host] = this.convertTreeToList(item, item.id);
nzTitle: '删除',
nzContent: '<b style="color: red;">确认删除该资源吗?</b>',
nzOkText: '确定',
nzOkType: 'danger',
nzOnOk: () => {
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
//批量删除资源
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 = {
params:this.batchDelList
}
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')
});
}
this.smartCreateGroup.showModal('添加分组',null);
}
//编辑分组
updateGroup(item){
this.smartCreateGroup.showModal('修改分组',item);
nzTitle: '删除',
nzContent: '<b style="color: red;">确认删除该分组吗?</b>',
nzOkText: '确定',
nzOkType: 'danger',
nzOnOk: () => {
const data = {params: []};
data.params.push(item.id);
this.overAllSer.deleteGroup(data).subscribe(
//添加告警
showAlarm(item){
this.smartAlarmModal.showModal(item);
}
'groupids': [item.groupid],
'hostExtend': {
'superiorHostid': null
if(res.data){
this.dataSet[item.host].list = res.data;
this.toTree();
}else{
this.message.info('该分组下无资源');
}
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);
}
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)
}
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
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')
});
}
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
//批量开启or停止监控
openBatchHost(item){
// this.modalService.confirm({
// nzTitle: '监控',
// nzContent: '确定开启监控设备'+item.name + '?',
// nzOkText: '确定',
// nzCancelText: '取消',
// nzOnOk: () => {
// const data = {
//
// }
// let params1 = 0;
// if(item.status == 1){
// params1 = 0;
// }
// const params2 = item.hostid;
// this.overAllSer.batchStopOrOpen(params1,params2).subscribe(
// (res) => {
// if (res.errCode == 10000) {
// this.message.info('修改成功');
// this.select();
// } else {
// this.message.info(res.errMsg);
// }
// }
// );
// },
// nzOnCancel: () => console.log('Cancel')
// });
}