济南项目
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.
 
 
 
 
 

91 lines
3.2 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';
import signalR from '../../../signalR'
@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 = null
isSuperAdmin
ngOnInit(): void {
//调用服务中的function刷新token
this.token.startUp()
this.user = JSON.parse(sessionStorage.getItem('userData')).name
let roles = JSON.parse(sessionStorage.getItem('userData')).roles
let isTrue = roles.find(item => {
return item.name == '超级管理员'
})
isTrue ? this.isSuperAdmin = true : this.isSuperAdmin = false
signalR.initSR();
// 接收来自中心的消息
(signalR.SR as any).on('receiveNotification', (message: string, senderName: string) => {
// 接收后要做的事
console.log('收到消息---', message)
})
}
signOut() {
this.router.navigate(['/login'])
}
ngOnDestroy(): void {
(signalR.SR as any).receiveNotification = []
signalR.stopSR()
}
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));
}
}