少林

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
//在当前页面打开一个子tab
parent.addChildTab(title, url, '');

//在当前页面关闭打开的子tab
parent.closeChildTab();

 

// 初始化菜单栏
function initMenu(menu) {
    var result = eval("(" + menu + ")");
    var data = result.data[0].children;
    if (data.length == 0) {
        self.location = "/logout.jsp";
        return;
    }    
    // 加载菜单栏
    for ( var i = 0; i < data.length; i++) {
        var content = "<div style='margin: 10px;'>";
        if(data[i].leaf == true){
            content += "<div style='margin: 5px;'><a href='#' onclick=\"javascript: addTab('"
                + data[i].name
                + "', '"
                + data[i].value.replace("(.*)", "list")
                + "');\">"
                + data[i].name + "</a></div>";
        }else{
            for (var j = 0; j < data[i].children.length; j++) {
                if (data[i].children[j].leaf==false){
                    var s=data[i].children[j];
                    fun(s,1,s.id);
                    content=$("#treeValue").html();
                }else{
                    content += "<div style='margin: 5px;'><a href='#' onclick=\"javascript: addTab('"
                            + data[i].children[j].name
                            + "', '"
                            + data[i].children[j].value.replace("(.*)", "list")
                            + "');\">"
                            + data[i].children[j].name + "</a></div>";
                }
            }
        }
        $("#treeValue").html("");
        $("#temporaryValue").html("");
        content += "</div>";
        var openFlag = false;
        
        if(data[i].name == "我的工作"){
            openFlag = true;
        }
        $("#manage-console").accordion("add", {
            id : data[i].value,
            title : data[i].name,
            content : content,
            selected : openFlag
        });
    }
    addChildTab("待办任务",'/task/do/list.htm');
}
function fun(obj,flag,id){
    var treeContext="";
    treeContext+="<ul class='easyui-tree' id='temporaryId"+id+"'>";
    treeContext+="</ul>";
    var temporaryContext="";
    $(obj).each(function(x,y){
        if (y.leaf==false){
            temporaryContext+='<li id="liId'+y.id+'">';
            temporaryContext+="<span id='span"+y.id+"'>"+y.name+"</span>";
            temporaryContext+="<ul id='ulId"+y.id+"'>";
            temporaryContext+="</ul>";
            temporaryContext+="</li>";
            if(flag==1){
                $("#temporaryValue").html(treeContext);
                $("#temporaryId"+y.id+"").append(temporaryContext);
                var valueHtml=$("#treeValue").html();
                $("#treeValue").html(valueHtml+=$("#temporaryValue").html());
                $("#liId"+id+"").attr("data-options","state:'closed'");
            }else{
                $("#ulId"+id+"").append(temporaryContext);
                $("#liId"+y.id+"").attr("data-options","state:'closed'");
            }
            fun(y.children,2,y.id);
        }else{
            var valueContext="";
            valueContext+="<li>";
            valueContext+="<span><a href='#' onclick=\"javascript: addTab('"
                + y.name
                + "', '"
                + y.value.replace("(.*)", "list")
                + "');\">"
                + y.name + "</a></span>";
            valueContext+="</li>";
            $("#ulId"+id+"").append(valueContext);
        }
    })
}
// 打开Tab页
function addTab(title, uri) {
    if(uri.indexOf("_") == 0)
        window.open(uri.substring(1));
    else {
        $("#manage-tabs").tabs("close", title);
        uri += uri.indexOf("?") > -1 ? "&" : "?";
        uri += "rand=" + Math.random();
        $("#manage-tabs").tabs("add", {
            title : title,
            content : "<iframe scrolling='auto' src='" + uri + "' frameborder='0' style='width:100%; height:100%;'></iframe>",
            closable : true
        });
    }
}

//打开子Tab页
function addChildTab(title, uri, parent) {
    $("#manage-tabs").tabs("close", title);
    uri += uri.indexOf("?") > -1 ? "&" : "?";
    uri += "rand=" + Math.random();
    $("#manage-tabs").tabs("add", {
        id : parent + "-" + title,
        title : title,
        content : "<iframe scrolling='auto' src='" + uri + "' frameborder='0' style='width:100%; height:100%;'></iframe>",
        closable : true
    });
}

//关闭Tab页
function closeTab() {
    var tabs = $("#manage-tabs").tabs("getSelected");
    $('#manage-tabs').tabs('close', tabs.panel("options").title);
}

//关闭子Tab页
function closeChildTab() {
    var tabs = $("#manage-tabs").tabs("getSelected");
    $("#manage-tabs").tabs("select", tabs.panel("options").id.split("-")[0]);
    var parentTab = $("#manage-tabs").tabs("getSelected");
    var iframe = parentTab.find("iframe")[0];
    var search = iframe.contentWindow.location.search;
    var href = iframe.contentWindow.location.href.replace(/#/g,"") + (search == "" ? "?" : "&") + "rand=" + Math.random();
    iframe.contentWindow.location.replace(href);
    $("#manage-tabs").tabs("close", tabs.panel("options").title);
}

//关闭子Tab页(刷新父页iframe)
function closeChildTabIframe() {
    var tabs = $("#manage-tabs").tabs("getSelected");
    $("#manage-tabs").tabs("select", tabs.panel("options").id.split("-")[0]);
    var parentTab = $("#manage-tabs").tabs("getSelected");
    var iframe = parentTab.find("iframe")[0]; 
    var search = iframe.contentWindow.right.location.search;
    var href = iframe.contentWindow.right.location.href.replace(/#/g,"") + (search == "" ? "?" : "&") + "rand=" + Math.random();
    iframe.contentWindow.right.location.replace(href);
    $("#manage-tabs").tabs("close", tabs.panel("options").title);
}

 

posted on 2015-11-04 15:02  Stanley_yu  阅读(261)  评论(0编辑  收藏  举报