1
1
import { Component , Inject , OnInit } from '@angular/core' ;
2
+ import { Router } from '@angular/router' ;
2
3
3
- // import { Router } from '@angular/router';
4
4
import {
5
5
AppstoreOutline ,
6
6
BellOutline ,
@@ -25,6 +25,7 @@ import {
25
25
import { ReuseCustomContextMenu } from '@delon/abc/reuse-tab' ;
26
26
import { ALAIN_I18N_TOKEN , Menu , MenuService , RTLService , SettingsService , User } from '@delon/theme' ;
27
27
import { LayoutDefaultOptions } from '@delon/theme/layout-default' ;
28
+ import { deepCopy } from '@delon/util/other' ;
28
29
import { NzIconService } from 'ng-zorro-antd/icon' ;
29
30
import { NzMessageService } from 'ng-zorro-antd/message' ;
30
31
@@ -60,6 +61,16 @@ const ICONS = [
60
61
<i nz-icon nzType="github"></i>
61
62
</a>
62
63
</layout-default-header-item>
64
+ <layout-default-header-item direction="middle">
65
+ <layout-default-top-menu-item
66
+ *ngFor="let m of topMenus"
67
+ (click)="changeMenu(m.key)"
68
+ [selected]="m.selected"
69
+ [disabled]="m.disabled"
70
+ >
71
+ <i nz-icon nzType="github"></i> {{ m.label }}
72
+ </layout-default-top-menu-item>
73
+ </layout-default-header-item>
63
74
<layout-default-header-item direction="right">
64
75
<a class="alain-default__nav-item" (click)="rtl.toggle()">{{ rtl.nextDir | uppercase }}</a>
65
76
</layout-default-header-item>
@@ -106,6 +117,11 @@ export class DevLayoutComponent implements OnInit {
106
117
get user ( ) : User {
107
118
return this . settings . user ;
108
119
}
120
+ topMenus : Array < { key : string ; label : string ; selected ?: boolean ; disabled ?: boolean } > = [
121
+ { key : '' , label : 'Default' , selected : true } ,
122
+ { key : 'bus' , label : 'Bus' , selected : false } ,
123
+ { key : 'disabled' , label : 'Disabbled' , disabled : true }
124
+ ] ;
109
125
110
126
menus : Menu [ ] = [
111
127
{
@@ -190,14 +206,32 @@ export class DevLayoutComponent implements OnInit {
190
206
private menuSrv : MenuService ,
191
207
public settings : SettingsService ,
192
208
public msgSrv : NzMessageService ,
193
- // private router: Router,
209
+ private router : Router ,
194
210
@Inject ( ALAIN_I18N_TOKEN ) private i18n : I18NService ,
195
211
public rtl : RTLService
196
212
) {
197
213
iconSrv . addIcon ( ...ICONS ) ;
198
214
// this.testReuse();
199
215
}
200
216
217
+ changeMenu ( key : string ) : void {
218
+ this . menuSrv . add (
219
+ key === ''
220
+ ? deepCopy ( this . menus )
221
+ : [
222
+ {
223
+ text : 'test' ,
224
+ group : true ,
225
+ children : [ { text : `TYPE - ${ key } ` , link : '/dev/view/1' , icon : 'anticon anticon-appstore' } ]
226
+ }
227
+ ]
228
+ ) ;
229
+ for ( let tm of this . topMenus ) {
230
+ tm . selected = tm . key === key ;
231
+ }
232
+ this . loadFirstValidMenu ( ) ;
233
+ }
234
+
201
235
// private testReuse(): void {
202
236
// const urls = ['/dev/l2', '/dev/l3', '/dev/l4', '/dev/l5', '/dev/l6'];
203
237
// const fn = (pos: number) => {
@@ -222,6 +256,17 @@ export class DevLayoutComponent implements OnInit {
222
256
}
223
257
224
258
ngOnInit ( ) : void {
225
- this . menuSrv . add ( this . menus ) ;
259
+ this . menuSrv . add ( deepCopy ( this . menus ) ) ;
260
+ }
261
+
262
+ private loadFirstValidMenu ( ) : void {
263
+ let res : Menu | undefined ;
264
+ this . menuSrv . visit ( this . menuSrv . menus , item => {
265
+ if ( res == null && item . hide !== true && item . link != null && item . link . length > 0 ) {
266
+ res = item ;
267
+ }
268
+ } ) ;
269
+ if ( res == null ) return ;
270
+ this . router . navigateByUrl ( res . link ! ! ) ;
226
271
}
227
272
}
0 commit comments