import { Component , Inject } from '@angular/core' ; import { NzMessageService , ModalOptionsForService } from 'ng-zorro-antd' ; import { SettingsService , ModalHelper , _HttpClient } from '@delon/theme' ; import { CoreService , AuthService } from 'generated' ; import { Router } from '@angular/router' ; import { BaseDetailComponent } from '@shared/base/base.detail.component' ; import { DA_SERVICE_TOKEN , ITokenService } from '@delon/auth' ; @ Component ( { selector : 'layout-sidebar' , templateUrl : './sidebar.component.html' , } ) export class SidebarComponent { changePasswordSchema = { type : 'object' , required : [ 'oldPassword' , 'newPassword' , 'confirm' ] , properties : { oldPassword : { type : 'string' , title : '旧密码' , ui : { type : 'password' } } , newPassword : { type : 'string' , title : '新密码' , ui : { type : 'password' } } , confirm : { type : 'string' , title : '确认密码' , ui : { type : 'password' } } } } ; constructor ( public settings , public coreService , public authService , public msgSrv , public router , public modalHelper , public client , @ Inject ( DA_SERVICE_TOKEN ) private tokenService ) { } logout ( ) { this . authService . authLogout ( ) . subscribe ( ( result ) => { if ( result ) { this . msgSrv . success ( '成功退出' ) ; this . router . navigateByUrl ( this . tokenService . login_url ) ; } } ) ; } get User ( ) { return this . settings . user as any ; } profile ( ) { this . router . navigate ( [ '/system/settings' ] ) ; } setSettings ( ) { this . router . navigate ( [ '/system/settings' ] ) ; } changePassword ( ) { const params = { nzTitle : '修改密码' , nzMaskClosable : false } ; this . modalHelper . static ( BaseDetailComponent , { schema : this . changePasswordSchema , formData : { } , onSave : this . save , context : this } , 420 , params ) . subscribe ( ( ) => { } ) ; } async save ( entry ) { const url = `api/user/password` ; return this . client . put ( url , entry ) . toPromise ( ) ; } }