Skip to content
ne-topology.component.ts 30.5 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import {AfterViewChecked, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
wangqinghua's avatar
wangqinghua committed
import {TopologyService} from '../topology.service';
import {NzMessageService} from 'ng-zorro-antd';
wangqinghua's avatar
wangqinghua committed
import {DomSanitizer} from '@angular/platform-browser';
wangqinghua's avatar
wangqinghua committed
import * as $ from 'jquery';
wangqinghua's avatar
wangqinghua committed
declare let editor:any;
wangqinghua's avatar
wangqinghua committed

@Component({
    selector: 'smart-ne-topology',
    templateUrl: './ne-topology.component.html',
    styles: []
})
wangqinghua's avatar
wangqinghua committed
export class NeTopologyComponent implements OnInit {
wangqinghua's avatar
wangqinghua committed
@ViewChild('topologyCanvas') topologyCanvas:ElementRef;
wangqinghua's avatar
wangqinghua committed

    dataSet;
    isVisible = false;
    image;

wangqinghua's avatar
wangqinghua committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 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
    data = {
        "code": 200,
        "msg": "",
        "result": "success",
        "data": {
            "topology_id": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
            "topology_json": {
                "version": "0.4.8",
                "wheelZoom": "0.95",
                "id": "ST172.19.105.52015100809430700001",
                "childs": [
                    {
                        "id": "S172.19.105.52015100809430700002",
                        "elementType": "scene",
                        "translateX": "106.5",
                        "translateY": "20",
                        "scaleX": "1",
                        "scaleY": "1",
                        "childs": [
                            {
                                "id": "L172.19.105.52015100811153300001",
                                "elementType": "link",
                                "x": "0",
                                "y": "0",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "undefined",
                                "nodeSrc": "1136300297928.587",
                                "nodeDst": "1406176935353.6848",
                                "lineType": "line",
                                "zindex": "2"
                            },
                            {
                                "id": "L172.19.105.52015100811153300002",
                                "elementType": "link",
                                "x": "0",
                                "y": "0",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "undefined",
                                "nodeSrc": "1394105924967.951",
                                "nodeDst": "1136300297928.587",
                                "lineType": "line",
                                "zindex": "2"
                            },
                            {
                                "id": "L172.19.105.52015100811153300004",
                                "elementType": "link",
                                "x": "0",
                                "y": "0",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "undefined",
                                "nodeSrc": "564241624829.4331",
                                "nodeDst": "318016674603.1266",
                                "lineType": "line",
                                "zindex": "2"
                            },
                            {
                                "id": "L172.19.105.52015100811153300005",
                                "elementType": "link",
                                "x": "0",
                                "y": "0",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "undefined",
                                "nodeSrc": "1062340763210.1544",
                                "nodeDst": "564241624829.4331",
                                "lineType": "line",
                                "zindex": "2"
                            },
                            {
                                "id": "L172.19.105.52015100811153300006",
                                "elementType": "link",
                                "x": "0",
                                "y": "0",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "undefined",
                                "nodeSrc": "564241624829.4331",
                                "nodeDst": "488323736331.2087",
                                "lineType": "line",
                                "zindex": "2"
                            },
                            {
                                "id": "L172.19.105.52015100811153300007",
                                "elementType": "link",
                                "x": "0",
                                "y": "0",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "undefined",
                                "nodeSrc": "564241624829.4331",
                                "nodeDst": "827722371280.0199",
                                "lineType": "line",
                                "zindex": "2"
                            },
                            {
                                "id": "L172.19.105.52015100811153300008",
                                "elementType": "link",
                                "x": "0",
                                "y": "0",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "undefined",
                                "nodeSrc": "564241624829.4331",
                                "nodeDst": "1045863334277.662",
                                "lineType": "line",
                                "zindex": "2"
                            },
                            {
                                "id": "L172.19.105.52015100811153300009",
                                "elementType": "link",
                                "x": "0",
                                "y": "0",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "undefined",
                                "nodeSrc": "1262070648024.5728",
                                "nodeDst": "564241624829.4331",
                                "lineType": "line",
                                "zindex": "2"
                            },
                            {
                                "id": "L172.19.105.52015100811153300010",
                                "elementType": "link",
                                "x": "0",
                                "y": "0",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "undefined",
                                "nodeSrc": "1262070648024.5728",
                                "nodeDst": "1136300297928.587",
                                "lineType": "line",
                                "zindex": "2"
                            },
                            {
                                "id": "L172.19.105.52015100811214600001",
                                "elementType": "link",
                                "x": "0",
                                "y": "0",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "undefined",
                                "nodeSrc": "253209434749.73596",
                                "nodeDst": "564241624829.4331",
                                "lineType": "line",
                                "zindex": "2"
                            },
                            {
                                "id": "L172.19.105.52015100811214600002",
                                "elementType": "link",
                                "x": "0",
                                "y": "0",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "undefined",
                                "nodeSrc": "253209434749.73596",
                                "nodeDst": "1136300297928.587",
                                "lineType": "line",
                                "zindex": "2"
                            },
                            {
                                "id": "L172.19.105.52015100811214600003",
                                "elementType": "link",
                                "x": "0",
                                "y": "0",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "undefined",
                                "nodeSrc": "520008948580.8119",
                                "nodeDst": "564241624829.4331",
                                "lineType": "line",
                                "zindex": "2"
                            },
                            {
                                "id": "L172.19.105.52015100811214600004",
                                "elementType": "link",
                                "x": "0",
                                "y": "0",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "undefined",
                                "nodeSrc": "520008948580.8119",
                                "nodeDst": "1136300297928.587",
                                "lineType": "line",
                                "zindex": "2"
                            },
                            {
                                "id": "L172.19.105.52015100811512000002",
                                "elementType": "link",
                                "x": "0",
                                "y": "0",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "undefined",
                                "nodeSrc": "809054608657.865",
                                "nodeDst": "1394105924967.951",
                                "lineType": "line",
                                "zindex": "2"
                            },
                            {
                                "id": "L172.19.105.52015100811512000004",
                                "elementType": "link",
                                "x": "0",
                                "y": "0",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "undefined",
                                "nodeSrc": "1250687739831.9912",
                                "nodeDst": "1062340763210.1544",
                                "lineType": "line",
                                "zindex": "2"
                            },
                            {
                                "id": "L172.19.105.52015100911051100001",
                                "elementType": "link",
                                "x": "0",
                                "y": "0",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "undefined",
                                "nodeSrc": "564241624829.4331",
                                "nodeDst": "597645745716.1871",
                                "lineType": "line",
                                "zindex": "2"
                            },
                            {
                                "elementType": "node",
                                "x": "198",
                                "y": "315",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "attack-network",
                                "textPosition": "Bottom_Center",
                                "nodeId": "1136300297928.587",
                                "nodeType": "EC",
                                "nodeImage": "icon_client.png",
                                "zindex": "3"
                            },
                            {
                                "id": "N172.19.105.52015100809465000001",
                                "elementType": "node",
                                "x": "196",
                                "y": "242",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "attackr-router",
                                "textPosition": "Bottom_Center",
                                "nodeId": "1394105924967.951",
                                "nodeType": "VR",
                                "nodeImage": "icon_client.png",
                                "zindex": "3"
                            },
                            {
                                "id": "N172.19.105.52015100809500700002",
                                "elementType": "node",
                                "x": "104",
                                "y": "383.5",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "attack-client",
                                "textPosition": "Bottom_Center",
                                "nodeId": "1406176935353.6848",
                                "nodeType": "VM",
                                "nodeImage": "icon_client.png",
                                "zindex": "3"
                            },
                            {
                                "id": "N172.19.105.52015100810295700002",
                                "elementType": "node",
                                "x": "539",
                                "y": "321.5",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "intert-networker",
                                "textPosition": "Bottom_Center",
                                "nodeId": "564241624829.4331",
                                "nodeType": "EC",
                                "nodeImage": "icon_switcher.png",
                                "zindex": "3"
                            },
                            {
                                "id": "N172.19.105.52015100810320100002",
                                "elementType": "node",
                                "x": "719",
                                "y": "160.5",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "ws-manage",
                                "textPosition": "Bottom_Center",
                                "nodeId": "318016674603.1266",
                                "nodeType": "VM",
                                "nodeImage": "icon_virtual_host.png",
                                "zindex": "3"
                            },
                            {
                                "id": "N172.19.105.52015100810402700002",
                                "elementType": "node",
                                "x": "725",
                                "y": "225.5",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "ws-browser",
                                "textPosition": "Bottom_Center",
                                "nodeId": "488323736331.2087",
                                "nodeType": "VM",
                                "nodeImage": "icon_client.png",
                                "zindex": "3"
                            },
                            {
                                "id": "N172.19.105.52015100810461200002",
                                "elementType": "node",
                                "x": "726",
                                "y": "293.5",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "internal-mssql",
                                "textPosition": "Bottom_Center",
                                "nodeId": "827722371280.0199",
                                "nodeType": "VM",
                                "nodeImage": "icon_server.png",
                                "zindex": "3"
                            },
                            {
                                "id": "N172.19.105.52015100810485100002",
                                "elementType": "node",
                                "x": "726",
                                "y": "361.5",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "internal-ossec",
                                "textPosition": "Bottom_Center",
                                "nodeId": "1045863334277.662",
                                "nodeType": "VM",
                                "nodeImage": "icon_server.png",
                                "zindex": "3"
                            },
                            {
                                "id": "N172.19.105.52015100810523500002",
                                "elementType": "node",
                                "x": "369",
                                "y": "245.5",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "internet-www",
                                "textPosition": "Bottom_Center",
                                "nodeId": "1262070648024.5728",
                                "nodeType": "ECVR",
                                "nodeImage": "icon_route_controller.png",
                                "zindex": "3"
                            },
                            {
                                "id": "N172.19.105.52015100811153300003",
                                "elementType": "node",
                                "x": "536",
                                "y": "237.5",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "intert-router",
                                "textPosition": "Bottom_Center",
                                "nodeId": "1062340763210.1544",
                                "nodeType": "VR",
                                "nodeImage": "icon_router.png",
                                "zindex": "3"
                            },
                            {
                                "id": "N172.19.105.52015100811163200002",
                                "elementType": "node",
                                "x": "367.5",
                                "y": "320",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "internet-blog",
                                "textPosition": "Bottom_Center",
                                "nodeId": "253209434749.73596",
                                "nodeType": "ECVR",
                                "nodeImage": "icon_route_controller.png",
                                "zindex": "3"
                            },
                            {
                                "id": "N172.19.105.52015100811204100002",
                                "elementType": "node",
                                "x": "370.5",
                                "y": "403",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "internet-vpn",
                                "textPosition": "Bottom_Center",
                                "nodeId": "520008948580.8119",
                                "nodeType": "ECVR",
                                "nodeParams": {},
                                "nodeImage": "icon_route_controller.png",
                                "zindex": "3"
                            },
                            {
                                "id": "N172.19.105.52015100811512000001",
                                "elementType": "node",
                                "x": "194.5",
                                "y": "166",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "attack-firewall",
                                "textPosition": "Bottom_Center",
                                "nodeId": "809054608657.865",
                                "nodeType": "FW",
                                "nodeParams": {},
                                "nodeImage": "icon_firewall.png",
                                "zindex": "3"
                            },
                            {
                                "id": "N172.19.105.52015100811512000003",
                                "elementType": "node",
                                "x": "534.5",
                                "y": "163",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "intert-firewall",
                                "textPosition": "Bottom_Center",
                                "nodeId": "1250687739831.9912",
                                "nodeType": "FW",
                                "nodeParams": {},
                                "nodeImage": "icon_firewall.png",
                                "zindex": "3"
                            },
                            {
                                "id": "N172.19.105.52015100911045400002",
                                "elementType": "node",
                                "x": "727.5",
                                "y": "430",
                                "width": "32",
                                "height": "32",
                                "rotate": "0",
                                "scaleX": "1",
                                "scaleY": "1",
                                "text": "defend-client",
                                "textPosition": "Bottom_Center",
                                "nodeId": "597645745716.1871",
                                "nodeType": "VM",
                                "nodeImage": "icon_client.png",
                                "zindex": "3"
                            }
                        ]
                    }
                ]
            }
        }
    }

    constructor(private topologySer: TopologyService, private message: NzMessageService,
                private sanitizer:DomSanitizer) {
wangqinghua's avatar
wangqinghua committed
    }

    ngOnInit() {
wangqinghua's avatar
wangqinghua committed
        this.loadCanvas();
wangqinghua's avatar
wangqinghua committed
        this.getList();
    }

wangqinghua's avatar
wangqinghua committed
    loadCanvas(){
        // 选择连线方式后的css样式
        $("#link-line").click( ()=> {
            $(this).css("background-color", "darkgray");
            $("#link-foldline-h").css("background-color", "white");
            $("#link-foldline-v").css("background-color", "white");
            $("#link-flexline-h").css("background-color", "white");
            $("#link-flexline-v").css("background-color", "white");
            $("#link-curveline").css("background-color", "white");
        });
        $("#link-foldline-h").click(()=> {
            $(this).css("background-color", "darkgray");
            $("#link-line").css("background-color", "white");
            $("#link-foldline-v").css("background-color", "white");
            $("#link-flexline-h").css("background-color", "white");
            $("#link-flexline-v").css("background-color", "white");
            $("#link-curveline").css("background-color", "white");
        });
        $("#link-foldline-v").click(()=> {
            $(this).css("background-color", "darkgray");
            $("#link-line").css("background-color", "white");
            $("#link-foldline-h").css("background-color", "white");
            $("#link-flexline-h").css("background-color", "white");
            $("#link-flexline-v").css("background-color", "white");
            $("#link-curveline").css("background-color", "white");
        });
        $("#link-flexline-h").click(()=> {
            $(this).css("background-color", "darkgray");
            $("#link-line").css("background-color", "white");
            $("#link-foldline-h").css("background-color", "white");
            $("#link-foldline-v").css("background-color", "white");
            $("#link-flexline-v").css("background-color", "white");
            $("#link-curveline").css("background-color", "white");
        });
        $("#link-flexline-v").click(()=> {
            $(this).css("background-color", "darkgray");
            $("#link-line").css("background-color", "white");
            $("#link-foldline-h").css("background-color", "white");
            $("#link-foldline-v").css("background-color", "white");
            $("#link-flexline-h").css("background-color", "white");
            $("#link-curveline").css("background-color", "white");
        });
        $("#link-curveline").click(()=> {
            $(this).css("background-color", "darkgray");
            $("#link-line").css("background-color", "white");
            $("#link-foldline-h").css("background-color", "white");
            $("#link-foldline-v").css("background-color", "white");
            $("#link-flexline-h").css("background-color", "white");
            $("#link-flexline-v").css("background-color", "white");
        });

        // 节点树中每个节点的拖放动作定义给拓扑图编辑器
        let nodes = $("[topo-div-type='topo-node']");
        let nodeLength = nodes.length;
        for (let i = 0; i < nodeLength; i++) {
            let text = $(nodes[i]).find("span").eq(0).text();
            editor.drag(nodes[i], document.getElementById('topology-canvas'), text);
        }
        editor.loadTopology( 'network.json', "img/backimg1.png");

wangqinghua's avatar
wangqinghua committed
    }

wangqinghua's avatar
wangqinghua committed
    //获取列表
    getList() {
        this.topologySer.find({}).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.dataSet = res.data;
                } else {
                    this.message.info(res.errMsg);
                }
            }
        );
    }

    //图表
    getImage(item) {
        this.isVisible = true;
        this.topologySer.findImage(item.sysmapid).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.image = res.data.image;
                } else {
                    this.message.info(res.errMsg);
                }
            }
        );
    }

    handleOk() {
        this.isVisible = false;
        this.image = null;
    }
}