From 4b2da45bf615e115cdea69545c940dcf9a35a5bd Mon Sep 17 00:00:00 2001 From: jiayi <690405541@qq.com> Date: Thu, 30 Nov 2017 15:00:35 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=85=B1=E4=BA=AB=E7=BB=84=E4=BB=B6):=20?= =?UTF-8?q?=20=E6=96=B0=E5=A2=9EBreadcrumb=E6=A8=A1=E5=9D=97=EF=BC=8C?= =?UTF-8?q?=E5=8F=8ABreadcrumb=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../breadcrumb/breadcrumb.component.html | 8 ++++ .../breadcrumb/breadcrumb.component.scss | 10 +++++ .../breadcrumb/breadcrumb.component.spec.ts | 25 +++++++++++ .../shared/breadcrumb/breadcrumb.component.ts | 41 +++++++++++++++++++ .../shared/breadcrumb/breadcrumb.module.ts | 21 ++++++++++ src/app/shared/breadcrumb/index.ts | 1 + 6 files changed, 106 insertions(+) create mode 100644 src/app/shared/breadcrumb/breadcrumb.component.html create mode 100644 src/app/shared/breadcrumb/breadcrumb.component.scss create mode 100644 src/app/shared/breadcrumb/breadcrumb.component.spec.ts create mode 100644 src/app/shared/breadcrumb/breadcrumb.component.ts create mode 100644 src/app/shared/breadcrumb/breadcrumb.module.ts create mode 100644 src/app/shared/breadcrumb/index.ts diff --git a/src/app/shared/breadcrumb/breadcrumb.component.html b/src/app/shared/breadcrumb/breadcrumb.component.html new file mode 100644 index 0000000..a07f5e6 --- /dev/null +++ b/src/app/shared/breadcrumb/breadcrumb.component.html @@ -0,0 +1,8 @@ +
    +
  1. + {{url}} + {{friendlyName(url)}} + {{friendlyName(url)}} + {{friendlyName('/')}} +
  2. +
\ No newline at end of file diff --git a/src/app/shared/breadcrumb/breadcrumb.component.scss b/src/app/shared/breadcrumb/breadcrumb.component.scss new file mode 100644 index 0000000..24b7e7d --- /dev/null +++ b/src/app/shared/breadcrumb/breadcrumb.component.scss @@ -0,0 +1,10 @@ +.sim-breadcrumbs { + margin: 0; + padding: 0 16px; + list-style: none; + font-weight: 400; + font-size: 20px; + li { + line-height: 64px; + } +} \ No newline at end of file diff --git a/src/app/shared/breadcrumb/breadcrumb.component.spec.ts b/src/app/shared/breadcrumb/breadcrumb.component.spec.ts new file mode 100644 index 0000000..1fddbf8 --- /dev/null +++ b/src/app/shared/breadcrumb/breadcrumb.component.spec.ts @@ -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; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ BreadcrumbComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(BreadcrumbComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/shared/breadcrumb/breadcrumb.component.ts b/src/app/shared/breadcrumb/breadcrumb.component.ts new file mode 100644 index 0000000..0bc78e0 --- /dev/null +++ b/src/app/shared/breadcrumb/breadcrumb.component.ts @@ -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 = []; + 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); + } */ + +} diff --git a/src/app/shared/breadcrumb/breadcrumb.module.ts b/src/app/shared/breadcrumb/breadcrumb.module.ts new file mode 100644 index 0000000..52b3da2 --- /dev/null +++ b/src/app/shared/breadcrumb/breadcrumb.module.ts @@ -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 } + ] + }; + } +} diff --git a/src/app/shared/breadcrumb/index.ts b/src/app/shared/breadcrumb/index.ts new file mode 100644 index 0000000..524f430 --- /dev/null +++ b/src/app/shared/breadcrumb/index.ts @@ -0,0 +1 @@ +export * from './breadcrumb.module';