40 lines
802 B
TypeScript
40 lines
802 B
TypeScript
import { Component, OnInit, Input } from '@angular/core';
|
|
import { Router } from '@angular/router'
|
|
|
|
@Component({
|
|
selector: 'app-bar-menu',
|
|
templateUrl: './bar-menu.component.html',
|
|
styleUrls: ['./bar-menu.component.scss']
|
|
})
|
|
export class BarMenuComponent implements OnInit {
|
|
|
|
@Input() data: Array<any>;
|
|
constructor(
|
|
private router: Router
|
|
) { }
|
|
|
|
ngOnInit() {
|
|
}
|
|
|
|
/**
|
|
* 判断是否有子节点
|
|
* @param item
|
|
*/
|
|
isLeaf(item: any) {
|
|
return !item.children || !item.children.length;
|
|
}
|
|
|
|
/**
|
|
* 菜单点击事件
|
|
* @param item
|
|
*/
|
|
itemClicked(item: any) {
|
|
if (!this.isLeaf(item)) {
|
|
item.isExpend = !item.isExpend;
|
|
} else {
|
|
this.router.navigate([item.path])
|
|
}
|
|
}
|
|
|
|
}
|