easyui tabs切换和单个页面手动刷新以及点击添加新的tabs

夹谷星河
2023-12-01

js

var showLogDialog = {
    codeMirror: null,
    num:0,
    str:'',
    tabsNum:'',
    init: function () {//刚打开页面
        var actionId = $("input[name='actionId']").val();
        var actionSid = $("input[name='actionSid']").val();
        var type = $("input[name='type']").val();
        var index = $.eleProgress();
        $.ajax({
            url: "xxxxxxxxx",
            type: "post",
            dataType: "json",
            data: {
                "actionId": actionId,
                "actionSid": actionSid,
                "type": type
            },
            success: function (data) {
                
                if (data.errorCode == 0) {
                    for (var i in data.returnObj) {
                        var logInfo = data.returnObj[i].logInfo;
                        var str=sql(logInfo);
                        showLogDialog.str=sql(data.returnObj[0].logInfo);
                        showLogDialog.num=data.returnObj[0].lastLineNum;
                        str = str.replace(/(&nbsp;)\1+(<br\/>)/g, '').replace(/(<br\/>)\1+/g, '<br/>');//多个<br>替换成一个

                        if (null != logInfo) {
                            $('#log_tabs').tabs('add', {
                                id: data.returnObj[i].logUrl,
                                title: data.returnObj[i].runServer + '第' + (data.returnObj.length - i) + '次',
                                // content: sql(logInfo),
                                content: str,
                                lastLineNum:data.returnObj[i].lastLineNum,
                                showStyle:"Refresh",
                                str:sql(data.returnObj[i].logInfo),
                                snum:0 //帮助判断是否是第一次点击tabs
                            });

                        } else {
                            $('#log_tabs').tabs('add', {
                                id: data.returnObj[i].logUrl,
                                title: data.returnObj[i].runServer + '第' + (data.returnObj.length - i) + '次',
                                content: "have no log",
                                lastLineNum:data.returnObj[i].lastLineNum,
                                showStyle:"Refresh",
                            });
                        }
                    }

                    $('#log_tabs').tabs('select', 0);
                    $.eleProgressClose(index);
                    showLogDialog.bindOnTabSelectEvent();

                    $('#log_tabs').tabs({
                        tools: '#tab-tools'
                    });

                } else {
                    $.eleAlert(data.message, 2);
                    $.eleProgressClose(index);
                    return;
                }
            }
        });
    },

    onRefreshBtnClicked: function () {//刷新
        var tab = $('#log_tabs').tabs('getSelected');
        var actionSid = $("input[name='actionSid']").val();

        if (null != tab.panel('options').id) {
            // index = $.eleProgress();
            $.ajax({
                url: "xxxxxxxxx",
                type: "post",
                dataType: "json",
                data: {
                    "logUrl": tab.panel('options').id,
                    "actionSid":actionSid,
                    "lastLineNum":showLogDialog.num,
                },
                success: function (data) {
                    if (data.errorCode == 0) {
                        tab.panel('options').snum++;
                        console.log(tab.panel('options').snum)
                        if (null != data.returnObj.logInfo&&data.returnObj.lastLineNum!=-1) {
                            if(data.returnObj.lastLineNum>-1){
                                showLogDialog.num=data.returnObj.lastLineNum;
                            }
                            var str=sql(data.returnObj.logInfo);
                            str = str.replace(/(&nbsp;)\1+(<br\/>)/g, '').replace(/(<br\/>)\1+/g, '<br/>');//多个<br>替换成一个
                            str=tab.panel('options').content+str
                            $('#log_tabs').tabs('update', {
                                tab: tab,
                                options: {
                                    content: str
                                }
                            });
                        } else if(null == data.returnObj.logInfo){
                            showLogDialog.num=data.returnObj.lastLineNum;
                            var str=tab.panel('options').content
                            str = str.replace(/(&nbsp;)\1+(<br\/>)/g, '').replace(/(<br\/>)\1+/g, '<br/>');//多个<br>替换成一个
                            $('#log_tabs').tabs('update', {
                                tab: tab,
                                options: {
                                    content: str
                                }
                            });
                        } else{
                            $('#log_tabs').tabs('update', {
                                tab: tab,
                                options: {
                                    content: "have no log"
                                }
                            });
                        }
                    } else {
                        $.eleAlert(data.message, 2);
                        return;
                    }
                }
            });
        }
    },

    bindOnTabSelectEvent: function () {//切换tabs
        var actionSid = $("input[name='actionSid']").val();
        $('#log_tabs').tabs({
            onSelect: function (title, index) {

                var tab = $('#log_tabs').tabs('getSelected');
                    // index = $.eleProgress();
                if(tab.panel('options').showStyle=="down"){
                    $("#down").css("display","block");
                    $("#Refresh").css("display","none");
                    showLogDialog.tabsNum=tab.panel('options').id

                }else if(tab.panel('options').showStyle=="Refresh"){
                    $("#down").css("display","none");
                    $("#Refresh").css("display","block");

                    if(tab.panel('options').snum==0){
                        tab.panel('options').snum++;
                        console.log(tab.panel('options').snum)
                        $.ajax({
                            url: "xxxxxxxxxx",
                            type: "post",
                            dataType: "json",
                            data: {
                                "logUrl": tab.panel('options').id,
                                "lastLineNum":tab.panel('options').lastLineNum,
                                "actionSid":actionSid,
                            },
                            success: function (data) {
                                if (data.errorCode == 0) {
                                    if (null != data.returnObj.logInfo&&data.returnObj.lastLineNum!=-1) {
                                        if(data.returnObj.lastLineNum>-1){
                                            showLogDialog.num=data.returnObj.lastLineNum;
                                            // showLogDialog.str=sql(data.returnObj.logInfo);
                                        }
                                        var str=sql(data.returnObj.logInfo);
                                        str = str.replace(/(&nbsp;)\1+(<br\/>)/g, '').replace(/(<br\/>)\1+/g, '<br/>');//多个<br>替换成一个
                                        str=tab.panel('options').content+str
                                        $('#log_tabs').tabs('update', {
                                            tab: tab,
                                            options: {
                                                content: str
                                            }
                                        });
                                    } else if(null == data.returnObj.logInfo){
                                        showLogDialog.num=data.returnObj.lastLineNum;
                                        var str=tab.panel('options').content;
                                        str = str.replace(/(&nbsp;)\1+(<br\/>)/g, '').replace(/(<br\/>)\1+/g, '<br/>');//多个<br>替换成一个
                                        $('#log_tabs').tabs('update', {
                                            tab: tab,
                                            options: {
                                                content: str
                                            }
                                        });
                                    }else{
                                        $('#log_tabs').tabs('update', {
                                            tab: tab,
                                            options: {
                                                content: 'have no log'
                                            }
                                        });
                                    }

                                    // $.eleProgressClose(index);
                                } else {
                                    $.eleAlert(data.message, 2);
                                    // $.eleProgressClose(index);
                                    return;
                                }
                            }
                        });
                    }else{
                        console.log("不进行点击调用")
                    }

                }


                }
            // }
        });
    },

}
$(function () {
    showLogDialog.init();

});
function addTab(jonId){//新增tabs
    showLogDialog.tabsNum=jonId;
    //判断选项卡是否重复打开
    if ($('#log_tabs').tabs('exists', "详情"+(jonId))) {
        $('#log_tabs').tabs('select', "详情"+(jonId));//选中并刷新
    } else {
        $.ajax({
            url: "xxxxxxxxxxxx",
            type: "post",
            dataType: "json",
            data: {
                "jobId": jonId,
            },
            success: function (data) {
                if (data.errorCode == 0) {
                    if(data.returnObj.length>0) {
                        $('#log_tabs').tabs('add', {
                            title: "详情"+(jonId),
                            id:jonId,
                            content: data.returnObj,
                            showStyle:"down"
                        });
                    } else {
                        $('#log_tabs').tabs('add', {
                            title: "详情"+(jonId),
                            id:jonId,
                            content: "have no log",
                            showStyle:"down"
                        });
                    }
                }

                $('#log_tabs').tabs('select', "详情"+(jonId));//点击定位到该tabs

                // $('#log_tabs').tabs({
                //     tools: '#tab-tools'
                // });

            }
        });
    }


}
function downBtnClicked(){//下载日志详情
    window.open("xxxxxxxxx?jobId="+showLogDialog.tabsNum)
}
复制代码

html

<html>
<head>
<#include "/base/header.ftl"/>
<link type="text/css" rel="stylesheet" href="/js/codemirror-5.2/lib/codemirror.css?v=${version!}" />
<link type="text/css" rel="stylesheet" href="/js/codemirror-5.2/addon/hint/show-hint.css?v=${version!}" />
<link href="${rc.contextPath}/css/wizard.css?v=${version!}" rel="stylesheet" />
<script type="text/javascript" src="/js/codemirror-5.2/lib/codemirror.js?v=${version!}"></script>
<script type="text/javascript" src="/js/codemirror-5.2/mode/sql/sql.js?v=${version!}"></script>
<script type="text/javascript" src="/js/codemirror-5.2/addon/hint/show-hint.js?v=${version!}"></script>
<script src="/js/wizard.js?v=${version!}"></script>
<script src="/js/hiveSqlFormatter.js?v=${version!}"></script>
<script src="/js/lib/action/action_wizard_edit.js?v=${version!}"></script>
<style type="text/css">

a{
	color: blue;
}
</style>
</head>
<body>
	<input type="hidden" name="actionId" value="${actionId}">
	<input type="hidden" name="actionSid" value="${actionSid}">
	<input type="hidden" name="type" value="${type}">
    <div id="log_tabs" class="easyui-tabs">
    </div>
    <div id="tab-tools" style="display: none;">
        <a href="#" id="Refresh" class="easyui-linkbutton" plain="true" iconCls="refresh-icon" onclick="showLogDialog.onRefreshBtnClicked();">刷新</a>
        <a style="display: none;" id="down" href="#" class="easyui-linkbutton" plain="true" iconCls="l-btn-icon go-icon" onclick="downBtnClicked();">下载</a>
    </div>
	<#include "/base/footer.ftl"/>
	<script src="/js/lib/log/show_log_dialog.js?v=${version!}"></script>
</body>
</html>
复制代码

转载于:https://juejin.im/post/5c74e37e6fb9a049c43e527e

 类似资料: