video.js 11.7 KB
var loading = loadingFunction();
var player = null;
$(document).ready(function () {
    $.getJSON("/video/tree", null, function (rep) {
        if (rep.status == "SUCCESS") {
            initTree(rep.data);
        }
        initTable();
    });

});

function initTree(data) {
    layui.use(function () {
        var tree = layui.tree;
        // 渲染
        tree.render({
            elem: '#video_tree',
            data: data,
            onlyIconControl: true,  // 是否仅允许节点左侧图标控制展开收缩
            showLine: true, // 是否开启连接线
            click: function (node) {
                initTable(node);
            }
        });
        closeLoading();
    });
}


function initTable(treeNode) {
    var queryURL = "/video/tree/table?size=5";
    if (treeNode) {
        if (treeNode.data.type === 1) {
            queryURL = queryURL + "&businessCode_eq=" + treeNode.data.code;
        }

        if (treeNode.data.type === 2) {
            queryURL = queryURL + "&brancheCompanyCode_eq=" + treeNode.data.code;
        }
    }
    layui.use(function () {
        var treeTable = layui.treeTable;
        // 渲染
        treeTable.render({
            elem: '#treeTable',
            url: queryURL,
            loading: true,
            treeColIndex: 1,
            treeSpid: 0,
            maxHeight: '701px',
            cols: [[
                {field: 'name', title: '车辆编号', width: 140},
                {field: 'insideCode', title: '内部编号', width: 120},
                {field: 'equipmentCode', title: '设备编号', width: 160},
                {field: 'carPlate', title: '车牌号', width: 160},
                {field: 'company', title: '所在公司', width: 160},
                {field: 'brancheCompany', title: '所在分公司', width: 160},
                {
                    field: 'sfdc', title: '电车', width: 80, templet: function (obj) {
                        if (obj.sfdc == 'true' || obj.sfdc == true) {
                            return "是"
                        } else if (obj.sfdc == 'false' || obj.sfdc == false) {
                            return "否";
                        }
                        return "未知";
                    }
                },
                {
                    field: 'scrapState', title: '状态', width: 80, templet: function (obj) {
                        if (obj.scrapState == 'true' || obj.scrapState == true) {
                            return "是"
                        } else if (obj.scrapState == 'false' || obj.scrapState == false) {
                            return "否";
                        }
                        return "未知";
                    }
                },
                { title:'操作', width: 80,  toolbar: '#treeTable-tools'}
            ]],
            page: true
        });
        treeTable.on('rowDouble(treeTable)', function (obj) {
            console.log("cccccccccccc");
            var targetDataIndex = obj.dataIndex + "-0";
            $("div[lay-table-id='treeTable']").find("tr").each(function (index, node) {
                var sourceDataIndex = $(node).attr("data-index");
                if (sourceDataIndex === targetDataIndex) {
                    queryChannelByCarNo(node, obj);
                    return;
                }
            });


        });

        treeTable.on('tool(treeTable)', function(obj){
            switch(obj.event){
                case 'SkeyeWebPlayerEvent':
                    skeyewebplayerOpen();
                    break;
            }
        });
    });
}

function queryChannelByCarNo(treeNode, obj) {
    loading = loadingFunction();
    var url = "/video/car/channel/" + obj.data.name;
    $.getJSON(url, function (rep) {
        if (rep.status === "SUCCESS") {
            var html = "<td data-field=\"name\" colspan='8'  data-key=\"1-" + obj.dataIndex + "-0\" class=\"\" >";
            html += "<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" class=\"layui-table\" style='padding-left: 15px;boder:1px solid #000;margin-bottom: 15px;'><thead><tr>";
            html += "<th data-field=\"name\" data-key=\"1-" + obj.dataIndex + "-0\" class=\"\" title=\"通道编号\"><div class=\"layui-table-cell \" style='width: 200px;'><span>通道编号</span></div></th>";
            html += "<th data-field=\"name\" data-key=\"2-" + obj.dataIndex + "-0\" class=\"\" title=\"设备编号\"><div class=\"layui-table-cell \" style='width: 200px;'><span>设备编号</span></div></th>";
            html += "<th data-field=\"name\" data-key=\"3-" + obj.dataIndex + "-0\" class=\"\" title=\"通道名称\"><div class=\"layui-table-cell\" style='width: 100px;'><span>通道名称</span></div></th>";
            html += "<th data-field=\"name\" data-key=\"4-" + obj.dataIndex + "-0\" class=\"\" title=\"快照\"><div class=\"layui-table-cell \"><span>快照</span></div></th>";
            html += "<th data-field=\"name\" data-key=\"5-" + obj.dataIndex + "-0\" class=\"\" title=\"厂家\"><div class=\"layui-table-cell \" style='width: 100px;'><span>厂家</span></div></th>";
            html += "<th data-field=\"name\" data-key=\"6-" + obj.dataIndex + "-0\" class=\"\" title=\"开启音频\"><div class=\"layui-table-cell \"><span>开启音频</span></div></th>";
            html += "<th data-field=\"name\" data-key=\"7-" + obj.dataIndex + "-0\" class=\"\" title=\"状态\"><div class=\"layui-table-cell \"><span>状态</span></div></th>";
            html += "<th data-field=\"name\" data-key=\"8-" + obj.dataIndex + "-0\" class=\"\" title=\"操作\"><div class=\"layui-table-cell \" style='width: 100px;'><span>操作</span></div></th>";
            html += "</tr>";
            if (rep.data) {
                $.each(rep.data, function (index, node) {
                    html += "<tr><td>" + node.channelId + "</td><td>" + node.deviceId + "</td><td>" + node.name + "</td><td>" + getBigSnap(rep.channelImageURL, node.deviceId, node.channelId) + "</td><td>" + node.manufacture;
                    html += "</td><td>" + hasAudioText(node.hasAudio) + "</td><td>" + wvpStatusText(node.status) + "</td><td><button class=\"layui-btn layui-btn-primary layui-border\" onclick=\"playWvpVideo('";
                    html += rep.wvpPlayURL + "','" + node.deviceId + "','" + node.channelId + "')\">播放</button><button class=\"layui-btn layui-btn-primary layui-border\" onclick=\"deviceVedioPage('" + node.deviceId + "','" + node.channelId + "')\">设备录像</button></td></tr>";
                });
            }

            html += "</thead></table></td>";

            $(treeNode).html(html);

            closeLoading();
        }
    })
}

function hasAudioText(hasAudio) {
    return "true" == hasAudio || true == hasAudio ? "开启" : "关闭";
}

function wvpStatusText(status) {
    return "true" == status || true == status ? "在线" : "离线";
}

function getBigSnap(imageURL, deviceId, channelId) {
    return "<image src=" + imageURL + deviceId + "/" + channelId + " />"
}

function playWvpVideo(playURL, deviceId, channelId) {
    var idDiv = "video_" + (Date.now());
    var html = "'<div id='" + idDiv + "' style='padding-top: 0;'></div>'";

    let player = null;
    var myVar = null;
    var playURL1 = playURL + deviceId + "_" + channelId + ".live.mp4";

    var index = layer.open({
        type: 1,
        title: "视频播放",
        area: ['1000px', '650px'],
        height: '800px',
        content: html,
        success: function (layero, index, that) {
            player = playVideo(playURL1, idDiv);
            player.play();

            myVar = setInterval(function () {
                if (player) {
                    player.destroy();
                    player = null;
                }
                player = playVideo(playURL1, idDiv);
                player.play();
            }, 300000);


        },
        beforeEnd: function (layero, index, that) {
            if (player) {
                player.destroy();
                player = null;
            }

            if (myVar) {
                window.clearInterval(myVar);
                myVar = null;
            }

            $("#" + idDiv).html("");
        }
    });
}

function playVideo(url, ID) {
    return new WebMediaPlayer(url, ID, function () {

    }, {
        cbUserPtr: this,
        decodeType: 'auto',
        openAudio: true,
        autoplay: true,
        bigPlay: false,
        showMode: false
    });
}

function loadingFunction() {
    closeLoading();
    var loading = layer.load(0, {
        shade: true
    });
    return loading;
}

function closeLoading() {
    console.log("===============?" + loading);
    if (loading) {
        layer.close(loading);
        loading = null;
    }
}

function deviceVedioPage(device, channel) {
    var idDiv = "device_video_" + (Date.now());
    var html = "<div id='" + idDiv + "'></div>";

    var index = layer.open({
        type: 1,
        title: "设备录像",
        area: ['1300px', '650px'],
        content: html,
        success: function (layero, index, that) {
            $("#" + idDiv).html($("#deviceVideoDiv").html());
            var $deviceVideoDiv = $("#" + idDiv);
            $("#deviceVideoDate", $deviceVideoDiv).datetimepicker({
                format: 'YYYY-MM-DD',
                locale: 'zh-cn'
            });

            $("#queryDeviecChannel", $deviceVideoDiv).click(function () {
                deviceVidemoQueryHistory(device, channel, $deviceVideoDiv, idDiv);
            })
        }, beforeEnd: function (layero, index, that) {
            if (player) {
                player.destroy();
                player = null;
            }
        }
    });
}

function deviceVidemoQueryHistory(device, channel, $deviceVideoDiv, idDiv) {
    var dateStr = $("#deviceVideoDate", $deviceVideoDiv).val();
    if (null === dateStr || undefined === dateStr || "" === dateStr) {
        layer.alert('请选择需要查看的时间');
        return;
    }
    loading = loadingFunction();
    var url = "/video/car/channel/history/" + device + "/" + channel + "/" + dateStr;
    $.getJSON(url, function (resp) {
        if (resp.status === "SUCCESS") {
            var html = "<tr>";
            $.each(resp.data, function (index, node) {
                html += "<td><button class=\"layui-btn layui-btn-primary layui-border\" onclick=\"playDeviceVidemoQueryHistory('" + idDiv + "','" + resp.wvpPlayURL + "','" + device + "','" + channel + "','" + node.startTime + "','" + node.endTime + "','" + resp.token + "')\">" + node.filePath + "</button></td>";

                if (index % 2 === 1) {
                    html += "</tr><tr>";
                }
            });

            $("#deviceVideoTbody", $deviceVideoDiv).html(html);
            closeLoading();
        }
    });
}

function playDeviceVidemoQueryHistory(idDiv, url, device, channel, startTime, endTime, token) {
    if (player) {
        player.destroy();
        player = null;
    }
    startTime = startTime.replace("-", "").replace("-", "").replace(":", "").replace(":", "").replace(" ", "");
    endTime = endTime.replace("-", "").replace("-", "").replace(":", "").replace(":", "").replace(" ", "");
    console.log(startTime);
    url = url + device + "_" + channel + "_" + startTime + "_" + endTime + ".live.mp4";
    console.log(url);
    var idDiv1 = "device_video_play_" + (Date.now());
    $("#videoPlay", $("#" + idDiv)).html("<div id='" + idDiv1 + "' style='height:550px;width:99%'></div>")
    player = playVideo(url, idDiv1);
    player.play();
}

function skeyewebplayerOpen(){
    layer.open({
        type: 1,
        content: '<div style="padding: 16px;" id="skeyewebplayer"></div>',
        area: ['320px', '195px'], // 初始宽高
        success: function(layero, index){
            layer.full(index); // 最大化
            $("#skeyewebplayer").html($("#skeyewebplayerDiv").html());
        }
    });
}