(function($, window, undefined) {
    var baseUrl = config.baseUrl;
    var $topnavmenu = config.$topnavmenu;
    var $sidebarUl = config.$sidebarUl;
    var userMenus = new Array();
    // if (uid) {
    //导航组装前集中获取设备能力信息
    if (URL_Request("isp2p") == "p6s") { //p6s
        sessionStorage.setItem("playstyle", "EasyVideo");
        sessionStorage.setItem("xystyle", "p6s");
        config.baseUrl = "http://" + URL_Request("hostname") + ":" + URL_Request("port");
        config.p6sURL = 'http://localhost:' + URL_Request("webServerPort");
        config.p2pId = URL_Request("id");
        config.easyvideodaaress = URL_Request("hostname");
        //config.isPush = enablePush(); //网络端口号
        config.user = Base64.decode(URL_Request("user")); //用户名
        config.password = Base64.decode(URL_Request("password")); //密码
        config.ipcsrc = "http://" + URL_Request("hostname") + ":" + URL_Request("port") + "/Snapshot/1/RemoteImageCapture?ImageFormat=2";
        config.url = "ws://127.0.0.1:" + URL_Request("websocketPort") + "/WebSocket/Connect";
        config.MacAddress = URL_Request("mac"); //mac地址
        if (window.deviceType == 'IPC') {
            document.getElementsByTagName("title")[0].innerText = 'IPCamera -' + URL_Request("hostname");
        } else {
            document.getElementsByTagName("title")[0].innerText = window.deviceType + ' - ' + URL_Request("hostname");
        }
        $.getScript("js/EasyVideo/playervideo.js", function() {
            config.refreshplayvideo = false;
        });
        Login();
        sessionStorage.setItem("language", URL_Request("language"));
        loadProperties(URL_Request("language"));
        bootbox.setLocale(URL_Request("language"));
        ! function(a) {
            a.fn.datepicker.dates["zh-CN"] = {
                days: $.i18n.prop("i18n-date-days").split(","),
                daysShort: $.i18n.prop("i18n-date-daysShort").split(","),
                daysMin: $.i18n.prop("i18n-date-daysMin").split(","),
                months: $.i18n.prop("i18n-date-months").split(","),
                monthsShort: $.i18n.prop("i18n-date-monthsShort").split(","),
                today: $.i18n.prop("i18n-date-today"),
                clear: $.i18n.prop("i18n-date-clear"),
                format: $.i18n.prop("i18n-date-format"),
                titleFormat: $.i18n.prop("i18n-date-titleFormat"),
                weekStart: 1
            };
        }(jQuery);

        (function($) {
            $.fn.datetimepicker.dates['zh-CN'] = {
                days: $.i18n.prop("i18n-date-days").split(","),
                daysShort: $.i18n.prop("i18n-date-daysShort1").split(","),
                daysMin: $.i18n.prop("i18n-date-daysMin1").split(","),
                months: $.i18n.prop("i18n-date-months").split(","),
                monthsShort: $.i18n.prop("i18n-date-months").split(","),
                today: $.i18n.prop("i18n-date-today"),
                suffix: [],
                meridiem: $.i18n.prop("i18n-date-meridiem").split(",")
            };
        }(jQuery));
    } else if (URL_Request("isp2p") == "p2p") { //p2p
        sessionStorage.setItem("xystyle", "p2p");
        sessionStorage.setItem("playstyle", "EasyVideo");
        $.getScript("js/EasyVideo/playervideo.js", function() {
            config.refreshplayvideo = false;
        });
        config.ipcsrc = URL_Request("hostname") + ":" + URL_Request("port") + "/mixinGet?url=" + "/Snapshot/1/1/RemoteImageCaptureV2?ImageFormat=2" + "&id=" + URL_Request("id");
        config.forceEV = URL_Request("forceEV");
        config.showAdvPtz = URL_Request("showAdvPtz");
        document.getElementsByTagName("title")[0].innerText = 'IPCamera -' + URL_Request("hostname");
        config.url = "ws://127.0.0.1:" + URL_Request("websocketPort") + "/WebSocket/Connect";
        config.p2pId = URL_Request("id");
        config.easyvideodaaress = URL_Request("did");
        if (window.deviceType == 'IPC') {
            document.getElementsByTagName("title")[0].innerText = "IPCamera - " + config.easyvideodaaress + " V" + config.webVersion;
        } else {
            document.getElementsByTagName("title")[0].innerText = window.deviceType + " - " + config.easyvideodaaress + " V" + config.webVersion;
        }
        config.password = Base64.decode(URL_Request("password")); //密码
        config.user = Base64.decode(URL_Request("user")); //用户名
        config.baseUrl = URL_Request("hostname") + ":" + URL_Request("port");
        config.ipcsrc = URL_Request("hostname") + ":" + URL_Request("port") + "/mixinGet?url=" + "/Snapshot/1/1/RemoteImageCaptureV2?ImageFormat=2" + "&id=" + URL_Request("id");
        sessionStorage.setItem("language", URL_Request("language"));
        loadProperties(URL_Request("language"));
        bootbox.setLocale(URL_Request("language"));
        config.MacAddress = URL_Request("mac"); //mac地址
        // config.Network = getHTTPprot(); //网络端口号
        // config.isPush = enablePush(); //网络端口号
        config.deviceInfo = getDeviceInfo(); //设备信息获取
        if (window.deviceType == "IPC") {
            config.deviceCap = getDeviceCap(); //设备能力
        } else {
            config.deviceCapV1=[];
            for (let i = 0; i < config.deviceInfo.VideoInputChannels; i++) {
                config.deviceCapV1.push(null);
            }
            config.deviceCap = getDeviceCap(1); //设备能力
        }
        config.deviceAiCap = getdeviceAiCap(); //ai能力
        if( config.deviceInfo.DeviceName=='NVR'){
            config.deviceCapV2 = getDeviceCapV2(); //设备能力
        }
        config.playMode = getplayMode(); //播放模式数组获取
        config.bitrate = getBitrate(); //设备状态分辨率获取
       
    } else if (URL_Request("isp2p") == "easyvideo") { //easyvideo
        // config.bitrate = getBitrate(); //设备状态分辨率获取
        config.playMode = getplayMode(); //播放模式数组获取
        ! function(a) {
            a.fn.datepicker.dates["zh-CN"] = {
                days: $.i18n.prop("i18n-date-days").split(","),
                daysShort: $.i18n.prop("i18n-date-daysShort").split(","),
                daysMin: $.i18n.prop("i18n-date-daysMin").split(","),
                months: $.i18n.prop("i18n-date-months").split(","),
                monthsShort: $.i18n.prop("i18n-date-monthsShort").split(","),
                today: $.i18n.prop("i18n-date-today"),
                clear: $.i18n.prop("i18n-date-clear"),
                format: $.i18n.prop("i18n-date-format"),
                titleFormat: $.i18n.prop("i18n-date-titleFormat"),
                weekStart: 1
            };
        }(jQuery);

        (function($) {
            $.fn.datetimepicker.dates['zh-CN'] = {
                days: $.i18n.prop("i18n-date-days").split(","),
                daysShort: $.i18n.prop("i18n-date-daysShort1").split(","),
                daysMin: $.i18n.prop("i18n-date-daysMin1").split(","),
                months: $.i18n.prop("i18n-date-months").split(","),
                monthsShort: $.i18n.prop("i18n-date-months").split(","),
                today: $.i18n.prop("i18n-date-today"),
                suffix: [],
                meridiem: $.i18n.prop("i18n-date-meridiem").split(",")
            };
        }(jQuery));
    } else { //本地
        var uid = localStorage.getItem("UID");
        if (uid == "loginsuccess") {
            config.easyvideodaaress = location.hostname;
            config.MacAddress = getMacAddress(); //mac地址
            config.Network = getHTTPprot(); //网络端口号
            config.isPush = enablePush(); //网络端口号
            config.deviceInfo = getDeviceInfo(); //设备信息获取
            if (window.deviceType == "IPC") {
                config.deviceCap = getDeviceCap(); //设备能力
            } else {
                config.deviceCapV1=[];
                for (let i = 0; i < config.deviceInfo.VideoInputChannels; i++) {
                    config.deviceCapV1.push(null);
                }
                config.deviceCap = getDeviceCap(1); //设备能力
            }
            config.deviceAiCap = getdeviceAiCap(); //ai能力
        
            if (config.deviceInfo.DeviceName == "NVR") {
                config.deviceCapV2 = getDeviceCapV2(); //设备能力
            }
            if (config.deviceInfo.DeviceName == "IPC") {
                config.bitrate = getBitrate(); //设备状态分辨率获取
            } else {
                config.bitrate = getBitrate(1); //设备状态分辨率获取
            }
            config.playMode = getplayMode(); //播放模式数组获取
            // config.user = Base64.decode($.cookie("userInfo")).split(":")[0]; //用户名
            // config.password = Base64.decode($.cookie("userInfo")).split(":")[1]; //密码// 存储时转义密码中的 `:`
            // 读取时恢复
            var decoded = Base64.decode($.cookie('userInfo'));
            var firstColonIndex = decoded.indexOf(':');
            var user = decoded.substring(0, firstColonIndex);
            var pwd = decoded.substring(firstColonIndex + 1).replace(/\\:/g, ':');
            config.user = user;
            config.password = pwd;

            loadProperties(sessionStorage.getItem("language"));
            bootbox.setLocale(sessionStorage.getItem("language"));
            ! function(a) {
                a.fn.datepicker.dates["zh-CN"] = {
                    days: $.i18n.prop("i18n-date-days").split(","),
                    daysShort: $.i18n.prop("i18n-date-daysShort").split(","),
                    daysMin: $.i18n.prop("i18n-date-daysMin").split(","),
                    months: $.i18n.prop("i18n-date-months").split(","),
                    monthsShort: $.i18n.prop("i18n-date-monthsShort").split(","),
                    today: $.i18n.prop("i18n-date-today"),
                    clear: $.i18n.prop("i18n-date-clear"),
                    format: $.i18n.prop("i18n-date-format"),
                    titleFormat: $.i18n.prop("i18n-date-titleFormat"),
                    weekStart: 1
                };
            }(jQuery);

            (function($) {
                $.fn.datetimepicker.dates['zh-CN'] = {
                    days: $.i18n.prop("i18n-date-days").split(","),
                    daysShort: $.i18n.prop("i18n-date-daysShort1").split(","),
                    daysMin: $.i18n.prop("i18n-date-daysMin1").split(","),
                    months: $.i18n.prop("i18n-date-months").split(","),
                    monthsShort: $.i18n.prop("i18n-date-months").split(","),
                    today: $.i18n.prop("i18n-date-today"),
                    suffix: [],
                    meridiem: $.i18n.prop("i18n-date-meridiem").split(",")
                };
            }(jQuery));
        } else {
            logout();
        }
    }
    var g_bIsIE = !(/(msie\s|trident.*rv:)([\w.]+)/.exec(navigator.userAgent.toLowerCase()) == null);
    if (!g_bIsIE || config.forceEV) { //非ie
        if (config.playMode.indexOf("EasyVideo") !== -1) {
            $.getScript("js/EasyVideo/playervideo.js", function() {
                if (config.playMode.indexOf("WebPlayer") !== -1) {
                    $.getScript("js/webPlayer/player.js", function() {
                        $.getScript("js/webPlayer/webgl.js", function() {
                            $.getScript("js/webPlayer/pcm-player.js", function() {
                                console.log('zheli');
                                config.refreshplayvideo = true;
                            });
                        });
                    });
                } else {
                    if (URL_Request("isp2p") != "p6s" && URL_Request("isp2p") != "p2p") {
                        config.refreshplayvideo = true;
                    }
                }
            });
        } else {
            if (config.playMode.indexOf("WebPlayer") !== -1) {
                $.getScript("js/webPlayer/player.js", function() { //请求成功后的回调函数
                    $.getScript("js/webPlayer/webgl.js", function() { //请求成功后的回调函数
                        $.getScript("js/webPlayer/pcm-player.js", function() {
                            console.log('zheli566667777');
                            config.refreshplayvideo = true;
                        });
                    });
                });
            }
        }
    }
    if (sessionStorage.getItem("playstyle") == "EasyVideo") {
        $("#downloadeasyplay").hide();
        $("#downlodeasyvideo").hide();
        $("#playCanvas").hide();
    }
    userMenus = getUserMenu();
    // //顶部导航栏渲染:取第一层数据做导航栏
    // renderNavMenu(userMenus, $topnavmenu);
    // renderSidebar(userMenus, $sidebarUl, true);
    if (URL_Request("isp2p") == "p6s" || URL_Request("isp2p") == "p2p") {
        $("#header").hide();
        var info = document.getElementById('left-panel');
        info.style.top = "7px";
        $('.left12').css('min-height', "calc(100vh - 20px)");
        $('#content').css('min-height', "calc(100vh - 20px)");
        setTimeout(function() {
            renderNavMenu(userMenus, $topnavmenu);
            renderSidebar(userMenus, $sidebarUl, true);
        }, 1000)
    } else {
        if ($("#top-nav-menu .navbar-nav").children(".active").length == 0) {
            $("#top-nav-menu .navbar-nav li#preview").addClass("active");
            if (config.isSupportMultiChannel == true) { //这里区分单目和多目
                $("#main").addClass("left23");
            } else {
                $("#main").addClass("left24");
            }
        }
        renderNavMenu(userMenus, $topnavmenu);
        renderSidebar(userMenus, $sidebarUl, true);
    }

    function getUserMenu() {
        var userMenus = new Array();
        var urlReq = ''
        if (config.deviceInfo.DeviceName === undefined || config.deviceInfo.DeviceName.length === 0) {
            $.optionBootoast($.i18n.prop("i18n-Networkerror"), "danger");
            return;
        }
        if (config.deviceInfo.DeviceName == 'IPC') {
            urlReq = 'ipc/js/route.json'
        } else if (config.deviceInfo.DeviceName == 'NVR') {
            urlReq = 'nvr/js/route.json'
        } else {
            urlReq = 'hvr/js/route.json'
        }
        $.ajax({
            type: "get",
            async: false,
            url: urlReq,
            dataType: "json",
            success: function(result) {
                if (result.userMenus && result.userMenus.length > 0) {
                    userMenus = result.userMenus;
                }
            },
            error: function(data) {
                $.optionBootoast($.i18n.prop("i18n-unsupportedOperations"), "danger");
            }
        });
        return userMenus;
    }

    function clsoed(topIndex) {
        config.peopleface_detect_list=[];
        config.enableelectron=true;
        if(topIndex!== "remoteplayback"){
            if (config.timebarSave) {
                // 清除setInterval
                clearInterval(config.timebarSave);
            }
            //如果回放存在声音关闭回放声音
            if (document.getElementById("closeround")!= null && document.getElementById("closeround")!= undefined){
                if (document.getElementById("closeround").getAttribute("src", 2) == "img/remoteplayback/soundopen.png") {
                    $("#closeround").click()
                }
            }
            if (sessionStorage.getItem("playstyle") == "EasyVideo" && config.lastnav != topIndex) {
                preHiddenDisplaywindow(4);
                if (config.deviceInfo.DeviceName == 'IPC') {
                    easyldspecialvideos(false); //关闭预览的流
                } else {
                    NVReasyldspecialvideos(false, "") //关闭nvr所有预览
                }
                remoteHiddenDisplaywindow(4);
                remotestopplay();
            } else if (sessionStorage.getItem("playstyle") == "WebPlayer") {
                closeWebPlayer();
            } else if (sessionStorage.getItem("playstyle") == "MJPEG") {
                clearInterval(config.gs_interval);
            }

        }
        if (config.deviceInfo.DeviceName == "IPC") {
            if (config.Bitratetime) {
                clearInterval(config.Bitratetime);
            }
        }
        if (config.deviceInfo.DeviceName == "NVR") {
            if (config.BitratetimeList.length != 0) {
                for (var j = 0; j < config.BitratetimeList.length; j++) {
                    clearInterval(config.BitratetimeList[j]);
                }
                config.thoroughfareList = [];
                config.BitratetimeList = []
            }
        }

        $("#main").removeClass("showchancel");
        // 当在预览开启录像时切到其他页面立即停止并保存录像,当声音开启的时候，关闭声音，，当对讲开启的时候，关闭对讲，保证声音始终只有一个
        var picts = document.getElementById("videoimg");
        if (picts != null && picts != undefined) {
            if (picts.getAttribute("src", 2) == "img/preview/videoselect.png") {
                picts.setAttribute("src", "img/preview/video.png");
                $("#videoimg").attr("title", $.i18n.prop('i18n-Startrecording'));
                if (sessionStorage.getItem("playstyle") == "ActiveX") {
                    if (config.deviceInfo.DeviceName == "IPC") {
                        StopRecord(); // 停止录像
                    } else {
                        nvrStopRecord(config.chnelNum);
                    }
                } else if (sessionStorage.getItem("playstyle") == "EasyVideo") {
                    // 停止录像
                    easyStopRecord();
                }
            }
        }
        if (config.intelligentState) {
            config.intelligentState = false
        }
        //声音若开启，关闭声音
        var pictssy = document.getElementById("soundopen");
        if (pictssy != null && pictssy != undefined) {
            if (pictssy.getAttribute("src", 2) == "img/preview/soundopen.png") {
                $("#soundopen").click();
            }
        }


        //对讲若是打开，关闭对讲
        var pictsdj = document.getElementById("intercom");
        if (pictsdj != null && pictsdj != undefined) {
            if (pictsdj.getAttribute("src", 2) == "img/preview/intercomselect.png") {
                $("#intercom").click();
            }
        }
        if (sessionStorage.getItem("playstyle") == "EasyVideo" && config.lastnav != topIndex) {
            preHiddenDisplaywindow(4)
            if (config.deviceInfo.DeviceName != "IPC") {
                NVReasyldspecialvideos(false, "") //关闭nvr所有预览
            }
        } else if (sessionStorage.getItem("playstyle") == "WebPlayer") {
            closeWebPlayer();
        } else if (sessionStorage.getItem("playstyle") == "MJPEG") {
            clearInterval(config.gs_interval);
        }
    }

    /**
     * 顶部导航栏渲染,取第一层数据
     * @param  {[type]} menu_list [顶部导航数据]
     * @param  {[type]} parent    [顶部导航容器]
     * @return {[type]}           [description]
     */
    function renderNavMenu(menu_list, parent) {
        var itemLi = function(menu_list, parent) {
            for (var index in menu_list) {
                var item = menu_list[index];
                var url = verifyUrl(item.url);
                var li = null;
                li = $("<li id='" + item.id + "'></li>");
                var sideBar = "";
                if (item.openSidebar == "N") {
                    sideBar = "sidebar=close";
                }
                var imgicon = item.id + "icon";
                $(li).append("<a href='" + url + "' " + sideBar + "><img src='" + item.icon + "' class='topicon' id='" + imgicon + "'><span class='toptitle'>" + $.i18n.prop(item.name) + "</span></a>").appendTo(parent);
            }
        };
        var $ul = $("<ul class='nav navbar-nav navbar-right navbar-brand'></ul>");
        itemLi(menu_list, $ul);

        parent.html($ul);
        if (config.deviceInfo.DeviceName == "IPC") {
            $("#log").hide();
            if (!(config.deviceCap[0].diskEnable == "true") || config.isSupportMultiChannel == true) { //多目回放暂时不做
                $("#remoteplayback").hide();
            }
        }
        // 这里因为通道能力暂时未获取，暂时让nvr默认展示回放
        // if (!(config.deviceCap.diskEnable == "true")) {
        //     $("#remoteplayback").hide();
        // }



        //渲染顶部菜单栏
        parent.children().topnavmenu({
            clickCallback: function($topLi) {
                var g_bIsIE = !(/(msie\s|trident.*rv:)([\w.]+)/.exec(navigator.userAgent.toLowerCase()) == null);
                if (g_bIsIE && !config.forceEV) {
                    clearInterval(config.gs_interval);
                }
                //点击顶部菜单栏，刷新侧边栏
                var topIndex = $topLi[0].id;
                if (topIndex !== "preview") {
                    clsoed(topIndex)
                } else{
                    if (config.timebarSave) {
                        // 清除setInterval
                        clearInterval(config.timebarSave);
                    }
                    if (config.intelligentState) {
                        config.intelligentState = false
                    }
                    //如果回放存在声音关闭回放声音
                    if (document.getElementById("closeround")!= null && document.getElementById("closeround")!= undefined){
                        if (document.getElementById("closeround").getAttribute("src", 2) == "img/remoteplayback/soundopen.png") {
                            $("#closeround").click()
                        }
                    }
                    if (config.refreshplayvideo) {
                        if (sessionStorage.getItem("playstyle") == "EasyVideo" && config.lastnav != topIndex) {
                            remoteHiddenDisplaywindow(4);
                            if (config.deviceInfo.DeviceName == 'IPC') {
                                easyldspecialvideos(true); //关闭配置页面的流
                            } else {
                                NVReasyldspecialvideos(false, '')
                            }
                            preHiddenDisplaywindow(6);
                            remotestopplay();
                        } else if (sessionStorage.getItem("playstyle") == "WebPlayer") {
                            closeWebPlayer();
                        } else if (sessionStorage.getItem("playstyle") == "MJPEG") {
                            clearInterval(config.gs_interval);
                        }
                    }
                }
                var icon = topIndex + "icon";
                var picts = document.getElementById(icon);
                var item = geticon(topIndex, menu_list);
                if (picts.getAttribute("src", 2) == item.icon) {
                    picts.setAttribute("src", item.selecticon);
                }
                $sidebarUl.children("nav.show").removeClass("show").addClass("hide");
                $sidebarUl.children("nav#" + topIndex).removeClass("hide").addClass("show");
                Router.openNavMenu();

                //顶部菜单切换，刷新侧边栏导航折叠
                if (config.deviceInfo.DeviceName == 'IPC') {
                    $("nav ul").sidebarfresh({
                        speed: 250,
                        closedSign: "<img src=\"ipc/img/icon/xiala.png\" class=\"downarrow\">",
                        openedSign: "<img src=\"ipc/img/icon/up.png\" class=\"uparrow\">"
                    });
                } else if (config.deviceInfo.DeviceName == 'NVR') {
                    $("nav ul").sidebarfresh({
                        speed: 250,
                        closedSign: "<img src=\"nvr/img/icon/xiala.png\" class=\"downarrow\">",
                        openedSign: "<img src=\"nvr/img/icon/up.png\" class=\"uparrow\">"
                    });
                } else {
                    $("nav ul").sidebarfresh({
                        speed: 250,
                        closedSign: "<img src=\"hvr/img/icon/xiala.png\" class=\"downarrow\">",
                        openedSign: "<img src=\"hvr/img/icon/up.png\" class=\"uparrow\">"
                    });
                }

            }
        });

    }

    function geticon(id, menu_list) {
        var s = {};
        for (var i = 0; i < menu_list.length; i++) {
            if (menu_list[i].id === id) {
                s = menu_list[i];
                break;
            }
        }
        return s;
    }

    /**
     * 侧边栏渲染
     * @param  {[type]} menu_list [侧边栏数据]
     * @param  {[type]} parent    [为要组合成html的容器] 侧边整体容器sidebarUl
     * @param  {[boolean]} global    [是否全局刷新]
     */
    function renderSidebar(userMenus, parent, global) {
        // var newMenu = config.newMenu;
        var itemLi = function(subMenu_list, parent) {

            for (var menu in subMenu_list) {
                var item = subMenu_list[menu];
                if (config.deviceInfo.DeviceName == 'IPC') {
                    if (item.id == "video" && config.isSupportMultiChannel) {
                        item.url = "ipc/pages/audioAndvideo/multiChannelVideo.html";
                    } else if (item.id == "video" && !config.isSupportMultiChannel) {
                        item.url = "ipc/pages/audioAndvideo/video.html";
                    }
                }
                var url = verifyUrl(item.url);
                var userMenusiscz = true;
                userMenusiscz = verifysiderUrl(item.url); //检测当前url资源是否存在
                if (!userMenusiscz) {
                    item.hide = true
                }
                var sideBar = "";
                if (item.openSidebar == "N") {
                    sideBar = "sidebar=close";
                }
                //如果有子节点，则遍历该子节点

                if (!!item.children) {
                    var childerhide = true;
                    childerhide = verifychilderitem(item.children);
                    if (childerhide) {
                        item.hide = true
                    }
                    var imgicon = item.id + "icon";
                    //创建一个子节点li
                    var li = $("<li id=" + item.id + "></li>");
                    //将li的文本设置好，并马上添加一个空白的ul子节点，并且将这个li添加到父亲节点中
                    $(li).append("<a href='" + url + "' " + sideBar + " title='" + $.i18n.prop(item.name) + "' class='" + (item.hide ? "slidehide" : "") + "'><img src='" + item.icon + "' id='" + imgicon + "' class='slideicon'><span class='menu-item-parent'>" + $.i18n.prop(item.name) + "</span></a>").append("<ul></ul>").appendTo(parent);
                    //将空白的ul作为下一个递归遍历的父亲节点传入
                    itemLi(item.children, $(li).children().eq(1));
                }
                //如果该节点没有子节点，则直接将该节点li以及文本创建好直接添加到父亲节点中
                else {
                    $("<li id=" + item.id + "></li>").append("<a href='" + url + "' " + sideBar + "  class='" + (item.hide ? "slidehide" : "") + "'><span class='menu-item-parent '>" + $.i18n.prop(item.name) + "</span></a>").appendTo(parent);
                }
            }
        };

        // for(var index in userMenus){
        var subItem = userMenus[2];
        var $ul = $("<ul></ul>");
        itemLi(subItem.children, $ul);
        var $nav = $("<nav id='" + subItem.id + "' class='hide'></nav>");
        $ul.appendTo($nav);
        parent.append($nav);
        // }

        //初始化路由
        Router.initRouter({
            menus: userMenus
        });
        //侧边栏渲染，事件绑定
        if (config.deviceInfo.DeviceName == 'IPC') {
            $("nav ul").sidebarmenu({
                speed: 250,
                closedSign: "<img src=\"ipc/img/icon/xiala.png\" class=\"downarrow\">",
                openedSign: "<img src=\"ipc/img/icon/up.png\" class=\"uparrow\">"
            });
        } else if (config.deviceInfo.DeviceName == 'NVR') {
            $("nav ul").sidebarmenu({
                speed: 250,
                closedSign: "<img src=\"nvr/img/icon/xiala.png\" class=\"downarrow\">",
                openedSign: "<img src=\"nvr/img/icon/up.png\" class=\"uparrow\">"
            });
        } else {
            $("nav ul").sidebarmenu({
                speed: 250,
                closedSign: "<img src=\"hvr/img/icon/xiala.png\" class=\"downarrow\">",
                openedSign: "<img src=\"hvr/img/icon/up.png\" class=\"uparrow\">"
            });
        }
    }

    /**
     * url url地址, 验证不通过返回#
     * @return {[type]} [description]
     */
    function verifyUrl(url) {
        if (url && url.trim() && url.endsWith(".html")) {
            return url;
        } else {
            return "#";
        }
    }
    /**
     * 验证url资源是否存在
     * @param url
     */
    function verifysiderUrl(url) {
        var userMenusiscz = true;
        $.ajax({
            type: "get",
            async: false,
            url: url,
            dataType: "html",
            success: function(result) {
                userMenusiscz = true
            },
            error: function() {
                userMenusiscz = false
            }
        });
        return userMenusiscz;
    }
    /**
     *
     * 验证子节点是否有一个没有隐藏
     * @param item
     */
    function verifychilderitem(item) {
        var ishide = true;
        if (config.deviceInfo.DeviceName != 'NVR' && config.deviceInfo.DeviceName != 'HVR') { //因为目前网页还不支持nvrV2能力接口所以暂时走以前的
            if (config.isSupportMultiChannel == true) {
                for (var n = 0; n < item.length; n++) {
                    if (item[n].id == "privacySettings") { //视频遮挡
                        if (!(config.deviceCap[0].isPrivacyZone == "true") || !(config.deviceCap[1].isPrivacyZone == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == "motion") { //移动侦测
                        if ((!(config.deviceCap[0].isMotion == "true") && !(config.deviceCap[0].isMotionTow == "true")) || (!(config.deviceCap[1].isMotion == "true") && !(config.deviceCap[1].isMotionTow == "true"))) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == "Alarm") { //遮挡报警
                        if (!(config.deviceAiCap[0].spzdaudioisShow == "true") || !(config.deviceAiCap[1].spzdaudioisShow == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == "AlarmIO") { //报警io
                        if (config.deviceInfo.AlarmInputChannels == "0" && config.deviceInfo.AlarmOutputChannels == "0") {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == "IntelligentVigilance") { //智能警戒能力用下面是否存在以下其中一个为准，存在及它为true
                        if (!(config.deviceAiCap[0].Electronsupport == "true" || config.deviceAiCap[0].Traversesupport == "true" || config.deviceAiCap[0].OffDetectsupport == "true" || config.deviceAiCap[0].PassengerFlowsupport == "true" || config.deviceAiCap[0].IntelligentTracksuport == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == "warehouse") { //算法仓库
                        if (!(config.deviceAiCap[0].isSupportAlgorithmWarehouse == "true") || !(config.deviceAiCap[1].isSupportAlgorithmWarehouse == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == "fcapture") { //人脸抓拍
                        if (!(config.deviceCap[0].FaceSnapshot == "true") || !(config.deviceCap[1].FaceSnapshot == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == "fcrecognition") { //人脸识别
                        if (!(config.deviceCap[0].IsFaceReco == "true") || !(config.deviceCap[1].IsFaceReco == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == "recordSet") { //录像设置
                        if (!(config.deviceCap[0].diskEnable == "true") || !(config.deviceCap[1].diskEnable == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == "disk") { //磁盘信息
                        if (!(config.deviceCap[0].diskEnable == "true") || !(config.deviceCap[1].diskEnable == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == "platformAccess") { //平台接入
                        var supportGB28181 = config.deviceCap[0].IsSupportGB28181;
                        var supportFTP = config.deviceCap[0].IsSupportFTP;
                        var supportEmail = config.deviceCap[0].IsSupportEmail;
                        if (supportGB28181 == 'false' && supportFTP == 'false' && supportEmail == 'false' || (!supportGB28181 && !supportFTP && !supportEmail)) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == "thirdParty") { //第三方协议
                        if (!(config.deviceCap[0].IsSupportThirdParty == "true") || !(config.deviceCap[1].IsSupportThirdParty == "true")) {
                            item[n].hide = true;
                        }

                    } else if (item[n].id == "ddns") {
                        if (!(config.deviceCap[0].ddns == "true") || !(config.deviceCap[1].ddns == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == 'Form-Detection') { //人形侦测
                        if ((!(config.deviceCap[0].HumanShape == "true") && !(config.deviceCap[0].HumanShapeTow == "true")) || (!(config.deviceCap[1].HumanShape == "true") && !(config.deviceCap[1].HumanShapeTow == "true"))) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == 'deviceUpgrade') { //云升级 vms不需要
                        if (sessionStorage.getItem("xystyle") == "p6s" || sessionStorage.getItem("xystyle") == "p2p") {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == 'rtmp') {
                        if (!(config.deviceInfo.rtmp == "success")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == 'WIFI') { //无线设置
                        if (!(config.deviceCap[0].wifiEnable == "true") || !(config.deviceCap[1].wifiEnable == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == 'licenseplate') { //车牌抓拍
                        if (!(config.deviceCap[0].carSupport == "true") || !(config.deviceCap[1].carSupport == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == 'registration') { //主动注册
                        if (!(config.deviceCap[0].ActiveResgist == "true") || !(config.deviceCap[1].ActiveResgist == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == 'SimCard') { //sim卡信息
                        if (!(config.deviceCap[0].FourGsupport == "true") || !(config.deviceCap[1].FourGsupport == "true")) {
                            item[n].hide = true;
                        }
                    }
                    if (!item[n].hide) {
                        ishide = false
                    }
                }
            } else {
                for (var n = 0; n < item.length; n++) {
                    if (item[n].id == "privacySettings") { //视频遮挡
                        if (!(config.deviceCap[0].isPrivacyZone == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == "motion") { //移动侦测
                        if ((!(config.deviceCap[0].isMotion == "true") && !(config.deviceCap[0].isMotionTow == "true"))) {
                            item[n].hide = true;
                        }
                    }
                    // else if (item[n].id == "Alarm") { //遮挡报警 这个界面重复了 但是不确定是否去除暂时保留
                    //     if (!(config.deviceAiCap[0].spzdaudioisShow == "true")) {
                    //         item[n].hide = true;
                    //     }
                    // }
                    else if (item[n].id == "AlarmIO") { //报警io
                        if (config.deviceInfo.AlarmInputChannels == "0" && config.deviceInfo.AlarmOutputChannels == "0") {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == "IntelligentVigilance") { //智能警戒能力用下面是否存在以下其中一个为准，存在及它为true
                        if(config.deviceAiCap.length!=0){
                            if (!(config.deviceAiCap[0].Electronsupport == "true" || config.deviceAiCap[0].Traversesupport == "true" || config.deviceAiCap[0].OffDetectsupport == "true" || config.deviceAiCap[0].PassengerFlowsupport == "true" || config.deviceAiCap[0].IntelligentTracksuport == "true")) {
                                item[n].hide = true;
                            }
                        }else{
                            item[n].hide = true;
                        }
                    } else if (item[n].id == "warehouse") { //算法仓库
                        if(config.deviceAiCap.length!=0){
                        if (!(config.deviceAiCap[0].isSupportAlgorithmWarehouse == "true")) {
                            item[n].hide = true;
                        } }else{
                            item[n].hide = true;
                        }
                    } else if (item[n].id == "fcapture") { //人脸抓拍
                        if (!(config.deviceCap[0].FaceSnapshot == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == "fcrecognition") { //人脸识别
                        if (!(config.deviceCap[0].IsFaceReco == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == "recordSet") { //录像设置
                        if (!(config.deviceCap[0].diskEnable == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == "disk") { //磁盘信息
                        if (!(config.deviceCap[0].diskEnable == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == "platformAccess") { //平台接入
                        var supportGB28181 = config.deviceCap[0].IsSupportGB28181;
                        var supportFTP = config.deviceCap[0].IsSupportFTP;
                        var supportEmail = config.deviceCap[0].IsSupportEmail;
                        if (supportGB28181 == 'false' && supportFTP == 'false' && supportEmail == 'false' || (!supportGB28181 && !supportFTP && !supportEmail)) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == "thirdParty") { //第三方协议
                        if (!(config.deviceCap[0].IsSupportThirdParty == "true")) {
                            item[n].hide = true;
                        }

                    } else if (item[n].id == "ddns") {
                        if (!(config.deviceCap[0].ddns == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == 'Form-Detection') { //人形侦测
                        if (!(config.deviceCap[0].HumanShape == "true") && !(config.deviceCap[0].HumanShapeTow == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == 'deviceUpgrade') { //云升级 vms不需要
                        if (sessionStorage.getItem("xystyle") == "p6s" || sessionStorage.getItem("xystyle") == "p2p") {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == 'rtmp') {
                        if (!(config.deviceInfo.rtmp == "success")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == 'WIFI') { //无线设置
                        if (!(config.deviceCap[0].wifiEnable == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == 'licenseplate') { //车牌抓拍
                        if (!(config.deviceCap[0].carSupport == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == 'registration') { //主动注册
                        if (!(config.deviceCap[0].ActiveResgist == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == 'SimCard') { //sim卡信息
                        if (!(config.deviceCap[0].FourGsupport == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == 'fireDetect') { //火焰检测
                        if(config.deviceAiCap.length!=0){
                        if (!(config.deviceAiCap[0].Firedetectsupport == "true")) {
                            item[n].hide = true;
                        } }else{
                            item[n].hide = true;
                        }
                    } else if (item[n].id == 'track') { //智能跟踪
                        if(config.deviceAiCap.length!=0){
                        if (!(config.deviceAiCap[0].IntelligentTracksuport == "true")) {
                            item[n].hide = true;
                        }}else{
                            item[n].hide = true;
                        }
                    } else if (item[n].id == 'licenseplateCheck') { //车牌布控
                        if (!(config.deviceCap[0].lincenPlate == "true")) {
                            item[n].hide = true;
                        }
                    } else if (item[n].id == "video-occlusionn") { //视频遮挡
                        if(config.deviceAiCap.length!=0){
                        if (!(config.deviceAiCap[0].spzdaudioisShow == "true")) {
                            item[n].hide = true;
                        }}else{
                            item[n].hide = true;
                        }
                    } else if (item[n].id == "electricScooter") { //电瓶车
                        if(config.deviceAiCap.length!=0){
                        if (!(config.deviceAiCap[0].ElectricBikesupport == "true")) {
                            item[n].hide = true;
                        }}else{
                            item[n].hide = true;
                        }
                    } else if (item[n].id == "gasTank") { //煤气罐
                        if(config.deviceAiCap.length!=0){
                        if (!(config.deviceAiCap[0].ForGasContainerShow == "true")) {
                            item[n].hide = true;
                        }}else{
                            item[n].hide = true;
                        }
                    }else if (item[n].id == "ipAddress") { //ip地址
                        if (!(config.deviceCap[0].WiredNetwork != "false")) {
                            item[n].hide = true;
                        }
                    }else if (item[n].id == "lighting") { //灯光参数
                        if (!(config.deviceCap[0].isSupportLightpage !== "true")) {
                            item[n].hide = true;
                        }
                    }
                    if (!item[n].hide) {
                        ishide = false
                    }
                }
            }

        } else {
            for (var n = 0; n < item.length; n++) {
                if (item[n].id == "privacySettings") { //视频遮挡
                    if (!(config.deviceCap.isPrivacyZone == "true")) {
                        item[n].hide = true;
                    }
                } else if (item[n].id == "motion") { //移动侦测
                    if ((!(config.deviceCap.isMotion == "true") && !(config.deviceCap.isMotionTow == "true"))) {
                        item[n].hide = true;
                    }
                }
                // else if (item[n].id == "Alarm") { //遮挡报警 这个界面重复了 但是不确定是否去除暂时保留
                //     if (!(config.deviceAiCap[0].spzdaudioisShow == "true")) {
                //         item[n].hide = true;
                //     }
                // }
                else if (item[n].id == "AlarmIO") { //报警io
                    if (config.deviceInfo.AlarmInputChannels == "0" && config.deviceInfo.AlarmOutputChannels == "0") {
                        item[n].hide = true;
                    }
                } else if (item[n].id == "IntelligentVigilance") { //智能警戒能力用下面是否存在以下其中一个为准，存在及它为true
                    if (!(config.deviceAiCap.Electronsupport == "true" || config.deviceAiCap.Traversesupport == "true" || config.deviceAiCap.OffDetectsupport == "true" || config.deviceAiCap.PassengerFlowsupport == "true" || config.deviceAiCap.IntelligentTracksuport == "true")) {
                        item[n].hide = true;
                    }
                } else if (item[n].id == "warehouse") { //算法仓库
                    if (!(config.deviceAiCap.isSupportAlgorithmWarehouse == "true")) {
                        item[n].hide = true;
                    }
                } else if (item[n].id == "fcapture") { //人脸抓拍
                    if (!(config.deviceCap.FaceSnapshot == "true")) {
                        item[n].hide = true;
                    }
                } else if (item[n].id == "fcrecognition") { //人脸识别
                    if (!(config.deviceCap.IsFaceReco == "true")) {
                        item[n].hide = true;
                    }
                } else if (item[n].id == "recordSet") { //录像设置
                    if (!(config.deviceCap.diskEnable == "true")) {
                        item[n].hide = true;
                    }
                } else if (item[n].id == "disk") { //磁盘信息
                    if (!(config.deviceCap.diskEnable == "true")) {
                        item[n].hide = true;
                    }
                } else if (item[n].id == "platformAccess") { //平台接入
                    var supportGB28181 = config.deviceCap.IsSupportGB28181;
                    var supportFTP = config.deviceCap.IsSupportFTP;
                    var supportEmail = config.deviceCap.IsSupportEmail;
                    if (supportGB28181 == 'false' && supportFTP == 'false' && supportEmail == 'false' || (!supportGB28181 && !supportFTP && !supportEmail)) {
                        item[n].hide = true;
                    }
                } else if (item[n].id == "thirdParty") { //第三方协议
                    if (!(config.deviceCap.IsSupportThirdParty == "true")) {
                        item[n].hide = true;
                    }

                } else if (item[n].id == "ddns") {
                    if (!(config.deviceCap.ddns == "true")) {
                        item[n].hide = true;
                    }
                } else if (item[n].id == 'Form-Detection') { //人形侦测
                    if (!(config.deviceCap.HumanShape == "true") && !(config.deviceCap.HumanShapeTow == "true")) {
                        item[n].hide = true;
                    }
                } else if (item[n].id == 'deviceUpgrade') { //云升级 vms不需要
                    if (sessionStorage.getItem("xystyle") == "p6s" || sessionStorage.getItem("xystyle") == "p2p") {
                        item[n].hide = true;
                    }
                } else if (item[n].id == 'rtmp') {
                    if (!(config.deviceInfo.rtmp == "success")) {
                        item[n].hide = true;
                    }
                } else if (item[n].id == 'WIFI') { //无线设置
                    if (!(config.deviceCap.wifiEnable == "true")) {
                        item[n].hide = true;
                    }
                } else if (item[n].id == 'licenseplate') { //车牌抓拍
                    if (!(config.deviceCap.carSupport == "true")) {
                        item[n].hide = true;
                    }
                } else if (item[n].id == 'registration') { //主动注册
                    if (!(config.deviceCap.ActiveResgist == "true")) {
                        item[n].hide = true;
                    }
                } else if (item[n].id == 'SimCard') { //sim卡信息
                    if (!(config.deviceCap.FourGsupport == "true")) {
                        item[n].hide = true;
                    }
                } else if (item[n].id == 'fireDetect') { //火焰检测
                    if (!(config.deviceAiCap.Firedetectsupport == "true")) {
                        item[n].hide = true;
                    }
                } else if (item[n].id == 'track') { //智能跟踪
                    if (!(config.deviceAiCap.IntelligentTracksuport == "true")) {
                        item[n].hide = true;
                    }
                } else if (item[n].id == 'licenseplateCheck') { //车牌布控
                    if (!(config.deviceCap.lincenPlate == "true")) {
                        item[n].hide = true;
                    }
                } else if (item[n].id == "video-occlusionn") { //视频遮挡
                    if (!(config.deviceAiCap.spzdaudioisShow == "true")) {
                        item[n].hide = true;
                    }
                } else if (item[n].id == "electricScooter") { //电瓶车
                    if (!(config.deviceAiCap.ElectricBikesupport == "true")) {
                        item[n].hide = true;
                    }
                } else if (item[n].id == "gasTank") { //煤气罐
                    if (!(config.deviceAiCap.ForGasContainerShow == "true")) {
                        item[n].hide = true;
                    }
                }
                if (!item[n].hide) {
                    ishide = false
                }
            }
        }

        return ishide;
    }

})(jQuery, this);
