import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; @Component({ selector: 'app-navigation', templateUrl: './navigation.component.html', styleUrls: ['./navigation.component.scss'] }) export class NavigationComponent implements OnInit { constructor(private router: Router) { } userMenu=[] menu=[] tap=[] menuList1=[] menuList2=[] menu1 = [ { name: '首页', url: '/homepage' }, { name: '数字油站', url: '/plan' }, { name: '今日预警', url: '/todaywarning' }, { name: '预警记录', url: '/records_nav' }, { name: '证照管理', url: '/audit' }, ] menu3 = [ { name: '组织机构管理', url: '/system/organization' ,img:'../../../assets/images/icon/organization.png'}, { name: '用户管理', url: '/system/user' ,img:'../../../assets/images/icon/user.png'}, { name: '角色管理', url: '/system/role' ,img:'../../../assets/images/icon/role.png'}, { name: '分析主机管理', url: '/system/host' ,img:'../../../assets/images/icon/host.png'}, { name: '推送管理', url: '/system/push' ,img:'../../../assets/images/icon/push.png'}, { name: '经营类证照管理', url: '/system/updateOfLicense' ,img:'../../../assets/images/icon/license.png'}, { name: '资产类证照管理', url: '/system/fileOfLicense' ,img:'../../../assets/images/icon/license.png'}, { name: '菜单管理', url: '/system/menu' ,img:'../../../assets/images/icon/license.png'}, ] ngOnInit(): void { let a= sessionStorage.getItem('userdata') this.userMenu=JSON.parse(a).menus for (let index = 0; index < this.userMenu.length; index++) { let a=this.userMenu[index].name this.tap.push(a) } for (let index = 0; index < this.menu1.length; index++) { for (let k = 0; k < this.tap.length; k++) { if (this.tap[k]==this.menu1[index].name) { this.menuList1.push(this.menu1[index]) } } // console.log(this.menuList1); } for (let index = 0; index < this.menu3.length; index++) { let url="" if(JSON.parse(a).userName=="admin"){ this.menuList2=this.menu3 }else{ for (let k = 0; k < this.tap.length; k++) { if (this.tap[k]==this.menu3[index].name) { this.menuList2.push(this.menu3[index]) } } } } } signOut() { this.router.navigate(['/login']) } pages() { sessionStorage.setItem('selectedMenu', this.menuList1[0].name) this.router.navigate([this.menuList1[0].url]) } }