Browse Source

[完善]递归过滤tree型数据

master
邵佳豪 4 years ago
parent
commit
0db3a4639c
  1. 8
      src/app/ui/collection-tools/collection-tools.component.html
  2. 38
      src/app/ui/collection-tools/collection-tools.component.ts
  3. 2
      src/app/working-area/model/singlePointIcon.ts
  4. 2
      src/app/working-area/working-area.component.ts

8
src/app/ui/collection-tools/collection-tools.component.html

@ -38,7 +38,7 @@
<div id="leftDiv" class='functionalDomainLeft publicCss scenarioAssignment' [ngClass]="{'togglePanel': toggleExpandPanel==true}" style="user-select: none;">
<!-- 处置预案 -->
<div class="handlePlan">
<div class="handlePlan" style="display: none;">
<div class="planarGraphHeader" (click)='toggleHandlePlan()'>
<mat-icon *ngIf="toggleHandlePlans">keyboard_arrow_up</mat-icon>
<mat-icon *ngIf="!toggleHandlePlans">keyboard_arrow_down</mat-icon>
@ -68,7 +68,7 @@
<!-- 处置预案 -->
<!-- 素材库 -->
<div id="materialBank">
<div id="materialBank" style="display: none;">
<div class="planarGraphHeader" (click)='toggleMaterial()'>
<mat-icon *ngIf="toggleMaterialBank">keyboard_arrow_up</mat-icon>
<mat-icon *ngIf="!toggleMaterialBank">keyboard_arrow_down</mat-icon>
@ -107,7 +107,7 @@
<!-- 消防列表树 -->
<mat-tree [dataSource]="dataSource" [treeControl]="treeControl">
<mat-tree-node [ngClass]="{'isLookPattern': !node.isLookPattern}" *matTreeNodeDef="let node;" matTreeNodePadding cdkTreeNodePaddingIndent='26' (click)="clickTreeNode(node)" class="treeNode">
<mat-tree-node *matTreeNodeDef="let node;" matTreeNodePadding cdkTreeNodePaddingIndent='26' (click)="clickTreeNode(node)" class="treeNode">
<button mat-icon-button disabled></button>
<span title="{{node.name}}" [ngClass]="{'treeText': !node.isTemplate}">
{{node.name}}
@ -116,7 +116,7 @@
<span class="isLookCss" (click)="clickLookItem(node)"><mat-icon [ngClass]="{'icongray': node.isLook == false}">visibility</mat-icon></span>
</mat-tree-node>
<mat-tree-node [ngClass]="{'isLookPattern': !node.isLookPattern}" *matTreeNodeDef="let node;when: hasChild" matTreeNodePadding (click)="clickTreeNode(node)"class="treeNode" >
<mat-tree-node *matTreeNodeDef="let node;when: hasChild" matTreeNodePadding (click)="clickTreeNode(node)"class="treeNode" >
<button mat-icon-button
matTreeNodeToggle
[attr.aria-label]="'toggle ' + node.name">

38
src/app/ui/collection-tools/collection-tools.component.ts

@ -1171,7 +1171,35 @@ export class CollectionToolsComponent implements OnInit {
if (!element.parentId) { treeData.push(element) }
});
this.dataSource.data = treeData
function recursionFilterEmpty(originalList, result) {
      for(let i = 0, length = originalList.length; i < length; i++) {
          const item = originalList[i];
          if (item.PropertyInfos) {
              // 最内层
              result.push(item);
          } else if (item.children && item.children.length) {
              const newChildren = [];
              // 递归调用,底层的真实数据会全部 push  newChildren 
              recursionFilterEmpty(item.children, newChildren);
              if (newChildren.length) {
                  // 替换原始数据
                  item.children = newChildren;
                  // 子项有真实的数据,就保留这一项
                  result.push(item);
              } // 如果没有这一项就会被删除
          }
      }
  }
  
  function filterEmpty(listData) {
      const result = [];
      recursionFilterEmpty(listData, result);
      return result;
  }
console.log(filterEmpty(treeData))
this.dataSource.data = filterEmpty(treeData)
this.treeControl.expandAll()
@ -1179,13 +1207,16 @@ export class CollectionToolsComponent implements OnInit {
//点击树节点
clickTreeNode(node){
if(this.canvasData.originalcompanyBuildingData.data[node.id]){
this.setAssetsProperty(this.canvasData.originalcompanyBuildingData.data[node.id])
}else if(this.canvasData.originaleveryStoreyData.data[node.id]){
this.setAssetsProperty(this.canvasData.originaleveryStoreyData.data[node.id])
}
//canvas上的素材高亮
// console.log(node)
// canvas上的素材高亮
let iconHighLightArr:any = []
if(node.isTemplate){//如果是模板,则开始向下找
node.children.forEach(item => {
@ -1200,6 +1231,7 @@ export class CollectionToolsComponent implements OnInit {
}else{
iconHighLightArr.push(node.id)
}
// console.log(456,iconHighLightArr)
this.canvas.setHighlight(iconHighLightArr)
}
@ -1276,6 +1308,8 @@ export class CollectionToolsComponent implements OnInit {
}else{
iconVisibleArr.push(node.id)
}
console.log(1,iconVisibleArr)
console.log(2,node.isLook)
this.canvas.setIconVisible(iconVisibleArr,!node.isLook)
}

2
src/app/working-area/model/singlePointIcon.ts

@ -59,7 +59,7 @@ export class SinglePointIcon extends AxShape {
this.image.y = 0;
this.image.width = this.assetData.Width;
this.image.height = this.assetData.Height;
console.log(this.getBounds());
// console.log(this.getBounds());
this.image.alpha = 1;
this.image.anchor.set(0.5);
this.image.interactive = true;

2
src/app/working-area/working-area.component.ts

@ -482,7 +482,7 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
// const floor = this.canvasData.selectStorey;
// // key=>属性名 data[key]=>属性值
Object.keys(floorData).forEach((key) => {
console.log(floorData[key]);
// console.log(floorData[key]);
switch (floorData[key].InteractiveMode) {
case 0:
const singleIcon = new SinglePointIcon(floorData[key], this);

Loading…
Cancel
Save