Jelajahi Sumber

前端树修改

demon 8 tahun lalu
induk
melakukan
7e6a2c266b

+ 12 - 0
src/main/java/com/yihu/hos/monitor/controller/ServerMonitorController.java

@ -72,4 +72,16 @@ public class ServerMonitorController {
    }
    @RequestMapping(value = "/trees", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取服务器树列表", produces = "application/json", notes = "获取服务器树列表")
    public Result trees() {
        try {
            return monitorService.getServerTreeList();
        } catch (Exception e) {
            return Result.error("获取服务树列表失败");
        }
    }
}

+ 17 - 0
src/main/java/com/yihu/hos/monitor/service/ServerMonitorService.java

@ -4,6 +4,7 @@ import com.mongodb.*;
import com.yihu.hos.core.datatype.DateUtil;
import com.yihu.hos.web.framework.model.ActionResult;
import com.yihu.hos.web.framework.model.Result;
import com.yihu.hos.web.framework.model.TreeView;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoOperations;
@ -100,4 +101,20 @@ public class ServerMonitorService {
        return actionResult;
    }
    public Result getServerTreeList() throws Exception {
        List<TreeView> treeList = new ArrayList<>();
        mongoOperations = new MongoTemplate(mongo, envHealth);
        Set<String> collections = mongoOperations.getCollectionNames();
        for (String host : collections) {
            TreeView rootTree = new TreeView();
            rootTree.setId("host" + host);
            rootTree.setPid("-1");
            rootTree.setText(host);
            treeList.add(rootTree);
        }
        JSONArray jsonArray = new JSONArray(treeList);
        return Result.success(jsonArray.toString());
    }
}

+ 2 - 2
src/main/webapp/WEB-INF/ehr/jsp/monitor/server/sEnvManage.jsp

@ -23,8 +23,8 @@
    <!--左边 区域-->
    <div position="left"  style="margin-left:10px;margin-top:10px;">
        <input type="hidden" id="nowHost">
        <ul    style="margin-left:50px;margin-top:10px;font-size: 17px;">服务器列表</ul>
        <ul id="div_wrapper_left_ul_resourcetree" class="m-snav"  style="margin-left:50px;margin-top:40px;"></ul>
        <ul    style="margin-left:30px;margin-top:10px;font-size: 17px;">服务器列表</ul>
        <ul id="div_wrapper_left_ul_resourcetree" class="m-snav"  style="margin-left:20px;margin-top:40px;"></ul>
    </div>
    <div position="center" style="margin-left:10px;margin-top:10px;margin-right:10px;">
        <!-- ####### 查询条件部分 ####### -->

+ 46 - 44
src/main/webapp/WEB-INF/ehr/jsp/monitor/server/sEnvManageJs.jsp

@ -6,7 +6,7 @@
    var host ="";
    var myChart;
    $(function () {
        initTree();
        getServerTree();
        //l-layout-left
        //初始化layout
        $("#div_wrapper").ligerLayout({
@ -36,34 +36,6 @@
        getServerInfo(host,type,beginTime,endTime);
        getInfo(host,type,endTime);
        //左侧栏目点击事件
        $('#div_wrapper_left_ul_resourcetree').on("click","li",function(){
           $(this).addClass("active");
            $(this).siblings("li").removeClass("active");
            $(this).find("div").addClass("f-bold");
            $(this).siblings("li").find("div").removeClass("f-bold");
            var host = $(this).find("div").text();
            var beginTime = $("#repeatStartTime").ligerDateEditor("getValue");
            var endTime = $("#repeatEndTime").ligerDateEditor("getValue");
            if(beginTime=="" && $endTime=="")
            {
                $.ligerDialog.error("请选择起始结束时间!");
                return false;
            }
            if(beginTime > endTime)
            {
                $.ligerDialog.error("开始时间不能大于结束时间!");
                return false;
            }
            var type = $(".div-menu .active").attr("data-item");
            //获取服务器监控数据
            getServerInfo(host,type,beginTime,endTime);
            getInfo(host,type,endTime);
        });
        //搜索按钮事件
        $(".m-form-control").on("click","#btnSearch",function(){
@ -82,7 +54,6 @@
            }
            var type = $(".div-menu .active").attr("data-item");
            host = $("#div_wrapper_left_ul_resourcetree").find("li.active").find("div").text();
            //获取服务器监控数据
            getServerInfo(host,type,beginTime,endTime);
            getInfo(host,type,endTime);
@ -102,31 +73,58 @@
                myChart.clear();
                return false;
            }
            host = $("#div_wrapper_left_ul_resourcetree").find("li.active").find("div").text();
            getServerInfo(host,type,beginTime,endTime);
            getInfo(host,type,endTime);
        })
    });
    function initTree(){
    function getServerTree(){
        var serviceTree = $("#div_wrapper_left_ul_resourcetree");
        //初始化树
        var $resourceTree = $('#div_wrapper_left_ul_resourcetree');
        $.ajax({
            type: "GET",
            url: "${contextRoot}/monitor/server/hosts",
            url: "${contextRoot}/monitor/server/trees",
            async: false,
            success: function (msg) {
                // 初始化树形菜单
                var data = msg.data;
                if(data!=null && data.length>0){
                    for(var i=0;i<data.length;i++){
                        if(i==0){
                            $resourceTree.append( "<li class='active'><div class='f-bold' style='margin-top:10px;cursor:pointer;'>"+data[i].host+"</div></li>");
                        }else{
                            $resourceTree.append( "<li><div style='margin-top:10px;cursor:pointer;'>"+data[i].host+"</div></li>");
                var data = JSON.parse(msg.message);
                host = data[0].text;
                if (msg.successFlg) {
                    // 初始化树形菜单
                    serviceTree = serviceTree.ligerTree({
                        data: data,
                        idFieldName: 'id',
                        nodeWidth: 200,
                        parentIDFieldName: 'pid',
                        isExpand: false,
                        onClick: function (obj) {
                            //初始化图表
                            host = obj.data.text;
                            var beginTime = $("#repeatStartTime").ligerDateEditor("getValue");
                            var endTime = $("#repeatEndTime").ligerDateEditor("getValue");
                            if(beginTime=="" && $endTime=="")
                            {
                                $.ligerDialog.error("请选择起始结束时间!");
                                return false;
                            }
                            if(beginTime > endTime)
                            {
                                $.ligerDialog.error("开始时间不能大于结束时间!");
                                return false;
                            }
                            var type = $(".div-menu .active").attr("data-item");
                            //获取服务器监控数据
                            getServerInfo(host,type,beginTime,endTime);
                            getInfo(host,type,endTime);
                        },
                        onSuccess: function (data) {
                            alert(2222);
                            host = data[0].text;
                        }
                    }
                    host = data[0].host;
                    });
                }
            }
        });
@ -271,6 +269,7 @@
         }
         else{
            //TODO 清除数据处理
             myChart.clear();
         }
    },
        memory:function(re){
@ -336,6 +335,7 @@
            }
            else{
               //TODO 清除数据
                myChart.clear();
            }
        },
        files:function(re){
@ -413,6 +413,7 @@
            }
            else{
                //TODO 清除数据
                myChart.clear();
            }
        },
        net:function(re){
@ -484,6 +485,7 @@
            }
            else{
               //TODO 清除数据
                myChart.clear();
            }
        }
    }