mainPage.js 29.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 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 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 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926
// 文本信息对象,即要国际化的字符串的key:value集合对象
var messages = {
    // 将以字段名为Key,解析成目标语言的文本,供后面直接引用
    text_info: "",
    // 字段类型为函数的,可以通过调用该函数,动态组成文本。
    main_plugin_newVersion: function(newVersion, currentVersion) {},
    columns_line_no: "",
    columns_plate_text: "",
    columns_plate_color: "",
    columns_plate_width: "",
    columns_violation_type: "",
    columns_velocity: "",
    columns_picture_time: "",
    columns_lane_no: "",
    columns_flow_count: "",
    columns_average_velocity: "",
    columns_occupation_rate: "",
    columns_distance_of_head: "",
    columns_queue_length: ""
};
// 按页面的初始化顺序来加载语言,脚本
// 加载语言配置
loadLanguage(function() {
    // 加载完语言,执行页面的其它初始化动作
    $().ready(function() {
        // 当页面加载完成,加载各种Js组件。
        // 调用封装好的方法,根据当前语言来动态加载EasyUI组件
        loadEasyuiModules(["layout", "messager", "datagrid"], function() {
            // 当加载完这些组件后,使用标签来初始化的组件会被自动解析并实例化。如:<div class="easyui-layout"></div>
            // 初始化表格
            initDataGrid();
        });
        // 其他的需要页面加载完后执行的方法。
        // 其他一些任务,检测Ocx,判断是否为Debug模式
        setTimeout(function() {
            isDebugModel(); //判断是否为Debug模式
            try {
                //检查Ocx是否有更新
                var hasUpdate = checkOcxUpdate();
                //如果Ocx没有更新,执行Ocx
                if (!hasUpdate) {
                    executeOcx();
                }
            } catch (err) {
                //Ocx安装弹窗
                showOcxInstallWindow();
            }
        }, 1000);

        $(".tabSelector").click(function(event) {
            var selectorText = $(event.currentTarget).attr("data-id");
            $(".tabSelector").toggleClass("tabSelected"); //切换标签选择页

            if (selectorText == "capture") {
                $(".datagridContainer").removeClass("up");
            } else {
                $(".datagridContainer").addClass("up");
            }
        });

        //开始查询数据
        setTimeout(function() {
            mainPageViewModel.getTime();
            mainPageViewModel.getVersionInfo();
        }, 500);

        //刷新前反初始化ocx控件
        window.onbeforeunload = function() {
            if (isOcxReady) {
                ocxController.uninit;
                window.parent.frames.uninitResultOcx();
            }
        };

        $(document).keyup(function(event) {
            // 同时按 alt + ctrl + d 开启调试视频流
            if (event.altKey && event.ctrlKey && event.keyCode == "68") {
                if (window.console) {
                    console.log("开启调试模式");
                }
                isDebug = !isDebug;
                playVideo();
            }
        });
    });
}, messages);

var count = 0;
var ocxController = new NvrOcxController(videoOcxObject);
// 消息控件
var infoOcxObj = window.parent.frames.getInfoOcx();
var mainPageViewModel = new MainPageViewModel();
var isDebug = true; // ocx调试模式
var captureWin = null;
// ocx保存图片的路径
var picSaveBasePath = "";
// 尝试获取ocx保存图片的路径,如果失败则设置一个默认值
try {
    picSaveBasePath = infoOcxObj.GetRootPath();
} catch (e) {}
if (picSaveBasePath == null || picSaveBasePath == "") {
    picSaveBasePath = "C:\\temp\\S2_savedPic";
}
var isOcxReady = false;

function executeOcx() {
    playVideo(); //播放视频流
    window.parent.frames.initResultOcx();
    setOcxMode(); //设置Ocx模式
    isOcxReady = true;
}

//设置Ocx模式
function setOcxMode() {
    var mode = window.parent.appModel.getSetting("captureMode");
    if (!mode) {
        getCameraBusinessMode(function(cameraMode) {
            //保存相机设置
            if (cameraMode) {
                mode = cameraMode;
                window.parent.appModel.setSetting("captureMode", cameraMode);
            }
            setCameraMode();
        });
    } else {
        setCameraMode();
    }
    // 设置Ocx抓拍模式
    function setCameraMode() {
        //卡口或公交模式,隐藏红灯状态
        if (mode == "2" || mode == "3") {
            ocxController.setKakouMode(true);
            //卡口模式下,隐藏红灯信号
            ocxController.setRedLightState(-1, -1, -1);
        }
    }
}

//显示Ocx安装窗口
function showOcxInstallWindow() {
    hideOcxObj();
    $("#ocxDownloadWin").window("open");
}

//关闭Ocx安装窗口后,刷新页面
function closeOcxInstallWindow() {
    showOcxObj();
    window.location.reload();
}

//检测Ocx是有升级版本
function checkOcxUpdate() {
    var installedVersion = ocxController.getVersion();
    var serverVersion = $("#videoOcxObject").attr("data-version");
    // 比较版本号
    if (compareVersion(serverVersion, installedVersion) > 0) {
        hideOcxObj();
        // 新插件的提示信息
        var newVersionMessage = messages.main_plugin_newVersion(
            serverVersion,
            installedVersion
        );
        $.messager.confirm(messages.text_info, newVersionMessage, function(r) {
            if (r) {
                showOcxInstallWindow();
            } else {
                //不升级Ocx
                showOcxObj();
                //继续执行原来的Ocx操作
                executeOcx();
            }
        });
        return true;
    }
    return false;
}

function hideOcxObj() {
    $("#videoOcxObject").hide();
}

function showOcxObj() {
    $("#videoOcxObject").show();
}

function isDebugModel() {
    var url = this.parent.location.href;
    if (url.indexOf("?debug") > 0) {
        isDebug = true;
    }
}
//获取视频的URL
function getVideoUrl(ip) {
    ocxController.init(isDebug);

    if (isDebug) {
        return "IPSocket://" + ip;
    }
    return "rtsp://" + ip + ":8557/h264";
}

//播放视频
function playVideo() {
    //获取当前url中ip
    var ip = window.location.hostname;
    // 			ip = "192.168.5.158";
    var videoUrl = getVideoUrl(ip);

    var channel = 1;
    ocxController.playVideo(videoUrl, 1, "", ip, 1);
}
// 相机运行模式
var cameraRunMode = -1;
// 初始化表格
function initDataGrid() {
    // 获取相机运行模式
    getCameraBusinessMode(function(mode) {
        cameraRunMode = mode;
        loadCaptureGrid(mode);
        loadFlowGrid(mode);
    });
}
// 根据相机运行模式,加载不同的表格
function loadCaptureGrid(mode) {
    var options = {
        columns: [
            [
                {
                    field: "LineNo",
                    title: messages.columns_line_no,
                    align: "center",
                    width: 20
                },
                {
                    field: "PlateText",
                    title: messages.columns_plate_text,
                    align: "center",
                    width: 40
                },
                {
                    field: "PlateColor",
                    title: messages.columns_plate_color,
                    align: "center",
                    width: 30
                },
                {
                    field: "PlateWidth",
                    title: messages.columns_plate_width,
                    align: "center",
                    width: 20
                },
                {
                    field: "ViolationType",
                    title: messages.columns_violation_type,
                    align: "center",
                    width: 100
                },
                {
                    field: "Velocity",
                    title: messages.columns_velocity,
                    align: "center",
                    width: 30,
                    formatter: fixNumber
                },
                {
                    field: "PictureTime",
                    title: messages.columns_picture_time,
                    align: "center",
                    width: 50
                }
            ]
        ],
        fit: true,
        fitColumns: true,
        striped: true,
        singleSelect: true,
        onSelect: selectCaptureInfo,
        rowStyler: captureInfoStyler,
        rownumbers: true
    };
    // 判断相机运行模式是否为 "4",即 “非机动车违法”模式
    if (mode == "4") {
        options.columns = [
            [
                {
                    field: "PlateText",
                    title: "类型",
                    align: "center",
                    width: 40
                },
                {
                    field: "ViolationType",
                    title: "状态",
                    align: "center",
                    width: 100
                },
                {
                    field: "PictureTime",
                    title: "时间",
                    align: "center",
                    width: 50
                }
            ]
        ];
    }
    $("#captureGrid").datagrid(options);
}
// 加载流量结果表
function loadFlowGrid(mode) {
    var options = {
        columns: [
            [
                {
                    field: "LaneNo",
                    title: messages.columns_lane_no,
                    align: "center",
                    width: 50
                },
                {
                    field: "FlowCount",
                    title: messages.columns_flow_count,
                    align: "center",
                    width: 40
                },
                {
                    field: "Velocity",
                    title: messages.columns_velocity,
                    align: "center",
                    width: 100,
                    formatter: fixNumber
                },
                {
                    field: "OccupationRate",
                    title: messages.columns_occupation_rate,
                    align: "center",
                    width: 50,
                    formatter: fixNumber
                },
                {
                    field: "DistanceOfHead",
                    title: messages.columns_distance_of_head,
                    align: "center",
                    width: 50,
                    formatter: fixNumber
                },
                {
                    field: "QueueLength",
                    title: messages.columns_queue_length,
                    align: "center",
                    width: 40,
                    formatter: fixNumber
                }
            ]
        ],
        fit: true,
        fitColumns: true,
        striped: true,
        singleSelect: true,
        onSelect: selectFlowInfo,
        rownumbers: true
    };
    // 判断相机运行模式
    if (mode == "4") {
        options.columns = [
            [
                {
                    field: "FlowCountUp",
                    title: "上行流量",
                    align: "center",
                    width: 50
                },
                {
                    field: "FlowCountDown",
                    title: "下行流量",
                    align: "center",
                    width: 50
                },
                {
                    field: "FlowCount",
                    title: "总流量",
                    align: "center",
                    width: 50
                },
                {
                    field: "Velocity",
                    title: "平均速度",
                    align: "center",
                    width: 100,
                    formatter: fixNumber
                }
            ]
        ];
    }
    $("#flowGrid").datagrid(options);
}

function fixNumber(value, row, index) {
    value = value + "";
    var indexOfDot = value.indexOf(".");
    if (indexOfDot > -1) {
        return value.substr(0, indexOfDot + 3);
    }
    return value;
}

//  主页的
function MainPageViewModel() {
    var self = this;
    var infoUrl = "/do/trafficController/trafficInfo";
    var timeUrl = "/do/trafficController/getTime"; //获取时间的Url
    /*自动推送的信息列表
            {
                time:{
                   year:2015,
                   month:12,
                   day:4,
                   hour:12,
                   minute:5,
                   second:10,
                   millisecond:123
                },
                signal:{
                    left:"",
                    straight:"",
                    right:""
                },
                captureInfo:{
                    "URL":
                        {
                            "PictureUrl":
                                {
                                    "PicUrl0": "第一张的url",
                                    "PicUrl1": "第一张的url",
                                    "PicUrl2": "第一张的url",
                                    "PicUrl3": "第一张的url"
                                },
                                "VideoUrl": "短时录像的url"
                        },
                    "LineNo": "车道",
                    "PlateText": "车牌号",
                    "PlateType": "车牌类型",
                    "PlateColor": "车牌颜色",
                    "PlateWidth": "车牌宽度",
                    "ViolationType": "状态",
                    "Velocity": "速度",
                    "CarColor": "车身颜色",
                    "PictureTime": "时间"
                }
            }
        */
    //默认的红绿灯信号(默认为空)
    var signalDefault = {
        Left: null,
        Straight: null,
        Right: null
    };

    self.signal = ko.observable(signalDefault); //信号

    self.signal.subscribe(function(newValue) {
        var leftSignal = convertSignal(newValue.Left);
        var straightSignal = convertSignal(newValue.Straight);
        var rightSignal = convertSignal(newValue.Right);
        ocxController.setRedLightState(leftSignal, straightSignal, rightSignal);
    });

    //版本信息
    var defaultVersion = {
        ver5: " ",
        ver6: " ",
		ver10: " "
    };
    self.versionInfo = ko.observable(defaultVersion);

    self.infoList = ko.observableArray([]); //抓拍结果列表
    //self.flowInfoList = ko.observableArray([]);//流量信息列表
    self.selectedInfoIndex = ko.observable(0); //已选择的抓拍结果索引
    self.selectedFlowInfoIndex = ko.observable(0); //已选择的流量结果索引
    //报警信息列表
    self.alarmList = ko.observableArray([
        //{
        //        "Content": "License_Detection--未读到注册信息",
        //        "Level": 2,
        //        "Section": "3",
        //        "Source": "192.168.5.156-0",
        //        "Target": "license"
        //}
    ]);

    self.flowList = ko.observableArray([]);

    //是否有未阅读的报警
    self.hasUnReadAlarm = ko.computed(function() {
        return self.alarmList().length > 0;
    });
    //已选择的数据行
    self.selectedInfo = ko.computed(function() {
        if (self.infoList().length > 0)
            return self.infoList()[self.selectedInfoIndex()];
        else {
            //返回一个空的对象,防止页面在无数据时不显示框架
            return {
                URL: {
                    PictureUrl: {
                        FULLVIEW1: "",
                        LANEVIEW1: "",
                        LANEVIEW2: "",
                        LANEVIEW3: ""
                    },
                    VideoUrl: ""
                },
                LineNo: "",
                PlateText: "",
                PlateWidth: "",
                Vehicle: {
                    left: 0,
                    top: 0,
                    bottom: 0,
                    right: 0,
                    width: 0,
                    height: 0
                }
            };
        }
    }, this);

    self.appendCaptureRow = function(data) {
        var index = self.infoList().length - 1;
        self.selectedInfoIndex(index);
        //加载数据
        $("#captureGrid").datagrid("appendRow", data);
    };
    //加载流量信息
    self.loadFlowInfoList = function(list) {
        var data = {
            total: list.length,
            rows: list
        };
        // 判断相机是否为 "非机动车违法模式"
        if (cameraRunMode == "4") {
            data.rows = (function() {
                var row = {
                    Velocity: 0
                };
                for (var index = 0; index < list.length; index++) {
                    var element = list[index];
                    switch (element.LaneNo) {
                        case 2:
                            row.FlowCountUp = element.FlowCount;
                            break;
                        case 1:
                            row.FlowCountDown = element.FlowCount;
                            break;
                        case 0:
                            row.FlowCount = element.FlowCount;
                            break;
                        default:
                            break;
                    }
                }
            })();
        }
        console.log("###################### flow flow flow flow flow flow ######################");
        $("#flowGrid").datagrid("loadData", data);
    };

    //加载流量信息
    self.appendFlowInfoRow = function(list) {
        for (var i = 0; i < list.length; i++) {
            $("#flowGrid").datagrid("appendRow", list[i]);
        }

        var index = self.flowList().length - 1;
        self.selectedFlowInfoIndex(index);
    };
    // 加载相机时间
    self.getTime = function() {
        $.ajax({
            url: timeUrl,
            type: "GET",
            dataType: "json",
            timeout: 5000,
            data: null,
            success: function(data, textStatus) {
                if (data.error) {
                    processTimeInfo(data);
                    //定时1分钟同步一次时间
                    if (textStatus == "success") {
                        setTimeout(self.getTime, 60000);
                    }
                } else {
                    self.getTime();
                }
            },
            error: function(XMLHttpRequest, textStatus, error) {
                //出错后,延迟两秒再请求,防止页面卡死
                //setTimeout(self.getTime, 6000);
                //请求出错,可能是相机Web后台挂掉,不再刷新
                processTimeInfo(null);
            }
        });
    };
    // 获取相机版本号信息
    self.getVersionInfo = function() {
        var parameterAdaptor = new ParameterAdaptor();
        parameterAdaptor.getParameters("deviceInfo", function(data) {
            if (data && data.feedback) {
                var d = {};
                for (var key in data.feedback) {
                    d["ver" + key] = data.feedback[key];
                }
                var versionInfo = $.extend(defaultVersion, d);
                self.versionInfo(versionInfo);
            }
        });
    };
    // 设置红绿灯信息
    self.signalLight = function(data) {
        if (data.Item) {
            for (var i = 0; i < data.Item.length; i++) {
                var currentItem = data.Item[i];
                //取出之前的红绿灯信息
                signalDefault = self.signal();
                //更新红绿灯信息
                $.extend(signalDefault, currentItem.Content || {});
                self.signal(signalDefault);
                //保存一份到父窗口,供跳转回来后使用
                window.parent.lightData = signalDefault;
            }
        }
    };

    // 处理Ocx抛出的信息
    self.processInfo = function(data) {
        if (data.Item) {
            for (var i = 0; i < data.Item.length; i++) {
                var currentItem = data.Item[i];
                switch (currentItem.Type) {
                    case "LightInfo":
                        //取出之前的红绿灯信息
                        signalDefault = self.signal();
                        //更新红绿灯信息
                        $.extend(signalDefault, currentItem.Content || {});
                        self.signal(signalDefault);
                        //保存一份到父窗口,供跳转回来后使用
                        window.parent.lightData = signalDefault;
                        break;
                    case "ResultInfo":
                        //判断已有记录的条数,如果已经达到100条,则清空
                        if (self.infoList().length >= 100) {
                            self.infoList([]);
                            //清空列表
                            $("#captureGrid").datagrid("loadData", {
                                total: 0,
                                rows: []
                            });
                        }
                        //添加该次的最新消息
                        self.infoList.push(currentItem.Content);
                        self.appendCaptureRow(currentItem.Content);
                        //选中最后添加的记录
                        var allLength = self.infoList().length;
                        selectRecord(allLength - 1);
                        break;
                    case "FlowInfo":
                        //self.flowInfoList(currentItem.Content);
                        //加载流量信息
                        self.loadFlowInfoList(currentItem.Content);
                        break;

                    default:
                        break;
                }
            }
        }
    };

    // 处理报警信息
    self.processAlarmInfo = function(data) {
        self.alarmList.push(data.AlarmInfo);
    };
    // 处理流量信息
    self.processFlowInfo = function(data) {
        for (var i = 0; i < data.Item.length; i++) {
            var content = data.Item[i].Content;
            self.flowList(content);
            self.loadFlowInfoList(content);
        }

        //             	selectFlowRecord(self.flowList().length-1);
    };

    function convertSignal(source) {
        switch (source) {
            case "R":
                return 2;
            case "Y":
                return 3;
            case "G":
                return 1;
            default:
                return 0;
        }
    }

    //处理时间信息,以当前消息中的时间为起点,每秒更新一次
    function processTimeInfo(time) {
        if (!time) {
            //如果time为空,则禁止显示时间
            ocxController.setShowTime(0, 0, 0, 0, 0, 0);
            return;
        }

        //调用Ocx方法,显示时间
        if (
            time.feedback.Year != null &&
            time.feedback.Month != null &&
            time.feedback.Day != null &&
            time.feedback.Hour != null &&
            time.feedback.Minute != null &&
            time.feedback.Second != null
        ) {
            ocxController.setShowTime(
                time.feedback.Year,
                time.feedback.Month,
                time.feedback.Day,
                time.feedback.Hour,
                time.feedback.Minute,
                time.feedback.Second
            );
        }
    }
    //读报警信息
    self.readAlarm = function() {
        if (self.hasUnReadAlarm) {
            $(".alarmPopup").animate({ bottom: "0" }, "fast");
        }
    };

    //关闭报警窗口
    self.closeAlarmPopup = function() {
        $(".alarmPopup").animate({ bottom: "-250px" }, "fast");
    };

    //选择结果记录
    function selectRecord(index) {
        $("#captureGrid").datagrid("selectRow", index);
    }
    // 选择流量记录
    function selectFlowRecord(index) {
        $("#flowGrid").datagrid("selectRow", index);
    }
}

//Ko 绑定
ko.applyBindings(mainPageViewModel);
//判断首页面是否存储有红绿灯数据,如果有就显示出来
var lightData = window.parent.lightData;
if (lightData) {
    mainPageViewModel.signal(lightData);
}

function getPicImg(url) {
    if (!url) {
        return "";
    }
    var picUrl = picSaveBasePath + url.replace(/\//g, "\\");
    picUrl = picUrl.replace(/\\/g, "\\\\");
    return picUrl;
}

//获取图片显示的Css样式
function getPicCss(url, elId) {
    if (!url) {
        return "";
    }
    $("#elId").fadeOut(100);
    var picUrl = picSaveBasePath + url.replace(/\//g, "\\");
    picUrl = picUrl.replace(/\\/g, "\\\\");
    var styleString = null;
    if ($("html").is(".lt-ie7, .lt-ie8, .lt-ie9")) {
        return (
            "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='scale',src='" +
            picUrl +
            "');"
        );
    } else {
        $("#elId").fadeIn("slow");
        styleString =
            "background:url(" +
            picUrl +
            ") no-repeat 0 0;-moz-background-size: 100% 100%;-o-background-size: 100% 100%;-webkit-background-size: 100% 100%;background-size: 100% 100%;";
        return styleString;
    }
}

//获取特写图的样式
function getFeaturePicCss(picUrl, clipPoint) {
    if (!picUrl && clipPoint) {
        return "";
    }
    // 打印出传入的参数
    console.log("-------------------");
    console.log("picUrl: " + picUrl);
    console.log("clipPoint:");
    console.log("   width: " + clipPoint.width);
    console.log("   height: " + clipPoint.height);
    console.log("   left: " + clipPoint.left);
    console.log("   right: " + clipPoint.right);
    console.log("   top: " + clipPoint.top);
    console.log("   bottom: " + clipPoint.bottom);

    $("#pic0").fadeOut(100);
    picUrl = picSaveBasePath + picUrl.replace(/\//g, "\\");
    picUrl = picUrl.replace(/\\/g, "\\\\");
    //图像加载完成后,根据原图大小,裁剪区大小进行图片的缩放,裁剪,显示
    var containerObj = $("#pic0");
    //1、获取原图的大小
    //var imgWidth = imgObj.width;
    //var imgHeight = imgObj.height;
    var imgWidth = clipPoint.width;
    var imgHeight = clipPoint.height;

    //2、获取图片显示区的大小
    var containerWidth = containerObj.width();
    var containerHeight = containerObj.height();

    console.log(
        "容器大小: width: " + containerWidth + ",height:" + containerHeight
    );

    //3、剪切区的大小
    var clipWidth = Math.floor(
        (clipPoint.right - clipPoint.left) / 1000 * imgWidth
    );
    var clipHeight = Math.floor(
        (clipPoint.bottom - clipPoint.top) / 1000 * imgHeight
    );

    console.log(
        "要剪切的区域大小: clipWidth: " +
            clipWidth +
            ",clipHeight:" +
            clipHeight
    );

    //4、根据剪切区与显示区在大小,计算等比缩放的缩放系数
    var isScaleBasedOnHeight = false;
    var scale = 0.0;
    if (clipHeight / containerHeight > clipWidth / containerWidth) {
        isScaleBasedOnHeight = true;
        scale = containerHeight / clipHeight;
    } else {
        scale = containerWidth / clipWidth;
    }
    //5、计算缩放后的图像大小
    var scaleImgWidth = Math.floor(imgWidth * scale);
    var scaleImgHeight = Math.floor(imgHeight * scale);

    //6、计算缩放后的图片上截图区的绝对像素坐标
    var top = Math.floor(clipPoint.top / 1000 * scaleImgHeight);
    var bottom = Math.floor(clipPoint.bottom / 1000 * scaleImgHeight);
    var left = Math.floor(clipPoint.left / 1000 * scaleImgWidth);
    var right = Math.floor(clipPoint.right / 1000 * scaleImgWidth);
    //7、拼接样式字符串
    var img = "";
    //判断是否是IE浏览器,IE浏览器(8以下),使用滤镜来显示图片(防止IE8下的内存泄露)
    if ($("html").is(".lt-ie7, .lt-ie8, .lt-ie9")) {
        img +=
            'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled="true",sizingMethod="scale",src="' +
            picUrl +
            '");';
    } else {
        img +=
            "background:url(" +
            picUrl +
            ") no-repeat 0 0;-moz-background-size: 100% 100%;-o-background-size: 100% 100%;-webkit-background-size: 100% 100%;background-size: 100% 100%;";
    }
    //8、计算缩放后图片的偏移量
    var leftFix = 0;
    var topFix = 0;
    img += "height:" + scaleImgHeight + "px;width:" + scaleImgWidth + "px;";

    //设置宽,高的CSS样式
    clipWidth = Math.floor(scale * clipWidth);
    clipHeight = Math.floor(clipHeight * scale);
    if (isScaleBasedOnHeight) {
        leftFix = (containerWidth - clipWidth) / 2;
    } else {
        topFix = (containerHeight - clipHeight) / 2;
    }
    $("#pic0").fadeIn("slow");
    img += "left:-" + Math.floor(left - leftFix) + "px;";
    img += "top:-" + Math.floor(top - topFix) + "px;";
    console.log("计算后的css: " + img);
    return img;
}

function selectCaptureInfo(index, data) {
    mainPageViewModel.selectedInfoIndex(index);
}

function selectFlowInfo(index, data) {
    mainPageViewModel.selectedFlowInfoIndex(index);
}

//表格行样式
function captureInfoStyler(index, row) {
    if (row.ViolationType != "正常" && row.ViolationType != "卡口")
        return "background-color:#c36d63";
    else {
        return null;
    }
}

function getCapturePic() {
    var url = "/do/trafficController/capturePicture?t=" + new Date().getTime();
    //captureWin = window.open(url);
    downloadByIframe(url);
}

function getFlashingCapturePic() {
    var url =
        "/do/trafficController/captureTrgPicture?t=" + new Date().getTime();
    downloadByIframe(url);
}