67 lines
1.9 KiB
TypeScript
67 lines
1.9 KiB
TypeScript
import { Component, inject, signal, OnInit } from '@angular/core';
|
|
import { CommonModule } from '@angular/common';
|
|
import { RouterOutlet, RouterLink, Router } from '@angular/router';
|
|
import { NzLayoutModule } from 'ng-zorro-antd/layout';
|
|
import { NzMenuModule } from 'ng-zorro-antd/menu';
|
|
import { NzIconModule } from 'ng-zorro-antd/icon';
|
|
import { NzButtonModule } from 'ng-zorro-antd/button';
|
|
import { NzDropDownModule } from 'ng-zorro-antd/dropdown';
|
|
import { NzSwitchModule } from 'ng-zorro-antd/switch';
|
|
import { FormsModule } from '@angular/forms';
|
|
import { AuthService } from '../../core/services/auth.service';
|
|
import { SettingsService } from '../../core/services/settings.service';
|
|
import { ApiService } from '../../core/services/api.service';
|
|
import { KeyToken } from '../../core/models';
|
|
|
|
@Component({
|
|
selector: 'app-main-layout',
|
|
standalone: true,
|
|
imports: [
|
|
CommonModule,
|
|
FormsModule,
|
|
RouterOutlet,
|
|
RouterLink,
|
|
NzLayoutModule,
|
|
NzMenuModule,
|
|
NzIconModule,
|
|
NzButtonModule,
|
|
NzDropDownModule,
|
|
NzSwitchModule,
|
|
],
|
|
templateUrl: './main-layout.component.html',
|
|
styleUrl: './main-layout.component.scss'
|
|
})
|
|
export class MainLayoutComponent implements OnInit {
|
|
private authService = inject(AuthService);
|
|
private apiService = inject(ApiService);
|
|
private router = inject(Router);
|
|
settingsService = inject(SettingsService);
|
|
|
|
isCollapsed = signal(false);
|
|
userId = this.authService.getUserId();
|
|
currentKey = signal<KeyToken | null>(null);
|
|
expertMode = this.settingsService.expertMode;
|
|
|
|
ngOnInit(): void {
|
|
this.loadCurrentKey();
|
|
}
|
|
|
|
private loadCurrentKey(): void {
|
|
const userId = this.userId;
|
|
if (!userId) return;
|
|
|
|
this.apiService.getCurrentKey(userId).subscribe({
|
|
next: (key) => this.currentKey.set(key)
|
|
});
|
|
}
|
|
|
|
toggleCollapsed(): void {
|
|
this.isCollapsed.update(v => !v);
|
|
}
|
|
|
|
logout(): void {
|
|
this.authService.logout();
|
|
this.router.navigate(['/login']);
|
|
}
|
|
}
|