创建基础数据服务

This commit is contained in:
zhouyuejun
2018-11-16 11:52:45 +08:00
parent 11cb7c366a
commit 08403bb834
5 changed files with 74 additions and 10 deletions
+11 -7
View File
@@ -1,5 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { Router, NavigationEnd, ActivatedRoute } from '@angular/router';
import { BasicDataService } from './basic-data-service'
import { map, filter, mergeMap } from 'rxjs/operators';
import { pipe } from 'rxjs'
@@ -39,7 +40,7 @@ export class PagesComponent implements OnInit {
"name": "基础数据",
"icon": 'fa-database',
"isExpend": false,
"children":[
"children": [
{
"name": "值机岛",
"icon": "fa-eercast",
@@ -184,17 +185,20 @@ export class PagesComponent implements OnInit {
}]
constructor(
private router: Router,
private basicDataService:BasicDataService,
private activatedRoute: ActivatedRoute
) { }
) {
this.basicDataService.loadBasicData();
}
ngOnInit() {
let activeRoute = this.router.url;
this.selectActiveMenu(this.menuData,activeRoute);
this.selectActiveMenu(this.menuData, activeRoute);
this.router.events.pipe(
filter(event => event instanceof NavigationEnd),
).subscribe((event) => {
this.selectActiveMenu(this.menuData,event['urlAfterRedirects'])
this.selectActiveMenu(this.menuData, event['urlAfterRedirects'])
});
}
@@ -207,7 +211,7 @@ export class PagesComponent implements OnInit {
return !item.children || !item.children.length;
}
selectActiveMenu(menuData,activeRoute) {
selectActiveMenu(menuData, activeRoute) {
menuData.forEach(item => {
if (this.isLeaf(item)) {
if (item.path === activeRoute) {
@@ -215,8 +219,8 @@ export class PagesComponent implements OnInit {
} else {
item.isActive = false;
}
}else{
this.selectActiveMenu(item.children,activeRoute)
} else {
this.selectActiveMenu(item.children, activeRoute)
}
})
}