2021-12-20 17:10:06 +08:00
|
|
|
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, Inject, OnInit} from '@angular/core';
|
|
|
|
|
import {NoticeIconSelect, NoticeItem } from '@delon/abc/notice-icon';
|
2021-11-28 14:58:20 +08:00
|
|
|
import { NzI18nService } from 'ng-zorro-antd/i18n';
|
|
|
|
|
import { NzMessageService } from 'ng-zorro-antd/message';
|
2021-12-20 17:10:06 +08:00
|
|
|
import {AlertService} from "../../../service/alert.service";
|
|
|
|
|
import {ALAIN_I18N_TOKEN} from "@delon/theme";
|
|
|
|
|
import {I18NService} from "@core";
|
|
|
|
|
import {Router} from "@angular/router";
|
2021-11-28 14:58:20 +08:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'header-notify',
|
|
|
|
|
template: `
|
|
|
|
|
<notice-icon
|
|
|
|
|
[data]="data"
|
|
|
|
|
[count]="count"
|
|
|
|
|
[loading]="loading"
|
|
|
|
|
btnClass="alain-default__nav-item"
|
|
|
|
|
btnIconClass="alain-default__nav-item-icon"
|
2021-12-20 17:10:06 +08:00
|
|
|
(clear)="gotoAlertCenter($event)"
|
2021-11-28 14:58:20 +08:00
|
|
|
(popoverVisibleChange)="loadData()"
|
|
|
|
|
></notice-icon>
|
|
|
|
|
`,
|
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
|
|
|
|
})
|
2021-12-20 17:10:06 +08:00
|
|
|
export class HeaderNotifyComponent implements OnInit{
|
|
|
|
|
|
2021-11-28 14:58:20 +08:00
|
|
|
data: NoticeItem[] = [
|
|
|
|
|
{
|
2021-12-20 17:10:06 +08:00
|
|
|
title: '近期未处理告警',
|
2021-11-28 14:58:20 +08:00
|
|
|
list: [],
|
2021-12-20 17:10:06 +08:00
|
|
|
emptyText: '暂无未处理告警',
|
2021-11-28 14:58:20 +08:00
|
|
|
emptyImage: 'https://gw.alipayobjects.com/zos/rmsportal/wAhyIChODzsoKIOBHcBk.svg',
|
2021-12-20 17:10:06 +08:00
|
|
|
clearText: '进入告警中心'
|
2021-11-28 14:58:20 +08:00
|
|
|
}
|
|
|
|
|
];
|
2021-12-20 17:10:06 +08:00
|
|
|
count = 0;
|
2021-11-28 14:58:20 +08:00
|
|
|
loading = false;
|
|
|
|
|
|
2021-12-20 17:10:06 +08:00
|
|
|
constructor(private msg: NzMessageService,
|
|
|
|
|
private nzI18n: NzI18nService,
|
|
|
|
|
private router: Router,
|
|
|
|
|
@Inject(ALAIN_I18N_TOKEN) private i18nSvc: I18NService,
|
|
|
|
|
private alertSvc: AlertService,
|
|
|
|
|
private cdr: ChangeDetectorRef) {}
|
2021-11-28 14:58:20 +08:00
|
|
|
|
2021-12-20 17:10:06 +08:00
|
|
|
ngOnInit(): void {
|
|
|
|
|
this.loadData();
|
2021-11-28 14:58:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadData(): void {
|
|
|
|
|
if (this.loading) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.loading = true;
|
2021-12-20 17:10:06 +08:00
|
|
|
let loadAlerts$ = this.alertSvc.searchAlerts(0, undefined,undefined, 0, 5)
|
|
|
|
|
.subscribe(message => {
|
|
|
|
|
loadAlerts$.unsubscribe();
|
|
|
|
|
if (message.code === 0) {
|
|
|
|
|
let page = message.data;
|
|
|
|
|
let alerts = page.content;
|
|
|
|
|
this.data[0].list = [];
|
|
|
|
|
alerts.forEach(alert => {
|
|
|
|
|
let item = {
|
|
|
|
|
id: alert.id,
|
|
|
|
|
avatar: 'https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png',
|
|
|
|
|
title: '监控-' + alert.monitorName +'-发出' + this.i18nSvc.fanyi(`alert.priority.${alert.priority}`),
|
|
|
|
|
datetime: alert.gmtCreate,
|
|
|
|
|
color: 'blue',
|
|
|
|
|
type: '近期未处理告警'
|
|
|
|
|
}
|
|
|
|
|
this.data[0].list.push(item);
|
|
|
|
|
})
|
|
|
|
|
this.count = page.totalElements;
|
|
|
|
|
} else {
|
|
|
|
|
console.warn(message.msg);
|
2021-11-28 14:58:20 +08:00
|
|
|
}
|
2021-12-20 17:10:06 +08:00
|
|
|
this.loading = false;
|
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
|
}, error => {
|
|
|
|
|
loadAlerts$.unsubscribe();
|
|
|
|
|
console.error(error.msg);
|
|
|
|
|
this.loading = false;
|
|
|
|
|
})
|
2021-11-28 14:58:20 +08:00
|
|
|
}
|
|
|
|
|
|
2021-12-20 17:10:06 +08:00
|
|
|
gotoAlertCenter(type: string): void {
|
|
|
|
|
this.router.navigateByUrl(`/alert/center`);
|
2021-11-28 14:58:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
select(res: NoticeIconSelect): void {
|
|
|
|
|
this.msg.success(`点击了 ${res.title} 的 ${res.item.title}`);
|
|
|
|
|
}
|
|
|
|
|
}
|