import { Component, OnInit } from '@angular/core'; import { HighlightResult } from 'ngx-highlightjs'; import { NzMessageService } from 'ng-zorro-antd/message'; @Component({ selector: 'app-left-right-layout', templateUrl: './left-right-layout.component.html', styleUrls: ['./left-right-layout.component.scss'] }) export class LeftRightLayoutComponent implements OnInit { constructor(private message: NzMessageService) { } response: HighlightResult; typeScriptCode = `import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; @Component({ selector: 'app-sub-left-right-layout', templateUrl: './sub-left-right-layout.component.html', styleUrls: ['./sub-left-right-layout.component.scss'] }) export class SubLeftRightLayoutComponent implements OnInit { constructor( private router: Router ) { } menuDatas=[]; menu = []; ngOnInit() { this.menuDatas = [ {children: null,fatherId: 0,id: 1,isEnable: "1",menuName: "layer1",menuUrl: "layer1/layer1",remark: null,weight: 1}, {children: [ {children: null,fatherId: 2,id: 21,isEnable: "1",menuName: "左右布局",menuUrl: "layer2/left-right-layout",remark: null,weight: 1}, ], fatherId: 0,id: 2,isEnable: "1",menuName: "layer2",menuUrl: "layer2",remark: null,weight: 2} ]; 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]); } } } `; htmlCode = `
`; scssCode = `@import "src/styles.scss"; nz-layout { background: $body-background; } .layout { width: 100%; height: 100%; .login_pannl { height: 100%; flex-direction: row; display: flex; align-items: center; justify-content: flex-end; .pannel { flex-direction: row; flex-wrap: nowrap; justify-content: space-around; margin: 0 1rem; } } .rightcontent { margin-top: 0.5%; } .inner-content { width: 99.5%; margin-left: 0.5%; min-height: 99%; background: $content-background; } .leftbanner { margin-top: 0.5%; display: flex; flex-wrap: nowrap; background: $content-background; .menu-list { margin-top: 1.4rem; } } .switch { display: flex; width: 100%; align-items: center; background: $content-background; } } #silder { font-size: 1.4rem; overflow-y: auto; overflow-x: hidden; background: $content-background; width: 90%; display: flex; flex-direction: column; &::-webkit-scrollbar { width: 0.11rem; } .ant-menu-inline { border: 0; } .ant-menu { background: 0; background-color: 0; } .innerul { .ant-menu { background: 0; background-color: 0; } } } nz-header { background: $header-background; color: $header-color; line-height: 0; padding: 0; height: 4.8rem; .ant-row { height: 100%; } .login_pannl { line-height: 100%; text-align: right; padding: 0 1rem; } .logo { // height: 8%; min-height: 3.5rem; height: 100%; display: inline-block; } } nz-breadcrumb { height: 5%; padding: 0.5% 0; font-size: 1.4rem; } nz-footer { text-align: center; padding: 1rem; } :host ::ng-deep { .ant-menu-sub.ant-menu-inline { background: $content-background; } .ant-menu-inline, .ant-menu-vertical, .ant-menu-vertical-left { border-right: unset } } .placeholder { //占位 margin: 0 16px; } `; ngOnInit() { } copied($event) { if ($event.isSuccess) { this.message.success('复制成功') } } }