hostTopo.jsp
8.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<%@page language="java" contentType="text/html;charset=utf-8" %>
<%@ page import="com.ui.contants.ProjectConstant"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="/jsp/common/include.jsp" flush="true"/>
<script src="<%=basePath %>js/antv/antv-g6-1.1.6.js" charset="UTF-8" type="text/javascript"></script>
<script>
var contextPath = '<%=basePath %>';
</script>
<title>YOHO!运维</title>
</head>
<body>
<!-- 头部 -->
<div id="head">
</div>
<!-- 右侧具体内容 -->
<div id="content">
<div id="breadcrumb">
<a href="#" title="Go to Home" class="tip-bottom"><i
class="icon-home"></i> Home</a> <a href="#" class="current">主机拓扑图</a>
</div>
<div class="container-fluid">
<div class="widget-box" style="min-height: 600px;">
<div id="hostListTopoDiv" style="width:600px;float:left">
</div>
<div class="widget-content nopadding" style="margin-left: 600px;border-left: 1px solid #E5E5E5;">
<div class="panel-body">
<div>
<div class="form-inline" role="form"
style="float: left;">
<div class="input-group" style="float: left;">
<span class="input-group-addon">云可用区:</span>
<select id="cloudDetailType" name="cloudDetailType" class="form-control">
<option value="0">全部</option>
<%--<option value="1">AWS</option>--%>
<option value="21">腾讯云</option>
<option value="22">腾讯云az2</option>
<option value="23">腾讯云az3</option>
<%--<option value="3">其他</option>--%>
</select>
</div>
<button class="btn btn-primary" style="margin-left: 18px;" onclick="queryHost()">搜索</button>
</div>
<div id="hostInfoTable" style="margin-top:2px;float: left;min-height: 500px;">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<script src="<%=basePath %>script/common/genarate_left_panel.js?v=<%=ProjectConstant.MENU_VERSION %>"></script>
<script>
$("#li_host").addClass("active open");
$("#li_hostTopo").addClass("active");
</script>
<script type="text/javascript">
// 第一步:获取数据
var data=${antvData};
// 第二步:注册图形
G6.registNode('rect', {
// 设置锚点
getAnchorPoints: function(){
return [
[0.5, 1], // 右边边的中点
[0, 0.5] // 左边边的中点
];
}
});
var nodes = data.nodes;
/* for(var i=0;i<nodes.length;i++){
nodes[i].size=[100,30];
}*/
var edges = [];//data.edges;
// 第三步:进行布局
/*var Layout = G6.Layout;
var margin = 60;
var height = 1000 - 2 * margin;
var width = 500 - 2 * margin;
var layout = new Layout.Flow({
nodes: nodes,
edges: edges
});
nodes = layout.getNodes();
nodes.map(function(node) {
var x = node.x * width + margin;
var y = node.y * height + margin;
node.x = y;
node.y = x;
});
console.log(nodes);*/
// 第四步:初始化图
var net = new G6.Net({
// fitView: 'autoZoom' // 自动缩放
height: ${antvHeight}, // 此处替换高度
behaviourFilter: ['wheelZoom', 'dragNode','dragBlank', 'dragCanvas'],
id: "hostListTopoDiv" // 此处替换容器id
});
// 第五步:载入数据
net.source(nodes, edges);
// 第六步:数据映射
net.node()
.style(function(obj){
var keepRatio=0;
if(obj.level==0){
keepRatio = 1;
}
var attrs = {};
attrs.fill = 'l (0) 0:#ccc ' + keepRatio + ':#ccc ' + keepRatio + ':#00A263';
//attrs.fill = '#00A263';// #':#E6504A';
attrs.fillOpacity = 0.4;
return attrs;
});
net.edge()
.shape('smooth')
.style({
stroke: "#00A263",
strokeOpacity: 0.6,
arrow: true
});
// 第七步:添加图例
// 第八步:渲染关系图
net.render();
//dblclick
var checkStyle = {
fill:"#FF0000",
lineWidth: 2
};
var normalStyle = {
fill:"#00A263",
lineWidth: 1
};
var page_selected_node=[];
net.on('click', function(ev){
if(ev.itemType !== 'node'){
return;
}
var model=ev.item.getModel();
if(model.level==0){
return ;
}
var changeStyle={};
if(model.checked){
model.checked=false;
changeStyle =normalStyle;
for(var arri=0;arri<page_selected_node.length;arri++){
if(page_selected_node[arri].id==model.id){
page_selected_node.splice(arri,1);
break;
}
}
}else{
model.checked=true;
changeStyle = checkStyle;
page_selected_node.push(model);
}
var keyShape = ev.item.getKeyShape();
keyShape.attr(changeStyle);
net.refresh();
});
$(function () {
//加载表格
$("#hostInfoTable").table({
columnAutoWidth : false,
striped : true,
title : "主机信息列表",
dataType : "json",
pagination : true,
pageSize : 10,
loadFilter : function(data) {
return defaultLoadFilter(data);
},
columns : [
{
title: 'NO',
width : "40px",
formatter: function (value, row, index) {
return index+1;
}
},
{
title : "IP",
field : "hostIp",
width : "30%"
}, {
title : "云可用区",
field : "cloudDetailType",
formatter : function(value, rowData, rowIndex) {
if(value == 1){
return 'AWS';
} else if(value == 21){
return '腾讯云';
}else if(value == 22){
return '腾讯云az2';
}else if(value == 23){
return '腾讯云az3';
}else{
return value;
}
},
width : "20%"
}, {
title : "标签",
field : "tags",
formatter : function(value, rowData, rowIndex) {
if(value != null && value != ""){
return value.substr(0,value.length-1);
}
}
}]
});
});
function queryHost() {
console.log(page_selected_node);
var opt = $("#hostInfoTable").data("table");
opt.url=contextPath +"hostInfoList/getHostInfos";
var cloudDetailType = $("#cloudDetailType").val();
var param={
'cloudDetailType': cloudDetailType,
tags:'["upstream-switch"]'
};
$("#hostInfoTable").table("load",param);
}
</script>