Commit 90972e43 authored by wangqinghua's avatar wangqinghua

directive

parent e1ff90e4
...@@ -43,35 +43,13 @@ ...@@ -43,35 +43,13 @@
</thead> </thead>
<tbody> <tbody>
<ng-template ngFor let-data [ngForOf]="nzTable.data"> <ng-template ngFor let-data [ngForOf]="nzTable.data">
<ng-template ngFor let-item [ngForOf]="expandDataCache[data.host]"> <ng-template ngFor let-item [ngForOf]="expandDataCache[data.serviceid]">
<tr *ngIf="(item.parent&&item.parent.expand)||!(item.parent)"> <tr *ngIf="(item.parent&&item.parent.expand)||!(item.parent)">
<td [nzIndentSize]="item.level*20" nzShowExpand [nzExpand]='item.expand' (nzExpandChange)="getChildren(item)"> <td [nzIndentSize]="item.level*20" [nzShowExpand]="!!item.children" [(nzExpand)]="item.expand" (nzExpandChange)="getChildren(item)">
<span (click)="showEditModal(item)" class="main-color cursor">{{item.name}}</span> {{item.name}}
</td>
<td class="round-tag tag-form">
<ng-container *ngIf="item.status == 0">
<nz-tag class="tag-green" [nzColor]="color.green"></nz-tag>
</ng-container>
<ng-container *ngIf="item.status == 2 || item.status == 3">
<nz-tag class="tag-yellow" [nzColor]="color.yellow"></nz-tag>
</ng-container>
<ng-container *ngIf="item.status == 4 || item.status == 5">
<nz-tag class="tag-red" [nzColor]="color.red"></nz-tag>
</ng-container>
</td>
<td class="cursor">
<span (click)="goTOInventory(item?.inventory?.id)">{{item?.inventory?.name}}</span>
</td>
<td class="handle main-color">
<span (click)="showBasicEditModal(item)">添加子节点</span>
<ng-container *ngIf="!item.level">
<span (click)="showBasicEditModal(item)">配置告警推送</span>
</ng-container>
<ng-container *ngIf="item.level">
<span (click)="editBasicModal(item)">编辑</span>
<span (click)="showDeleteConfirm(item)">移除</span>
</ng-container>
</td> </td>
<td>{{item.age}}</td>
<td>{{item.address}}</td>
</tr> </tr>
</ng-template> </ng-template>
</ng-template> </ng-template>
......
...@@ -18,46 +18,59 @@ export class BConfigComponent implements OnInit { ...@@ -18,46 +18,59 @@ export class BConfigComponent implements OnInit {
allChecked = false; allChecked = false;
isLoading = false; //加载中 isLoading = false; //加载中
dataSet; //数据list
expandDataCache = {};
constructor(private busineSer:BusinessService,private message:NzMessageService) { constructor(private busineSer:BusinessService,private message:NzMessageService) {
} }
convertTreeToList(root: any, serviceid: string, index): TreeNodeInterface[] { dataSet: any[];
expandDataCache = {};
collapse(array: TreeNodeInterface[], data: TreeNodeInterface, $event: boolean): void {
if ($event === false) {
if (data.children) {
data.children.forEach(d => {
const target = array.find(a => a.serviceid === d.serviceid);
target.expand = false;
this.collapse(array, target, false);
});
} else {
return;
}
}
}
convertTreeToList(root: object): TreeNodeInterface[] {
const stack = []; const stack = [];
const array = []; const array = [];
const hashMap = {}; const hashMap = {};
if (root.host == index) { stack.push({ ...root, level: 0, expand: true });
stack.push({...root, level: 0, expand: true});
} else {
stack.push({...root, level: 0, expand: false});
}
while (stack.length !== 0) { while (stack.length !== 0) {
const node = stack.pop(); const node = stack.pop();
this.visitNode(node, hashMap, array); this.visitNode(node, hashMap, array);
if (node.list) { if (node.children) {
for (let i = node.list.length - 1; i >= 0; i--) { for (let i = node.children.length - 1; i >= 0; i--) {
stack.push({...node.list[i], level: node.level + 1, expand: true,serviceid: serviceid, parent: node, checked: false}); stack.push({ ...node.children[ i ], level: node.level + 1, expand: false, parent: node });
} }
} }
} }
// console.log(array);
return array; return array;
} }
visitNode(node: TreeNodeInterface, hashMap: object, array: TreeNodeInterface[]): void { visitNode(node: TreeNodeInterface, hashMap: object, array: TreeNodeInterface[]): void {
if (!hashMap[node.host]) { console.log(hashMap);
hashMap[node.host] = true; if (!hashMap[ node.serviceid ]) {
hashMap[ node.serviceid ] = true;
array.push(node); array.push(node);
} }
} }
toTree(index) { toTree(index) {
this.dataSet.forEach(item => { this.dataSet.forEach((item,i) => {
this.expandDataCache[item.host] = this.convertTreeToList(item, item.serviceid, index); this.expandDataCache[item.serviceid] = this.convertTreeToList(item);
}); });
console.log(this.expandDataCache);
} }
ngOnInit() { ngOnInit() {
...@@ -76,9 +89,9 @@ export class BConfigComponent implements OnInit { ...@@ -76,9 +89,9 @@ export class BConfigComponent implements OnInit {
if(res.errCode == 10000){ if(res.errCode == 10000){
this.dataSet = res.data; this.dataSet = res.data;
this.dataSet.forEach((e,index)=>{ this.dataSet.forEach((e,index)=>{
e.host = index;
e.checked = false; e.checked = false;
}) e.children = [];
});
this.toTree(null); this.toTree(null);
}else{ }else{
this.message.error(res.errMsg); this.message.error(res.errMsg);
...@@ -89,14 +102,6 @@ export class BConfigComponent implements OnInit { ...@@ -89,14 +102,6 @@ export class BConfigComponent implements OnInit {
// //
getChildren(item){ getChildren(item){
if (item.list) {
if (item.expand) {
item.expand = false;
} else {
item.expand = true;
}
return false;
}
this.isLoading = true; this.isLoading = true;
const data = { const data = {
"sid":item.serviceid, "sid":item.serviceid,
...@@ -104,11 +109,13 @@ export class BConfigComponent implements OnInit { ...@@ -104,11 +109,13 @@ export class BConfigComponent implements OnInit {
this.busineSer.findChild(data).subscribe( this.busineSer.findChild(data).subscribe(
(res)=>{ (res)=>{
if (res.data) { if (res.data) {
this.dataSet[item.host].list = res.data; this.dataSet.forEach(e=>{
this.toTree(item.host); if(e.serviceid == item.serviceid){
e.children = res.data;
}
});
this.toTree(item.service);
} else { } else {
this.dataSet[item.host].list = [];
this.toTree(item.host);
this.message.info('该分组下无资源'); this.message.info('该分组下无资源');
} }
this.isLoading = false; this.isLoading = false;
......
...@@ -18,11 +18,10 @@ import {JhiMainComponent} from '../../layouts'; ...@@ -18,11 +18,10 @@ import {JhiMainComponent} from '../../layouts';
export interface TreeNodeInterface { export interface TreeNodeInterface {
host: any; host: any;
serviceid: any;
name: string; name: string;
age: number;
level: number; level: number;
expand: boolean; expand: boolean;
address: string;
children?: TreeNodeInterface[]; children?: TreeNodeInterface[];
} }
...@@ -120,7 +119,6 @@ export class BasicComponent implements OnInit { ...@@ -120,7 +119,6 @@ export class BasicComponent implements OnInit {
} }
} }
} }
return array; return array;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment