You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.6 KiB
70 lines
2.6 KiB
import { Component, OnInit, ViewContainerRef } from '@angular/core'; |
|
import { Router } from '@angular/router'; |
|
import { CacheTokenService } from 'src/app/service/cache-token.service'; |
|
import { HttpClient } from '@angular/common/http'; |
|
import { ChangePasswordComponent } from '../change-password/change-password.component'; |
|
import { NzModalService } from 'ng-zorro-antd/modal'; |
|
import { NzMessageService } from 'ng-zorro-antd/message'; |
|
@Component({ |
|
selector: 'app-nav', |
|
templateUrl: './nav.component.html', |
|
styleUrls: ['./nav.component.scss'] |
|
}) |
|
export class NavComponent implements OnInit { |
|
|
|
constructor( private modal: NzModalService,private http: HttpClient,private message: NzMessageService,private viewContainerRef: ViewContainerRef,private router: Router, public token: CacheTokenService) { } |
|
user:"" |
|
ngOnInit(): void { |
|
//调用服务中的function刷新token |
|
this.token.startUp() |
|
this.user=JSON.parse(sessionStorage.getItem('userData')).organizationName |
|
} |
|
signOut() { |
|
this.router.navigate(['/login']) |
|
} |
|
ngOnDestroy(): void { |
|
this.token.delete() |
|
} |
|
|
|
changePassword() { |
|
const modal: any = this.modal.create({ |
|
nzTitle: '修改密码', |
|
nzContent: ChangePasswordComponent, |
|
nzViewContainerRef: this.viewContainerRef, |
|
nzWidth: 288, |
|
nzComponentParams: {}, |
|
nzOnOk: async () => { |
|
if (instance.validateForm.valid) { |
|
if (instance.validateForm.value.newpassword != instance.validateForm.value.affirmpassword) { |
|
this.message.create('warning', '两次密码输入不一致!'); |
|
return false |
|
} else { |
|
await new Promise((resolve, reject) => { |
|
let body = { |
|
oldPassword: instance.validateForm.value.oldpassword, |
|
newPassword: instance.validateForm.value.newpassword |
|
} |
|
this.http.patch('/api/Accounts/ChangePassword', body).subscribe(data => { |
|
resolve(data) |
|
this.message.create('success', '修改成功!'); |
|
return true |
|
}, err => { |
|
this.message.create('warning', err.error.error.message); |
|
modal.config.nzOkLoading = false |
|
return false |
|
}) |
|
}) |
|
} |
|
|
|
} else { |
|
this.message.create('warning', '请填写完整!'); |
|
return false |
|
} |
|
} |
|
}); |
|
const instance = modal.getContentComponent(); |
|
modal.afterOpen.subscribe(() => console.log('[afterOpen] emitted!')); |
|
// Return a result when closed |
|
modal.afterClose.subscribe(result => console.log('[afterClose] The result is:', result)); |
|
} |
|
}
|
|
|