Skip to content
basic-detail.component.ts 30.9 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import {AfterViewInit, Component, ElementRef, OnInit, Renderer, ViewChild,} from '@angular/core';
wangqinghua's avatar
wangqinghua committed
import {ActivatedRoute, Router} from '@angular/router';
wangqinghua's avatar
wangqinghua committed
import {OverAllService} from '../../overAll.service';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {NzMessageService} from 'ng-zorro-antd';
import {BasiCheckComponent} from '../../../modal/basi-check/basi-check.component';
import {NzModalService} from 'ng-zorro-antd';
wangqinghua's avatar
wangqinghua committed
import {color, pageSize} from '../../../app.constants';
wangqinghua's avatar
wangqinghua committed
import {WarnListComponent} from '../../../modal/warn-list/warn-list.component';
wangqinghua's avatar
wangqinghua committed
import {DatePipe} from '@angular/common';
wangqinghua's avatar
wangqinghua committed
import {ThresholdComponent} from '../../../modal/threshold/threshold.component';
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
@Component({
wangqinghua's avatar
wangqinghua committed
    selector: 'jhi-basic-detail',
    templateUrl: './basic-detail.component.html',
    styles: [
wangqinghua's avatar
wangqinghua committed
        `
wangqinghua's avatar
wangqinghua committed
            .checkTags {
                position: absolute;
wangqinghua's avatar
wangqinghua committed
                top: 12px;
wangqinghua's avatar
wangqinghua committed
                left: 233px;
xiaowenjie's avatar
xiaowenjie committed
                z-index: 989;
wangqinghua's avatar
wangqinghua committed
            }
wangqinghua's avatar
wangqinghua committed
            .time-select{
                position: absolute;
                top: 55px;
                right: 15px;
                z-index: 999;
            }
wangqinghua's avatar
wangqinghua committed
            .select-border{
                border: 1px solid #6097b7;
                border-radius: 5px;
                padding: 2px;
                margin-right: 5px;
            }
wangqinghua's avatar
wangqinghua committed
            :host ::ng-deep .tabs-smart .ant-tabs-nav-scroll div.ant-tabs-tab:nth-child(3){
wangqinghua's avatar
wangqinghua committed
                margin-right: 180px !important;
wangqinghua's avatar
wangqinghua committed
            }
wangqinghua's avatar
wangqinghua committed
            :host ::ng-deep .ant-radio-button-wrapper{
                margin: 4px;
            }
wangqinghua's avatar
wangqinghua committed
        `
    ]
wangqinghua's avatar
wangqinghua committed
})
wangqinghua's avatar
wangqinghua committed
export class BasicDetailComponent implements OnInit, AfterViewInit {
wangqinghua's avatar
wangqinghua committed
    @ViewChild('smartCheck') smartCheck: BasiCheckComponent;
wangqinghua's avatar
wangqinghua committed
    @ViewChild('smartThreshold') smartThreshold: ThresholdComponent;
wangqinghua's avatar
wangqinghua committed
    @ViewChild('thirdTabs') thirdTabs: ElementRef;
    @ViewChild('warnList') warnList: WarnListComponent;
wangqinghua's avatar
wangqinghua committed
    @ViewChild('colorEle') colorEle:ElementRef;
    @ViewChild('checkEle') checkEle:ElementRef;
wangqinghua's avatar
wangqinghua committed
    color = color;
wangqinghua's avatar
wangqinghua committed
    loading = false;
wangqinghua's avatar
wangqinghua committed
    hostId: string;
wangqinghua's avatar
wangqinghua committed
    tabNum = 0;
wangqinghua's avatar
wangqinghua committed
    hostName;
wangqinghua's avatar
wangqinghua committed
    realName;
wangqinghua's avatar
wangqinghua committed
    size = 'default';
wangqinghua's avatar
wangqinghua committed
    changeStates;
wangqinghua's avatar
wangqinghua committed
    chartOption1;
    responseTimeStr;
    losedStr;
    cpuUsedStr;
    usedStr;
    chartOption2;
    chartOption3;
    chartOption4;
    secondOptionLeft;
    secondOptionRight;
wangqinghua's avatar
wangqinghua committed
    dataSet: any[];
    panel1 = {active: true, name: '响应时间与丢包率', disabled: false};
wangqinghua's avatar
wangqinghua committed
    panel2 = {active: true, name: 'CPU使用率及内存使用率',disabled: false};
wangqinghua's avatar
wangqinghua committed
    panel3 = {active: true, name: '磁盘使用情况', disabled: false};
wangqinghua's avatar
wangqinghua committed

    //监控点
    isBasicEdit;
wangqinghua's avatar
wangqinghua committed
    itemTypeValue;
wangqinghua's avatar
wangqinghua committed
    interfaceList: any[];
    itemTypeList: any[];
wangqinghua's avatar
wangqinghua committed

    //
wangqinghua's avatar
wangqinghua committed
    checkList: any[];
wangqinghua's avatar
wangqinghua committed
    isCheck = false;
    checkStatus = {
wangqinghua's avatar
wangqinghua committed
        warning: null,
        normal: null,
        disabled: null,
        high: null
wangqinghua's avatar
wangqinghua committed
    };
wangqinghua's avatar
wangqinghua committed

    isKey = false;
wangqinghua's avatar
wangqinghua committed
    keyList: any[];
wangqinghua's avatar
wangqinghua committed
    keyType = '1';

    //图表
    isGrapha = false;
wangqinghua's avatar
wangqinghua committed
    selectGraphadata;
wangqinghua's avatar
wangqinghua committed
    chartOptionGrapha;
wangqinghua's avatar
wangqinghua committed
    imageSelectDate = new Date();
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
    pageSize = pageSize;
wangqinghua's avatar
wangqinghua committed

    //分页--监控点
    pageIndex = 1;  //当前页数
wangqinghua's avatar
wangqinghua committed
    totalNum;   //总数据长度
    applicationId;    //分类ID

wangqinghua's avatar
wangqinghua committed
    //进出口流量-分页
    pageNum = 1;
wangqinghua's avatar
wangqinghua committed
    pageCount = 5;
wangqinghua's avatar
wangqinghua committed
    totalNumInOut;
wangqinghua's avatar
wangqinghua committed
    inOutLoading;
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
    //分页--告警
    warn_totalNum;
    warn_pageNum = 1;

wangqinghua's avatar
wangqinghua committed
    searchName;

wangqinghua's avatar
wangqinghua committed
    validateForm: FormGroup;

wangqinghua's avatar
wangqinghua committed
    isSpinning;  //刷新
wangqinghua's avatar
wangqinghua committed
    units;   //图表单位
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
    constructor(private routerInfo: ActivatedRoute, private message: NzMessageService,
wangqinghua's avatar
wangqinghua committed
                private overAllSer: OverAllService, private renderer: Renderer,private router:Router,
wangqinghua's avatar
wangqinghua committed
                private fb: FormBuilder, private modalService: NzModalService,private datePipe:DatePipe) {
wangqinghua's avatar
wangqinghua committed
        this.routerInfo.queryParams.subscribe(queryParams => {
            this.hostId = queryParams.hostId;
wangqinghua's avatar
wangqinghua committed
            this.overAllSer.findDetailed(this.hostId).subscribe(
                (res)=>{
                    let data = res.data[0]
                    this.hostName = data.name;   //显示名
                    this.realName = data.host;   //主机名
                }
            )
wangqinghua's avatar
wangqinghua committed
        });
wangqinghua's avatar
wangqinghua committed
    }

    ngOnInit() {
wangqinghua's avatar
wangqinghua committed
        this.isSpinning = true;
        this.responseTime();
        this.losed();
        this.cpused();
        this.used();
        // this.inOutInfo();

        //监测点
        this.getList();

        //历史告警
        const obj = {};
        this.warnList.getList(obj);
        this.disks();
wangqinghua's avatar
wangqinghua committed
    }

    ngAfterViewInit() {
wangqinghua's avatar
wangqinghua committed
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852
        this.checkEle.nativeElement.children[1].children[0].children[0].children[2].children[0].children[0].children[2].style.marginRight = this.colorEle.nativeElement.offsetWidth +'px';
    }

    //平均响应时间
    responseTime() {
        this.overAllSer.responseTime(this.hostId).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.responseTimeStr = res.data.responseTime.toFixed(2);
                    const responseTime = this.responseTimeStr;
                    const other = 100 - this.responseTimeStr;
                    const data = [
                        {value: responseTime},
                        {value: other},
                        {
                            value: 100, name: '', tooltip: {
                                formatter: function(a) {
                                    return '';
                                }
                            }
                        }
                    ];
                    this.chartOption1 = {
                        title: {
                            text: '平均响应时间',
                            top: '5%',
                            left: '35%',
                            textStyle: {
                                color: '#999',
                                fontSize: 12,
                            }
                        },
                        tooltip: {
                            trigger: 'item',
                            show: false,
                            formatter: '{a} <br/>{b} : {c} ({d}%)'
                        },
                        color: ['#7eb6ea', '#eeeeee', 'transparent'],
                        series: [
                            {
                                type: 'pie',
                                startAngle: 180,
                                radius: ['50%', '85%'],
                                center: ['50%', '75%'],
                                hoverAnimation: true,
                                data: data,
                                itemStyle: {
                                    normal: {
                                        show: false,
                                        position: 'center'
                                    },
                                    emphasis: {
                                        shadowBlur: 10,
                                        shadowOffsetX: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                },
                                labelLine: {
                                    normal: {
                                        show: false
                                    }
                                },
                            }
                        ]
                    };
                } else {
                    this.message.info(res.errMsg);
                }

            }
        );
    }

    //丢包率
    losed() {
        this.overAllSer.losed(this.hostId).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.losedStr = res.data.losed;
                    const losed = res.data.losed;
                    const other = 100 - res.data.losed;
                    const data = [
                        {value: losed},
                        {value: other},
                        {
                            value: 100, name: '', tooltip: {
                                formatter: function(a) {
                                    return '';
                                }
                            }
                        }
                    ];
                    this.chartOption2 = {
                        title: {
                            text: '丢包率',
                            top: '5%',
                            left: '38%',
                            textStyle: {
                                color: '#999',
                                fontSize: 12,
                            }
                        },
                        tooltip: {
                            trigger: 'item',
                            show: false,
                            formatter: '{a} <br/>{b} : {c} ({d}%)'
                        },
                        color: ['#7eb6ea', '#eeeeee', 'transparent'],
                        series: [
                            {
                                type: 'pie',
                                startAngle: 180,
                                radius: ['50%', '85%'],
                                center: ['50%', '75%'],
                                hoverAnimation: true,
                                data: data,
                                itemStyle: {
                                    normal: {
                                        show: false,
                                        position: 'center'
                                    },
                                    emphasis: {
                                        shadowBlur: 10,
                                        shadowOffsetX: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                },
                                labelLine: {
                                    normal: {
                                        show: false
                                    }
                                },
                            }
                        ]
                    };
                } else {
                    this.message.info(res.errMsg);
                }

            }
        );
    }

    //cup使用率
    cpused() {
        const data = {
            hostId: this.hostId,
        };
        this.overAllSer.cupUsed(data).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.cpuUsedStr = res.data.cpuUsed;
                    const losed = res.data.cpuUsed;
                    const other = 100 - res.data.cpuUsed;
                    const data = [
                        {value: losed},
                        {value: other},
                        {
                            value: 100, name: '', tooltip: {
                                formatter: function(a) {
                                    return '';
                                }
                            }
                        }
                    ];
                    this.chartOption3 = {
                        title: {
                            text: 'CPU使用率',
                            top: '5%',
                            left: '38%',
                            textStyle: {
                                color: '#999',
                                fontSize: 12,
                            }
                        },
                        tooltip: {
                            trigger: 'item',
                            show: false,
                            formatter: '{a} <br/>{b} : {c} ({d}%)'
                        },
                        color: ['#7eb6ea', '#eeeeee', 'transparent'],
                        series: [
                            {
                                type: 'pie',
                                startAngle: 180,
                                radius: ['50%', '85%'],
                                center: ['50%', '75%'],
                                hoverAnimation: true,
                                data: data,
                                itemStyle: {
                                    normal: {
                                        show: false,
                                        position: 'center'
                                    },
                                    emphasis: {
                                        shadowBlur: 10,
                                        shadowOffsetX: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                },
                                labelLine: {
                                    normal: {
                                        show: false
                                    }
                                },
                            }
                        ]
                    };
                } else {
                    this.message.info(res.errMsg);
                }

            }
        );
    }

    //内存使用率
    used() {
        const data = {
            hostId: this.hostId,
        };
        this.overAllSer.used(data).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.usedStr = res.data.used;
                    const used = res.data.used;
                    const other = 100 - res.data.used;
                    const data = [
                        {value: used},
                        {value: other},
                        {
                            value: 100, name: '', tooltip: {
                                formatter: function(a) {
                                    return '';
                                }
                            }
                        }
                    ];
                    this.chartOption4 = {
                        title: {
                            text: '内存使用率',
                            top: '5%',
                            left: '38%',
                            textStyle: {
                                color: '#999',
                                fontSize: 12,
                            }
                        },
                        tooltip: {
                            trigger: 'item',
                            show: false,
                            formatter: '{a} <br/>{b} : {c} ({d}%)'
                        },
                        color: ['#7eb6ea', '#eeeeee', 'transparent'],
                        series: [
                            {
                                type: 'pie',
                                startAngle: 180,
                                radius: ['50%', '85%'],
                                center: ['50%', '75%'],
                                hoverAnimation: true,
                                data: data,
                                itemStyle: {
                                    normal: {
                                        show: false,
                                        position: 'center'
                                    },
                                    emphasis: {
                                        shadowBlur: 10,
                                        shadowOffsetX: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                },
                                labelLine: {
                                    normal: {
                                        show: false
                                    }
                                },
                            }
                        ]
                    };
                } else {
                    this.message.info(res.errMsg);
                }

            }
        );
    }

    //磁盘使用率
    disks() {
        const data = {
            hostId: this.hostId,
        };
        this.overAllSer.disks(data).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.secondOptionLeft = {
                        grid: {
                            left: '8%',
                            right: '0',
                            bottom: '1%',
                            containLabel: true
                        },
                        tooltip: {
                            trigger: 'axis',
                        },
                        xAxis: {
                            type: 'value',
                            show: false,
                        },
                        yAxis: {
                            triggerEvent: true,
                            type: 'category',
                            axisTick: {
                                show: false
                            },
                            axisLine: {
                                show: false,
                            },
                            // 分割线设置
                            splitLine: {
                                show: true,  //显示分割线
                            },
                            data: res.data.disks.map((item) => {
                                return item.name;
                            }),
                            axisLabel:res.data.disks.map((item) => {
                                let data = item.name;
                                if(data.length > 5) {
                                    data = data.substring(0, 4) + "..";
                                }
                                return data;
                            }),
                        },
                        color: ['#ed7a7b', '#f2f2f2'],
                        series: [
                            {
                                name: '已使用',
                                type: 'bar',
                                stack: '总空间',
                                label: {
                                    normal: {
                                        show: true,
                                        position: 'insideRight',
                                        formatter: (obj) => {
                                            const item = (res.data.disks[obj.dataIndex].used / (1024 * 1024 * 1024)).toFixed(2);
                                            return item + 'G';
                                        }
                                    }
                                },
                                itemStyle: {
                                    normal: {
                                        color: '#0D5DCB'
                                    },
                                },
                                data: res.data.disks.map((item) => {
                                    const pre = ( (item.used / item.total) * 100 ).toFixed(2);  //已使用百分比
                                    return pre;
                                })
                            },
                            {
                                name: '剩余空间',
                                type: 'bar',
                                stack: '总空间',
                                label: {
                                    normal: {
                                        show: true,
                                        position: 'insideRight',
                                        formatter: (obj) => {
                                            const cut = (res.data.disks[obj.dataIndex].total - res.data.disks[obj.dataIndex].used);
                                            const item = (cut / (1024 * 1024 * 1024)).toFixed(2);
                                            return item + 'G';
                                        }
                                    }
                                },
                                itemStyle: {
                                    normal: {
                                        color: '#bfbfbf'
                                    },
                                },
                                data: res.data.disks.map((item) => {
                                    const pre = ( (item.total - item.used) / (item.total) * 100 ).toFixed(2); //剩余百分比
                                    return pre;
                                })
                            },
                        ]
                    };

                    let total = res.data.disks.map((item) => {
                        return item.total;
                    });
                    total = this.add(total);

                    let used = res.data.disks.map((item) => {
                        return item.used;
                    });
                    used = this.add(used);

                    const arr = [
                        {
                            name:"已使用",
                            value:used,
                        },
                        {
                            name:"未使用",
                            value:total,
                        }
                    ];

                    this.secondOptionRight = {
                        title: {
                            text: '磁盘总体使用占比',
                            x: 'center'
                        },
                        tooltip: {
                            trigger: 'item',
                            formatter: '{a} <br/>{b} : {c} ({d}%)'
                        },
                        color: ['#3194e0','#bfbfbf'],
                        series: [
                            {
                                name: '',
                                type: 'pie',
                                radius: '55%',
                                center: ['50%', '60%'],
                                data: arr,
                                itemStyle: {
                                    normal: {
                                        label: {
                                            position: 'inner',
                                            show: true,
                                            formatter: '{b} : {c} ({d}%)'
                                        },
                                        labelLine: {show: true}
                                    }
                                },
                                labelLine: {
                                    normal: {
                                        show: false
                                    }
                                },
                            }
                        ]
                    };

                } else {
                    this.message.info(res.errMsg);
                }
                this.isSpinning = false;
            }
        );
    }

    extension(){

    }

    add(arr) {
        let total = 0;
        for (let i = 0; i < arr.length; i++) {
            total += arr[i];
        }
        return (total / 1024 / 1024 / 1024).toFixed(2);
    }

    //进出口流量-SNMP
    inOutInfo() {
        this.inOutLoading = true;
        const data = {
            obj:{
                hostid:Number(this.hostId)
            },
            pageNum:this.pageNum,
            pageCount:this.pageCount
        }
        this.overAllSer.inOutInfoSnmp(data).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.dataSet = res.data.data;
                    this.inOutLoading = false;
                    this.totalNumInOut = res.data.totalNum;
                }else{
                    this.message.info(res.errMsg);
                }
            }
        );
    }

    //进出口流量 翻页
    changeInoutInfo(e){
        this.pageNum = e;
        // this.inOutInfo();
    }

    //添加监测点
    showCheckModal() {
        this.smartCheck.showAddModal(this.hostId,this.realName,'添加监测点');
    }

    //编辑监测点
    showEditModal(item){
        this.smartCheck.showEditModal(this.hostId,item.itemid,this.realName,item.templateid,'编辑监测点');
    }

    //添加阈值
    showAddThresholdModal(item){
        this.smartThreshold.showAddModal("添加阈值",item.itemid,this.realName);
    }

    //编辑阈值
    showEditThresholdModal(item){
        this.smartThreshold.showEditModal("编辑阈值",item.itemid,this.hostId,this.realName);
    }

    //添加or编辑监测点 之后
    getList(){
        this.getCheckList();
        this.findItemType();
    }

    handleKeyCancel() {
        this.isKey = false;
    }

    handleKeyOk() {
        this.isKey = false;
    }

    //监测点列表
    getCheckList() {
        this.getCheckStatus();
        this.loading = true;
        const data = {
            pageNum: this.pageIndex,
            pageCount: pageSize,
            obj:{
                applicationid: this.applicationId,
                hostid: this.hostId,
                priorityName:this.changeStates,
                name:this.searchName
            }
        };
        this.overAllSer.findCheckByType(data).subscribe(
            (res) => {
                this.checkList = res.data.data;
                this.totalNum = res.data.totalNum;
                this.loading = false;
            }
        );
    }

    changeState(state){
        this.tabNum = 1;
        this.changeStates = state;
        this.getCheckList();
    }

    //分页
    change(e) {
        this.pageIndex = e;
        this.getCheckList();
    }

    changeType(item) {
        this.pageIndex = 1;
        if(item.name == "全部"){
            this.changeStates = null;
        }
        this.applicationId = item.applicationid;
        this.getCheckList();
    }

    //监测点状态
    getCheckStatus() {
        this.overAllSer.findItemCount(this.hostId).subscribe(
            (res) => {
                if(res.errCode == 10000){
                    this.checkStatus = res.data;
                }
            }
        );
    }

    //删除监测点
    deleteCheckItem(item) {
        this.modalService.confirm({
            nzTitle: '删除',
            nzContent: '<b style="color: red;">确认删除该监测点吗?</b>',
            nzOkText: '确定',
            nzOkType: 'danger',
            nzOnOk: () => {
                const data = {
                    itemids:[item.itemid],
                    templateid:item.templateid
                };
                this.overAllSer.deleteItem(data).subscribe(
                    (res) => {
                        if (res.errCode == 10000) {
                            this.message.success('删除成功');
                            this.getCheckList();
                        } else {
                            this.message.error(res.errMsg);
                        }
                    }
                );
            },
            nzCancelText: '取消',
            nzOnCancel: () => console.log('Cancel')
        });
    }

    //图表
    showImageModal(data) {
        this.isGrapha = true;
        this.selectGraphadata = data;

        this.getGraphDate();
    }

    //获取图表数据
    getGraphDate(){
        const data = {
            date: this.datePipe.transform(this.imageSelectDate,'yyyy-MM-dd'),
            itemid: this.selectGraphadata.itemid
        };
        this.overAllSer.findGraphData(data).subscribe(
            (res) => {
                if (res.errCode == 10000 && res.data.length > 0) {
                    const result = res.data;
                    this.chartOptionGrapha = {
                        title: {
                            text: this.selectGraphadata.name
                        },
                        tooltip: {
                            trigger: 'axis'
                        },
                        xAxis: {
                            data: result.map((item) => {
                                return item.time;
                            })
                        },
                        yAxis: {
                            splitLine: {
                                show: false
                            },
                            axisLabel:{   //Y轴数据
                                formatter:(value)=>{
                                    return value+ " " +this.selectGraphadata.units;   //负数取绝对值变正数
                                },
                            },
                        },
                        dataZoom: [{
                            startValue: '2014-06-01'
                        }, {
                            type: 'inside'
                        }],
                        series: {
                            type: 'line',
                            data: result.map((item) => {
                                return item.value ;
                            }),

                        }
                    };
                }
            }
        );
    }

    handleImageCancel() {
        this.isGrapha = false;
        this.chartOptionGrapha = null;
    }

    //监控项分类
    findItemType() {
        const data = {
            'hostids': []
        };
        data.hostids.push(this.hostId);
        this.overAllSer.findItemType(data).subscribe(
            (res) => {
                this.itemTypeList = res.data;
                const data = {
                    applicationid:'',
                    name:'全部'
                };
                if (null!=res.data){
                    this.itemTypeList.unshift(data);
                }
                this.itemTypeValue = '';

            }
        );
wangqinghua's avatar
wangqinghua committed
    }

wangqinghua's avatar
wangqinghua committed
    //停止/启用监控项  0  启用   1停止
    updateItem(itemid, status) {
        const data = {
            'status': status,
            'itemid': itemid
        };
        this.modalService.confirm({
            nzTitle: '',
            nzContent: '<b style="color: red;">确认修改监控项状态吗?</b>',
            nzOkText: '确定',
            nzOkType: 'danger',
            nzOnOk: () => {
                this.overAllSer.itemUpdate(data).subscribe(
                    (res) => {
                        if (res.errCode == 10000) {
                            this.getCheckList();
                        }
                        this.message.info(res.errMsg);
                    }
                );
            },
            nzCancelText: '取消',
            nzOnCancel: () => console.log('Cancel')
        });
    }

    //删除单个资源
    showDeleteConfirm() {
        this.modalService.confirm({
            nzTitle: '删除',
            nzContent: '<b style="color: red;">确认删除该资源吗?</b>',
            nzOkText: '确定',
            nzOkType: 'danger',
            nzOnOk: () => {
                const data = {
                    hostids:[]
                };
                data.hostids.push(this.hostId);
                this.overAllSer.deleteHostPost(data).subscribe(
                    (res) => {
                        if (res.errCode == 10000) {
                            this.message.success('删除成功');
                            this.router.navigate(['app/main/basic']);
                        } else {
                            this.message.error(res.errMsg);
                        }
                    }
                );
            },
            nzCancelText: '取消',
            nzOnCancel: () => console.log('Cancel')
        });
    }
wangqinghua's avatar
wangqinghua committed
}
wangqinghua's avatar
wangqinghua committed