Skip to content

Commit 22200a2

Browse files
committed
tab管理功能
1 parent 21b355d commit 22200a2

File tree

5 files changed

+93
-54
lines changed

5 files changed

+93
-54
lines changed

src/app/app.routing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Demo3Component } from './demo/demo3/demo3.component';
1010
const appRoutes: Routes = [
1111
{
1212
path: '',
13-
redirectTo: 'demo',
13+
redirectTo: '/home',
1414
pathMatch: 'full'
1515
},
1616
{ path: 'demo1', component: Demo1Component },
Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
1-
#tab_manage_btn {
2-
position: absolute;
3-
top: 41px;
4-
}
1+
2+
md2-tabs { position: absolute; left: 240px; top: 36px; /*overflow: hidden;*/ display: block; margin-right: 45px; border-radius: 2px; }
3+
.md2-tabs-header-wrapper { position: relative; display: block; height: 35px; border-radius: 5px 5px 0 0; display: block; margin: 0; padding: 0; list-style: none;
4+
-webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; }
5+
.md2-tabs-header-wrapper:after { content: ''; display: table; clear: both; }
6+
.md2-prev-button,
7+
.md2-next-button { position: absolute; top: 0; height: 100%; width: 32px; padding: 10px 0; z-index: 2; cursor: pointer; }
8+
.md2-prev-button { left: 0; }
9+
.md2-next-button { right: 0; }
10+
.md2-prev-button.disabled,
11+
.md2-next-button.disabled { opacity: .4; cursor: default; }
12+
.md2-prev-button .prev-icon,
13+
.md2-next-button .next-icon { display: block; width: 10px; height: 10px; font-size: 0; border-width: 0 0 2px 2px;
14+
border-style: solid; border-color: #757575; border-radius: 1px; transform: rotate(45deg); margin: 8px; }
15+
.md2-next-button .next-icon { border-width: 2px 2px 0 0; }
16+
.md2-tabs-canvas { position: relative; height: 100%; /*overflow: hidden;*/ display: block; outline: none; }
17+
.md2-tabs-canvas.md2-paginated { margin: 0 32px; }
18+
.md2-tabs-header { position: relative; display: inline-block; height: 100%; white-space: nowrap; -moz-transition: 0.5s cubic-bezier(0.35,0,0.25,1); -o-transition: 0.5s cubic-bezier(0.35,0,0.25,1); -webkit-transition: 0.5s cubic-bezier(0.35,0,0.25,1); transition: 0.5s cubic-bezier(0.35,0,0.25,1); }
19+
.md2-tab-label { position: relative; height: 100%; color: rgba(0,0,0,0.54); font-size: 14px; text-align: center; line-height: 24px; border-radius: 5px 5px 0 0 ; padding: 4px 20px; -moz-transition: background-color .35s cubic-bezier(.35,0,.25,1); -o-transition: background-color .35s cubic-bezier(.35,0,.25,1); -webkit-transition: background-color .35s cubic-bezier(.35,0,.25,1); transition: background-color .35s cubic-bezier(.35,0,.25,1); cursor: pointer; white-space: nowrap; text-transform: uppercase; display: inline-block; font-weight: 500; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; overflow: hidden; -ms-text-overflow: ellipsis; -o-text-overflow: ellipsis; text-overflow: ellipsis; }
20+
.md2-tab-label.active { background-color: #fff; }
21+
.md2-tab-label a { font-size:16px; vertical-align: super;}
22+
.md2-tabs-canvas:focus .md2-tab-label.focus { background: rgba(0,0,0,0.05); }
23+
.md2-tab-label.disabled { color: rgba(0,0,0,0.26); pointer-events: none; -webkit-user-select: none; -moz-user-select: none;
24+
-ms-user-select: none; user-select: none; -webkit-user-drag: none; opacity: 0.5; cursor: default; }
25+
.md2-tab-ink-bar { position: absolute; bottom: 0; height: 2px; background: rgb(255,82,82); transition: .25s cubic-bezier(.35,0,.25,1); }
26+
.md2-tabs-body-wrapper { position: relative; min-height: 0; display: block; clear: both; }
27+
md2-tab { padding: 16px; display: none; position: relative; }
28+
md2-tab.active { display: block; position: relative;}
29+
.white {color:#fff;}
30+
#tab_manage_btn {vertical-align: top;min-width:40px;}
31+
#tab_manage_btn .fa-lg {vertical-align: initial;}
32+

src/app/layout/header/tab/tab.component.html

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,4 @@
66
</template>
77
</md2-tab>
88

9-
</md2-tabs>
10-
11-
<button mdl-button #btn1="mdlButton" (click)="m1.toggle($event, btn1)" id="tab_manage_btn" mdl-ripple>
12-
<mdl-icon></mdl-icon>
13-
</button>
14-
<mdl-menu #m1="mdlMenu" mdl-menu-position="bottom-right">
15-
<mdl-menu-item mdl-ripple mdl-menu-item-full-bleed-divider (click)="closeAll()">关闭所有选项卡</mdl-menu-item>
16-
<mdl-menu-item *ngFor="let tab of tabControlServiceModal.tabs" (click)="goToTab(tab)" mdl-ripple mdl-menu-item-full-bleed-divider>
17-
<a [routerLink]='tab.link'>{{tab.name}}</a>
18-
<!--<i *ngIf="tab.link !== '/test1'" class="material-icons" (click)="closeTab(tab)">close</i>-->
19-
</mdl-menu-item>
20-
</mdl-menu>
9+
</md2-tabs>

src/app/layout/header/tab/tabs.ts

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import {
1717
} from '@angular/core';
1818
import { CommonModule } from '@angular/common';
1919
import { Router } from '@angular/router';
20+
21+
import { ShareModule } from '../../../share/share.module';
2022
import { MdlModule } from '@angular-mdl/core';
2123

2224
import { TabControlServiceModal } from './TabControlServiceModal';
@@ -85,41 +87,22 @@ export class Md2TabLabel {
8587
[class.disabled]="tab.disabled" (click)="goToTab(tab.reallyTab)">
8688
<span [md2Transclude]="tab.labelRef">{{tab.label}}</span>
8789
</div>
88-
<div class="md2-tab-ink-bar" [style.left]="inkBarLeft" [style.width]="inkBarWidth"></div>
90+
<button mdl-button #btn1="mdlButton" (click)="m1.toggle($event, btn1)" id="tab_manage_btn" mdl-ripple>
91+
<i class="fa fa-sort-down fa-lg white"></i>
92+
</button>
93+
<mdl-menu #m1="mdlMenu" mdl-menu-position="bottom-left">
94+
<mdl-menu-item mdl-ripple mdl-menu-item-full-bleed-divider (click)="reloadNow()">刷新当前页</mdl-menu-item>
95+
<mdl-menu-item mdl-ripple mdl-menu-item-full-bleed-divider (click)="closeAll()">关闭所有选项卡</mdl-menu-item>
96+
<mdl-menu-item mdl-ripple mdl-menu-item-full-bleed-divider (click)="closeOther()">关闭其它选项卡</mdl-menu-item>
97+
<mdl-menu-item mdl-ripple mdl-menu-item-full-bleed-divider (click)="closeNow()">关闭当前选项卡</mdl-menu-item>
98+
</mdl-menu>
99+
<div class="md2-tab-ink-bars" [style.left]="inkBarLeft" [style.width]="inkBarWidth"></div>
89100
</div>
90101
</div>
91102
92103
</div>
93104
`,
94-
styles: [`
95-
md2-tabs { position: absolute; left: 240px; top: 36px; overflow: hidden; display: block; margin-right: 45px; border-radius: 2px; }
96-
.md2-tabs-header-wrapper { position: relative; display: block; height: 35px; border-radius: 5px 5px 0 0; display: block; margin: 0; padding: 0; list-style: none;
97-
-webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; }
98-
.md2-tabs-header-wrapper:after { content: ''; display: table; clear: both; }
99-
.md2-prev-button,
100-
.md2-next-button { position: absolute; top: 0; height: 100%; width: 32px; padding: 10px 0; z-index: 2; cursor: pointer; }
101-
.md2-prev-button { left: 0; }
102-
.md2-next-button { right: 0; }
103-
.md2-prev-button.disabled,
104-
.md2-next-button.disabled { opacity: .4; cursor: default; }
105-
.md2-prev-button .prev-icon,
106-
.md2-next-button .next-icon { display: block; width: 10px; height: 10px; font-size: 0; border-width: 0 0 2px 2px;
107-
border-style: solid; border-color: #757575; border-radius: 1px; transform: rotate(45deg); margin: 8px; }
108-
.md2-next-button .next-icon { border-width: 2px 2px 0 0; }
109-
.md2-tabs-canvas { position: relative; height: 100%; overflow: hidden; display: block; outline: none; }
110-
.md2-tabs-canvas.md2-paginated { margin: 0 32px; }
111-
.md2-tabs-header { position: relative; display: inline-block; height: 100%; white-space: nowrap; -moz-transition: 0.5s cubic-bezier(0.35,0,0.25,1); -o-transition: 0.5s cubic-bezier(0.35,0,0.25,1); -webkit-transition: 0.5s cubic-bezier(0.35,0,0.25,1); transition: 0.5s cubic-bezier(0.35,0,0.25,1); }
112-
.md2-tab-label { position: relative; height: 100%; color: rgba(0,0,0,0.54); font-size: 14px; text-align: center; line-height: 24px; border-radius: 5px 5px 0 0 ; padding: 4px 20px; -moz-transition: background-color .35s cubic-bezier(.35,0,.25,1); -o-transition: background-color .35s cubic-bezier(.35,0,.25,1); -webkit-transition: background-color .35s cubic-bezier(.35,0,.25,1); transition: background-color .35s cubic-bezier(.35,0,.25,1); cursor: pointer; white-space: nowrap; text-transform: uppercase; display: inline-block; font-weight: 500; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; overflow: hidden; -ms-text-overflow: ellipsis; -o-text-overflow: ellipsis; text-overflow: ellipsis; }
113-
.md2-tab-label.active { background-color: #fff; }
114-
.md2-tab-label a { font-size:16px; vertical-align: super;}
115-
.md2-tabs-canvas:focus .md2-tab-label.focus { background: rgba(0,0,0,0.05); }
116-
.md2-tab-label.disabled { color: rgba(0,0,0,0.26); pointer-events: none; -webkit-user-select: none; -moz-user-select: none;
117-
-ms-user-select: none; user-select: none; -webkit-user-drag: none; opacity: 0.5; cursor: default; }
118-
.md2-tab-ink-bar { position: absolute; bottom: 0; height: 2px; background: rgb(255,82,82); transition: .25s cubic-bezier(.35,0,.25,1); }
119-
.md2-tabs-body-wrapper { position: relative; min-height: 0; display: block; clear: both; }
120-
md2-tab { padding: 16px; display: none; position: relative; }
121-
md2-tab.active { display: block; position: relative; }
122-
`],
105+
styleUrls: ['tab.component.css'],
123106
host: {
124107
'[class]': 'class',
125108
'(window:resize)': 'onWindowResize($event)'
@@ -135,10 +118,7 @@ export class Md2Tabs implements OnInit, AfterContentInit {
135118
private offsetLeft = 0;
136119
private inkBarLeft = '0';
137120
private inkBarWidth = '0';
138-
tabControlServiceModal: TabControlServiceModal = {
139-
tabs: [{ 'name': '收件箱', 'link': '/inbox' }],
140-
activeTab: 0
141-
};
121+
tabControlServiceModal: TabControlServiceModal;
142122
@Input() class: string;
143123
@Input()
144124
set selectedIndex(value: any) {
@@ -196,6 +176,33 @@ export class Md2Tabs implements OnInit, AfterContentInit {
196176
}
197177
}
198178

179+
// tab管理菜单
180+
// 关闭所有页面
181+
closeAll() {
182+
this.tabControlServiceModal.tabs.length = 1;
183+
this.tabControlServiceModal.activeTab = 0;
184+
}
185+
186+
// 关闭其它页面
187+
closeOther() {
188+
let retainList = [],
189+
currentTabIndex = this.tabControlServiceModal.activeTab;
190+
retainList.push(this.tabControlServiceModal.tabs[0]);
191+
retainList.push(this.tabControlServiceModal.tabs[currentTabIndex]);
192+
this.tabControlServiceModal.tabs = retainList;
193+
this.tabControlServiceModal.activeTab = 1;
194+
}
195+
196+
// 关闭当前页面
197+
closeNow() {
198+
const index = this.tabControlServiceModal.activeTab;
199+
if (index === 0) {
200+
return
201+
}
202+
this.tabControlServiceModal.tabs.splice(index, 1);
203+
this.tabControlServiceModal.activeTab = index - 1;
204+
}
205+
199206
/**
200207
* 判断激活的Tab并调整Tabs的位移,不存在时设为默认
201208
*/
@@ -222,10 +229,12 @@ export class Md2Tabs implements OnInit, AfterContentInit {
222229
/**
223230
* 激活的Tab下边框计算
224231
*/
225-
_updateInkBar(): void {
232+
_updateInkBar(activeIndex?: number): void {
226233
const elements = this.element;
227234
if (!elements.tabs[this.tabControlServiceModal.activeTab]) { return; }
228-
const tab = elements.tabs[this.tabControlServiceModal.activeTab];
235+
debugger
236+
const index = activeIndex || this.tabControlServiceModal.activeTab;
237+
const tab = elements.tabs[index];
229238
this.inkBarLeft = tab.offsetLeft + 'px';
230239
this.inkBarWidth = tab.offsetWidth + 'px';
231240
}
@@ -367,7 +376,7 @@ export const MD2_TABS_DIRECTIVES: any[] = [Md2TabLabel, Md2Tabs, Md2Tab];
367376

368377
@NgModule({
369378
declarations: [Md2Transclude, Md2TabLabel, Md2Tabs, Md2Tab],
370-
imports: [CommonModule],
379+
imports: [CommonModule, MdlModule],
371380
exports: MD2_TABS_DIRECTIVES,
372381
})
373382
export class Md2TabsModule {

src/app/share/share.module.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
4+
import { MdlModule } from '@angular-mdl/core';
5+
6+
@NgModule({
7+
imports: [
8+
CommonModule
9+
],
10+
declarations: [],
11+
exports: [MdlModule]
12+
})
13+
export class ShareModule { }

0 commit comments

Comments
 (0)