diff --git a/src/app/routes/config/layout/manage/path/path.component.html b/src/app/routes/config/layout/manage/path/path.component.html index e7b50a2..0c49475 100644 --- a/src/app/routes/config/layout/manage/path/path.component.html +++ b/src/app/routes/config/layout/manage/path/path.component.html @@ -16,9 +16,9 @@ {{ data.req_ip }} {{ data.req_frequency }} - 白名单 - - 灰名单 + 白名单 + + 灰名单 @@ -39,10 +39,10 @@ {{ data.req_frequency }} {{ data.req_jobnum }} - 白名单 - - 灰名单 - + 白名单 + + 灰名单 + @@ -59,17 +59,17 @@ - + {{ data.interface_addr }} {{ data.req_ip }} {{ data.req_account }} {{ data.req_frequency }} {{ data.req_jobnum }} - 白名单 - - 灰名单 - + 白名单 + + 灰名单 + @@ -93,10 +93,10 @@ {{ data.req_frequency }} {{ data.req_jobnum }} - 白名单 - - 灰名单 - + 白名单 + + 灰名单 + diff --git a/src/app/routes/config/layout/manage/path/path.component.ts b/src/app/routes/config/layout/manage/path/path.component.ts index f838d47..5576769 100644 --- a/src/app/routes/config/layout/manage/path/path.component.ts +++ b/src/app/routes/config/layout/manage/path/path.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, OnInit } from '@angular/core'; +import { Component, Input, OnInit, OnChanges, SimpleChanges } from '@angular/core'; import { NzMessageService } from 'ng-zorro-antd'; import { NoticeService } from '../../../service/https/notice.service'; @@ -7,10 +7,13 @@ import { NoticeService } from '../../../service/https/notice.service'; templateUrl: './path.component.html', styleUrls: ['./path.component.styl'] }) -export class PathComponent implements OnInit { +export class PathComponent implements OnInit, OnChanges { @Input() detail_data: any; data; viewType = 0; + whiteListParam = {}; + greyListParam = {}; + rules; constructor( private noticeService: NoticeService, @@ -22,31 +25,144 @@ export class PathComponent implements OnInit { // if (this.detail_data == null) { // this.detail_data = JSON.parse(jsonStr); // } - this.parseData(this.detail_data); + this.parseData(); + if (this.rules == null) { + this.noticeService.getDefaultRule().subscribe( + resp => { + if (resp.status === 200) { + this.rules = resp.data; + } else { + this.message.error(resp.msg); + } + }, + error => { + this.message.error('服务器错误'); + } + ); + } + } + + ngOnChanges(changes: SimpleChanges) { + if ('detail_data' in changes) { + this.parseData(); + // 在这里处理接收到的数据 + } } - parseData(detail_data: any) { - for (const dataKey in detail_data) { - if (detail_data.hasOwnProperty(dataKey)) { + parseData() { + for (const dataKey in this.detail_data) { + if (this.detail_data.hasOwnProperty(dataKey)) { if (dataKey === 'type') { - this.viewType = detail_data[dataKey]; + this.viewType = this.detail_data[dataKey]; } else { - this.data = detail_data[dataKey]; + this.data = this.detail_data[dataKey]; + this.data.forEach(item => { + item['is_in_white_list'] = 0; + item['is_in_grey_list'] = 0; + }); } } } } clickWihteList(data) { - alert("点击白名单"); + let index = -1; + // this.message.success('添加白名单成功!'); + // this.data[index]['is_in_white_list'] = 1; + this.whiteListParam['range'] = ["ueba"]; + this.whiteListParam['des'] = ""; + this.whiteListParam['is_enable'] = 1; + switch(this.viewType) { + case 1: + this.whiteListParam['fields'] = ["sip"]; + this.whiteListParam['name'] = data.req_ip + '-' + this.getCurrentTime(); + this.whiteListParam['content'] = {"sip": data.req_ip}; + this.whiteListParam['alert_rule_id'] = this.rules["white_list"]["ip"]; + index = this.data.findIndex(item => item.req_ip === data.req_ip); + break; + case 2: + this.whiteListParam['fields'] = ["url"]; + this.whiteListParam['name'] = data.interface_addr + '-' + this.getCurrentTime(); + this.whiteListParam['content'] = {"url": data.interface_addr}; + this.whiteListParam['alert_rule_id'] = this.rules["white_list"]["interface"]; + index = this.data.findIndex(item => item.interface_addr === data.interface_addr); + break; + case 3: + break; + case 4: + break; + } + this.noticeService.addWhitelist(this.whiteListParam).subscribe( + resp => { + if (resp.status === 200) { + this.message.success('添加白名单成功!'); + this.data[index]['is_in_white_list'] = 1; + } else { + this.message.error(resp.msg); + } + }, + error => { + this.message.error('服务器错误'); + } + ); } clickGreyList(data) { - alert("点击灰名单"); + let index = -1; + // this.message.success('添加灰名单成功!'); + // this.data[index]['is_in_grey_list'] = 1; + this.greyListParam['des'] = ""; + this.greyListParam['is_enable'] = 1; + switch(this.viewType) { + case 1: + this.greyListParam['fields'] = ["sip"]; + this.greyListParam['name'] = data.req_ip + '-' + this.getCurrentTime(); + this.greyListParam['content'] = {"sip": data.req_ip}; + this.greyListParam['alert_rule_id'] = this.rules["grey_list"]["ip"]; + index = this.data.findIndex(item => item.req_ip === data.req_ip); + break; + case 2: + this.greyListParam['fields'] = ["url"]; + this.greyListParam['name'] = data.interface_addr + '-' + this.getCurrentTime(); + this.greyListParam['content'] = {"url": data.interface_addr}; + this.greyListParam['alert_rule_id'] = this.rules["grey_list"]["interface"]; + index = this.data.findIndex(item => item.interface_addr === data.interface_addr); + break; + case 3: + break; + case 4: + break; + } + this.noticeService.addGreyList(this.greyListParam).subscribe( + resp => { + if (resp.status === 200) { + this.message.success('添加灰名单成功!'); + this.data[index]['is_in_grey_list'] = 1; + } else { + this.message.error(resp.msg); + } + }, + error => { + this.message.error('服务器错误'); + } + ); } clickFrequency(data) { alert("点击超链接"); } + // 在组件类中 + getCurrentTime(): string { + const now = new Date(); + const year = now.getFullYear(); + const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份是从0开始的 + const day = String(now.getDate()).padStart(2, '0'); + const hours = String(now.getHours()).padStart(2, '0'); + const minutes = String(now.getMinutes()).padStart(2, '0'); + const seconds = String(now.getSeconds()).padStart(2, '0'); + + return `${year}/${month}/${day} ${hours}:${minutes}:${seconds}`; + } + }