Skip to content

Commit 21b355d

Browse files
committed
完成多个tab布局
1 parent 193b2ee commit 21b355d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1206
-222
lines changed

src/app/app.component.html

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
<div class="container" mdl-shadow="2">
2-
<mdl-layout>
3-
<mdl-layout-content>
4-
<div class="layout-header">
5-
<app-layout-header></app-layout-header>
6-
</div>
7-
<div class="main-body">
8-
<div class="layout-nav">
9-
<app-layout-nav></app-layout-nav>
10-
</div>
11-
<div class="layout-body">
12-
<app-layout-body></app-layout-body>
13-
</div>
14-
</div>
15-
</mdl-layout-content>
16-
</mdl-layout>
17-
</div>
1+
<mdl-layout>
2+
<mdl-layout-header>
3+
<app-layout-header></app-layout-header>
4+
</mdl-layout-header>
5+
<mdl-layout-content>
6+
<app-layout-nav></app-layout-nav>
7+
<app-layout-body></app-layout-body>
8+
</mdl-layout-content>
9+
</mdl-layout>

src/app/app.module.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,39 @@ import { BrowserModule } from '@angular/platform-browser';
33
import { NgModule } from '@angular/core';
44
import { FormsModule } from '@angular/forms';
55
import { HttpModule } from '@angular/http';
6+
import { RouteReuseStrategy } from '@angular/router';
67

78
// App模块
89
import { AppComponent } from './app.component';
10+
import { routing, CustomReuseStrategy } from './app.routing';
911

1012
// 第三方模块
1113
import { MdlModule } from '@angular-mdl/core';
1214

1315
// 项目内模块
1416
import { LayoutModule } from './layout/layout.module';
17+
import { DemoModule } from './demo/demo.module';
1518

1619
@NgModule({
17-
declarations: [
18-
AppComponent
19-
],
20-
imports: [
21-
// Angular模块
22-
BrowserModule,
23-
FormsModule,
24-
HttpModule,
25-
// 第三方模块
26-
MdlModule,
27-
// 项目内模块
28-
LayoutModule
29-
// App模块
30-
],
31-
providers: [],
32-
bootstrap: [AppComponent]
20+
declarations: [
21+
AppComponent
22+
],
23+
imports: [
24+
// Angular模块
25+
BrowserModule,
26+
FormsModule,
27+
HttpModule,
28+
// 第三方模块
29+
MdlModule,
30+
// 项目内模块
31+
LayoutModule,
32+
DemoModule,
33+
// App模块
34+
routing
35+
],
36+
providers: [
37+
{ provide: RouteReuseStrategy, useClass: CustomReuseStrategy }
38+
],
39+
bootstrap: [AppComponent]
3340
})
3441
export class AppModule { }

src/app/app.routing.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { ModuleWithProviders } from '@angular/core';
2+
import { Routes, RouterModule, RouteReuseStrategy, DetachedRouteHandle, ActivatedRouteSnapshot } from '@angular/router';
3+
import { AppComponent } from './app.component';
4+
5+
import { DemoComponent } from './demo/demo/demo.component';
6+
import { Demo1Component } from './demo/demo1/demo1.component';
7+
import { Demo2Component } from './demo/demo2/demo2.component';
8+
import { Demo3Component } from './demo/demo3/demo3.component';
9+
10+
const appRoutes: Routes = [
11+
{
12+
path: '',
13+
redirectTo: 'demo',
14+
pathMatch: 'full'
15+
},
16+
{ path: 'demo1', component: Demo1Component },
17+
{ path: 'demo2', component: Demo2Component },
18+
{ path: 'demo3', component: Demo3Component }
19+
];
20+
21+
export const appRoutingProviders: any[] = [];
22+
23+
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
24+
25+
export class CustomReuseStrategy implements RouteReuseStrategy {
26+
27+
handlers: { [key: string]: DetachedRouteHandle } = {};
28+
29+
shouldDetach(route: ActivatedRouteSnapshot): boolean {
30+
console.log('CustomReuseStrategy:shouldDetach', route);
31+
return true;
32+
}
33+
34+
store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle): void {
35+
console.log('CustomReuseStrategy:store', route, handle);
36+
this.handlers[route.routeConfig.path] = handle;
37+
}
38+
39+
shouldAttach(route: ActivatedRouteSnapshot): boolean {
40+
console.log('CustomReuseStrategy:shouldAttach', route);
41+
return !!route.routeConfig && !!this.handlers[route.routeConfig.path];
42+
}
43+
44+
retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle {
45+
console.log('CustomReuseStrategy:retrieve', route);
46+
return this.handlers[route.routeConfig.path];//从暂存处取回
47+
}
48+
49+
shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
50+
//在此处可以取得跳转前和跳转后的路由路径
51+
console.log('CustomReuseStrategy:shouldReuseRoute', future, curr);
52+
return future.routeConfig === curr.routeConfig;
53+
}
54+
}

src/app/demo/demo.module.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import { NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';
3+
import { FormsModule } from '@angular/forms';
4+
5+
import { MdlModule } from '@angular-mdl/core';
6+
37
import { DemoComponent } from './demo/demo.component';
8+
import { Demo1Component } from './demo1/demo1.component';
9+
import { Demo2Component } from './demo2/demo2.component';
10+
import { Demo3Component } from './demo3/demo3.component';
411

512
@NgModule({
6-
imports: [
7-
CommonModule
8-
],
9-
declarations: [DemoComponent]
13+
imports: [
14+
CommonModule, FormsModule, MdlModule
15+
],
16+
declarations: [DemoComponent, Demo1Component, Demo2Component, Demo3Component]
1017
})
1118
export class DemoModule { }
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<p>
2-
demo works!
2+
demo works!
33
</p>
4+
<mdl-textfield type="text" [(ngModel)]="theText" icon="search"></mdl-textfield>
File renamed without changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<p>
2+
demo1 works!
3+
</p>
4+
<mdl-textfield type="text" [(ngModel)]="theText" icon="search"></mdl-textfield>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { Demo1Component } from './demo1.component';
4+
5+
describe('Demo1Component', () => {
6+
let component: Demo1Component;
7+
let fixture: ComponentFixture<Demo1Component>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ Demo1Component ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(Demo1Component);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should be created', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-demo1',
5+
templateUrl: './demo1.component.html',
6+
styleUrls: ['./demo1.component.css']
7+
})
8+
export class Demo1Component implements OnInit {
9+
10+
constructor() { }
11+
12+
ngOnInit() {
13+
}
14+
15+
}

src/app/demo/demo2/demo2.component.css

Whitespace-only changes.

0 commit comments

Comments
 (0)