Skip to content

Commit

Permalink
feat(共享组件): 新增Breadcrumb模块,及Breadcrumb组件
Browse files Browse the repository at this point in the history
  • Loading branch information
jiayisheji committed Nov 30, 2017
1 parent 95bbf96 commit 4b2da45
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/app/shared/breadcrumb/breadcrumb.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<ol class="sim-breadcrumbs" fxLayout="row">
<li *ngFor="let url of urls; let last = last; let first = first" [ngClass]="{'active': last}" fxLayout="row" fxLayoutAlign="center center">
<a role="button" *ngIf="!last && url == prefix">{{url}}</a>
<a role="button" *ngIf="!last && url != prefix">{{friendlyName(url)}}</a>
<span *ngIf="last">{{friendlyName(url)}}</span>
<span *ngIf="last && url == prefix">{{friendlyName('/')}}</span>
</li>
</ol>
10 changes: 10 additions & 0 deletions src/app/shared/breadcrumb/breadcrumb.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.sim-breadcrumbs {
margin: 0;
padding: 0 16px;
list-style: none;
font-weight: 400;
font-size: 20px;
li {
line-height: 64px;
}
}
25 changes: 25 additions & 0 deletions src/app/shared/breadcrumb/breadcrumb.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { BreadcrumbComponent } from './breadcrumb.component';

describe('BreadcrumbComponent', () => {
let component: BreadcrumbComponent;
let fixture: ComponentFixture<BreadcrumbComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ BreadcrumbComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(BreadcrumbComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
41 changes: 41 additions & 0 deletions src/app/shared/breadcrumb/breadcrumb.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Component, OnInit, Inject } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';
import { INav } from '../nav';
import { Subscription } from 'rxjs/Subscription';
@Component({
selector: 'sim-breadcrumb',
templateUrl: './breadcrumb.component.html',
styleUrls: ['./breadcrumb.component.scss']
})
export class BreadcrumbComponent implements OnInit {
_breadcrumbs: Array<INav> = [];
private _routerSubscription: Subscription;
constructor(private _router: Router, @Inject('BREADCRUMB_CONFIG') private _nav) { }

ngOnInit() {
// console.log(this.getFriendlyNameForRoute(this._router.url), this._nav[0].children)
this._breadcrumbs.push(this._nav[0]);
this._routerSubscription = this._router.events.subscribe((navigationEnd: NavigationEnd) => {
console.log('navigationEnd.urlAfterRedirects', navigationEnd.urlAfterRedirects, navigationEnd.url)
/* this.urls.length = 0; //Fastest way to clear out array
this.generateBreadcrumbTrail(navigationEnd.urlAfterRedirects ? navigationEnd.urlAfterRedirects : navigationEnd.url); */
});
}

ngOnDestroy(): void {
this._routerSubscription.unsubscribe();
}


getFriendlyNameForRoute(route: string): string[] {
return route.split('/');
}

/* getFriendlyPath(nav: INav): INav {
if (!nav.children) {
return;
}
return this.getFriendlyPath(nav: INav);
} */

}
21 changes: 21 additions & 0 deletions src/app/shared/breadcrumb/breadcrumb.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { NgModule, ModuleWithProviders } from '@angular/core';
import { CommonModule } from '@angular/common';
import { BreadcrumbComponent } from './breadcrumb.component';
import { INav } from '../nav';
@NgModule({
imports: [
CommonModule
],
declarations: [BreadcrumbComponent],
exports: [BreadcrumbComponent]
})
export class BreadcrumbModule {
static forRoot(config: any = []): ModuleWithProviders {
return {
ngModule: BreadcrumbModule,
providers: [
{ provide: 'BREADCRUMB_CONFIG', useValue: config }
]
};
}
}
1 change: 1 addition & 0 deletions src/app/shared/breadcrumb/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './breadcrumb.module';

0 comments on commit 4b2da45

Please sign in to comment.