import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; @Component({ selector: 'app-default', templateUrl: './default.component.html', styleUrls: ['./default.component.scss'] }) export class DefaultComponent implements OnInit { constructor( private router: Router ) { } menuDatas = []; menu = []; ngOnInit() { this.menuDatas = [ { children: [ { children: null, fatherId: 2, id: 21, isEnable: "1", menuName: "layer1-1", menuUrl: "layer1/layer1-1", remark: null, weight: 1 }, ], fatherId: 0, id: 1, isEnable: "1", menuName: "layer1", menuUrl: "layer1", remark: null, weight: 1 }, { children: [ { children: null, fatherId: 2, id: 21, isEnable: "1", menuName: "左右布局", menuUrl: "layer2/left-right-layout", remark: null, weight: 1 }, // {children: null,fatherId: 2,id: 22,isEnable: "1",menuName: "sider",menuUrl: "layer2/sider",remark: null,weight: 2}, // {children: null,fatherId: 2,id: 23,isEnable: "1",menuName: "comtent",menuUrl: "layer2/comtent",remark: null,weight: 3} ], fatherId: 0, id: 2, isEnable: "1", menuName: "layer2", menuUrl: "layer2", remark: null, weight: 2 }, { children: [ { children: [ { children: [ { children: null, fatherId: 311, id: 3111, isEnable: "1", menuName: "基础折线图", menuUrl: "layer3/charts/line-chart/basic-line-chart", remark: null, weight: 1 }, { children: null, fatherId: 311, id: 3112, isEnable: "1", menuName: "大数据量线图", menuUrl: "layer3/charts/line-chart/big-data-line-chart", remark: null, weight: 2 }, { children: null, fatherId: 311, id: 3113, isEnable: "1", menuName: "点值折线图", menuUrl: "layer3/charts/line-chart/point-value-line-chart", remark: null, weight: 3 }, { children: null, fatherId: 311, id: 3114, isEnable: "1", menuName: "标记折线图", menuUrl: "layer3/charts/line-chart/annotations-line-chart", remark: null, weight: 4 }, { children: null, fatherId: 311, id: 3115, isEnable: "1", menuName: "声学分析折线图", menuUrl: "layer3/charts/line-chart/noiseAnalysis-line-chart", remark: null, weight: 5 } ], fatherId: 31, id: 311, isEnable: "1", menuName: "折线图", menuUrl: "layer3/charts/line-chart", remark: null, weight: 1 }, { children: [ { children: null, fatherId: 311, id: 3121, isEnable: "1", menuName: "基础柱状图", menuUrl: "layer3/charts/bar-chart/base-column-chart", remark: null, weight: 1 }, { children: null, fatherId: 311, id: 3122, isEnable: "1", menuName: "条形图", menuUrl: "layer3/charts/bar-chart/base-bar-chart", remark: null, weight: 2 }, { children: null, fatherId: 311, id: 3123, isEnable: "1", menuName: "负值柱状图", menuUrl: "layer3/charts/bar-chart/negative-bar-chart", remark: null, weight: 3 }, { children: null, fatherId: 311, id: 3124, isEnable: "1", menuName: "分组堆叠柱状图", menuUrl: "layer3/charts/bar-chart/stack-column-chart", remark: null, weight: 3 }, { children: null, fatherId: 311, id: 3125, isEnable: "1", menuName: "人口金字塔图", menuUrl: "layer3/charts/bar-chart/pyramid-bar-chart", remark: null, weight: 4 }, // { children: null, fatherId: 311, id: 3126, isEnable: "1", menuName: "柱型范围图", menuUrl: "layer3/charts/bar-chart/custom-column-chart", remark: null, weight: 5 }, { children: null, fatherId: 311, id: 3127, isEnable: "1", menuName: "测试柱状图", menuUrl: "layer3/charts/bar-chart/test-chart", remark: null, weight: 6 } ], fatherId: 31, id: 312, isEnable: "1", menuName: "柱状图", menuUrl: "layer3/charts/bar-chart", remark: null, weight: 1 }, { children: [ { children: null, fatherId: 311, id: 3121, isEnable: "1", menuName: "基础饼图", menuUrl: "layer3/charts/pie-chart/basic-pie-chart", remark: null, weight: 1 }, { children: null, fatherId: 311, id: 3122, isEnable: "1", menuName: "带图例的饼图", menuUrl: "layer3/charts/pie-chart/legend-pie-chart", remark: null, weight: 1 }, { children: null, fatherId: 311, id: 3123, isEnable: "1", menuName: "南丁格尔玫瑰图", menuUrl: "layer3/charts/pie-chart/rose-pie-chart", remark: null, weight: 1 }, // { children: null, fatherId: 311, id: 3122, isEnable: "1", menuName: "", menuUrl: "layer3/charts/pie-chart/", remark: null, weight: 2 } ], fatherId: 31, id: 313, isEnable: "1", menuName: "饼图", menuUrl: "layer3/charts/pie-chart", remark: null, weight: 1 } ], fatherId: 3, id: 31, isEnable: "1", menuName: "图表", menuUrl: "layer3/charts", remark: null, weight: 1 }, { children: [ { children: [], fatherId: 32, id: 321, isEnable: "1", menuName: "基础表", menuUrl: "layer3/tables/basic-table", remark: null, weight: 1 }, { children: [], fatherId: 32, id: 322, isEnable: "1", menuName: "数据表", menuUrl: "layer3/tables/data-table", remark: null, weight: 2 }, { children: [], fatherId: 32, id: 323, isEnable: "1", menuName: "common-table", menuUrl: "layer3/tables/merge-header-table", remark: null, weight: 3 }, ], fatherId: 3, id: 32, isEnable: "1", menuName: "表格", menuUrl: "layer3/tables", remark: null, weight: 2 }, { children: [ ], fatherId: 3, id: 33, isEnable: "1", menuName: "icons", menuUrl: "layer3/icons", remark: null, weight: 3 }, { children: [ { children: [], fatherId: 34, id: 341, isEnable: "1", menuName: "common-form", menuUrl: "layer3/forms/common-form", remark: null, weight: 1 } ], fatherId: 3, id: 34, isEnable: "1", menuName: "forms", menuUrl: "layer3/forms", remark: null, weight: 4 }, ], fatherId: 0, id: 3, isEnable: "1", menuName: "layer3", menuUrl: "layer3", remark: null, weight: 3 } ]; this.menu = this.extractMenuTree(this.menuDatas); } //TODO 提取菜单树方法 extractMenuTree(data) { let treeNodes = []; for (const item of data) { let nodeData if (item.isEnable && item.isEnable === '1') { nodeData = { title: item.menuName, link: "", path: "/" + item.menuUrl, children: [] } if (item.children && item.children.length > 0) { nodeData.children = this.extractMenuTree(item.children) } treeNodes.push(nodeData) } } // console.log("treeNodes", treeNodes); return treeNodes } // TODO 点击菜单 clickMenu(item) { event.stopPropagation(); if (item.children && item.children.length > 0) { return } else { this.router.navigate([item.path]); } } }