Showing
7 changed files
with
3472 additions
and
10 deletions
@@ -76,7 +76,7 @@ layui.define(['table', 'form', 'laydate', 'admin', 'layer', 'laytpl', 'common', | @@ -76,7 +76,7 @@ layui.define(['table', 'form', 'laydate', 'admin', 'layer', 'laytpl', 'common', | ||
76 | }); | 76 | }); |
77 | //绑定业务下拉选择数据 | 77 | //绑定业务下拉选择数据 |
78 | admin.req({ | 78 | admin.req({ |
79 | - url: domainName + '/api-web/home/business/findUserBusTypeAll?table=b_alarm', | 79 | + url: domainName + '/api-web/home/business/findAllBusType', |
80 | success: function (response) { | 80 | success: function (response) { |
81 | if (response && response.success) { | 81 | if (response && response.success) { |
82 | busTypeList = response.data; | 82 | busTypeList = response.data; |
@@ -102,7 +102,7 @@ layui.define(['table', 'form', 'laydate', 'admin', 'layer', 'laytpl', 'common', | @@ -102,7 +102,7 @@ layui.define(['table', 'form', 'laydate', 'admin', 'layer', 'laytpl', 'common', | ||
102 | show: true, | 102 | show: true, |
103 | list: ['ALL', 'REVERSE', 'CLEAR'] | 103 | list: ['ALL', 'REVERSE', 'CLEAR'] |
104 | }, | 104 | }, |
105 | - height: '170px', | 105 | + height: 'auto', |
106 | tree: { | 106 | tree: { |
107 | show: true, | 107 | show: true, |
108 | showFolderIcon: true, | 108 | showFolderIcon: true, |
@@ -55,7 +55,7 @@ layui.define(['table', 'form', 'laydate', 'admin', 'layer', 'laytpl', 'common', | @@ -55,7 +55,7 @@ layui.define(['table', 'form', 'laydate', 'admin', 'layer', 'laytpl', 'common', | ||
55 | 55 | ||
56 | //绑定业务下拉选择数据 | 56 | //绑定业务下拉选择数据 |
57 | admin.req({ | 57 | admin.req({ |
58 | - url: domainName + '/api-web/home/business/findUserBusTypeAll?table=b_alarm_his', | 58 | + url: domainName + '/api-web/home/business/findAllBusType', |
59 | success: function (response) { | 59 | success: function (response) { |
60 | if (response && response.success) { | 60 | if (response && response.success) { |
61 | busTypeList = response.data; | 61 | busTypeList = response.data; |
@@ -80,7 +80,7 @@ layui.define(['table', 'form', 'laydate', 'admin', 'layer', 'laytpl', 'common', | @@ -80,7 +80,7 @@ layui.define(['table', 'form', 'laydate', 'admin', 'layer', 'laytpl', 'common', | ||
80 | show: true, | 80 | show: true, |
81 | list: ['ALL', 'REVERSE', 'CLEAR'] | 81 | list: ['ALL', 'REVERSE', 'CLEAR'] |
82 | }, | 82 | }, |
83 | - height: '170px', | 83 | + height: 'auto', |
84 | tree: { | 84 | tree: { |
85 | show: true, | 85 | show: true, |
86 | showFolderIcon: true, | 86 | showFolderIcon: true, |
@@ -155,7 +155,7 @@ layui.define(['admin', 'table', 'common','sessions','commonDetail'], function (e | @@ -155,7 +155,7 @@ layui.define(['admin', 'table', 'common','sessions','commonDetail'], function (e | ||
155 | tableContent += '<tr>' + td + '</tr>'; | 155 | tableContent += '<tr>' + td + '</tr>'; |
156 | }); | 156 | }); |
157 | if (jbxx.length == 0){ | 157 | if (jbxx.length == 0){ |
158 | - tableContent = '<tr style="background-color: white;"> <td class="none" colspan="4" style="text-align: center;color: #999;background-color: white">无数据</td> </tr>'; | 158 | + tableContent = '<tr style="background-color: white;"> <td class="layui-td-value" colspan="4" style="text-align: center;color: #999;background-color: white">无数据</td> </tr>'; |
159 | } | 159 | } |
160 | $("#hostminicomputer_property").html(tabletop+ tableTh+ tableContent + tablebottom); | 160 | $("#hostminicomputer_property").html(tabletop+ tableTh+ tableContent + tablebottom); |
161 | $(".layui-td-title").css("backgroundColor", "#F1F6F9") | 161 | $(".layui-td-title").css("backgroundColor", "#F1F6F9") |
@@ -349,7 +349,6 @@ layui.define(['common', 'tree', 'laypage', 'laytpl', 'admin', 'form', 'table', ' | @@ -349,7 +349,6 @@ layui.define(['common', 'tree', 'laypage', 'laytpl', 'admin', 'form', 'table', ' | ||
349 | 349 | ||
350 | //加载虚拟化数据(平台、资源池、物理机、虚拟机) | 350 | //加载虚拟化数据(平台、资源池、物理机、虚拟机) |
351 | function loadVirtualizationView(parentNode, data, node, options) { | 351 | function loadVirtualizationView(parentNode, data, node, options) { |
352 | - $('#res_coll_protocol_select_div').show(); | ||
353 | //绑定业务 | 352 | //绑定业务 |
354 | // common.bizTypeSelect("treetableBizTypes", function () { | 353 | // common.bizTypeSelect("treetableBizTypes", function () { |
355 | // form.render("select"); | 354 | // form.render("select"); |
@@ -1338,7 +1337,6 @@ layui.define(['common', 'tree', 'laypage', 'laytpl', 'admin', 'form', 'table', ' | @@ -1338,7 +1337,6 @@ layui.define(['common', 'tree', 'laypage', 'laytpl', 'admin', 'form', 'table', ' | ||
1338 | limit: -1 | 1337 | limit: -1 |
1339 | } | 1338 | } |
1340 | }).done(function (res) { | 1339 | }).done(function (res) { |
1341 | - $('#res_coll_protocol_select_div').show(); | ||
1342 | xmSelect.render({ | 1340 | xmSelect.render({ |
1343 | el: '#collProtocolSelect' | 1341 | el: '#collProtocolSelect' |
1344 | , filterable: true | 1342 | , filterable: true |
@@ -1373,14 +1371,12 @@ layui.define(['common', 'tree', 'laypage', 'laytpl', 'admin', 'form', 'table', ' | @@ -1373,14 +1371,12 @@ layui.define(['common', 'tree', 'laypage', 'laytpl', 'admin', 'form', 'table', ' | ||
1373 | } | 1371 | } |
1374 | }) | 1372 | }) |
1375 | }) | 1373 | }) |
1376 | - }else{ | ||
1377 | - $('#res_coll_protocol_select_div').hide(); | ||
1378 | } | 1374 | } |
1379 | if (resType === 'HOST_MINICOMPUTER_PARTITION') { | 1375 | if (resType === 'HOST_MINICOMPUTER_PARTITION') { |
1380 | $("#res_minicomputer").parent().parent().removeClass("hide"); | 1376 | $("#res_minicomputer").parent().parent().removeClass("hide"); |
1381 | var minicomputerStr = ''; | 1377 | var minicomputerStr = ''; |
1382 | minicomputerStr = '<option value="">=小型机服务器=</option>'; | 1378 | minicomputerStr = '<option value="">=小型机服务器=</option>'; |
1383 | - let url = `${common.domainName}/api-web/home/res-list/hostMinicomputerPartitionParents?access_token=${accessToken}` | 1379 | + let url = `${common.domainName}/api-web/home/res-list/HOST_MINICOMPUTER?access_token=${accessToken}&page=1&limit=30&resCategory=resources` |
1384 | $.ajax({ | 1380 | $.ajax({ |
1385 | url: url, | 1381 | url: url, |
1386 | method: 'get', | 1382 | method: 'get', |
1 | +//活动告警 | ||
2 | +layui.define(['table', 'form', 'laydate', 'admin', 'layer', 'laytpl', 'common', 'sessions','commonDetail','soulTable', 'treeTable'], function (exports) { | ||
3 | + var $ = layui.$; | ||
4 | + var form = layui.form; | ||
5 | + var layer = layui.layer; | ||
6 | + var admin = layui.admin; | ||
7 | + var table = layui.table; | ||
8 | + var laydate = layui.laydate; | ||
9 | + var laytpl = layui.laytpl; | ||
10 | + var treeTable = layui.treeTable; | ||
11 | + var common = layui.common; | ||
12 | + var commonDetail=layui.commonDetail; | ||
13 | + var domainName = common.domainName; | ||
14 | + var todayStr = ''; | ||
15 | + //对外暴露的接口 | ||
16 | + exports('activewarning', function () { | ||
17 | + var sessions = layui.sessions; | ||
18 | + var accessToken = sessions.getToken()['access_token']; | ||
19 | + var router = layui.router(); | ||
20 | + var alarmLevel = router.search.level; //告警级别 | ||
21 | + var checkList = common.checkPermission(accessToken); | ||
22 | + var resId = router.search.resId;//资源Id | ||
23 | + var kpiId = router.search.kpiId;//指标Id | ||
24 | + var bizId = router.search.bizId;//业务Id | ||
25 | + var alarmNo = router.search.alarmNo;//告警编号 | ||
26 | + var busIdSelect; | ||
27 | + var busTypeList = []; | ||
28 | + if(!bizId){ | ||
29 | + bizId=''; | ||
30 | + } | ||
31 | + if (resId) { | ||
32 | + resId = decodeURIComponent(resId); | ||
33 | + } | ||
34 | + if (alarmNo) { | ||
35 | + $("#activewarningkw").val(alarmNo); | ||
36 | + } | ||
37 | + var netFlag = router.search.netFlag;//网络标识 | ||
38 | + var resType = router.search.restype ? router.search.restype : '';//资源类型 | ||
39 | + var soulTable = layui.soulTable; | ||
40 | + | ||
41 | + var sortKey = ''; | ||
42 | + | ||
43 | + if ($("#alarmLevelSearchBox").val()) { | ||
44 | + alarmLevel = $("#alarmLevelSearchBox").val() | ||
45 | + } | ||
46 | + //回显告警级别 | ||
47 | + $("#alarmLevelSearchBox").val(alarmLevel); | ||
48 | + form.render("select"); | ||
49 | + | ||
50 | + function initDate() { | ||
51 | + //开始时间 | ||
52 | + var start = laydate.render({ | ||
53 | + elem: '#activewarningStartdate' | ||
54 | + , trigger: 'click' | ||
55 | + , done: function (value, date) { | ||
56 | + date.month--; | ||
57 | + end.config.min = date; | ||
58 | + var endDate = $("#activewarningEnddate").val(); | ||
59 | + if (endDate != null && endDate != "") { | ||
60 | + reloadTable(); | ||
61 | + } | ||
62 | + } | ||
63 | + }); | ||
64 | + //结束时间 | ||
65 | + var end = laydate.render({ | ||
66 | + elem: '#activewarningEnddate' | ||
67 | + , trigger: 'click' | ||
68 | + , done: function (value, date) { | ||
69 | + date.month--; | ||
70 | + start.config.max = date; | ||
71 | + var benginDate = $("#activewarningStartdate").val(); | ||
72 | + if (benginDate != null && benginDate != "") { | ||
73 | + reloadTable(); | ||
74 | + } | ||
75 | + } | ||
76 | + }); | ||
77 | + //绑定业务下拉选择数据 | ||
78 | + admin.req({ | ||
79 | + url: domainName + '/api-web/home/business/findUserBusTypeAll?table=b_alarm', | ||
80 | + success: function (response) { | ||
81 | + if (response && response.success) { | ||
82 | + busTypeList = response.data; | ||
83 | + var bizList = response.data.map(item => { | ||
84 | + return { | ||
85 | + name: item.busTypeName, | ||
86 | + value: item.busId, | ||
87 | + parentId: item.parentId | ||
88 | + } | ||
89 | + }); | ||
90 | + var bizTree=common.pidToChildren(bizList, 'value', 'parentId'); | ||
91 | + | ||
92 | + // 影响业务下拉框 | ||
93 | + busIdSelect = xmSelect.render({ | ||
94 | + el: '#bisTypeSearchBox', | ||
95 | + name: 'bizId', | ||
96 | + tips: '=所属业务=', | ||
97 | + //开启搜索 | ||
98 | + filterable: true, | ||
99 | + clickClose: true, | ||
100 | + initValue: [bizId.split(',')[0]], | ||
101 | + toolbar: { | ||
102 | + show: true, | ||
103 | + list: ['ALL', 'REVERSE', 'CLEAR'] | ||
104 | + }, | ||
105 | + height: '170px', | ||
106 | + tree: { | ||
107 | + show: true, | ||
108 | + showFolderIcon: true, | ||
109 | + showLine: true, | ||
110 | + strict: true, | ||
111 | + //间距 | ||
112 | + indent: 20, | ||
113 | + }, | ||
114 | + model: { | ||
115 | + label: { | ||
116 | + type: 'text' | ||
117 | + } | ||
118 | + }, | ||
119 | + data: bizTree, | ||
120 | + on: function (data) { | ||
121 | + if (data.arr.length != 0) { | ||
122 | + var str=''; | ||
123 | + $.each(data.arr,function (i,v) { | ||
124 | + str+=v.value+','; | ||
125 | + }) | ||
126 | + bizId = str.substring(0,str.length-1); | ||
127 | + } else { | ||
128 | + bizId = ''; | ||
129 | + } | ||
130 | + form.render(); | ||
131 | + reloadTable(); | ||
132 | + } | ||
133 | + }); | ||
134 | + if(busIdSelect){ | ||
135 | + //追加样式 | ||
136 | + $('#bisTypeSearchBox').find('.xm-body').eq(0).css("width","230px"); | ||
137 | + } | ||
138 | + } else { | ||
139 | + layer.msg('获取业务失败', {icon: 2}); | ||
140 | + } | ||
141 | + }, | ||
142 | + error: function () { | ||
143 | + layer.msg('获取业务失败', {icon: 2}); | ||
144 | + } | ||
145 | + }); | ||
146 | + | ||
147 | + $.ajax({ | ||
148 | + url: common.domainName + '/api-web/manage/kpi/findKpiInAlarm?access_token='+accessToken+'&tableName=b_alarm', | ||
149 | + type: "get", | ||
150 | + success:function (res) { | ||
151 | + var kpis = res.data; | ||
152 | + var html = '<option value="">=指标名称=</option>' | ||
153 | + $.each(kpis,function (i,e) { | ||
154 | + html+='<option value="'+e.kpiId+'">'+e.kpiName+'</option>' | ||
155 | + }) | ||
156 | + $("#alarmKpiSearchBox").html(''); | ||
157 | + $("#alarmKpiSearchBox").append(html); | ||
158 | + form.render(); | ||
159 | + } | ||
160 | + }) | ||
161 | + $.ajax({ | ||
162 | + url: `${common.domainName}/api-web/manage/restype/list?access_token=${accessToken}`, | ||
163 | + method: 'GET', | ||
164 | + success: function (res) { | ||
165 | + // 资源类型下拉框 | ||
166 | + var resTypeList = res.data.map(item => { | ||
167 | + return { | ||
168 | + name: item.resTypeName, | ||
169 | + value: item.resTypeCode, | ||
170 | + parentId: item.parentId | ||
171 | + } | ||
172 | + }); | ||
173 | + var resTypeTree = treeTable.pidToChildren(resTypeList, "value", "parentId"); | ||
174 | + xmSelect.render({ | ||
175 | + el: '#resTypeSearchBox', | ||
176 | + name: "resType", | ||
177 | + tips: '=资源类型=', | ||
178 | + filterable: true, | ||
179 | + radio: true, | ||
180 | + clickClose: true, | ||
181 | + initValue: [resType], | ||
182 | + toolbar: { | ||
183 | + show: true, | ||
184 | + list: ['CLEAR'] | ||
185 | + }, | ||
186 | + tree: { | ||
187 | + show: true, | ||
188 | + showFolderIcon: true, | ||
189 | + showLine: true, | ||
190 | + strict: false, | ||
191 | + indent: 20 | ||
192 | + }, | ||
193 | + model: { | ||
194 | + label: { | ||
195 | + type: 'text' | ||
196 | + } | ||
197 | + }, | ||
198 | + height: 'auto', | ||
199 | + data: resTypeTree, | ||
200 | + on: function (data) { | ||
201 | + if(data.isAdd){ | ||
202 | + if (data.arr.length != 0) { | ||
203 | + resType = data.arr[0].value; | ||
204 | + } else { | ||
205 | + resType = ''; | ||
206 | + } | ||
207 | + reloadTable(); | ||
208 | + } | ||
209 | + } | ||
210 | + }); | ||
211 | + } | ||
212 | + }); | ||
213 | + } | ||
214 | + | ||
215 | + //回车搜索 | ||
216 | + $('#activewarningkw, input[name="durationVal"]').keydown(function (e) { | ||
217 | + if (e.keyCode === 13) { | ||
218 | + reloadTable(); | ||
219 | + } | ||
220 | + }); | ||
221 | + //选择框搜索事件 | ||
222 | + bindSelectEvent(); | ||
223 | + initDate(); | ||
224 | + | ||
225 | + function initToolBarClickEvent() { | ||
226 | + //告警消除 | ||
227 | + $("#clearBtn").unbind('click').on('click', function () { | ||
228 | + if ($.inArray('app:alarm:clear', checkList) == -1) { | ||
229 | + layer.msg('暂无权限!', {icon: 7, time: 3000}); | ||
230 | + return; | ||
231 | + } | ||
232 | + var ids = []; | ||
233 | + var data = table.checkStatus('activewarningTable').data; | ||
234 | + if (data.length == 0) { | ||
235 | + layer.msg('请最少选择一项数据', {icon: 7, time: 2000}); | ||
236 | + return; | ||
237 | + } | ||
238 | + //选中的告警ID放到集合中 | ||
239 | + $.each(data, function (i, obj) { | ||
240 | + ids.push(obj.id) | ||
241 | + }); | ||
242 | + //获取以往告警消除意见 | ||
243 | + admin.req({ | ||
244 | + url: common.domainName + '/api-web/home/alarm/clear/reason', | ||
245 | + type: "get", | ||
246 | + data:{ | ||
247 | + alarmId: ids.toString() | ||
248 | + }, | ||
249 | + done:function (data) { | ||
250 | + var clearReson = "暂无参考处理方案,请输入处理方案"; | ||
251 | + var hisReason = ""; | ||
252 | + var reasonlist = data.reason; | ||
253 | + if(reasonlist && reasonlist.length > 0){ | ||
254 | + hisReason = "参考方案:\n"; | ||
255 | + $.each(reasonlist,function (i,v) { | ||
256 | + var idx = i + 1; | ||
257 | + hisReason += idx +":"+v +"\n"; | ||
258 | + }); | ||
259 | + } | ||
260 | + | ||
261 | + layer.prompt({id: "alarms_clear_id", title: '告警消除', area: ['400px'], formType: 2,value: hisReason}, function (text, index) { | ||
262 | + admin.req({ | ||
263 | + url: common.domainName + '/api-web/home/alarm/clear' | ||
264 | + , type: "post" | ||
265 | + , data: { | ||
266 | + ids: ids.toString(), | ||
267 | + reason: text, | ||
268 | + access_token: accessToken, | ||
269 | + noticeFlag: $('input[name="noticeFlag"]:checked').val() | ||
270 | + } | ||
271 | + , done: function (res) { | ||
272 | + //如果消除成功,关闭弹出框然后重新加载页面 | ||
273 | + if (res.success) { | ||
274 | + layer.close(index); | ||
275 | + layer.msg('告警已消除!', {icon: 1, time: 2000}); | ||
276 | + reloadTable(); | ||
277 | + } else { | ||
278 | + layer.msg('告警消除失败,请与管理员联系!', {icon: 7, time: 3000}); | ||
279 | + } | ||
280 | + } | ||
281 | + }); | ||
282 | + }); | ||
283 | + | ||
284 | + $("#alarms_clear_id").find('textarea.layui-layer-input').attr("placeholder", clearReson); | ||
285 | + $("#alarms_clear_id").append('<div style="padding-top: 15px;"><span>是否通知:</span> ' + | ||
286 | + '<input type="radio" name="noticeFlag" value="true" title="是" > 是' + | ||
287 | + '<input type="radio" name="noticeFlag" value="false" title="否" checked="" style="margin-left: 20px;"> 否</div> '); | ||
288 | + } | ||
289 | + }); | ||
290 | + }); | ||
291 | + //告警关闭 | ||
292 | + $("#closeBtn").unbind('click').on("click", function () { | ||
293 | + if ($.inArray('app:alarm:close', checkList) == -1) { | ||
294 | + layer.msg('暂无权限!', {icon: 7, time: 3000}); | ||
295 | + return; | ||
296 | + } | ||
297 | + var ids = []; | ||
298 | + var data = table.checkStatus('activewarningTable').data; | ||
299 | + var alarmStatus = true; | ||
300 | + if (data.length == 0) { | ||
301 | + layer.msg('请最少选择一项数据', {icon: 7, time: 2000}); | ||
302 | + return; | ||
303 | + } | ||
304 | + //选中的告警ID放到集合中 | ||
305 | + $.each(data, function (i, obj) { | ||
306 | + var status = JSON.stringify(obj.alarmStatus); | ||
307 | + if (status && status == '1') { | ||
308 | + alarmStatus = false; | ||
309 | + } | ||
310 | + ids.push(obj.id) | ||
311 | + }); | ||
312 | + if (!alarmStatus) { | ||
313 | + layer.msg('已关闭的告警不可重复关闭!', {icon: 7, time: 3000}); | ||
314 | + return; | ||
315 | + } | ||
316 | + layer.prompt({ | ||
317 | + id: "alarms_cloes_id", | ||
318 | + formType: 2, | ||
319 | + title: '告警关闭', | ||
320 | + area: ['400px'] | ||
321 | + }, | ||
322 | + function (value, index) { | ||
323 | + if (value === "") { | ||
324 | + layer.msg('请填写关闭意见', {icon: 7, time: 3000}); | ||
325 | + } | ||
326 | + if ($('#closeDuration').val() === "") { | ||
327 | + layer.msg('请填写关闭时长', {icon: 7, time: 3000}); | ||
328 | + return; | ||
329 | + } | ||
330 | + admin.req({ | ||
331 | + url: common.domainName + '/api-web/home/alarm/close' | ||
332 | + , type: "post" | ||
333 | + , data: { | ||
334 | + ids: ids.toString(), | ||
335 | + reason: value, | ||
336 | + duration: $('#closeDuration').val() * 60, | ||
337 | + closeType: $('input[name="closeType"]:checked').val(), | ||
338 | + noticeFlag: $('input[name="noticeFlag"]:checked').val(), | ||
339 | + kpiAllFlag: $('input[name="kpiAllFlag"]:checked').val(), | ||
340 | + access_token: accessToken | ||
341 | + } | ||
342 | + , done: function (res) { | ||
343 | + if (res.success) { | ||
344 | + layer.close(index); | ||
345 | + layer.msg('关闭成功', {icon: 1, time: 2000}, function () { | ||
346 | + reloadTable(); | ||
347 | + }); | ||
348 | + } else { | ||
349 | + layer.msg('告警关闭失败,请与管理员联系!', {icon: 7, time: 3000}); | ||
350 | + } | ||
351 | + } | ||
352 | + }); | ||
353 | + }); | ||
354 | + $("#alarms_cloes_id").find('textarea.layui-layer-input').attr("placeholder", "请输入关闭意见(必填)");// /[^(\d||/.)]/g,'' | ||
355 | + $("#alarms_cloes_id").append('<br/>' + | ||
356 | + '<input type="number" id="closeDuration" class="layui-input" min="0" oninput="if(value.length>5)value=value.slice(0,5)" onkeyup="value=value.replace(/(\\d*\\.\\d).*/,\'$1\')" placeholder="输入关闭时长,单位小时(必填)"/>'); | ||
357 | + | ||
358 | + $("#alarms_cloes_id").append('<br/><div style="line-height: 38px;"><span>关闭类型:</span> ' + | ||
359 | + '<input type="radio" name="closeType" value="0" title="关闭告警" checked=""> 关闭告警' + | ||
360 | + '<input type="radio" name="closeType" value="1" title="关闭通知" style="margin-left: 20px;"> 关闭通知</div> '); | ||
361 | + | ||
362 | + $("#alarms_cloes_id").append('<div style="line-height: 38px;"><span>是否关闭该指标所有告警/通知:</span> ' + | ||
363 | + '<input type="radio" name="kpiAllFlag" value="true" title="是"> 是' + | ||
364 | + '<input type="radio" name="kpiAllFlag" value="false" title="否" checked="" style="margin-left: 20px;"> 否</div> '); | ||
365 | + | ||
366 | + $("#alarms_cloes_id").append('<div style="line-height: 38px;"><span>是否通知:</span> ' + | ||
367 | + '<input type="radio" name="noticeFlag" value="true" title="是"> 是' + | ||
368 | + '<input type="radio" name="noticeFlag" value="false" title="否" checked="" style="margin-left: 20px;"> 否</div> '); | ||
369 | + }); | ||
370 | + //告警确认 | ||
371 | + $("#confirmBtn").unbind('click').on("click", function () { | ||
372 | + if ($.inArray('app:alarm:confirm', checkList) == -1) { | ||
373 | + layer.msg('暂无权限!', {icon: 7, time: 3000}); | ||
374 | + return; | ||
375 | + } | ||
376 | + var ids = []; | ||
377 | + var data = table.checkStatus('activewarningTable').data; | ||
378 | + if (data.length == 0) { | ||
379 | + layer.msg('请最少选择一项数据', {icon: 7, time: 2000}); | ||
380 | + return; | ||
381 | + } | ||
382 | + $.each(data, function (i, obj) { | ||
383 | + ids.push(obj.id) | ||
384 | + }); | ||
385 | + layer.prompt({ | ||
386 | + id: "alarms_confirm_id", | ||
387 | + formType: 2, | ||
388 | + title: '告警确认', | ||
389 | + area: ['400px'] | ||
390 | + }, | ||
391 | + function (value, index) { | ||
392 | + if (value === "") { | ||
393 | + layer.msg('请填确认意见', {icon: 7, time: 3000}); | ||
394 | + } | ||
395 | + admin.req({ | ||
396 | + url: common.domainName + '/api-web/home/alarm/confirm' | ||
397 | + , type: "post" | ||
398 | + , data: { | ||
399 | + ids: ids.toString(), | ||
400 | + reason: value, | ||
401 | + level: $('input[name="confrimlevel"]:checked').val(), | ||
402 | + access_token: accessToken | ||
403 | + } | ||
404 | + , done: function (res) { | ||
405 | + if (res.success) { | ||
406 | + layer.close(index); | ||
407 | + layer.msg('告警确认成功', {icon: 1, time: 2000}, function () { | ||
408 | + reloadTable(); | ||
409 | + }); | ||
410 | + } else { | ||
411 | + layer.msg('告警确认失败,请与管理员联系!', {icon: 7, time: 3000}); | ||
412 | + } | ||
413 | + } | ||
414 | + }); | ||
415 | + }); | ||
416 | + $("#alarms_confirm_id").find('textarea.layui-layer-input').attr("placeholder", "请输入意见(必填)"); | ||
417 | + $("#alarms_confirm_id").append('<br/> ' + | ||
418 | + '<input type="radio" name="confrimlevel" value="0" title="紧急" checked=""> 紧急' + | ||
419 | + '<input type="radio" name="confrimlevel" value="1" title="非常紧急" style="margin-left: 20px;"> 非常紧急' + | ||
420 | + '<input type="radio" name="confrimlevel" value="2" title="不紧急" style="margin-left: 20px;"> 不紧急'); | ||
421 | + }); | ||
422 | + //告警恢复 | ||
423 | + $("#resumeBtn").unbind('click').on("click", function () { | ||
424 | + if ($.inArray('app:alarm:resume', checkList) == -1) { | ||
425 | + layer.msg('暂无权限!', {icon: 7, time: 3000}); | ||
426 | + return; | ||
427 | + } | ||
428 | + var ids = []; | ||
429 | + var closeIds = []; | ||
430 | + var data = table.checkStatus('activewarningTable').data; | ||
431 | + var resumeStatus = true; | ||
432 | + if (data.length == 0) { | ||
433 | + layer.msg('请最少选择一项数据', {icon: 7, time: 2000}); | ||
434 | + return; | ||
435 | + } | ||
436 | + var msg = ""; | ||
437 | + //选中的告警ID放到集合中 | ||
438 | + $.each(data, function (i, obj) { | ||
439 | + var alarmStatus = JSON.stringify(obj.alarmStatus); | ||
440 | + //已关闭的告警才可以恢复,告警状态,0告警,1关闭 | ||
441 | + if (alarmStatus && alarmStatus == '0') { | ||
442 | + resumeStatus = false; | ||
443 | + msg = '只能恢复已关闭状态的告警,请重新选择!'; | ||
444 | + } | ||
445 | + ids.push(obj.id); | ||
446 | + closeIds.push(obj.closeId); | ||
447 | + }); | ||
448 | + if (!resumeStatus) { | ||
449 | + layer.msg(msg, {icon: 7, time: 3000}); | ||
450 | + return; | ||
451 | + } | ||
452 | + layer.prompt({title: '恢复说明(必填)', formType: 2}, function (text, index) { | ||
453 | + admin.req({ | ||
454 | + url: common.domainName + '/api-web/home/alarm/resume' | ||
455 | + , type: "post" | ||
456 | + , data: { | ||
457 | + ids: ids.toString(), | ||
458 | + reason: text, | ||
459 | + closeId: closeIds.toString(), | ||
460 | + resumeType: '0',//0告警关闭,1历史告警 | ||
461 | + access_token: accessToken | ||
462 | + } | ||
463 | + , done: function (res) { | ||
464 | + //如果消除成功,关闭弹出框然后重新加载页面 | ||
465 | + if (res.success) { | ||
466 | + layer.close(index); | ||
467 | + layer.msg('告警已恢复!', {icon: 1, time: 3000}, function () { | ||
468 | + reloadTable(); | ||
469 | + }); | ||
470 | + } else { | ||
471 | + layer.msg('告警恢复失败,请与管理员联系!', {icon: 7, time: 3000}); | ||
472 | + } | ||
473 | + } | ||
474 | + }); | ||
475 | + }) | ||
476 | + }); | ||
477 | + //导出 | ||
478 | + $("#exportAarmBtn").unbind('click').on("click", function () { | ||
479 | + if ($.inArray('app:alarm:export', checkList) == -1) { | ||
480 | + layer.msg('暂无权限!', {icon: 7, time: 3000}); | ||
481 | + return; | ||
482 | + } | ||
483 | + var data = table.checkStatus('activewarningTable').data; | ||
484 | + if (data.length == 0) { | ||
485 | + //确认提示框 | ||
486 | + layer.confirm('当前没选择告警,将全量导出数据,请确认', { | ||
487 | + btn: ['确定', '取消'] //按钮 | ||
488 | + }, function () { | ||
489 | + var url = common.domainName + '/api-web/home/alarm/exportExcel?access_token=' + accessToken; | ||
490 | + window.open(url); | ||
491 | + layer.closeAll(); | ||
492 | + }); | ||
493 | + } else { | ||
494 | + var ids = []; | ||
495 | + //讲选中的告警ID放到集合中 | ||
496 | + $.each(data, function (i, obj) { | ||
497 | + ids.push(obj.id); | ||
498 | + }); | ||
499 | + ids = ids.toString(); | ||
500 | + var url = common.domainName + '/api-web/home/alarm/exportExcel?alarmIds=' + ids + "&access_token=" + accessToken; | ||
501 | + window.open(url) | ||
502 | + } | ||
503 | + }); | ||
504 | + //发送通知 | ||
505 | + $("#sendNoticeBtn").unbind('click').on("click", function () { | ||
506 | + if ($.inArray('app:alarm:sendnotice', checkList) == -1) { | ||
507 | + layer.msg('暂无权限!', {icon: 7, time: 3000}); | ||
508 | + return; | ||
509 | + } | ||
510 | + var ids = []; | ||
511 | + var resIds = []; | ||
512 | + var data = table.checkStatus('activewarningTable').data; | ||
513 | + if (data.length == 0) { | ||
514 | + layer.msg('请最少选择一项数据', {icon: 7, time: 2000}); | ||
515 | + return; | ||
516 | + } | ||
517 | + if (data.length > 1) { | ||
518 | + layer.msg('请最多选择一项数据', {icon: 7, time: 2000}); | ||
519 | + return; | ||
520 | + } | ||
521 | + //将选中的告警ID放到集合中 | ||
522 | + $.each(data, function (i, obj) { | ||
523 | + ids.push(obj.id); | ||
524 | + resIds.push(obj.resId); | ||
525 | + }); | ||
526 | + admin.req({ | ||
527 | + url: common.domainName + '/api-web/home/alarm/subscribe/user/' + resIds.toString() | ||
528 | + , done: function (res) { | ||
529 | + if (res.data && res.data.length > 0) { | ||
530 | + var username = ''; | ||
531 | + var begin = '<div style="padding: 0 5px 0 5px;"><table class="layui-table"><thead>' + | ||
532 | + '<tr><th></th><th>名称</th><th>电话</th><th>邮箱</th></tr></thead><tbody>'; | ||
533 | + var end = '</tbody></table></div>'; | ||
534 | + $.each(res.data, function (i, v) { | ||
535 | + username += '<tr><td><input class="userName" type="checkbox" data-name="' + v.username + '" checked></td><td>' + v.nickname + '</td><td>' + v.phone + '</td><td>' + v.email + '</td></tr>'; | ||
536 | + }); | ||
537 | + //获取告警通知接收人 | ||
538 | + var reciveUsers = begin + username + end; | ||
539 | + layer.open({ | ||
540 | + type: 1 | ||
541 | + , title: "通知接收人" | ||
542 | + , shade: 0.8 | ||
543 | + , area: ['600px', '390px'] | ||
544 | + , id: 'lay_users' //设定一个id,防止重复弹出 | ||
545 | + , content: reciveUsers | ||
546 | + , btn: ['发送', '关闭'] | ||
547 | + , yes: function () { | ||
548 | + var names = []; | ||
549 | + $("input[class='userName']:checked").each(function(i){ | ||
550 | + names.push($(this).attr("data-name")); | ||
551 | + }); | ||
552 | + if(names.length<1){ | ||
553 | + layer.msg('请最少选择一个用户', {icon: 7, time: 2000}); | ||
554 | + return; | ||
555 | + } | ||
556 | + admin.req({ | ||
557 | + url: common.domainName + '/api-web/home/alarm/sendnotice' | ||
558 | + , type: "post" | ||
559 | + , data: { | ||
560 | + ids: ids.toString(), | ||
561 | + names:names.toString(), | ||
562 | + access_token: accessToken | ||
563 | + } | ||
564 | + , done: function (res) { | ||
565 | + layer.closeAll(); | ||
566 | + if (res.success) { | ||
567 | + layer.msg('发送成功', {icon: 1, time: 2000}); | ||
568 | + } else { | ||
569 | + layer.msg('发送失败,稍后再试', {icon: 7, time: 2000}); | ||
570 | + } | ||
571 | + } | ||
572 | + }); | ||
573 | + } | ||
574 | + }); | ||
575 | + } else { | ||
576 | + layer.msg('未获取到接收所选通知的用户!', {icon: 7, time: 2000}); | ||
577 | + } | ||
578 | + } | ||
579 | + }); | ||
580 | + }); | ||
581 | + } | ||
582 | + | ||
583 | + //告警处理及时率 | ||
584 | + getAlarmCount(); | ||
585 | + | ||
586 | + var activeAlarmTable; | ||
587 | + //获取配置的列 | ||
588 | + common.getTableCols({ | ||
589 | + domId: 'activewarningTable', | ||
590 | + moduleId: 'activewarning', | ||
591 | + resType: '' | ||
592 | + },function (retCols) { | ||
593 | + var cols = [ | ||
594 | + {type: 'checkbox', fixed: 'left'} | ||
595 | + , { | ||
596 | + field: 'alarmLevel', title: '级别', align: 'center', width: 120, sort: true, | ||
597 | + templet: ` | ||
598 | + <div> | ||
599 | + {{# if (d.alarmLevel == 3) { | ||
600 | + }} <span class="layui-table-warn" style="width: 100%;">严重</span> {{# | ||
601 | + } else if (d.alarmLevel == 2) { | ||
602 | + }} <span class="layui-table-close" style="width: 100%;">重要</span> {{# | ||
603 | + } else if (d.alarmLevel == 1) { | ||
604 | + }} <span class="layui-table-normal" style="width: 100%;">一般</span> {{# | ||
605 | + } }} | ||
606 | + </div> | ||
607 | + ` | ||
608 | + } | ||
609 | + , { | ||
610 | + field: 'alarmNo', title: '告警编号', align: 'center', width: 140, sort: true, | ||
611 | + } | ||
612 | + , { | ||
613 | + field: 'resName', title: '资源名称', width: 230, sort: true, | ||
614 | + templet:` | ||
615 | + <div> | ||
616 | + {{# if (d.confirmStatus == 0 || d.confirmStatus == null) { }} | ||
617 | + <i lay-tips="新的告警未确认,告警确认后消失!" class="shake iconfont" style="color: red;font-size: 28px;"></i> | ||
618 | + {{# } }} | ||
619 | + <span data-resid="{{d.resId}}" data-restype="{{d.resType}}" data-warn-zymc="{{d.id}}" data-ip="{{d.ip}}" | ||
620 | + data-resname="{{d.resName}}" data-pingenable="{{d.pingEnable}}" class="layui-table-link">{{d.resName}}</span> | ||
621 | + <a class="layui-icon layui-icon-picture reslist-view-topo hide" data-resid="{{d.resId}}" style="color: #FEB61E; font-size: 14px; margin-left: 10px;" lay-tips="查看资源拓扑"></a> | ||
622 | + </div> | ||
623 | + ` | ||
624 | + } | ||
625 | + , { | ||
626 | + field: 'kpiName', title: '指标名称', align: 'center', width: 120, sort: true, | ||
627 | + templet: ` | ||
628 | + <div> | ||
629 | + {{# | ||
630 | + var kpiName = d.kpiName == 'TYPE'?'ERRPT':d.kpiName; | ||
631 | + if (d.kpiIdent != 1) { | ||
632 | + if(d.isWarning != 1) { | ||
633 | + }} <div>{{kpiName}}</div> {{# | ||
634 | + } else { }} | ||
635 | + <div><span data-ident="{{d.kpiIdent}}" data-trend="{{d.isTrend}}" data-warning="{{d.isWarning}}" data-resid="{{d.resId}}" data-flag="{{d.flag}}" data-kpi="{{d.kpiId}}" data-warn-zbmc="{{d.id}}" data-name="{{kpiName}}" class="layui-table-link">{{kpiName}}</span></div> | ||
636 | + {{# } | ||
637 | + } else { }} | ||
638 | + <div><span data-ident="{{d.kpiIdent}}" data-trend="{{d.isTrend}}" data-warning="{{d.isWarning}}" data-resid="{{d.resId}}" data-flag="{{d.flag}}" data-kpi="{{d.kpiId}}" data-warn-zbmc="{{d.id}}" data-name="{{kpiName}}" class="layui-table-link">{{kpiName}}</span></div> | ||
639 | + {{# } | ||
640 | + }} | ||
641 | + </div>` | ||
642 | + } | ||
643 | + , {field: 'alarmContent', title: '告警内容', align: 'center', width: 500} | ||
644 | + , { | ||
645 | + field: 'alarmResource', title: '告警来源', align: 'center', minWidth: 120, templet: `<div> | ||
646 | + {{# if (d.alarmResource == 1) { }} | ||
647 | + <div>华为告警</div> | ||
648 | + {{# } else { }} | ||
649 | + <div>监控系统</div> | ||
650 | + {{# } }} | ||
651 | + </div>` | ||
652 | + } | ||
653 | + , {field: 'updateTime', title: '告警时间', align: 'center', minWidth: 180, sort: true} | ||
654 | + , {field: 'alarmTime', title: '首次告警时间', align: 'center', minWidth: 180, sort: true} | ||
655 | + , {field: 'durationStr', title: '持续时间', align: 'center', width: 190} | ||
656 | + , {field: 'alarmRepeatCnt', title: '告警次数', align: 'center', width: 180} | ||
657 | + , {field: 'nickName', title: '通知人', align: 'center', width: 180} | ||
658 | + , {field: 'adminName', title: '负责人', align: 'center', width: 180} | ||
659 | + , {field: 'noticeTime', title: '通知时间', align: 'center', width: 180, hide: true} | ||
660 | + , { | ||
661 | + title: '操作', align: 'center', minWidth: 100, | ||
662 | + templet: '<div><span data-warn-view="{{d.id}}" class="layui-table-link">查看</span> <span data-warn-path="{{d.id}}" class="layui-table-link">轨迹</span></div>' | ||
663 | + } | ||
664 | + ]; | ||
665 | + | ||
666 | + if (retCols) { | ||
667 | + cols = retCols; | ||
668 | + } | ||
669 | + | ||
670 | + //渲染表格 | ||
671 | + activeAlarmTable = table.render({ | ||
672 | + elem: '#activewarningTable' | ||
673 | + , url: domainName + '/api-web/home/alarm/alarmListPage' | ||
674 | + , id: 'activewarningTable' | ||
675 | + , toolbar: '#activeAlarmtoolbar' //开启头部工具栏,并为其绑定左侧模板 | ||
676 | + , defaultToolbar: ['filter'] | ||
677 | + , where: { | ||
678 | + access_token: accessToken, | ||
679 | + kpiName: $("#activewarningkw").val(), | ||
680 | + busId: bizId, | ||
681 | + resId: resId, | ||
682 | + kpiId: kpiId, | ||
683 | + alarmStatus: $("#alarmStatusSearchBox").val(), | ||
684 | + alarmLevel: alarmLevel, | ||
685 | + confirmStatus: $("#alarmConfirmSearchBox").val(), | ||
686 | + beginTime: $("#activewarningStartdate").val(), | ||
687 | + endTime: $("#activewarningEnddate").val(), | ||
688 | + sortKey: sortKey, | ||
689 | + alarmKpi: $("#alarmKpiSearchBox").val(), | ||
690 | + durationVal: $('#inline-condition-duration input[name="durationVal"]').val(), | ||
691 | + durationUnit: $('#inline-condition-duration select[name="durationUnit"]').val(), | ||
692 | + netFlag: netFlag, | ||
693 | + resType:resType | ||
694 | + } | ||
695 | + , height: 'full-245' | ||
696 | + , cellMinWidth: 80 | ||
697 | + , page: { | ||
698 | + layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'] | ||
699 | + , theme: '#1E9FFF' | ||
700 | + } | ||
701 | + , even: true | ||
702 | + , drag: {toolbar: false} | ||
703 | + , cols: [cols], | ||
704 | + done: function (res, curr, count) { | ||
705 | + soulTable.render(this) | ||
706 | + var groupurl = domainName + '/api-web/home/alarm/countAlarmNumByAlarmLevel?alarmTimeDay=' + todayStr + '&access_token=' + accessToken; | ||
707 | + $.ajax({ | ||
708 | + url: groupurl, | ||
709 | + type: 'get', | ||
710 | + data: { | ||
711 | + access_token: accessToken, | ||
712 | + kpiName: $("#activewarningkw").val(), | ||
713 | + busId: bizId, | ||
714 | + resId: resId, | ||
715 | + kpiId: kpiId, | ||
716 | + alarmStatus: $("#alarmStatusSearchBox").val(), | ||
717 | + alarmLevel: alarmLevel, | ||
718 | + confirmStatus: $("#alarmConfirmSearchBox").val(), | ||
719 | + beginTime: $("#activewarningStartdate").val(), | ||
720 | + endTime: $("#activewarningEnddate").val(), | ||
721 | + sortKey: sortKey, | ||
722 | + alarmKpi: $("#alarmKpiSearchBox").val(), | ||
723 | + durationVal: $('#inline-condition-duration input[name="durationVal"]').val(), | ||
724 | + durationUnit: $('#inline-condition-duration select[name="durationUnit"]').val(), | ||
725 | + netFlag: netFlag, | ||
726 | + resType:resType | ||
727 | + }, | ||
728 | + success: function (res) { | ||
729 | + var map = res.map; | ||
730 | + if (map) { | ||
731 | + layui.use('laytpl', function () { | ||
732 | + var laytpl = layui.laytpl; | ||
733 | + var getTpl = document.getElementById("alarm-count-id-tpl").innerHTML; | ||
734 | + laytpl(getTpl).render(map, function (html) { | ||
735 | + $('#alarm-count-id').html(html); | ||
736 | + }); | ||
737 | + //告警升级量 悬浮提示 | ||
738 | + var alarmUpRate, alarmDealRate; | ||
739 | + $("#alarm_level_up_area_id").hover(function () { | ||
740 | + alarmUpRate = layer.tips("活动告警中升级的告警总量及占比", | ||
741 | + '#alarm_level_up_area_id', {tips: [1]}); | ||
742 | + }, function () { | ||
743 | + layer.close(alarmUpRate); | ||
744 | + }); | ||
745 | + //告警处理及时率 | ||
746 | + $("#alarm_deal_rate_area_id").hover(function () { | ||
747 | + alarmDealRate = layer.tips("活动告警中及时处理的告警量占比", | ||
748 | + '#alarm_deal_rate_area_id', {tips: [1]}); | ||
749 | + }, function () { | ||
750 | + layer.close(alarmDealRate); | ||
751 | + }); | ||
752 | + | ||
753 | + $('[data-warn-zymc]').unbind('click').on('click', function () { | ||
754 | + //先去查找资源有没有权限 | ||
755 | + | ||
756 | + var resId = $(this).data("resid"); | ||
757 | + var resType = $(this).data("restype"); | ||
758 | + var ip = $(this).data("ip") ? $(this).data("ip") : ""; | ||
759 | + var resName = $(this).data("resname"); | ||
760 | + var pingEnable = $(this).data("pingenable"); //获取pingEnable的值 joke add 20200619 | ||
761 | + var resTypeName = ''; | ||
762 | + var adminName = ''; | ||
763 | + var manageIp = ''; | ||
764 | + var collProtocol = ''; | ||
765 | + var sign='false'; | ||
766 | + $.ajax({ | ||
767 | + url: common.domainName + "/api-web/home/resource/findById?resId="+resId + '&access_token='+ accessToken, | ||
768 | + async: false, | ||
769 | + type:'get', | ||
770 | + success: function (res) { | ||
771 | + sign=res.str; | ||
772 | + var data = res.object; | ||
773 | + resType = data.resType; | ||
774 | + adminName = data.adminName; | ||
775 | + manageIp = data.manageIp; | ||
776 | + collProtocol = data.collProtocol; | ||
777 | + resTypeName = data.resTypeName; | ||
778 | + } | ||
779 | + }) | ||
780 | + if(sign=='false'){ | ||
781 | + layer.msg('当前用户暂无此资源权限!', {icon: 7, time: 3000}); | ||
782 | + return false; | ||
783 | + } | ||
784 | + let title = resName; | ||
785 | + if (title && title !== '') { | ||
786 | + title += '|'; | ||
787 | + } | ||
788 | + if (resTypeName && resType !== 'HOST_X86SERVER') { | ||
789 | + title += resTypeName + '|'; | ||
790 | + } | ||
791 | + if (ip) { | ||
792 | + if (resType === 'HOST_X86SERVER') { | ||
793 | + if (collProtocol && (collProtocol.split(",").length > 1 || collProtocol === 'SSH')) { | ||
794 | + title += '应用IP-' + ip + '|'; | ||
795 | + } | ||
796 | + } else { | ||
797 | + title += ip + '|'; | ||
798 | + } | ||
799 | + } | ||
800 | + if (resType === 'HOST_X86SERVER' && collProtocol && collProtocol.indexOf('SNMP') !== -1 ) { | ||
801 | + if (manageIp) { | ||
802 | + title += '管理IP-' + manageIp + '|'; | ||
803 | + } | ||
804 | + } | ||
805 | + if (adminName) { | ||
806 | + title += adminName + '|'; | ||
807 | + } | ||
808 | + if (title.length > 0) { | ||
809 | + title = title.substr(0, title.length - 1); | ||
810 | + } | ||
811 | + if (pingEnable == '2') { //如果pingEnable为2,则进入ping状态详情页面 | ||
812 | + commonDetail.openNewWin('template/detail/pingIndex', title, {'resId': resId}, false); | ||
813 | + } else { //否则进入监控详情页面 | ||
814 | + commonDetail.openDetail(resId, resType, title); | ||
815 | + } | ||
816 | + }); | ||
817 | + | ||
818 | + //指标名称点击事件 | ||
819 | + $('[data-warn-zbmc]').unbind("click").on('click', function () { | ||
820 | + var name = $(this).data("name"); | ||
821 | + var params = { | ||
822 | + resId: $(this).data("resid"), | ||
823 | + kpiId: $(this).data("kpi"), | ||
824 | + flag: $(this).data("flag"), | ||
825 | + name: name, | ||
826 | + warning: $(this).data("warning"), | ||
827 | + ident: $(this).data("ident"), | ||
828 | + trend: $(this).data("trend") | ||
829 | + }; | ||
830 | + common.openLineChart(name, params); | ||
831 | + }); | ||
832 | + | ||
833 | + //告警操作日志 | ||
834 | + $('[data-warn-view]').unbind('click').on('click', function () { | ||
835 | + admin.req({ | ||
836 | + url: common.domainName + '/api-web/home/alarm/info' | ||
837 | + , data: { | ||
838 | + alarmId: $(this).data('warn-view'), | ||
839 | + access_token: accessToken | ||
840 | + } | ||
841 | + }).done(function (res) { | ||
842 | + laytpl($('#warnViewWinTpl').html()).render(res.obj, function (html) { | ||
843 | + layer.open({ | ||
844 | + area: '750px', | ||
845 | + title: ['告警操作信息', 'font-size:18px;'], | ||
846 | + type: 1, | ||
847 | + content: html | ||
848 | + }); | ||
849 | + }); | ||
850 | + }); | ||
851 | + }); | ||
852 | + | ||
853 | + //告警轨迹 | ||
854 | + $('[data-warn-path]').unbind('click').on('click', function () { | ||
855 | + var id = $(this).attr('data-warn-path'); | ||
856 | + var view = layui.view; | ||
857 | + var params = { | ||
858 | + "warnId": id | ||
859 | + }; | ||
860 | + view('commonViewModel').render("template/detail/warn_gj").then(function (res) { | ||
861 | + layer.open({ | ||
862 | + title: ['告警轨迹', 'font-size:18px;'], | ||
863 | + type: 1, | ||
864 | + area: ['900px', '650px'], | ||
865 | + content: laytpl(res.body).render(JSON.stringify(params)) | ||
866 | + }); | ||
867 | + }); | ||
868 | + }); | ||
869 | + | ||
870 | + }); | ||
871 | + //点击严重重要一般统计告警 | ||
872 | + $("#alarm-count-id").find(".warn-count-item").unbind('click').on("click", function () { | ||
873 | + var alarmLevel = $(this).attr("alarm-level"); | ||
874 | + if (alarmLevel != '' && alarmLevel != null && alarmLevel != undefined) { | ||
875 | + $("#alarmLevelSearchBox").val(alarmLevel) | ||
876 | + layui.form.render('select'); | ||
877 | + reloadTable(); | ||
878 | + } else { | ||
879 | + $("#alarmLevelSearchBox").val(""); | ||
880 | + layui.form.render('select'); | ||
881 | + if (alarmLevel === '') { | ||
882 | + reloadTable(); | ||
883 | + } | ||
884 | + } | ||
885 | + }); | ||
886 | + initToolBarClickEvent(); | ||
887 | + //表格排序监听 joke add 20200408 | ||
888 | + table.on('sort(activewarningTable)', function (obj) { | ||
889 | + //有些时候,你可能需要根据当前排序的字段,重新向服务端发送请求,从而实现服务端排序,如: | ||
890 | + if (obj.type != null) { | ||
891 | + sortKey = obj.field + ' ' + obj.type; | ||
892 | + } else { | ||
893 | + sortKey = ''; | ||
894 | + } | ||
895 | + reloadTable('sort'); | ||
896 | + }) | ||
897 | + } | ||
898 | + } | ||
899 | + }) | ||
900 | + | ||
901 | + //触发拖动列事件,参数为保存按钮的id | ||
902 | + common.dragCols("activewarning_cols_save"); | ||
903 | + | ||
904 | + //保存列顺序 | ||
905 | + $("#activewarning_cols_save").unbind("click").on("click", function () { | ||
906 | + var params = { | ||
907 | + domId: 'activewarningTable', | ||
908 | + moduleId: 'activewarning', | ||
909 | + resType: '', | ||
910 | + cols: JSON.stringify(activeAlarmTable.config.cols) | ||
911 | + } | ||
912 | + common.saveTableCols(params); | ||
913 | + }); | ||
914 | + resTopo(); | ||
915 | + } | ||
916 | + }); | ||
917 | + }); | ||
918 | + | ||
919 | + //绑定下拉搜索事件 | ||
920 | + function bindSelectEvent() { | ||
921 | + //选择业务搜索 | ||
922 | + form.on('select(bisTypeSearch)', function (data) { | ||
923 | + bizId = data.value; | ||
924 | + reloadTable(); | ||
925 | + }); | ||
926 | + //选择业务搜索 | ||
927 | + form.on('select(alarmKpiSearch)', function (data) { | ||
928 | + reloadTable(); | ||
929 | + }); | ||
930 | + // 告警状态 | ||
931 | + form.on('select(alarmStatusSearch)', function (data) { | ||
932 | + reloadTable(); | ||
933 | + }); | ||
934 | + //告警级别 | ||
935 | + form.on('select(alarmLevelSearch)', function (data) { | ||
936 | + reloadTable(); | ||
937 | + }); | ||
938 | + // 告警确认 | ||
939 | + form.on('select(alarmConfirmSearch)', function (data) { | ||
940 | + reloadTable(); | ||
941 | + }); | ||
942 | + } | ||
943 | + | ||
944 | + $("#todayOrAllBtn").unbind().on("click",function () { | ||
945 | + var $that = $(this); | ||
946 | + var str = $(this).text(); | ||
947 | + if(str.indexOf("今日") > -1){ | ||
948 | + $that.text("全部告警") | ||
949 | + todayStr = common.getToday('day'); | ||
950 | + }else{ | ||
951 | + todayStr = '' | ||
952 | + $that.text("今日告警") | ||
953 | + } | ||
954 | + reloadTable(); | ||
955 | + }) | ||
956 | + | ||
957 | + | ||
958 | + //刷新表格 | ||
959 | + function reloadTable(type) { | ||
960 | + if (type != 'sort'){ | ||
961 | + sortKey = ''; | ||
962 | + } | ||
963 | + activeAlarmTable.reload({ | ||
964 | + page: { | ||
965 | + curr: 1 | ||
966 | + } | ||
967 | + ,where: { | ||
968 | + access_token: accessToken, | ||
969 | + kpiName: $("#activewarningkw").val(), | ||
970 | + busId: bizId, | ||
971 | + resId: resId, | ||
972 | + kpiId: kpiId, | ||
973 | + alarmStatus: $("#alarmStatusSearchBox").val(), | ||
974 | + alarmLevel: $("#alarmLevelSearchBox").val(), | ||
975 | + confirmStatus: $("#alarmConfirmSearchBox").val(), | ||
976 | + beginTime: $("#activewarningStartdate").val(), | ||
977 | + endTime: $("#activewarningEnddate").val(), | ||
978 | + sortKey: sortKey, | ||
979 | + alarmKpi: $("#alarmKpiSearchBox").val(), | ||
980 | + durationVal: $('#inline-condition-duration input[name="durationVal"]').val(), | ||
981 | + durationUnit: $('#inline-condition-duration select[name="durationUnit"]').val(), | ||
982 | + alarmTimeDay:todayStr, | ||
983 | + resType:resType | ||
984 | + } | ||
985 | + }); | ||
986 | + } | ||
987 | + | ||
988 | + //获取告警统计信息 | ||
989 | + function getAlarmCount() { | ||
990 | + admin.req({ | ||
991 | + url: common.domainName + "/api-web/home/alarm/countByAlarmLevel" | ||
992 | + , type: "get" | ||
993 | + , done: function (data) { | ||
994 | + var alarms = data.data; | ||
995 | + if (data.code == 0) { | ||
996 | + $.each(alarms, function (i, v) { | ||
997 | + if (v.alarmLevel == 5) {//及时率 | ||
998 | + $("#alarm_dealRate").html(v.alarmNum + "%"); | ||
999 | + } | ||
1000 | + }); | ||
1001 | + } else { | ||
1002 | + console.error("接口请求失败") | ||
1003 | + console.log(data.msg); | ||
1004 | + } | ||
1005 | + } | ||
1006 | + }) | ||
1007 | + } | ||
1008 | + | ||
1009 | + form.render(null, 'activewarning-form'); | ||
1010 | + //60秒倒计时 | ||
1011 | + (function () { | ||
1012 | + var autoBtn = $('#activewarningAutoFlush'); | ||
1013 | + var timer = null; | ||
1014 | + | ||
1015 | + function autoFlush(target) { | ||
1016 | + var el = target.find('span'); | ||
1017 | + var checked = target.find('input').prop('checked'); | ||
1018 | + localStorage.setItem('alarm_auto__flush', checked); | ||
1019 | + function fn() { | ||
1020 | + var second = el.data('second'); | ||
1021 | + var checked = target.find('input').prop('checked'); | ||
1022 | + if (!checked) { | ||
1023 | + return; | ||
1024 | + } | ||
1025 | + --second; | ||
1026 | + el.data('second', second); | ||
1027 | + el.html(second + '秒'); | ||
1028 | + | ||
1029 | + timer = setTimeout(fn, 1000); | ||
1030 | + if (second <= 0) { | ||
1031 | + clearTimeout(timer); | ||
1032 | + reloadTable() | ||
1033 | + $(el).data('second', 60); | ||
1034 | + $(el).text("60秒"); | ||
1035 | + fn(); | ||
1036 | + } | ||
1037 | + } | ||
1038 | + if (checked) { | ||
1039 | + timer = setTimeout(fn, 1000); | ||
1040 | + } else { | ||
1041 | + clearTimeout(timer); | ||
1042 | + } | ||
1043 | + } | ||
1044 | + form.on("checkbox(warnActiveAutoFlush)",function (data) { | ||
1045 | + autoFlush(autoBtn); | ||
1046 | + }) | ||
1047 | + /*autoBtn.change(function () { | ||
1048 | + autoFlush(autoBtn); | ||
1049 | + });*/ | ||
1050 | + var auto = localStorage.getItem('alarm_auto__flush') | ||
1051 | + auto = auto ? auto : false; | ||
1052 | + autoBtn.find('input').prop('checked', auto); | ||
1053 | + | ||
1054 | + autoFlush(autoBtn); | ||
1055 | + | ||
1056 | + admin.on('hash(*)', function (router) { | ||
1057 | + if (router.href === '/activewarning') { | ||
1058 | + autoFlush(autoBtn); | ||
1059 | + } else { | ||
1060 | + clearTimeout(timer); | ||
1061 | + } | ||
1062 | + }); | ||
1063 | + })(); | ||
1064 | + | ||
1065 | + function resTopo() { | ||
1066 | + | ||
1067 | + //绑定鼠标移入移出事件 | ||
1068 | + $('table tr').hover(function (obj) { | ||
1069 | + $(obj.currentTarget).find('.reslist-view-topo').removeClass('hide'); | ||
1070 | + }, function (obj) { | ||
1071 | + $(obj.currentTarget).find('.reslist-view-topo').addClass('hide'); | ||
1072 | + }) | ||
1073 | + | ||
1074 | + // 加入/移出收藏夹 | ||
1075 | + $('a.reslist-view-topo').unbind('click').on('click', function () { | ||
1076 | + common.viewResTopo($(this).data('resid')); | ||
1077 | + }); | ||
1078 | + | ||
1079 | + } | ||
1080 | + }); | ||
1081 | +}); |
1 | +layui.define(['table', 'form', 'laydate', 'admin', 'layer', 'laytpl', 'common', 'sessions',"commonDetail",'soulTable'], function (exports) { | ||
2 | + var $ = layui.$; | ||
3 | + var form = layui.form; | ||
4 | + var layer = layui.layer; | ||
5 | + var admin = layui.admin; | ||
6 | + var table = layui.table; | ||
7 | + var laydate = layui.laydate; | ||
8 | + var laytpl = layui.laytpl; | ||
9 | + var common = layui.common; | ||
10 | + var commonDetail = layui.commonDetail; | ||
11 | + var domainName = common.domainName; | ||
12 | + var soulTable = layui.soulTable; | ||
13 | + //对外暴露的接口 | ||
14 | + exports('historywarning', function () { | ||
15 | + var sessions = layui.sessions; | ||
16 | + var router = layui.router(); | ||
17 | + var accessToken = sessions.getToken()['access_token']; | ||
18 | + var sortKey = ''; | ||
19 | + var checkList = common.checkPermission(accessToken); | ||
20 | + var alarmNo = router.search.alarmNo;//告警编号 | ||
21 | + var bizId='';//业务Id | ||
22 | + var busIdSelect; | ||
23 | + var busTypeList = []; | ||
24 | + | ||
25 | + if (alarmNo) { | ||
26 | + $("#historywarningkw").val(alarmNo); | ||
27 | + } | ||
28 | + | ||
29 | + function initDate() { | ||
30 | + var start = laydate.render({ | ||
31 | + elem: '#historywarningStartdate' | ||
32 | + , trigger: 'click' | ||
33 | + , done: function (value, date) { | ||
34 | + date.month--; | ||
35 | + end.config.min = date; | ||
36 | + var endDate = $("#historywarningEnddate").val(); | ||
37 | + if (endDate != null && endDate != "") { | ||
38 | + reloadTable(); | ||
39 | + } | ||
40 | + } | ||
41 | + }); | ||
42 | + | ||
43 | + var end = laydate.render({ | ||
44 | + elem: '#historywarningEnddate' | ||
45 | + , trigger: 'click' | ||
46 | + , done: function (value, date) { | ||
47 | + date.month--; | ||
48 | + start.config.max = date; | ||
49 | + var benginDate = $("#historywarningStartdate").val(); | ||
50 | + if (benginDate != null && benginDate != "") { | ||
51 | + reloadTable(); | ||
52 | + } | ||
53 | + } | ||
54 | + }); | ||
55 | + | ||
56 | + //绑定业务下拉选择数据 | ||
57 | + admin.req({ | ||
58 | + url: domainName + '/api-web/home/business/findUserBusTypeAll?table=b_alarm_his', | ||
59 | + success: function (response) { | ||
60 | + if (response && response.success) { | ||
61 | + busTypeList = response.data; | ||
62 | + var bizList = response.data.map(item => { | ||
63 | + return { | ||
64 | + name: item.busTypeName, | ||
65 | + value: item.busId, | ||
66 | + parentId: item.parentId | ||
67 | + } | ||
68 | + }); | ||
69 | + var bizTree=common.pidToChildren(bizList, 'value', 'parentId'); | ||
70 | + // 影响业务下拉框 | ||
71 | + busIdSelect = xmSelect.render({ | ||
72 | + el: '#historyBisTypeSearchBox', | ||
73 | + name: 'bizId', | ||
74 | + tips: '=所属业务=', | ||
75 | + //开启搜索 | ||
76 | + filterable: true, | ||
77 | + clickClose: true, | ||
78 | + initValue: [bizId.split(',')[0]], | ||
79 | + toolbar: { | ||
80 | + show: true, | ||
81 | + list: ['ALL', 'REVERSE', 'CLEAR'] | ||
82 | + }, | ||
83 | + height: '170px', | ||
84 | + tree: { | ||
85 | + show: true, | ||
86 | + showFolderIcon: true, | ||
87 | + showLine: true, | ||
88 | + strict: true, | ||
89 | + //间距 | ||
90 | + indent: 20, | ||
91 | + }, | ||
92 | + model: { | ||
93 | + label: { | ||
94 | + type: 'text' | ||
95 | + } | ||
96 | + }, | ||
97 | + data: bizTree, | ||
98 | + on: function (data) { | ||
99 | + if (data.arr.length != 0) { | ||
100 | + var str=''; | ||
101 | + $.each(data.arr,function (i,v) { | ||
102 | + str+=v.value+','; | ||
103 | + }) | ||
104 | + bizId = str.substring(0,str.length-1); | ||
105 | + } else { | ||
106 | + bizId = ''; | ||
107 | + } | ||
108 | + form.render(); | ||
109 | + reloadTable(); | ||
110 | + } | ||
111 | + }); | ||
112 | + if(busIdSelect){ | ||
113 | + //追加样式 | ||
114 | + $('#historyBisTypeSearchBox').find('.xm-body').eq(0).css("width","230px"); | ||
115 | + } | ||
116 | + } else { | ||
117 | + layer.msg('获取业务失败', {icon: 2}); | ||
118 | + } | ||
119 | + }, | ||
120 | + error: function () { | ||
121 | + layer.msg('获取业务失败', {icon: 2}); | ||
122 | + } | ||
123 | + }); | ||
124 | + $.ajax({ | ||
125 | + url: common.domainName + '/api-web/manage/kpi/findKpiInAlarm?access_token='+accessToken+'&tableName=b_alarm_his', | ||
126 | + type: "get", | ||
127 | + success:function (res) { | ||
128 | + var kpis = res.data; | ||
129 | + var html = '<option value="">=指标名称=</option>' | ||
130 | + $.each(kpis,function (i,e) { | ||
131 | + html+='<option value="'+e.kpiId+'">'+e.kpiName+'</option>' | ||
132 | + }) | ||
133 | + $("#alarmKpiHisSearchBox").html(''); | ||
134 | + $("#alarmKpiHisSearchBox").append(html); | ||
135 | + form.render(); | ||
136 | + } | ||
137 | + }) | ||
138 | + } | ||
139 | + | ||
140 | + | ||
141 | + | ||
142 | + //回车事件 | ||
143 | + $('#historywarningkw, input[name="durationVal"]').keydown(function (e) { | ||
144 | + if (e.keyCode === 13) { | ||
145 | + reloadTable(); | ||
146 | + } | ||
147 | + }); | ||
148 | + | ||
149 | + //选择框搜索事件 | ||
150 | + bindSelectEvent(); | ||
151 | + | ||
152 | + initDate(); | ||
153 | + | ||
154 | + function initHistoryBtnCLick() { | ||
155 | + //告警恢复 | ||
156 | + $("#historyResumeBtn").unbind("click").on("click", function () { | ||
157 | + if ($.inArray('app:alarm:resume', checkList) == -1) { | ||
158 | + layer.msg('暂无权限!', {icon: 7, time: 3000}); | ||
159 | + return; | ||
160 | + } | ||
161 | + var ids = []; | ||
162 | + var closeIds = []; | ||
163 | + var data = table.checkStatus('historywarningTable').data; | ||
164 | + var resumeStatus = true; | ||
165 | + if (data.length == 0) { | ||
166 | + layer.msg('请最少选择一项数据', {icon: 7, time: 2000}); | ||
167 | + return; | ||
168 | + } | ||
169 | + var msg = ""; | ||
170 | + //选中的告警ID放到集合中 | ||
171 | + $.each(data, function (i, obj) { | ||
172 | + ids.push(obj.id); | ||
173 | + closeIds.push(obj.closeId); | ||
174 | + }); | ||
175 | + if (!resumeStatus) { | ||
176 | + layer.msg(msg, {icon: 7, time: 3000}); | ||
177 | + return; | ||
178 | + } | ||
179 | + layer.prompt({title: '恢复说明(必填)', formType: 2}, function (text, index) { | ||
180 | + admin.req({ | ||
181 | + url: common.domainName + '/api-web/home/alarm/resume' | ||
182 | + , type: "post" | ||
183 | + , data: { | ||
184 | + ids: ids.toString(), | ||
185 | + reason: text, | ||
186 | + closeId: closeIds.toString(), | ||
187 | + resumeType: '1',//0告警关闭,1历史告警 | ||
188 | + access_token: accessToken | ||
189 | + } | ||
190 | + , done: function (res) { | ||
191 | + //如果消除成功,关闭弹出框然后重新加载页面 | ||
192 | + if (res.success) { | ||
193 | + layer.close(index); | ||
194 | + layer.msg('告警已恢复!', {icon: 1, time: 3000}, function () { | ||
195 | + reloadTable(); | ||
196 | + }); | ||
197 | + } else { | ||
198 | + layer.msg('告警恢复失败,请与管理员联系!', {icon: 7, time: 3000}); | ||
199 | + } | ||
200 | + } | ||
201 | + }); | ||
202 | + }) | ||
203 | + }); | ||
204 | + } | ||
205 | + | ||
206 | + //渲染表格 | ||
207 | + var historywarningTable; | ||
208 | + //获取配置的列 | ||
209 | + common.getTableCols({ | ||
210 | + domId: 'historywarningTable', | ||
211 | + moduleId: 'historywarning', | ||
212 | + resType: '' | ||
213 | + }, function (retCols) { | ||
214 | + var cols; | ||
215 | + if (retCols) { | ||
216 | + cols = retCols; | ||
217 | + } else { | ||
218 | + cols = [ | ||
219 | + {type: 'checkbox', fixed: 'left'} | ||
220 | + , { | ||
221 | + field: 'alarmLevel', title: '级别', align: 'center', width: 120, sort: true, | ||
222 | + templet: `<div> | ||
223 | + {{# if (d.alarmLevel == 3) { }} | ||
224 | + <span class="layui-table-warn" style="width: 100%;">严重</span> | ||
225 | + {{# } else if (d.alarmLevel == 2) { }} | ||
226 | + <span class="layui-table-close" style="width: 100%;">重要</span> | ||
227 | + {{# } else if (d.alarmLevel == 1) { }} | ||
228 | + <span class="layui-table-normal" style="width: 100%;">一般</span> | ||
229 | + {{# } }} | ||
230 | + </div>` | ||
231 | + } | ||
232 | + , { | ||
233 | + field: 'alarmNo', title: '告警编号', align: 'center', width: 140, sort: true, | ||
234 | + } | ||
235 | + , { | ||
236 | + field: 'resName', title: '资源名称', width: 230, sort: true, | ||
237 | + templet: '<div><span data-hiswarn-zymc="{{d.id}}" data-resid="{{d.resId}}" data-restype="{{d.resType}}" data-ip="{{d.ip}}" data-resname="{{d.resName}}" class="layui-table-link">{{d.resName}}</span></div>' | ||
238 | + } | ||
239 | + , { | ||
240 | + field: 'kpiName', title: '指标名称', align: 'center', width: 150, sort: true, | ||
241 | + templet: '#historywarngingKpiNameTpl' | ||
242 | + } | ||
243 | + , {field: 'alarmContent', title: '告警内容', align: 'center', width: 500} | ||
244 | + , { | ||
245 | + field: 'alarmResource', title: '告警来源', align: 'center', minWidth: 100, templet: `<div> | ||
246 | + {{# if (d.alarmResource == 1) { }} | ||
247 | + <div>华为告警</div> | ||
248 | + {{# } else { }} | ||
249 | + <div>监控系统</div> | ||
250 | + {{# } }} | ||
251 | + </div>` | ||
252 | + } | ||
253 | + , {field: 'updateTime', title: '告警时间', align: 'center', minWidth: 180, sort: true} | ||
254 | + , {field: 'alarmTime', title: '首次告警时间', align: 'center', minWidth: 180, sort: true} | ||
255 | + , {field: 'durationStr', title: '持续时间', align: 'center', width: 190} | ||
256 | + , { | ||
257 | + title: '操作', align: 'center', minWidth: 100, | ||
258 | + templet: '<div><span history-data-warn-view="{{d.id}}" class="layui-table-link">查看</span> <span history-data-warn-path="{{d.id}}" class="layui-table-link">轨迹</span></div>' | ||
259 | + } | ||
260 | + ]; | ||
261 | + } | ||
262 | + | ||
263 | + historywarningTable = table.render({ | ||
264 | + elem: '#historywarningTable' | ||
265 | + , url: domainName + '/api-web/home/alarm/alarmListPage' | ||
266 | + , toolbar: '#hisAlarmtoolbar' //开启头部工具栏,并为其绑定左侧模板 | ||
267 | + , defaultToolbar: ['filter'] | ||
268 | + , where: { | ||
269 | + access_token: accessToken, | ||
270 | + hisFlag: true, | ||
271 | + kpiName: $("#historywarningkw").val(), | ||
272 | + busId: bizId, | ||
273 | + alarmStatus: $("#historyAlarmStatusSearchBox").val(), | ||
274 | + alarmLevel: $("#historyAlarmLevelSearchBox").val(), | ||
275 | + confirmStatus: $("#historyAlarmConfirmSearchBox").val(), | ||
276 | + beginTime: $("#historywarningStartdate").val(), | ||
277 | + endTime: $("#historywarningEnddate").val(), | ||
278 | + durationVal: $('#his_inline-condition-duration input[name="durationVal"]').val(), | ||
279 | + durationUnit: $('#his_inline-condition-duration select[name="durationUnit"]').val(), | ||
280 | + sortKey: sortKey, | ||
281 | + alarmKpi: $("#alarmKpiHisSearchBox").val(), | ||
282 | + } | ||
283 | + , height: 'full-245' | ||
284 | + , cellMinWidth: 80 | ||
285 | + , page: { | ||
286 | + layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'] | ||
287 | + , theme: '#1E9FFF' | ||
288 | + } | ||
289 | + , even: true | ||
290 | + , drag: {toolbar: false} | ||
291 | + , cols: [cols], | ||
292 | + done: function (res, curr, count) { | ||
293 | + soulTable.render(this) | ||
294 | + initHistoryBtnCLick(); | ||
295 | + var groupurl = domainName + '/api-web/home/alarm/countAlarmNumByAlarmLevel?access_token=' + accessToken; | ||
296 | + $.ajax({ | ||
297 | + url: groupurl, | ||
298 | + type: 'get', | ||
299 | + data: { | ||
300 | + access_token: accessToken, | ||
301 | + hisFlag: true, | ||
302 | + kpiName: $("#historywarningkw").val(), | ||
303 | + busId: bizId, | ||
304 | + alarmStatus: $("#historyAlarmStatusSearchBox").val(), | ||
305 | + alarmLevel: '', | ||
306 | + confirmStatus: $("#historyAlarmConfirmSearchBox").val(), | ||
307 | + beginTime: $("#historywarningStartdate").val(), | ||
308 | + endTime: $("#historywarningEnddate").val(), | ||
309 | + durationVal: $('#his_inline-condition-duration input[name="durationVal"]').val(), | ||
310 | + durationUnit: $('#his_inline-condition-duration select[name="durationUnit"]').val(), | ||
311 | + sortKey: sortKey, | ||
312 | + alarmKpi: $("#alarmKpiHisSearchBox").val(), | ||
313 | + }, | ||
314 | + success: function (res) { | ||
315 | + var map = res.map; | ||
316 | + if (!isEmptyObject(map)) { | ||
317 | + layui.use('laytpl', function () { | ||
318 | + var laytpl = layui.laytpl; | ||
319 | + var getTpl = document.getElementById("his-alarm-count-id-tpl").innerHTML; | ||
320 | + laytpl(getTpl).render(map, function (html) { | ||
321 | + $('#his-alarm-count-id').html(html); | ||
322 | + }); | ||
323 | + }); | ||
324 | + } | ||
325 | + //告警操作日志 | ||
326 | + $('[history-data-warn-view]').unbind("click").on('click', function () { | ||
327 | + admin.req({ | ||
328 | + url: common.domainName + '/api-web/home/alarm/info' | ||
329 | + , data: { | ||
330 | + alarmId: $(this).attr('history-data-warn-view'), | ||
331 | + access_token: accessToken | ||
332 | + } | ||
333 | + }).done(function (res) { | ||
334 | + laytpl($('#warnViewWinTpl').html()).render(res.obj, function (html) { | ||
335 | + layer.open({ | ||
336 | + area: ['80%', '90%'], | ||
337 | + title: ['告警操作信息', 'font-size:18px;'], | ||
338 | + type: 1, | ||
339 | + content: html | ||
340 | + }); | ||
341 | + }); | ||
342 | + }); | ||
343 | + }); | ||
344 | + //告警轨迹 | ||
345 | + $('[history-data-warn-path]').unbind("click").on('click', function () { | ||
346 | + var id = $(this).attr('history-data-warn-path'); | ||
347 | + var view = layui.view; | ||
348 | + var params = { | ||
349 | + "warnId": id | ||
350 | + }; | ||
351 | + view('commonViewModel').render("template/detail/warn_gj").then(function (res) { | ||
352 | + layer.open({ | ||
353 | + title: ['告警轨迹', 'font-size:18px;'], | ||
354 | + type: 1, | ||
355 | + area: ['80%', '90%'], | ||
356 | + content: laytpl(res.body).render(JSON.stringify(params)) | ||
357 | + }); | ||
358 | + }); | ||
359 | + }); | ||
360 | + //资源名称,查看详细 | ||
361 | + $('[data-hiswarn-zymc]').unbind("click").on('click', function () { | ||
362 | + var resId = $(this).data("resid"); | ||
363 | + var resType = $(this).data("restype"); | ||
364 | + var ip = $(this).data("ip") ? $(this).data("ip") : ""; | ||
365 | + var resName = $(this).data("resname"); | ||
366 | + var pingEnable = $(this).data("pingenable"); //获取pingEnable的值 joke add 20200619 | ||
367 | + var resTypeName = ''; | ||
368 | + var adminName = ''; | ||
369 | + var manageIp = ''; | ||
370 | + var collProtocol = ''; | ||
371 | + var sign='false'; | ||
372 | + $.ajax({ | ||
373 | + url: common.domainName + "/api-web/home/resource/findById?resId="+resId + '&access_token='+ accessToken, | ||
374 | + async: false, | ||
375 | + type:'get', | ||
376 | + success: function (res) { | ||
377 | + sign=res.str; | ||
378 | + var data = res.object; | ||
379 | + resType = data.resType; | ||
380 | + adminName = data.adminName; | ||
381 | + manageIp = data.manageIp; | ||
382 | + collProtocol = data.collProtocol; | ||
383 | + resTypeName = data.resTypeName; | ||
384 | + } | ||
385 | + }) | ||
386 | + if(sign=='false'){ | ||
387 | + layer.msg('当前用户暂无此资源权限!', {icon: 7, time: 3000}); | ||
388 | + return false; | ||
389 | + } | ||
390 | + let title = resName; | ||
391 | + if (title && title !== '') { | ||
392 | + title += '|'; | ||
393 | + } | ||
394 | + if (resTypeName && resType !== 'HOST_X86SERVER') { | ||
395 | + title += resTypeName + '|'; | ||
396 | + } | ||
397 | + if (ip) { | ||
398 | + if (resType === 'HOST_X86SERVER') { | ||
399 | + if (collProtocol && (collProtocol.split(",").length > 1 || collProtocol === 'SSH')) { | ||
400 | + title += '应用IP-' + ip + '|'; | ||
401 | + } | ||
402 | + } else { | ||
403 | + title += ip + '|'; | ||
404 | + } | ||
405 | + } | ||
406 | + if (resType === 'HOST_X86SERVER' && collProtocol && collProtocol.indexOf('SNMP') !== -1 ) { | ||
407 | + if (manageIp) { | ||
408 | + title += '管理IP-' + manageIp + '|'; | ||
409 | + } | ||
410 | + } | ||
411 | + if (adminName) { | ||
412 | + title += adminName + '|'; | ||
413 | + } | ||
414 | + if (title.length > 0) { | ||
415 | + title = title.substr(0, title.length - 1); | ||
416 | + } | ||
417 | + if (pingEnable == '2') { //如果pingEnable为2,则进入ping状态详情页面 | ||
418 | + commonDetail.openNewWin('template/detail/pingIndex', title, {'resId': resId}, false); | ||
419 | + } else { //否则进入监控详情页面 | ||
420 | + commonDetail.openDetail(resId, resType, title); | ||
421 | + } | ||
422 | + }); | ||
423 | + //指标性能曲线图 | ||
424 | + $(' [data-warn-zbmc]').unbind("click").on('click', function () { | ||
425 | + var name = $(this).data("name"); | ||
426 | + var params = { | ||
427 | + resId: $(this).data("resid"), | ||
428 | + kpiId: $(this).data("kpi"), | ||
429 | + flag: $(this).data("flag"), | ||
430 | + name: name, | ||
431 | + warning: $(this).data("warning"), | ||
432 | + ident: $(this).data("ident"), | ||
433 | + trend: $(this).data("trend") | ||
434 | + }; | ||
435 | + common.openLineChart(name, params); | ||
436 | + }); | ||
437 | + //表格排序监听 joke add 20200408 | ||
438 | + table.on('sort(historywarningTable)', function (obj) { | ||
439 | + //有些时候,你可能需要根据当前排序的字段,重新向服务端发送请求,从而实现服务端排序,如: | ||
440 | + if (obj.type != null) { | ||
441 | + sortKey = obj.field + ' ' + obj.type; | ||
442 | + } else { | ||
443 | + sortKey = ''; | ||
444 | + } | ||
445 | + reloadTable('sort'); | ||
446 | + }) | ||
447 | + //点击严重重要一般统计告警 | ||
448 | + $("#his-alarm-count-id").find(".warn-count-item").unbind("click").on("click", function () { | ||
449 | + var alarmLevel = $(this).attr("alarm-level"); | ||
450 | + if (alarmLevel != '' && alarmLevel != null && alarmLevel != undefined) { | ||
451 | + $("#historyAlarmLevelSearchBox").val(alarmLevel) | ||
452 | + layui.form.render('select'); | ||
453 | + reloadTable(); | ||
454 | + } else { | ||
455 | + $("#historyAlarmLevelSearchBox").val(""); | ||
456 | + layui.form.render('select'); | ||
457 | + reloadTable(); | ||
458 | + } | ||
459 | + }); | ||
460 | + } | ||
461 | + }); | ||
462 | + //触发拖动列事件,参数为保存按钮的id | ||
463 | + common.dragCols("historywarning_cols_save"); | ||
464 | + | ||
465 | + //保存列顺序 | ||
466 | + $("#historywarning_cols_save").unbind("click").on("click", function () { | ||
467 | + var params = { | ||
468 | + domId: 'historywarningTable', | ||
469 | + moduleId: 'historywarning', | ||
470 | + resType: '', | ||
471 | + cols: JSON.stringify(historywarningTable.config.cols) | ||
472 | + } | ||
473 | + common.saveTableCols(params); | ||
474 | + }); | ||
475 | + } | ||
476 | + }); | ||
477 | + }); | ||
478 | + function isEmptyObject(e) { | ||
479 | + var t; | ||
480 | + for (t in e) | ||
481 | + return !1; | ||
482 | + return !0 | ||
483 | + } | ||
484 | + | ||
485 | + | ||
486 | + //绑定下拉搜索事件 | ||
487 | + function bindSelectEvent() { | ||
488 | + form.on('select(alarmKpiHisSearch)', function (data) { | ||
489 | + reloadTable(); | ||
490 | + }); | ||
491 | + // 告警状态 | ||
492 | + form.on('select(historyAlarmStatusSearch)', function (data) { | ||
493 | + reloadTable(); | ||
494 | + }); | ||
495 | + //告警级别 | ||
496 | + form.on('select(historyAlarmLevelSearch)', function (data) { | ||
497 | + reloadTable(); | ||
498 | + }); | ||
499 | + // 告警确认 | ||
500 | + form.on('select(historyAlarmConfirmSearch)', function (data) { | ||
501 | + reloadTable(); | ||
502 | + }); | ||
503 | + } | ||
504 | + | ||
505 | + //刷新表格 | ||
506 | + function reloadTable(type) { | ||
507 | + if (type != 'sort'){ | ||
508 | + sortKey = ''; | ||
509 | + } | ||
510 | + historywarningTable.reload({ | ||
511 | + page: { | ||
512 | + curr: 1 | ||
513 | + } | ||
514 | + ,where: { | ||
515 | + access_token: accessToken, | ||
516 | + kpiName: $("#historywarningkw").val(), | ||
517 | + busId: bizId, | ||
518 | + alarmStatus: $("#historyAlarmStatusSearchBox").val(), | ||
519 | + alarmLevel: $("#historyAlarmLevelSearchBox").val(), | ||
520 | + confirmStatus: $("#historyAlarmConfirmSearchBox").val(), | ||
521 | + beginTime: $("#historywarningStartdate").val(), | ||
522 | + endTime: $("#historywarningEnddate").val(), | ||
523 | + durationVal: $('#his_inline-condition-duration input[name="durationVal"]').val(), | ||
524 | + durationUnit: $('#his_inline-condition-duration select[name="durationUnit"]').val(), | ||
525 | + sortKey: sortKey, | ||
526 | + alarmKpi: $("#alarmKpiHisSearchBox").val(), | ||
527 | + } | ||
528 | + }); | ||
529 | + } | ||
530 | + | ||
531 | + /* //获取告警统计信息 | ||
532 | + function getAlarmCount() { | ||
533 | + admin.req({ | ||
534 | + url: common.domainName + "/api-web/home/alarm/countByAlarmLevel?hisFlag=true" | ||
535 | + , type: "get" | ||
536 | + , done: function (data) { | ||
537 | + var alarms = data.data; | ||
538 | + if (data.code === 0) { | ||
539 | + let total = 0; | ||
540 | + $.each(alarms,function (i,v) { | ||
541 | + if(v.alarmLevel<4){ | ||
542 | + total+=v.alarmNum; | ||
543 | + } | ||
544 | + if(v.alarmLevel == 3){//严重告警 | ||
545 | + $("#history_alarm_serious").text(v.alarmNum); | ||
546 | + } | ||
547 | + if(v.alarmLevel == 2){//重要告警 | ||
548 | + $("#history_alarm_important").text(v.alarmNum); | ||
549 | + } | ||
550 | + if(v.alarmLevel == 1){//一般告警 | ||
551 | + $("#history_alarm_commonly").text(v.alarmNum); | ||
552 | + } | ||
553 | + }); | ||
554 | + $("#history_alarm_total").text(total); | ||
555 | + } else { | ||
556 | + console.log(data.msg); | ||
557 | + } | ||
558 | + } | ||
559 | + }); | ||
560 | + }*/ | ||
561 | + | ||
562 | + | ||
563 | + form.render(null, 'historywarning-form'); | ||
564 | + | ||
565 | + (function () { | ||
566 | + var autoBtn = $('#historywarningAutoFlush'); | ||
567 | + var timer = null; | ||
568 | + | ||
569 | + function autoFlush(target) { | ||
570 | + var el = target.find('span'); | ||
571 | + var checked = target.find('input').prop('checked'); | ||
572 | + localStorage.setItem('auto__flush', checked); | ||
573 | + | ||
574 | + function fn() { | ||
575 | + var second = el.data('second'); | ||
576 | + var checked = target.find('input').prop('checked'); | ||
577 | + if (!checked) { | ||
578 | + return; | ||
579 | + } | ||
580 | + --second; | ||
581 | + el.data('second', second); | ||
582 | + el.html(second + '秒'); | ||
583 | + | ||
584 | + timer = setTimeout(fn, 1000); | ||
585 | + if (second <= 0) { | ||
586 | + clearTimeout(timer); | ||
587 | + reloadTable() | ||
588 | + $(el).data('second', 60); | ||
589 | + $(el).text("60秒") | ||
590 | + fn(); | ||
591 | + //layui.index.render(); | ||
592 | + } | ||
593 | + } | ||
594 | + | ||
595 | + if (checked) { | ||
596 | + timer = setTimeout(fn, 1000); | ||
597 | + } else { | ||
598 | + clearTimeout(timer); | ||
599 | + } | ||
600 | + } | ||
601 | + | ||
602 | + /*autoBtn.change(function () { | ||
603 | + autoFlush(autoBtn); | ||
604 | + });*/ | ||
605 | + form.on("checkbox(hisWarnActiveAutoFlush)",function (data) { | ||
606 | + autoFlush(autoBtn); | ||
607 | + }) | ||
608 | + | ||
609 | + var auto = localStorage.getItem('auto__flush') | ||
610 | + auto = auto ? auto : false; | ||
611 | + autoBtn.find('input').prop('checked', auto); | ||
612 | + | ||
613 | + autoFlush(autoBtn); | ||
614 | + | ||
615 | + admin.on('hash(*)', function (router) { | ||
616 | + if (router.href === '/historywarning') { | ||
617 | + autoFlush(autoBtn); | ||
618 | + } else { | ||
619 | + clearTimeout(timer); | ||
620 | + } | ||
621 | + }); | ||
622 | + })(); | ||
623 | + | ||
624 | + }); | ||
625 | + | ||
626 | +}); |
1 | +//资源视图 | ||
2 | +layui.define(['common', 'tree', 'laypage', 'laytpl', 'admin', 'form', 'table', 'sessions', | ||
3 | + "commonDetail",'tableTree','soulTable','commonCols'], function (exports) { | ||
4 | + var $ = layui.$; | ||
5 | + var common = layui.common; | ||
6 | + var table = layui.table; | ||
7 | + | ||
8 | + //对外暴露的接口 | ||
9 | + exports('resindex', function (data) { | ||
10 | + var laytpl = layui.laytpl; | ||
11 | + var tree = layui.tree; | ||
12 | + var form = layui.form; | ||
13 | + var view = layui.view; | ||
14 | + var router = layui.router(); | ||
15 | + | ||
16 | + var soulTable = layui.soulTable; | ||
17 | + var tableTree = layui.tableTree; | ||
18 | + var commonCols = layui.commonCols; | ||
19 | + var admin = layui.admin; | ||
20 | + var commonDetail = layui.commonDetail; | ||
21 | + var domainName = common.domainName; | ||
22 | + | ||
23 | + var resTypeSelectExclude = ['HOST_MINICOMPUTER', 'HOST_MINICOMPUTER_SERVER', 'HOST_BMC', 'HOST_X86SERVER'] | ||
24 | + | ||
25 | + var curTreeNode = ''; | ||
26 | + var currentResType = '';//当前选中节点的资源类型 | ||
27 | + var accessToken; | ||
28 | + var sortKey = ''; | ||
29 | + // 资源类型视图表格 | ||
30 | + var resListTable; | ||
31 | + var parentResListTable; | ||
32 | + | ||
33 | + var bizId=''; | ||
34 | + var busIdSelect; | ||
35 | + var busTypeList = []; | ||
36 | + var collProtocols = ''; | ||
37 | + | ||
38 | + var editFlag = false; | ||
39 | + if (data.choose == '1') { | ||
40 | + editFlag = true; | ||
41 | + $(".choose-resKpiInfo").show(); | ||
42 | + } else { | ||
43 | + // 隐藏左侧菜单 | ||
44 | + $('#LAY_app_flexible').click(); | ||
45 | + } | ||
46 | + | ||
47 | + | ||
48 | + function autoHeight(el) { | ||
49 | + // var height = el.parents('.layui-card').height(); | ||
50 | + // el.css('min-height', height - 75); | ||
51 | + } | ||
52 | + var sessions = layui.sessions; | ||
53 | + accessToken = sessions.getToken().access_token; | ||
54 | + //点击卡片 | ||
55 | + $('#resindexTable').on('click', '[data-res-card]', function () { | ||
56 | + var nodeId = $(this).attr("data-res-card"); | ||
57 | + currentResType = nodeId;//将当前点击的资源类型付给参数 | ||
58 | + selectedTreeNode('[data-id="' + currentResType + '"]','[data-id="' + currentResType.split('_')[0] + '"]'); | ||
59 | + renderList(currentResType,''); | ||
60 | + // renderList($(this).data("res-card")); | ||
61 | + // $("div[data-id='"+nodeId+"']").find(".layui-tree-entry:first span.layui-tree-txt").trigger("click") | ||
62 | + }); | ||
63 | + | ||
64 | + // 树收缩事件 | ||
65 | + $('#resindex-leftree-shrink').on('click', function () { | ||
66 | + $(".resIndexLeft").animate({width:0,minWidth:0,marginLeft:0},300,function () { | ||
67 | + $("#resindex-leftree_btn").show(); | ||
68 | + $('#resindex-leftree-shrink').hide(); | ||
69 | + }); | ||
70 | + }); | ||
71 | + //获取全部协议 | ||
72 | + function initProtocolSelect() { | ||
73 | + admin.req({ | ||
74 | + url: common.domainName + '/api-web/manage/protocol/page', | ||
75 | + data: { | ||
76 | + access_token: accessToken, | ||
77 | + startTime: '', | ||
78 | + endTime: '', | ||
79 | + keyword: '', | ||
80 | + hasParam: '', | ||
81 | + limit: -1 | ||
82 | + } | ||
83 | + }).done(function (res) { | ||
84 | + xmSelect.render({ | ||
85 | + el: '#collProtocolSelect' | ||
86 | + , filterable: true | ||
87 | + , tips: '=采集协议=' | ||
88 | + , name: 'collProtocols' | ||
89 | + , prop: { | ||
90 | + name: 'protocolName', | ||
91 | + value: 'protocolCode', | ||
92 | + } | ||
93 | + , model: { | ||
94 | + label: { | ||
95 | + type: 'block', | ||
96 | + block: { | ||
97 | + //最大显示数量, 0:不限制 | ||
98 | + showCount: 1, | ||
99 | + //是否显示删除图标 | ||
100 | + showIcon: true, | ||
101 | + } | ||
102 | + } | ||
103 | + } | ||
104 | + , data: res.data | ||
105 | + ,hide: function () { | ||
106 | + var selectValue = xmSelect.get('#collProtocolSelect', true).getValue('value'); | ||
107 | + collProtocols = selectValue.join(','); | ||
108 | + form.render() | ||
109 | + reloadTable(); | ||
110 | + } | ||
111 | + }) | ||
112 | + }) | ||
113 | + } | ||
114 | + //树展开事件 | ||
115 | + $("#resindex-leftree_btn").on("click",function () { | ||
116 | + $("#resindex-leftree_btn").hide(); | ||
117 | + $("#resindex-leftree-shrink").show(); | ||
118 | + $(".resIndexLeft").animate({minWidth:170,marginLeft:10},300); | ||
119 | + }); | ||
120 | + | ||
121 | + var loading = layer.load(2, {shade: 0.2}); | ||
122 | + //统计 | ||
123 | + function renderIndex(resType) { | ||
124 | + $('#resIndexContent').show(); | ||
125 | + $('#resListContent').hide(); | ||
126 | + $('#resDetailContent').empty(); | ||
127 | + $('#resDetailContent').hide(); | ||
128 | + $('#treeTableContent').hide(); | ||
129 | + | ||
130 | + //如果是阿里云,则显示阿里云的列表 | ||
131 | + if(resType && resType == 'ALI_CLOUD_PLAT'){ | ||
132 | + $(".resindexlist").show(); | ||
133 | + renderTableList("ALI_CLOUD_PLAT"); | ||
134 | + }else{ | ||
135 | + $(".resindexlist").hide(); | ||
136 | + } | ||
137 | + | ||
138 | + var resindexTable = $('#resindexTable'); | ||
139 | + | ||
140 | + autoHeight(resindexTable); | ||
141 | + | ||
142 | + window.setResizeEvents('autoHeight', autoHeight); | ||
143 | + admin.req({ | ||
144 | + url: common.domainName + '/api-web/home/resource/healthByResType?pResType=' + resType, | ||
145 | + }).done(function (res) { | ||
146 | + laytpl($('#resindexTpl').html()).render({list: res.data}, function (html) { | ||
147 | + resindexTable.html(html); | ||
148 | + }); | ||
149 | + }); | ||
150 | + } | ||
151 | + | ||
152 | + admin.req({ | ||
153 | + url: common.domainName + '/api-web/home/resType/getTree?notExist=machineroom&table=resources&exist=HOST_MINICOMPUTER_SERVER', | ||
154 | + type: 'get', | ||
155 | + sync: true, | ||
156 | + done: function (res) { | ||
157 | + layer.close(loading); | ||
158 | + loadResTree(res.data); | ||
159 | + //joke add 20200407,如果没有资源树,则默认资源页给提示无数据 开始 | ||
160 | + if (res.data.length === 0) { | ||
161 | + var resindexTable = $('#resindexTable'); | ||
162 | + autoHeight(resindexTable); | ||
163 | + laytpl($('#resindexTpl').html()).render({list: res.data}, function (html) { | ||
164 | + resindexTable.html(html); | ||
165 | + }); | ||
166 | + } | ||
167 | + loadParamSelect(); | ||
168 | + //joke add 20200407,如果没有资源树,则默认资源页给提示无数据 开始 | ||
169 | + } | ||
170 | + }).error(function () { | ||
171 | + layer.close(loading); | ||
172 | + //joke add 20200407 | ||
173 | + //树无数据提示 | ||
174 | + tree.render({ | ||
175 | + elem: '#resindextree', | ||
176 | + showLine: false, | ||
177 | + data: new Array() | ||
178 | + }); | ||
179 | + //右侧无数据提示 | ||
180 | + var resindexTable = $('#resindexTable'); | ||
181 | + autoHeight(resindexTable); | ||
182 | + laytpl($('#resindexTpl').html()).render({list: new Array()}, function (html) { | ||
183 | + resindexTable.html(html); | ||
184 | + }); | ||
185 | + }); | ||
186 | + | ||
187 | + //不带分页的列表 | ||
188 | + function renderTableList(resType) { | ||
189 | + //渲染表格 | ||
190 | + var resTableList; | ||
191 | + //获取配置的列 | ||
192 | + common.getTableCols({ | ||
193 | + domId: 'resTableList', | ||
194 | + moduleId: 'resIndex', | ||
195 | + resType: resType | ||
196 | + },function (retCols) { | ||
197 | + var cols; | ||
198 | + if (retCols) { | ||
199 | + cols = retCols; | ||
200 | + } else { | ||
201 | + cols = commonCols.resTypeCls[resType]; | ||
202 | + } | ||
203 | + resTableList = table.render({ | ||
204 | + elem: '#resindexList' | ||
205 | + , id: 'resindexList' | ||
206 | + , url: common.domainName + '/api-web/home/res-list/' + resType | ||
207 | + , toolbar: '<div><button id="resTableIndex_cols_save" class="layui-btn layui-btn-primary layui-btn-xs toolbar-btn" lay-tips="保存列顺序"><i class="iconfont"></i></button></div>' | ||
208 | + , where: { | ||
209 | + access_token: accessToken, | ||
210 | + resCategory: 'resources' | ||
211 | + } | ||
212 | + , height: '100' | ||
213 | + , cellMinWidth: 80 | ||
214 | + , page: false | ||
215 | + , cols: [cols] | ||
216 | + , done: function (res, curr, count) { | ||
217 | + //2021/10/18 徐毫杰 阿里云服务器更改样式 | ||
218 | + if(resType=='ALI_CLOUD_PLAT'){ | ||
219 | + $('.layui-table-view').height(170); | ||
220 | + $('.layui-table-main').height(70); | ||
221 | + } | ||
222 | + //调用收藏方法 | ||
223 | + resFavorites(); | ||
224 | + resTopo(); | ||
225 | + | ||
226 | + commonCols.colsClickEvent(editFlag); | ||
227 | + | ||
228 | + //触发拖动列事件,参数为保存按钮的id | ||
229 | + common.dragCols("resTableIndex_cols_save"); | ||
230 | + | ||
231 | + //保存列顺序 | ||
232 | + $("#resTableIndex_cols_save").unbind("click").on("click", function () { | ||
233 | + var params = { | ||
234 | + domId: 'resTableList', | ||
235 | + moduleId: 'resIndex', | ||
236 | + resType: resType, | ||
237 | + cols: resTableList.config.cols | ||
238 | + } | ||
239 | + common.saveTableCols(params); | ||
240 | + }); | ||
241 | + } | ||
242 | + }); | ||
243 | + }); | ||
244 | + } | ||
245 | + //左侧树 | ||
246 | + function loadResTree(data) { | ||
247 | + //默认展开全部一级节点 | ||
248 | + $.each(data,function (i,v) { | ||
249 | + v.spread = true; | ||
250 | + }) | ||
251 | + tree.render({ | ||
252 | + elem: '#resindextree', | ||
253 | + showLine: false, | ||
254 | + data: data, | ||
255 | + click: function (node) { | ||
256 | + if (node.data.children.length == 1) { | ||
257 | + $('[data-id="'+ node.data.children[0].id +'"]').find('.layui-tree-iconClick:first').click() | ||
258 | + } | ||
259 | + | ||
260 | + curTreeNode = node; | ||
261 | + currentResType = node.data.id; | ||
262 | + | ||
263 | + var el = null; | ||
264 | + if (node.data.children) { | ||
265 | + el = $(node.elem[0]).find('>.layui-tree-entry .layui-tree-txt'); | ||
266 | + } else { | ||
267 | + el = $(node.elem[0]).find('.layui-tree-txt'); | ||
268 | + } | ||
269 | + | ||
270 | + var action = 'removeClass'; | ||
271 | + if (!el.hasClass('tree-node-select') && node.state === 'open') { | ||
272 | + action = 'addClass'; | ||
273 | + el.parents('.layui-tree').find('.tree-node-select').removeClass('tree-node-select'); | ||
274 | + } | ||
275 | + | ||
276 | + el[action]('tree-node-select'); | ||
277 | + | ||
278 | + // 决定显示那个视图 | ||
279 | + var optionsStr = JSON.parse(node.data.code)['options']; | ||
280 | + if (optionsStr && optionsStr != "") { | ||
281 | + options = JSON.parse(optionsStr); | ||
282 | + var callback = options.viewCallBack; | ||
283 | + var fun = eval(callback); | ||
284 | + // 获取回调方法 | ||
285 | + if ($.isFunction(fun)) { | ||
286 | + fun.call(this, data, node.data, options); | ||
287 | + } | ||
288 | + | ||
289 | + } | ||
290 | + } | ||
291 | + }); | ||
292 | + if (data.length > 0) { | ||
293 | + var optionsStr = JSON.parse(data[0].code)['options']; | ||
294 | + if (optionsStr && optionsStr != "") { | ||
295 | + options = JSON.parse(optionsStr); | ||
296 | + var callback = options.viewCallBack; | ||
297 | + var fun = eval(callback); | ||
298 | + // 获取回调方法 | ||
299 | + if ($.isFunction(fun)) { | ||
300 | + fun.call(this, data, data[0], options); | ||
301 | + currentResType = data[0].id; | ||
302 | + curTreeNode = data[0]; | ||
303 | + } | ||
304 | + } | ||
305 | + } | ||
306 | + } | ||
307 | + | ||
308 | + //回选树节点 | ||
309 | + function selectedTreeNode(target,parentTarget) { | ||
310 | + var el = $(target).find('.layui-tree-txt').eq(0); | ||
311 | + var action = 'removeClass'; | ||
312 | + if (!el.hasClass('tree-node-select')) { | ||
313 | + action = 'addClass'; | ||
314 | + el.parents('.layui-tree').find('.tree-node-select').removeClass('tree-node-select'); | ||
315 | + } | ||
316 | + el[action]('tree-node-select'); | ||
317 | + el.parents('.layui-tree').find(parentTarget).find(".layui-tree-set").addClass("layui-tree-spread"); | ||
318 | + el.parents('.layui-tree').find(parentTarget).find(".layui-tree-pack").show(); | ||
319 | + | ||
320 | + } | ||
321 | + | ||
322 | + //资源详细页 | ||
323 | + function loadResDetailInfo(parentNode, data, node, options) { | ||
324 | + var resId = data.id; | ||
325 | + var resType = data.pid; | ||
326 | + renderDetail(resId, resType); | ||
327 | + } | ||
328 | + | ||
329 | + //子节点统计 | ||
330 | + function loadChildResTypeCount(parentNode, data, node, options) { | ||
331 | + var resId = data.id; | ||
332 | + for (var i = 0; i < parentNode.length; i++) { | ||
333 | + if (parentNode.id == data.id) { | ||
334 | + resId = ''; | ||
335 | + break; | ||
336 | + } | ||
337 | + } | ||
338 | + renderIndex(resId); | ||
339 | + } | ||
340 | + | ||
341 | + //资源视图列表 | ||
342 | + function openResourceView(parentNode, data, node, options) { | ||
343 | + renderList(data.id); | ||
344 | + } | ||
345 | + //资源视图父级列表 | ||
346 | + function openParentResourceView(parentNode, data, node, options) { | ||
347 | + renderParentList(data.id); | ||
348 | + } | ||
349 | + | ||
350 | + //加载虚拟化数据(平台、资源池、物理机、虚拟机) | ||
351 | + function loadVirtualizationView(parentNode, data, node, options) { | ||
352 | + $('#res_coll_protocol_select_div').show(); | ||
353 | + //绑定业务 | ||
354 | + // common.bizTypeSelect("treetableBizTypes", function () { | ||
355 | + // form.render("select"); | ||
356 | + // }); | ||
357 | + //$('#treetableBizTypes').val(''); | ||
358 | + //绑定采集协议 | ||
359 | + admin.req({ | ||
360 | + url: domainName + '/api-web/manage/protocol/page', | ||
361 | + data: { | ||
362 | + access_token: accessToken, | ||
363 | + startTime: '', | ||
364 | + endTime: '', | ||
365 | + keyword: '', | ||
366 | + hasParam: '', | ||
367 | + limit: -1 | ||
368 | + } | ||
369 | + }).done(function (res) { | ||
370 | + xmSelect.render({ | ||
371 | + el: '#collProtocolSelect' | ||
372 | + , filterable: true | ||
373 | + , tips: '=采集协议=' | ||
374 | + , name: 'collProtocols' | ||
375 | + , prop: { | ||
376 | + name: 'protocolName', | ||
377 | + value: 'protocolCode', | ||
378 | + } | ||
379 | + , model: { | ||
380 | + label: { | ||
381 | + type: 'block', | ||
382 | + block: { | ||
383 | + //最大显示数量, 0:不限制 | ||
384 | + showCount: 1, | ||
385 | + //是否显示删除图标 | ||
386 | + showIcon: true, | ||
387 | + } | ||
388 | + } | ||
389 | + } | ||
390 | + , data: res.data | ||
391 | + ,hide: function () { | ||
392 | + var selectValue = xmSelect.get('#collProtocolSelect', true).getValue('value'); | ||
393 | + collProtocols = selectValue.join(','); | ||
394 | + form.render() | ||
395 | + reloadTable(); | ||
396 | + if (collProtocols) { | ||
397 | + xmSelect.get('#collProtocolSelect', true).setValue([]); | ||
398 | + collProtocols=''; | ||
399 | + form.render(); | ||
400 | + } | ||
401 | + } | ||
402 | + }) | ||
403 | + }) | ||
404 | + //绑定业务下拉选择数据 | ||
405 | + admin.req({ | ||
406 | + url: domainName + '/api-web/home/business/findAllBusType', | ||
407 | + success: function (response) { | ||
408 | + if (response && response.success) { | ||
409 | + busTypeList = response.data; | ||
410 | + var bizList = response.data.map(item => { | ||
411 | + return { | ||
412 | + name: item.busTypeName, | ||
413 | + value: item.busId, | ||
414 | + parentId: item.parentId | ||
415 | + } | ||
416 | + }); | ||
417 | + var bizTree=common.pidToChildren(bizList, 'value', 'parentId'); | ||
418 | + | ||
419 | + // 影响业务下拉框 | ||
420 | + busIdSelect = xmSelect.render({ | ||
421 | + el: '#treetableBizTypes', | ||
422 | + name: 'bizId', | ||
423 | + tips: '=所属业务=', | ||
424 | + //开启搜索 | ||
425 | + filterable: true, | ||
426 | + initValue: [bizId.split(',')[0]], | ||
427 | + toolbar: { | ||
428 | + show: true, | ||
429 | + list: ['ALL', 'REVERSE', 'CLEAR'] | ||
430 | + }, | ||
431 | + height: '400px', | ||
432 | + tree: { | ||
433 | + show: true, | ||
434 | + showFolderIcon: true, | ||
435 | + showLine: true, | ||
436 | + strict: true, | ||
437 | + //间距 | ||
438 | + indent: 20, | ||
439 | + }, | ||
440 | + data: bizTree, | ||
441 | + on: function (data) { | ||
442 | + if (data.arr.length != 0) { | ||
443 | + var str=''; | ||
444 | + $.each(data.arr,function (i,v) { | ||
445 | + str+=v.value+','; | ||
446 | + }) | ||
447 | + bizId = str.substring(0,str.length-1); | ||
448 | + } else { | ||
449 | + bizId = ''; | ||
450 | + } | ||
451 | + form.render(); | ||
452 | + renderTreeTable(curTreeNode.data.id) | ||
453 | + } | ||
454 | + }); | ||
455 | + if(busIdSelect){ | ||
456 | + //追加样式 | ||
457 | + $('#treetableBizTypes').find('.xm-body').eq(0).css("width","230px"); | ||
458 | + } | ||
459 | + } else { | ||
460 | + layer.msg('获取业务失败', {icon: 2}); | ||
461 | + } | ||
462 | + }, | ||
463 | + error: function () { | ||
464 | + layer.msg('获取业务失败', {icon: 2}); | ||
465 | + } | ||
466 | + }); | ||
467 | + | ||
468 | + if (data.id != 'VIRTUALIZATION_VMWARE' && data.id != 'VIRTUALIZATION_HUAWEI') { | ||
469 | + $("#virtual_platform_div_id").show(); | ||
470 | + //绑定虚拟化平台 | ||
471 | + common.virtualPlatFormSelect("virtual_platForm_select", "", function () { | ||
472 | + form.render("select"); | ||
473 | + }, data.id.match(/(VIRTUALIZATION_((?!_).)+)(.*)/)[1]); | ||
474 | + $('#virtual_platForm_select').val(''); | ||
475 | + } | ||
476 | + //初始化业务下拉数据 | ||
477 | + if (busIdSelect) { | ||
478 | + busIdSelect.setValue([]); | ||
479 | + bizId=''; | ||
480 | + form.render(); | ||
481 | + } | ||
482 | + renderTreeTable(data.id); | ||
483 | + } | ||
484 | + | ||
485 | + //加载weblogic | ||
486 | + function loadWeblogicView(parentNode, data, node, options) { | ||
487 | + // //绑定业务 | ||
488 | + //common.bizTypeSelect("treetableBizTypes", function () { | ||
489 | + // form.render("select"); | ||
490 | + // }); | ||
491 | + // $('#treetableBizTypes').val(''); | ||
492 | + //绑定业务下拉选择数据 | ||
493 | + admin.req({ | ||
494 | + url: domainName + '/api-web/home/business/findAllBusType', | ||
495 | + success: function (response) { | ||
496 | + if (response && response.success) { | ||
497 | + busTypeList = response.data; | ||
498 | + var bizList = response.data.map(item => { | ||
499 | + return { | ||
500 | + name: item.busTypeName, | ||
501 | + value: item.busId, | ||
502 | + parentId: item.parentId | ||
503 | + } | ||
504 | + }); | ||
505 | + var bizTree=common.pidToChildren(bizList, 'value', 'parentId'); | ||
506 | + | ||
507 | + // 影响业务下拉框 | ||
508 | + busIdSelect = xmSelect.render({ | ||
509 | + el: '#treetableBizTypes', | ||
510 | + name: 'bizId', | ||
511 | + tips: '=所属业务=', | ||
512 | + //开启搜索 | ||
513 | + filterable: true, | ||
514 | + | ||
515 | + initValue: [bizId.split(',')[0]], | ||
516 | + toolbar: { | ||
517 | + show: true, | ||
518 | + list: ['ALL', 'REVERSE', 'CLEAR'] | ||
519 | + }, | ||
520 | + height: '400px', | ||
521 | + tree: { | ||
522 | + show: true, | ||
523 | + showFolderIcon: true, | ||
524 | + showLine: true, | ||
525 | + strict: true, | ||
526 | + //间距 | ||
527 | + indent: 20, | ||
528 | + }, | ||
529 | + data: bizTree, | ||
530 | + on: function (data) { | ||
531 | + if (data.arr.length != 0) { | ||
532 | + var str=''; | ||
533 | + $.each(data.arr,function (i,v) { | ||
534 | + str+=v.value+','; | ||
535 | + }) | ||
536 | + bizId = str.substring(0,str.length-1); | ||
537 | + } else { | ||
538 | + bizId = ''; | ||
539 | + } | ||
540 | + form.render(); | ||
541 | + renderTreeTable(curTreeNode.data.id); | ||
542 | + } | ||
543 | + }); | ||
544 | + if(busIdSelect){ | ||
545 | + //追加样式 | ||
546 | + $('#treetableBizTypes').find('.xm-body').eq(0).css("width","230px"); | ||
547 | + } | ||
548 | + } else { | ||
549 | + layer.msg('获取业务失败', {icon: 2}); | ||
550 | + } | ||
551 | + }, | ||
552 | + error: function () { | ||
553 | + layer.msg('获取业务失败', {icon: 2}); | ||
554 | + } | ||
555 | + }); | ||
556 | + renderParentList(data.id); | ||
557 | + } | ||
558 | + | ||
559 | + // //业务选择事件 | ||
560 | + // form.on('select(resListBizTypes)', function (data) { | ||
561 | + // // renderList(currentResType); | ||
562 | + // reloadTable(); | ||
563 | + // }); | ||
564 | + //绑定业务下拉选择数据 | ||
565 | + admin.req({ | ||
566 | + url: domainName + '/api-web/home/business/findAllBusType', | ||
567 | + success: function (response) { | ||
568 | + if (response && response.success) { | ||
569 | + busTypeList = response.data; | ||
570 | + var bizList = response.data.map(item => { | ||
571 | + return { | ||
572 | + name: item.busTypeName, | ||
573 | + value: item.busId, | ||
574 | + parentId: item.parentId | ||
575 | + } | ||
576 | + }); | ||
577 | + var bizTree=common.pidToChildren(bizList, 'value', 'parentId'); | ||
578 | + | ||
579 | + // 影响业务下拉框 | ||
580 | + busIdSelect = xmSelect.render({ | ||
581 | + el: '#resListBizTypes', | ||
582 | + name: 'bizId', | ||
583 | + tips: '=所属业务=', | ||
584 | + //开启搜索 | ||
585 | + filterable: true, | ||
586 | + | ||
587 | + initValue: [bizId.split(',')[0]], | ||
588 | + toolbar: { | ||
589 | + show: true, | ||
590 | + list: ['ALL', 'REVERSE', 'CLEAR'] | ||
591 | + }, | ||
592 | + height: '400px', | ||
593 | + tree: { | ||
594 | + show: true, | ||
595 | + showFolderIcon: true, | ||
596 | + showLine: true, | ||
597 | + strict: true, | ||
598 | + //间距 | ||
599 | + indent: 20, | ||
600 | + }, | ||
601 | + data: bizTree, | ||
602 | + on: function (data) { | ||
603 | + if (data.arr.length != 0) { | ||
604 | + var str=''; | ||
605 | + $.each(data.arr,function (i,v) { | ||
606 | + str+=v.value+','; | ||
607 | + }) | ||
608 | + bizId = str.substring(0,str.length-1); | ||
609 | + } else { | ||
610 | + bizId = ''; | ||
611 | + } | ||
612 | + form.render(); | ||
613 | + reloadTable(); | ||
614 | + } | ||
615 | + }); | ||
616 | + if(busIdSelect){ | ||
617 | + //追加样式 | ||
618 | + $('#resListBizTypes').find('.xm-body').eq(0).css("width","230px"); | ||
619 | + } | ||
620 | + } else { | ||
621 | + layer.msg('获取业务失败', {icon: 2}); | ||
622 | + } | ||
623 | + }, | ||
624 | + error: function () { | ||
625 | + layer.msg('获取业务失败', {icon: 2}); | ||
626 | + } | ||
627 | + }); | ||
628 | + //连接状态 | ||
629 | + form.on('select(link_state)', function (data) { | ||
630 | + // renderList(currentResType); | ||
631 | + reloadTable(); | ||
632 | + }); | ||
633 | + //集群选择事件 | ||
634 | + form.on('select(res_cluster)', function (data) { | ||
635 | + // renderList(currentResType); new | ||
636 | + reloadTable(); | ||
637 | + }); | ||
638 | + //资源池选择事件 | ||
639 | + form.on('select(res_colony)', function (data) { | ||
640 | + // renderList(currentResType); new | ||
641 | + reloadTable(); | ||
642 | + }); | ||
643 | + | ||
644 | + //资源状态 | ||
645 | + form.on('select(resStatus)', function (data) { | ||
646 | + // renderList(currentResType); | ||
647 | + reloadTable(); | ||
648 | + }); | ||
649 | + //资源连接状态 | ||
650 | + form.on('select(state)', function (data) { | ||
651 | + reloadTable(); | ||
652 | + }); | ||
653 | + //资源池选择事件 | ||
654 | + form.on('select(res_platform)', function (data) { | ||
655 | + // renderList(currentResType); | ||
656 | + reloadTable(); | ||
657 | + }); | ||
658 | + //阿里云平台选择事件 | ||
659 | + form.on('select(aliyun_plantform)', function (data) { | ||
660 | + // renderList(currentResType); | ||
661 | + reloadTable(); | ||
662 | + }); | ||
663 | + //厂商选择事件 | ||
664 | + form.on('select(res_vendor)', function (data) { | ||
665 | + // renderList(currentResType); | ||
666 | + reloadTable(); | ||
667 | + }); | ||
668 | + //小型服务器选择事件 | ||
669 | + form.on('select(res_minicomputer)', function (data) { | ||
670 | + reloadTable(); | ||
671 | + }); | ||
672 | + //资源池选择事件 | ||
673 | + form.on('select(sub_restype)', function (data) { | ||
674 | + if(data.value){ | ||
675 | + loadRightResTypeSelectEvent(data.value,"normal") | ||
676 | + }else{ | ||
677 | + loadRightResTypeSelectEvent(currentResType,"normal") | ||
678 | + } | ||
679 | + // renderList(currentResType); | ||
680 | + reloadTable(); | ||
681 | + }); | ||
682 | + //回车搜索 | ||
683 | + $('#resindex_keyword').keydown(function (e) { | ||
684 | + if (e.keyCode === 13) { | ||
685 | + // renderList(currentResType); | ||
686 | + reloadTable(); | ||
687 | + return false; | ||
688 | + } | ||
689 | + }); | ||
690 | + | ||
691 | + //资源详细信息 | ||
692 | + function renderDetail(resId, resType) { | ||
693 | + $('#resIndexContent').hide(); | ||
694 | + $('#resListContent').hide(); | ||
695 | + $('#resDetailContent').show(); | ||
696 | + $('#treeTableContent').hide(); | ||
697 | + var url = common.detailPath(resType,resId); | ||
698 | + view('commonViewModel').render(url).then(function (res) { | ||
699 | + var params = { | ||
700 | + "resId": resId, | ||
701 | + "resType": resType | ||
702 | + }; | ||
703 | + laytpl(res.body).render(JSON.stringify(params), function (html) { | ||
704 | + $("#resDetailContent").html(html); | ||
705 | + }); | ||
706 | + | ||
707 | + }); | ||
708 | + } | ||
709 | + | ||
710 | + //树表格 | ||
711 | + function renderTreeTable(resType) { | ||
712 | + $('#resIndexContent').hide(); | ||
713 | + $('#resListContent').hide(); | ||
714 | + $('#resDetailContent').empty(); | ||
715 | + $('#resDetailContent').hide(); | ||
716 | + $('#treeTableContent').show(); | ||
717 | + $(".top-head-info").removeClass("hide"); | ||
718 | + if("MIDDLEWARE_WEBLOGIC" == resType){ | ||
719 | + $("#res_platform_id").hide() | ||
720 | + } | ||
721 | + if(resType.indexOf("VIRTUALIZATION") >-1){ | ||
722 | + $("#tree_linkstate_area").hide() | ||
723 | + } | ||
724 | + | ||
725 | + | ||
726 | + if (resType == 'VIRTUALIZATION_VMWARE' || resType == 'VIRTUALIZATION_HUAWEI' || resType == 'MIDDLEWARE_WEBLOGIC') { | ||
727 | + $("#virtual_platform_div_id").hide(); | ||
728 | + } | ||
729 | + | ||
730 | + var index = layer.load(2); //加载层 | ||
731 | + | ||
732 | + var cols = commonCols.resTypeCls[resType]; | ||
733 | + admin.req({ | ||
734 | + url: common.domainName + "/api-web/home/virtual-res-list/" + resType | ||
735 | + , type: "get" | ||
736 | + , data: { | ||
737 | + ptId: $("#virtual_platForm_select").val(), | ||
738 | + busId: bizId, | ||
739 | + keyWords: $("#treetable_keyword").val(), | ||
740 | + health: $("#treetable_resStatus").val(), | ||
741 | + state: $("#treetable_res_state").val(), | ||
742 | + resCategory: 'resources', | ||
743 | + collProtocols : collProtocols | ||
744 | + | ||
745 | + } | ||
746 | + , done: function (res) { | ||
747 | + layer.close(index); | ||
748 | + if (res.code == 0) { | ||
749 | + //渲染表格 | ||
750 | + var tableTreeVirtual; | ||
751 | + //获取配置的列 | ||
752 | + common.getTableCols({ | ||
753 | + domId: 'tableTreeVirtual', | ||
754 | + moduleId: 'resIndex', | ||
755 | + resType: resType | ||
756 | + },function (retCols) { | ||
757 | + if (retCols) { | ||
758 | + cols = retCols; | ||
759 | + } | ||
760 | + tableTreeVirtual = table.render({ | ||
761 | + elem: '#virtual_platform_treeTable', | ||
762 | + autoColumnWidth: false, | ||
763 | + page: false, | ||
764 | + limit: 9999, | ||
765 | + data: res.data, | ||
766 | + tree: { | ||
767 | + iconIndex: 1 | ||
768 | + }, | ||
769 | + cols: [cols] | ||
770 | + , height: 'full-220', | ||
771 | + done: function (res) { | ||
772 | + soulTable.render(this); | ||
773 | + | ||
774 | + //调用收藏方法 | ||
775 | + resFavorites(); | ||
776 | + resTopo(); | ||
777 | + | ||
778 | + common.treeTableDragCols('#virtual_platform_treeTable', '#resTreeList-top-head-info-tpl'); | ||
779 | + loadRightResTypeSelectEvent(curTreeNode.data.id,"tree") | ||
780 | + // 保存列顺序 | ||
781 | + $('#virtual_platform_treeTable').next().find('.btn_save_cols').unbind('click').on('click', function (){ | ||
782 | + common.saveTableCols({ | ||
783 | + domId: 'tableTreeVirtual', | ||
784 | + moduleId: 'resIndex', | ||
785 | + resType: resType, | ||
786 | + cols: tableTreeVirtual.config.cols | ||
787 | + }); | ||
788 | + }); | ||
789 | + | ||
790 | + commonCols.colsClickEvent(editFlag); | ||
791 | + } | ||
792 | + }); | ||
793 | + /** | ||
794 | + /**表格的增删改都会回调此方法 | ||
795 | + * 与table.on(tool(lay-filter))用法一致。 | ||
796 | + **/ | ||
797 | + /*tableTreeVirtual.on('tool(tableEvent)',function (obj) { | ||
798 | + if(!obj.data.treeList){ | ||
799 | + var field = obj.field; //单元格字段 | ||
800 | + var value = obj.value; //修改后的值 | ||
801 | + var data = obj.data; //当前行数据 | ||
802 | + var event = obj.event; //当前单元格事件属性值 | ||
803 | + var subResType = ''; | ||
804 | + if(data.resType == 'VIRTUALIZATION_VMWARE' || data.resType == 'VIRTUALIZATION_HUAWEI'){ | ||
805 | + subResType = data.resType=='VIRTUALIZATION_VMWARE'?'VIRTUALIZATION_VMWARE_CLUSTER':'VIRTUALIZATION_HUAWEI_CLUSTER'; | ||
806 | + }else if(data.resType.indexOf('CLUSTER')>-1){ | ||
807 | + subResType = data.resType=='VIRTUALIZATION_VMWARE_CLUSTER'?'VIRTUALIZATION_VMWARE_PHYSICSHOST':'VIRTUALIZATION_HUAWEI_PHYSICSHOST'; | ||
808 | + }else if(data.resType.indexOf('PHYSICSHOST')>-1){ | ||
809 | + subResType = data.resType=='VIRTUALIZATION_VMWARE_PHYSICSHOST'?'VIRTUALIZATION_VMWARE_VHOST':'VIRTUALIZATION_HUAWEI_VHOST'; | ||
810 | + }else{ | ||
811 | + subResType = data.resType | ||
812 | + } | ||
813 | + if(event === 'loadChildren'){ | ||
814 | + $.ajax({ | ||
815 | + url: common.domainName + "/api-web/home/virtual-res-list/" + subResType | ||
816 | + , type: "get" | ||
817 | + , data: { | ||
818 | + ptId: $("#virtual_platForm_select").val(), | ||
819 | + health: $("#treetable_resStatus").val(), | ||
820 | + busId: $("#treetableBizTypes").val(), | ||
821 | + keyWords: $("#treetable_keyword").val(), | ||
822 | + state: $("#treetable_state").val(), | ||
823 | + access_token:accessToken, | ||
824 | + parentId:data.resId | ||
825 | + } | ||
826 | + ,success:function (res) { | ||
827 | + if(res.data.length>0){ | ||
828 | + obj.loadChildren(res.data); | ||
829 | + commonCols.colsClickEvent(); | ||
830 | + } | ||
831 | + } | ||
832 | + }) | ||
833 | + } | ||
834 | + } | ||
835 | + });*/ | ||
836 | + //统计总数 | ||
837 | + // $('#virtual_platform_treeTable').next().find('.layui-table-box').after(laytpl($('#treetable-countTpl').html()).render(res.data.length)); | ||
838 | + }); | ||
839 | + } else { | ||
840 | + console.log(data.msg); | ||
841 | + } | ||
842 | + //关键字回车事件 | ||
843 | + $('#treetable_keyword').keydown(function (e) { | ||
844 | + if (e.keyCode === 13) { | ||
845 | + renderTreeTable(curTreeNode.data.id) | ||
846 | + return false; | ||
847 | + } | ||
848 | + }); | ||
849 | + //选择资源状态 | ||
850 | + form.on('select(treetable_resStatus)', function (data) { | ||
851 | + renderTreeTable(curTreeNode.data.id); | ||
852 | + }); | ||
853 | + // //选择业务 | ||
854 | + // form.on('select(treetableBizTypes)', function (data) { | ||
855 | + // renderTreeTable(curTreeNode.data.id); | ||
856 | + // }); | ||
857 | + //选择平台 | ||
858 | + form.on('select(virtual_platForm_select)', function (data) { | ||
859 | + renderTreeTable(curTreeNode.data.id); | ||
860 | + }); | ||
861 | + //选择资源连接状态 | ||
862 | + form.on('select(treetable_state)', function (data) { | ||
863 | + renderTreeTable(curTreeNode.data.id); | ||
864 | + }); | ||
865 | + form.on('select(treetable_res_state)', function (data) { | ||
866 | + renderTreeTable(curTreeNode.data.id); | ||
867 | + }); | ||
868 | + | ||
869 | + commonCols.colsClickEvent(editFlag); | ||
870 | + | ||
871 | + } | ||
872 | + }).error(function () { | ||
873 | + layer.close(index); | ||
874 | + }); | ||
875 | + } | ||
876 | + | ||
877 | + | ||
878 | + | ||
879 | + | ||
880 | + // //绑定业务下拉选择数据 | ||
881 | + // common.bizTypeSelect("resListBizTypes", function () { | ||
882 | + // form.render("select"); | ||
883 | + // }); | ||
884 | + //绑定业务下拉选择数据 | ||
885 | + admin.req({ | ||
886 | + url: domainName + '/api-web/home/business/findAllBusType', | ||
887 | + success: function (response) { | ||
888 | + if (response && response.success) { | ||
889 | + busTypeList = response.data; | ||
890 | + var bizList = response.data.map(item => { | ||
891 | + return { | ||
892 | + name: item.busTypeName, | ||
893 | + value: item.busId, | ||
894 | + parentId: item.parentId | ||
895 | + } | ||
896 | + }); | ||
897 | + var bizTree=common.pidToChildren(bizList, 'value', 'parentId'); | ||
898 | + | ||
899 | + // 影响业务下拉框 | ||
900 | + busIdSelect = xmSelect.render({ | ||
901 | + el: '#resListBizTypes', | ||
902 | + name: 'bizId', | ||
903 | + tips: '=所属业务=', | ||
904 | + //开启搜索 | ||
905 | + filterable: true, | ||
906 | + initValue: [bizId.split(',')[0]], | ||
907 | + toolbar: { | ||
908 | + show: true, | ||
909 | + list: ['ALL', 'REVERSE', 'CLEAR'] | ||
910 | + }, | ||
911 | + height: '400px', | ||
912 | + tree: { | ||
913 | + show: true, | ||
914 | + showFolderIcon: true, | ||
915 | + showLine: true, | ||
916 | + strict: true, | ||
917 | + //间距 | ||
918 | + indent: 20, | ||
919 | + }, | ||
920 | + data: bizTree, | ||
921 | + on: function (data) { | ||
922 | + if (data.arr.length != 0) { | ||
923 | + var str=''; | ||
924 | + $.each(data.arr,function (i,v) { | ||
925 | + str+=v.value+','; | ||
926 | + }) | ||
927 | + bizId = str.substring(0,str.length-1); | ||
928 | + } else { | ||
929 | + bizId = ''; | ||
930 | + } | ||
931 | + form.render(); | ||
932 | + reloadTable(); | ||
933 | + } | ||
934 | + }); | ||
935 | + if(busIdSelect){ | ||
936 | + //追加样式 | ||
937 | + $('#resListBizTypes').find('.xm-body').eq(0).css("width","230px"); | ||
938 | + } | ||
939 | + } else { | ||
940 | + layer.msg('获取业务失败', {icon: 2}); | ||
941 | + } | ||
942 | + }, | ||
943 | + error: function () { | ||
944 | + layer.msg('获取业务失败', {icon: 2}); | ||
945 | + } | ||
946 | + }); | ||
947 | + | ||
948 | + form.render(null, 'res-list-form'); | ||
949 | + | ||
950 | + //父级资源列表 | ||
951 | + function renderParentList(resType) { | ||
952 | + $('#resIndexContent').hide(); | ||
953 | + $('#resListContent').show(); | ||
954 | + $('#resDetailContent').empty(); | ||
955 | + $('#resDetailContent').hide(); | ||
956 | + $('#treeTableContent').hide(); | ||
957 | + //加载查询条件 | ||
958 | + renderSerach(resType,true); | ||
959 | + | ||
960 | + // , {field: 'state', title: '连接状态', minWidth: 100, align: 'center', templet: '#resListContentTpl'}]; | ||
961 | + if (resType && resType != 'PASSWORD_SERVER' && !/VIRTUALIZATION_((?!_).)+_(PHYSICSHOST|VHOST)/.test(resType)){ | ||
962 | + $('#link_state_div').show(); | ||
963 | + $('#host_state_div').hide(); | ||
964 | + $('#power_state_div').hide(); | ||
965 | + } else if(/VIRTUALIZATION_((?!_).)+_PHYSICSHOST/.test(resType)){ | ||
966 | + $('#link_state_div').hide(); | ||
967 | + $('#host_state_div').show(); | ||
968 | + $('#power_state_div').hide(); | ||
969 | + } else if(/VIRTUALIZATION_((?!_).)+_VHOST/.test(resType)){ | ||
970 | + $('#link_state_div').hide(); | ||
971 | + $('#host_state_div').hide(); | ||
972 | + $('#power_state_div').show(); | ||
973 | + } | ||
974 | + //渲染表格 | ||
975 | + var cols = commonCols.resTypeCls[resType]; | ||
976 | + //获取配置的列 | ||
977 | + common.getTableCols({ | ||
978 | + domId: 'parentResListTable', | ||
979 | + moduleId: 'resIndex', | ||
980 | + resType: resType | ||
981 | + },function (retCols) { | ||
982 | + if(retCols){ | ||
983 | + cols = retCols; | ||
984 | + } | ||
985 | + | ||
986 | + parentResListTable = table.render({ | ||
987 | + elem: '#resListTable' | ||
988 | + , id: 'resListTable' | ||
989 | + , toolbar: '#resList-top-head-info-tpl' //开启头部工具栏,并为其绑定左侧模板 | ||
990 | + , defaultToolbar: ['filter'] | ||
991 | + , drag: {toolbar: false} | ||
992 | + , url: common.domainName + '/api-web/home/res-list/' + resType | ||
993 | + , where: { | ||
994 | + access_token: accessToken, | ||
995 | + resName: $("#resindex_keyword").val(), | ||
996 | + busId: bizId, | ||
997 | + resHealth: $("#resStatus").val(), | ||
998 | + colonlyId: $("#res_colony").val(), | ||
999 | + parentId: $("#res_cluster").val(), | ||
1000 | + sortKey: sortKey, | ||
1001 | + state: $("#state").val(), | ||
1002 | + linkState: $("#link_state").val(), | ||
1003 | + hostState: $("#host_state").val(), | ||
1004 | + powerState: $("#power_state").val(), | ||
1005 | + resCategory: 'resources' | ||
1006 | + } | ||
1007 | + , height: 'full-165' | ||
1008 | + , cellMinWidth: 80 | ||
1009 | + , page: { | ||
1010 | + layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'] | ||
1011 | + , theme: '#1E9FFF' | ||
1012 | + } | ||
1013 | + , autoSort: false | ||
1014 | + , limit: 150 | ||
1015 | + , limits: [150, 200, 300] | ||
1016 | + , cols: [cols] | ||
1017 | + , done: function (res, curr, count) { | ||
1018 | + //更改样式 | ||
1019 | + function noClick($that) { | ||
1020 | + $that.css("color", "#666"); | ||
1021 | + $that.css("text-decoration", "none"); | ||
1022 | + $that.attr("lay-tips", "未监控到数据"); | ||
1023 | + } | ||
1024 | + | ||
1025 | + // 共享设备,厂商是H3C、HDS的设备不让点击并且提示暂无监控信息 | ||
1026 | + var $hsc_ = $('span[data-restype="STORAGE_SHARE"][data-provider="H3C"]'); | ||
1027 | + $.each($hsc_, function (i, v) { | ||
1028 | + noClick($(this)); | ||
1029 | + }); | ||
1030 | + var $hds = $('span[data-restype="STORAGE_SHARE"][data-provider="HDS"]'); | ||
1031 | + $.each($hds, function (i, v) { | ||
1032 | + noClick($(this)); | ||
1033 | + }); | ||
1034 | + //华为云,阿里云不让点击,并且提示暂无监控信息 | ||
1035 | + // var $hds = $('span[data-restype="HUAWEI_CLOUD_PLAT"]'); | ||
1036 | + // $.each($hds, function (i, v) { | ||
1037 | + // noClick($(this)); | ||
1038 | + // }); | ||
1039 | + // var $hds = $('span[data-restype="ALI_CLOUD_PLAT"]'); | ||
1040 | + // $.each($hds, function (i, v) { | ||
1041 | + // noClick($(this)); | ||
1042 | + // }); | ||
1043 | + | ||
1044 | + soulTable.render(this) | ||
1045 | + | ||
1046 | + //调用收藏方法 | ||
1047 | + resFavorites(); | ||
1048 | + resTopo(); | ||
1049 | + | ||
1050 | + commonCols.colsClickEvent(editFlag); | ||
1051 | + | ||
1052 | + //表格排序监听 joke add 20200408 | ||
1053 | + table.on('sort(resListTable)', function (obj) { | ||
1054 | + //有些时候,你可能需要根据当前排序的字段,重新向服务端发送请求,从而实现服务端排序,如: | ||
1055 | + if (obj.type != null) { | ||
1056 | + if (obj.field == 'ip') { | ||
1057 | + sortKey = 'INET_ATON(' + obj.field + ') ' + obj.type; | ||
1058 | + } else { | ||
1059 | + sortKey = obj.field + ' ' + obj.type; | ||
1060 | + } | ||
1061 | + } else { | ||
1062 | + sortKey = ''; | ||
1063 | + } | ||
1064 | + reloadTable(); | ||
1065 | + }) | ||
1066 | + | ||
1067 | + | ||
1068 | + //触发拖动列事件,参数为保存按钮的id | ||
1069 | + common.dragCols("parentResIndex_cols_save"); | ||
1070 | + | ||
1071 | + //保存列顺序 | ||
1072 | + $("#parentResIndex_cols_save").unbind("click").on("click", function () { | ||
1073 | + var params = { | ||
1074 | + domId: 'parentResListTable', | ||
1075 | + moduleId: 'resIndex', | ||
1076 | + resType: resType, | ||
1077 | + cols: parentResListTable.config.cols | ||
1078 | + } | ||
1079 | + common.saveTableCols(params); | ||
1080 | + }); | ||
1081 | + // 渲染统计数据 | ||
1082 | + loadRightResTypeSelectEvent(resType,"normal"); | ||
1083 | + } | ||
1084 | + }); | ||
1085 | + }); | ||
1086 | + } | ||
1087 | + | ||
1088 | + //资源列表 | ||
1089 | + function renderList(resType,id) { | ||
1090 | + $('#resIndexContent').hide(); | ||
1091 | + $('#resListContent').show(); | ||
1092 | + $('#resDetailContent').empty(); | ||
1093 | + $('#resDetailContent').hide(); | ||
1094 | + $('#treeTableContent').hide(); | ||
1095 | + //加载查询条件 | ||
1096 | + renderSerach(resType); | ||
1097 | + | ||
1098 | + // , {field: 'state', title: '连接状态', minWidth: 100, align: 'center', templet: '#resListContentTpl'}]; | ||
1099 | + if (resType && resType != 'PASSWORD_SERVER' && !/VIRTUALIZATION_((?!_).)+_(PHYSICSHOST|VHOST)/.test(resType)){ | ||
1100 | + $('#link_state_div').show(); | ||
1101 | + $('#host_state_div').hide(); | ||
1102 | + $('#power_state_div').hide(); | ||
1103 | + } else if(/VIRTUALIZATION_((?!_).)+_PHYSICSHOST/.test(resType)){ | ||
1104 | + $('#link_state_div').hide(); | ||
1105 | + $('#host_state_div').show(); | ||
1106 | + $('#power_state_div').hide(); | ||
1107 | + } else if(/VIRTUALIZATION_((?!_).)+_VHOST/.test(resType)){ | ||
1108 | + $('#link_state_div').hide(); | ||
1109 | + $('#host_state_div').hide(); | ||
1110 | + $('#power_state_div').show(); | ||
1111 | + } | ||
1112 | + var cols = commonCols.resTypeCls[resType]; | ||
1113 | + //获取配置的列 | ||
1114 | + common.getTableCols({ | ||
1115 | + domId: 'resListTable', | ||
1116 | + moduleId: 'resIndex', | ||
1117 | + resType: resType | ||
1118 | + },function (retCols) { | ||
1119 | + if (retCols) { | ||
1120 | + cols = retCols; | ||
1121 | + } | ||
1122 | + resListTable = table.render({ | ||
1123 | + elem: '#resListTable' | ||
1124 | + , id: 'resListTable' | ||
1125 | + , toolbar: '<div><button id="resIndex_cols_save" class="layui-btn layui-btn-primary layui-btn-xs toolbar-btn" lay-tips="保存列顺序"><i class="iconfont"></i></button></div>' //开启头部工具栏,并为其绑定左侧模板 | ||
1126 | + , defaultToolbar: ['filter'] | ||
1127 | + , drag: {toolbar: false} | ||
1128 | + , url: common.domainName + '/api-web/home/res-list/' + resType | ||
1129 | + , where: { | ||
1130 | + access_token: accessToken, | ||
1131 | + resName: $("#resindex_keyword").val() !== '' ? $("#resindex_keyword").val() : id, | ||
1132 | + busId: bizId, | ||
1133 | + resHealth: $("#resStatus").val(), | ||
1134 | + colonlyId: $("#res_colony").val(), | ||
1135 | + parentId: $("#res_cluster").val(), | ||
1136 | + sortKey: sortKey, | ||
1137 | + state: $("#state").val(), | ||
1138 | + linkState: $("#link_state").val(), | ||
1139 | + hostState: $("#host_state").val(), | ||
1140 | + powerState: $("#power_state").val(), | ||
1141 | + provider: $("#res_vendor").val(), | ||
1142 | + resCategory: 'resources' | ||
1143 | + } | ||
1144 | + , height: 'full-165' | ||
1145 | + , cellMinWidth: 80 | ||
1146 | + , page: { | ||
1147 | + layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'] | ||
1148 | + , theme: '#1E9FFF' | ||
1149 | + } | ||
1150 | + , autoSort: false | ||
1151 | + , limit: 150 | ||
1152 | + , limits: [150, 200, 300] | ||
1153 | + , cols: [cols] | ||
1154 | + , done: function (res, curr, count) { | ||
1155 | + soulTable.render(this) | ||
1156 | + | ||
1157 | + //调用收藏方法 | ||
1158 | + resFavorites(); | ||
1159 | + resTopo(); | ||
1160 | + | ||
1161 | + commonCols.colsClickEvent(editFlag); | ||
1162 | + | ||
1163 | + //表格排序监听 joke add 20200408 | ||
1164 | + table.on('sort(resListTable)', function (obj) { | ||
1165 | + //有些时候,你可能需要根据当前排序的字段,重新向服务端发送请求,从而实现服务端排序,如: | ||
1166 | + if (obj.type != null) { | ||
1167 | + sortKey = obj.field + ' ' + obj.type; | ||
1168 | + } else { | ||
1169 | + sortKey = ''; | ||
1170 | + } | ||
1171 | + reloadTable(); | ||
1172 | + }) | ||
1173 | + | ||
1174 | + //触发拖动列事件,参数为保存按钮的id | ||
1175 | + common.dragCols("resIndex_cols_save"); | ||
1176 | + | ||
1177 | + //保存列顺序 | ||
1178 | + $("#resIndex_cols_save").unbind("click").on("click", function () { | ||
1179 | + var params = { | ||
1180 | + domId: 'resListTable', | ||
1181 | + moduleId: 'resIndex', | ||
1182 | + resType: resType, | ||
1183 | + cols: resListTable.config.cols | ||
1184 | + } | ||
1185 | + common.saveTableCols(params); | ||
1186 | + $(this).addClass("hide"); | ||
1187 | + }); | ||
1188 | + } | ||
1189 | + }); | ||
1190 | + }); | ||
1191 | + } | ||
1192 | + | ||
1193 | + | ||
1194 | + | ||
1195 | + | ||
1196 | + function getResCount(resType) { | ||
1197 | + admin.req({ | ||
1198 | + url: common.domainName + "/api-web/home/res-list/count/" + resType | ||
1199 | + , type: "get" | ||
1200 | + , done: function (data) { | ||
1201 | + var rest = data.map; | ||
1202 | + if (data.code === 0) { | ||
1203 | + $("#resGoodCount").text("优:" + rest.good); | ||
1204 | + $("#resWorseCount").text("良:" + rest.worse); | ||
1205 | + $("#resWorstCount").text("中:" + rest.worst); | ||
1206 | + } else { | ||
1207 | + console.log(data.msg); | ||
1208 | + } | ||
1209 | + } | ||
1210 | + }); | ||
1211 | + } | ||
1212 | + | ||
1213 | + //加载资源池、集群等查询条件 | ||
1214 | + function renderSerach(resType,subflag) { | ||
1215 | + //清空查询条件 joke add 20200409 开始 | ||
1216 | + $('#resindex_keyword').val(''); | ||
1217 | + $('#resStatus').val(''); | ||
1218 | + // $('#resListBizTypes').val(''); | ||
1219 | + if(xmSelect.get("#resListBizTypes") && xmSelect.get("#resListBizTypes")[0]){ | ||
1220 | + xmSelect.get("#resListBizTypes")[0].setValue([]); | ||
1221 | + } | ||
1222 | + $("#aliyun_plantform").val(''); | ||
1223 | + $('#res_colony').val(''); | ||
1224 | + $('#res_cluster').val(''); | ||
1225 | + $('#state').val(''); | ||
1226 | + $('#link_state').val(''); | ||
1227 | + | ||
1228 | + //虚拟化查询条件清空 | ||
1229 | + $("#virtual_platForm_select").val(''); | ||
1230 | + $("#treetable_resStatus").val(''); | ||
1231 | + //$("#treetableBizTypes").val(''); | ||
1232 | + if(xmSelect.get("#treetableBizTypes") && xmSelect.get("#treetableBizTypes")[0]){ | ||
1233 | + xmSelect.get("#treetableBizTypes")[0].setValue([]); | ||
1234 | + } | ||
1235 | + // if(xmSelect.get("#collProtocolSelect") && xmSelect.get("#collProtocolSelect")[0]){ | ||
1236 | + // xmSelect.get("#collProtocolSelect")[0].setValue([]); | ||
1237 | + // } | ||
1238 | + | ||
1239 | + $("#treetable_keyword").val(''); | ||
1240 | + $("#treetable_state").val(''); | ||
1241 | + $("#host_state").val(''); | ||
1242 | + $("#power_state").val(''); | ||
1243 | + | ||
1244 | + if(busIdSelect){ | ||
1245 | + busIdSelect.setValue([]); | ||
1246 | + bizId = ''; | ||
1247 | + } | ||
1248 | + form.render('select'); | ||
1249 | + form.render(); | ||
1250 | + //清空查询条件 joke add 20200409 结束 | ||
1251 | + | ||
1252 | + var targetId = ''; | ||
1253 | + var searchType = ""; | ||
1254 | + var optons = ""; | ||
1255 | + //阿里云显示平台 | ||
1256 | + if(/ALI_CLOUD/.test(resType)){ | ||
1257 | + $("#aliyun_plantform").parent().parent().removeClass("hide"); | ||
1258 | + form.render("select"); | ||
1259 | + }else{ | ||
1260 | + $("#aliyun_plantform").parent().parent().addClass("hide"); | ||
1261 | + } | ||
1262 | + //华为云物理机,加载华为云集群查询条件 | ||
1263 | + if (resType == 'HUAWEI_CLOUD_PHYSICSHOST') { | ||
1264 | + optons = "<option value=''>=所属集群=</option>" | ||
1265 | + searchType = "HUAWEI_CLOUD_CLUSTER"; | ||
1266 | + targetId = "res_cluster"; | ||
1267 | + $("#res_cluster_id").show(); | ||
1268 | + } else if ("MIDDLEWARE_WEBLOGIC" == resType) { | ||
1269 | + optons = "<option value=''>=所属控制台=</option>" | ||
1270 | + searchType = "MIDDLEWARE_WEBLOGIC"; | ||
1271 | + targetId = 'res_cluster' | ||
1272 | + $("#res_cluster_id").show(); | ||
1273 | + } else { | ||
1274 | + $("#res_cluster_id").hide(); | ||
1275 | + } | ||
1276 | + //vmware虚拟机 joke add 20200528 | ||
1277 | + if (/VIRTUALIZATION_((?!_).)+_(PHYSICSHOST|VHOST)/.test(resType)) { | ||
1278 | + $("#res_platform_id").show(); | ||
1279 | + //绑定虚拟化平台 | ||
1280 | + common.virtualPlatFormSelect("res_platform", "", function () { | ||
1281 | + form.render("select"); | ||
1282 | + }, resType.match(/(VIRTUALIZATION_((?!_).)+)_(PHYSICSHOST|VHOST)/)[1]); | ||
1283 | + } else { | ||
1284 | + $("#res_platform_id").hide(); | ||
1285 | + } | ||
1286 | + //华为云的集群、虚拟化物理机、虚拟机,查询条件绑定资源池 | ||
1287 | + if (resType == 'HUAWEI_CLOUD_CLUSTER' || /VIRTUALIZATION_((?!_).)+_(PHYSICSHOST|VHOST)/.test(resType)) { | ||
1288 | + optons = "<option value=''>=所属资源池=</option>" | ||
1289 | + if (/VIRTUALIZATION_((?!_).)+_(PHYSICSHOST|VHOST)/.test(resType)) { | ||
1290 | + searchType = "VIRTUALIZATION_" + resType.match(/VIRTUALIZATION_(((?!_).)+)_(PHYSICSHOST|VHOST)/)[1] + "_CLUSTER"; | ||
1291 | + } | ||
1292 | + if (resType == 'HUAWEI_CLOUD_CLUSTER') { | ||
1293 | + searchType = "HUAWEI_CLOUD_COLONY"; | ||
1294 | + } | ||
1295 | + targetId = "res_colony"; | ||
1296 | + $("#res_colony_id").show(); | ||
1297 | + } else { | ||
1298 | + $("#res_colony_id").hide(); | ||
1299 | + } | ||
1300 | + if ("MIDDLEWARE_WEBLOGIC" == resType) { | ||
1301 | + $("#res_platform_id").hide() | ||
1302 | + } | ||
1303 | + | ||
1304 | + if (resType == 'VIRTUALIZATION_VMWARE' || resType == 'VIRTUALIZATION_HUAWEI' || resType == 'MIDDLEWARE_WEBLOGIC') { | ||
1305 | + $("#virtual_platform_div_id").hide(); | ||
1306 | + } | ||
1307 | + | ||
1308 | + if (resType == 'HOST_BMC') { | ||
1309 | + $("#res_vendor").parent().parent().removeClass("hide"); | ||
1310 | + var providerStr = ''; | ||
1311 | + $.ajax({ | ||
1312 | + url: `${common.domainName}/api-web/manage/ddic/findSucDdics/provider?access_token=${accessToken}`, | ||
1313 | + method: 'POST', | ||
1314 | + success: function (res) { | ||
1315 | + if (res && res.data) { | ||
1316 | + var ddiclist = res.data; | ||
1317 | + $.each(ddiclist, function (i, v) { | ||
1318 | + providerStr += '<option value="' + v.ddicCode + '">' + v.ddicName + '</option>'; | ||
1319 | + }); | ||
1320 | + $("#res_vendor").append(providerStr) | ||
1321 | + form.render("select"); | ||
1322 | + } | ||
1323 | + } | ||
1324 | + }) | ||
1325 | + } else { | ||
1326 | + $("#res_vendor").parent().parent().addClass("hide"); | ||
1327 | + } | ||
1328 | + if(/HUAWEI_CLOUD_VIRTUALHOST/.test(resType) || /ALI_CLOUD_ECS/.test(resType) || /VIRTUALIZATION_VMWARE_VHOST/.test(resType)){ | ||
1329 | + //绑定采集协议 | ||
1330 | + admin.req({ | ||
1331 | + url: domainName + '/api-web/manage/protocol/page', | ||
1332 | + data: { | ||
1333 | + access_token: accessToken, | ||
1334 | + startTime: '', | ||
1335 | + endTime: '', | ||
1336 | + keyword: '', | ||
1337 | + hasParam: '', | ||
1338 | + limit: -1 | ||
1339 | + } | ||
1340 | + }).done(function (res) { | ||
1341 | + $('#res_coll_protocol_select_div').show(); | ||
1342 | + xmSelect.render({ | ||
1343 | + el: '#collProtocolSelect' | ||
1344 | + , filterable: true | ||
1345 | + , tips: '=采集协议=' | ||
1346 | + , name: 'collProtocols' | ||
1347 | + , prop: { | ||
1348 | + name: 'protocolName', | ||
1349 | + value: 'protocolCode', | ||
1350 | + } | ||
1351 | + , model: { | ||
1352 | + label: { | ||
1353 | + type: 'block', | ||
1354 | + block: { | ||
1355 | + //最大显示数量, 0:不限制 | ||
1356 | + showCount: 1, | ||
1357 | + //是否显示删除图标 | ||
1358 | + showIcon: true, | ||
1359 | + } | ||
1360 | + } | ||
1361 | + } | ||
1362 | + , data: res.data | ||
1363 | + , hide: function () { | ||
1364 | + var selectValue = xmSelect.get('#collProtocolSelect', true).getValue('value'); | ||
1365 | + collProtocols = selectValue.join(','); | ||
1366 | + form.render() | ||
1367 | + reloadTable(); | ||
1368 | + if (collProtocols) { | ||
1369 | + xmSelect.get('#collProtocolSelect', true).setValue([]); | ||
1370 | + collProtocols = ''; | ||
1371 | + form.render(); | ||
1372 | + } | ||
1373 | + } | ||
1374 | + }) | ||
1375 | + }) | ||
1376 | + }else{ | ||
1377 | + $('#res_coll_protocol_select_div').hide(); | ||
1378 | + } | ||
1379 | + if (resType === 'HOST_MINICOMPUTER_PARTITION') { | ||
1380 | + $("#res_minicomputer").parent().parent().removeClass("hide"); | ||
1381 | + var minicomputerStr = ''; | ||
1382 | + minicomputerStr = '<option value="">=小型机服务器=</option>'; | ||
1383 | + let url = `${common.domainName}/api-web/home/res-list/hostMinicomputerPartitionParents?access_token=${accessToken}` | ||
1384 | + $.ajax({ | ||
1385 | + url: url, | ||
1386 | + method: 'get', | ||
1387 | + success: function (res) { | ||
1388 | + if (res && res.data) { | ||
1389 | + var list = res.data; | ||
1390 | + $.each(list, function (i, v) { | ||
1391 | + minicomputerStr += '<option value="' + v.resId + '">' + v.resName + '</option>'; | ||
1392 | + }); | ||
1393 | + $("#res_minicomputer").empty(); | ||
1394 | + $("#res_minicomputer").append(minicomputerStr) | ||
1395 | + form.render("select"); | ||
1396 | + } | ||
1397 | + } | ||
1398 | + }) | ||
1399 | + } else { | ||
1400 | + $("#res_minicomputer").parent().parent().addClass("hide"); | ||
1401 | + } | ||
1402 | + | ||
1403 | + if (targetId && searchType) { | ||
1404 | + var url = "/api-web/home/res-list/" + searchType + "?page=1&limit=50"; | ||
1405 | + if(searchType == 'MIDDLEWARE_WEBLOGIC'){ | ||
1406 | + url += '&parentId=null&parentType=parent' | ||
1407 | + } | ||
1408 | + admin.req({ | ||
1409 | + url: common.domainName + url | ||
1410 | + }).done(function (res) { | ||
1411 | + if (res.data) { | ||
1412 | + $.each(res.data, function (i, v) { | ||
1413 | + optons += '<option value="' + v.resId + '">' + v.resName + '</option>'; | ||
1414 | + }); | ||
1415 | + } | ||
1416 | + $('#' + targetId).html(optons); | ||
1417 | + form.render("select"); | ||
1418 | + }) | ||
1419 | + } | ||
1420 | + | ||
1421 | + if(subflag && !resTypeSelectExclude.includes(resType)){ | ||
1422 | + if(/ALI_CLOUD_/.test(resType) || /HUAWEI_CLOUD_/.test(resType)) { | ||
1423 | + | ||
1424 | + return; | ||
1425 | + } | ||
1426 | + $("#res_sub_restype").parent().parent().removeClass("hide"); | ||
1427 | + $(".top-head-info").removeClass("hide"); | ||
1428 | + | ||
1429 | + var url = `${common.domainName}/api-web/bResource/finsResTypeListByParentId?resType=${resType}` | ||
1430 | + admin.req({ | ||
1431 | + url: url | ||
1432 | + }).done(function (res) { | ||
1433 | + var subhtml = '<option value="">=资源类型=</option>'; | ||
1434 | + if (res.data) { | ||
1435 | + $.each(res.data, function (i, v) { | ||
1436 | + subhtml += '<option value="' + v.name + '">' + v.val + '</option>'; | ||
1437 | + }); | ||
1438 | + } | ||
1439 | + $('#res_sub_restype').html(subhtml); | ||
1440 | + form.render("select"); | ||
1441 | + }) | ||
1442 | + }else{ | ||
1443 | + if(!$("#resListContent").find(".top-head-info").hasClass("hide")){ | ||
1444 | + $("#resListContent").find(".top-head-info").addClass("hide") | ||
1445 | + } | ||
1446 | + if(!$("#res_sub_restype").parent().parent().hasClass("hide")){ | ||
1447 | + $("#res_sub_restype").parent().parent().addClass("hide"); | ||
1448 | + } | ||
1449 | + } | ||
1450 | + form.render(); | ||
1451 | + } | ||
1452 | + //加载右侧资源类型下拉框 | ||
1453 | + function loadRightResTypeSelectEvent(resType,type) { | ||
1454 | + layer.closeAll('tips'); | ||
1455 | + var counturl = `${common.domainName}/api-web/bResource/resCountInfomation?resType=${resType}` | ||
1456 | + admin.req({ | ||
1457 | + url: counturl, | ||
1458 | + data:{ | ||
1459 | + access_token: accessToken, | ||
1460 | + subResType:$("#res_sub_restype").val(), | ||
1461 | + resCategory: 'resources', | ||
1462 | + resName: $("#resindex_keyword").val(), | ||
1463 | + busId: bizId, | ||
1464 | + health: $("#resStatus").val(), | ||
1465 | + colonlyId: $("#res_colony").val(), | ||
1466 | + parentId: $("#res_cluster").val() ? $("#res_cluster").val() : $('#res_minicomputer').val(), | ||
1467 | + state: $("#state").val(), | ||
1468 | + linkState: $("#link_state").val(), | ||
1469 | + hostState: $("#host_state").val(), | ||
1470 | + powerState: $("#power_state").val(), | ||
1471 | + ptId: $("#res_platform").val(), | ||
1472 | + provider: $("#res_vendor").val() | ||
1473 | + } | ||
1474 | + }).done(function (res) { | ||
1475 | + var str = ''; | ||
1476 | + var domStr = 'resListContent' | ||
1477 | + var fun = reloadTable; | ||
1478 | + if(type == 'tree'){ | ||
1479 | + str = 'tree_' | ||
1480 | + domStr = 'treeTableContent' | ||
1481 | + fun = renderTreeTable | ||
1482 | + } | ||
1483 | + var map = res.object; | ||
1484 | + $.each(map,function(key,values){ | ||
1485 | + $("#"+str+key+"_res").html(map[key]) | ||
1486 | + }); | ||
1487 | + $("#"+domStr).find(".info-box-count .num span").unbind().on("click",function () { | ||
1488 | + var val = $(this).data("value"),target =$(this).data("target"); | ||
1489 | + if(val && target){ | ||
1490 | + $("#"+target).val(val); | ||
1491 | + form.render("select"); | ||
1492 | + fun(resType); | ||
1493 | + }else{ | ||
1494 | + $('#resindex_keyword').val(''); | ||
1495 | + $('#resStatus').val(''); | ||
1496 | + // $('#resListBizTypes').val(''); | ||
1497 | + $('#res_colony').val(''); | ||
1498 | + $('#res_cluster').val(''); | ||
1499 | + $('#state').val(''); | ||
1500 | + $('#link_state').val(''); | ||
1501 | + $("#virtual_platForm_select").val(''); | ||
1502 | + | ||
1503 | + $("#treetable_keyword").val(''); | ||
1504 | + $("#treetable_resStatus").val(''); | ||
1505 | + $("#treetable_res_state").val(''); | ||
1506 | + form.render("select"); | ||
1507 | + fun(resType); | ||
1508 | + if(busIdSelect){ | ||
1509 | + busIdSelect.setValue([ ]); | ||
1510 | + bizId=''; | ||
1511 | + form.render(); | ||
1512 | + } | ||
1513 | + } | ||
1514 | + | ||
1515 | + }) | ||
1516 | + form.render("select"); | ||
1517 | + form.render(); | ||
1518 | + }) | ||
1519 | + } | ||
1520 | + | ||
1521 | + //重新load表格 | ||
1522 | + function reloadTable() { | ||
1523 | + resListTable = parentResListTable = table.reload('resListTable', { | ||
1524 | + page: { | ||
1525 | + curr: 1 | ||
1526 | + } | ||
1527 | + , where: { //请求参数(注意:这里面的参数可任意定义,并非下面固定的格式) | ||
1528 | + access_token: accessToken, | ||
1529 | + resName: $("#resindex_keyword").val(), | ||
1530 | + busId: bizId, | ||
1531 | + resHealth: $("#resStatus").val(), | ||
1532 | + colonlyId: $("#res_colony").val(), | ||
1533 | + parentId: $("#res_cluster").val() ? $("#res_cluster").val() : $('#res_minicomputer').val(), | ||
1534 | + sortKey: sortKey, | ||
1535 | + state: $("#state").val(), | ||
1536 | + linkState: $("#link_state").val(), | ||
1537 | + hostState: $("#host_state").val(), | ||
1538 | + powerState: $("#power_state").val(), | ||
1539 | + ptId: $("#res_platform").val(), | ||
1540 | + subResType:$("#res_sub_restype").val(), | ||
1541 | + provider: $("#res_vendor").val(), | ||
1542 | + resCategory: 'resources', | ||
1543 | + collProtocols:collProtocols, | ||
1544 | + platform: $("#aliyun_plantform").val(), | ||
1545 | + } | ||
1546 | + }) | ||
1547 | + } | ||
1548 | + | ||
1549 | + //对比分析调用当前页面 开始 | ||
1550 | + function tabDom(resName,kpiName,name,info) { | ||
1551 | + //<div class="choose-tab"><span>浙江税务_出口退税_sc_134-内存使用率</span><a href="javascript:;">x</a></div> | ||
1552 | + var html = | ||
1553 | + '<div class="choose-tab">' + | ||
1554 | + '<input type="hidden" name="chooseDataInfo">'+ | ||
1555 | + '<span>'+resName+'-'+kpiName+'</span>' + | ||
1556 | + '<a href="javascript:;">x</a>' + | ||
1557 | + '</div>' | ||
1558 | + var $dom = $(html) | ||
1559 | + $dom.find("input[type=hidden][name=chooseDataInfo]").val(info); | ||
1560 | + $(".choose-resKpiInfo>.layui-card-header").append($dom); | ||
1561 | + } | ||
1562 | + | ||
1563 | + //获取选中的数据 | ||
1564 | + function getCheckData() { | ||
1565 | + var arr = []; | ||
1566 | + $.each($("input[type=hidden][name=chooseDataInfo]"),function (i,e) { | ||
1567 | + arr.push(JSON.parse(e.value)) | ||
1568 | + }) | ||
1569 | + return arr; | ||
1570 | + } | ||
1571 | + | ||
1572 | + //从当前路由中获取数据参数自动定位 | ||
1573 | + function loadParamSelect() { | ||
1574 | + if (router.search.resType) { | ||
1575 | + currentResType = router.search.resType; | ||
1576 | + var currentResId = router.search.resId ? router.search.resId : ''; | ||
1577 | + selectedTreeNode('[data-id="' + currentResType + '"]','[data-id="' + currentResType.split('_')[0] + '"]'); | ||
1578 | + renderList(currentResType,currentResId); | ||
1579 | + } | ||
1580 | + } | ||
1581 | + | ||
1582 | + //资源收藏 | ||
1583 | + function resFavorites() { | ||
1584 | + | ||
1585 | + //绑定鼠标移入移出事件 | ||
1586 | + $('table tr').hover(function (obj) { | ||
1587 | + $(obj.currentTarget).find('.layui-icon-rate').removeClass('hide'); | ||
1588 | + },function (obj) { | ||
1589 | + $(obj.currentTarget).find('.layui-icon-rate').addClass('hide'); | ||
1590 | + }) | ||
1591 | + | ||
1592 | + // 加入/移出收藏夹 | ||
1593 | + $('a.layui-icon-rate').unbind('click').on('click',rate ); | ||
1594 | + | ||
1595 | + function rate() { | ||
1596 | + var $aDom = $(this); | ||
1597 | + var resId = $aDom.data('id'); | ||
1598 | + var favIdList = $aDom.data('favid') && $aDom.data('favid') != 'null' ? $aDom.data('favid').split(',') : []; | ||
1599 | + admin.req({ | ||
1600 | + url: common.domainName + '/api-web/favorites/treeSelectData' | ||
1601 | + }).done(function (response) { | ||
1602 | + var data = response.data; | ||
1603 | + if (data.length == 0) { | ||
1604 | + var selectValue = ''; | ||
1605 | + saveFavs($aDom,selectValue,resId,'true') | ||
1606 | + } else if (data.length == 1) { | ||
1607 | + var selectValue = data[0].value; | ||
1608 | + saveFavs($aDom,selectValue,resId,'false'); | ||
1609 | + } else { | ||
1610 | + layer.open({ | ||
1611 | + type: '1', | ||
1612 | + title: '选择收藏夹', | ||
1613 | + id: 'layer-select-favorites', | ||
1614 | + content: '<div class="div-select-favorites"><div id="slt-favorites-tree"></div></div>', | ||
1615 | + offset: '150px', | ||
1616 | + area: ['20%', '25%'], | ||
1617 | + btn: ['选择', '取消'], | ||
1618 | + resize: false, | ||
1619 | + success: function () { | ||
1620 | + admin.req({ | ||
1621 | + url: common.domainName + '/api-web/favorites/treeSelectData' | ||
1622 | + }).done(function (response) { | ||
1623 | + xmSelect.render({ | ||
1624 | + el: '#slt-favorites-tree', | ||
1625 | + radio: true, | ||
1626 | + clickClose: true, | ||
1627 | + autoRow: true, | ||
1628 | + filterable: true, | ||
1629 | + height: '200px', | ||
1630 | + toolbar: { | ||
1631 | + show: true, | ||
1632 | + }, | ||
1633 | + model: { | ||
1634 | + label: { | ||
1635 | + type: 'text' | ||
1636 | + } | ||
1637 | + }, | ||
1638 | + tree: { | ||
1639 | + show: true, | ||
1640 | + showFolderIcon: true, | ||
1641 | + showLine: true, | ||
1642 | + indent: 20, | ||
1643 | + expandedKeys: true, | ||
1644 | + strict: false | ||
1645 | + }, | ||
1646 | + data: data | ||
1647 | + }); | ||
1648 | + }); | ||
1649 | + }, | ||
1650 | + yes: function (layerIndex) { | ||
1651 | + var selectValue = xmSelect.get('#slt-favorites-tree', true).getValue('value'); | ||
1652 | + if (favIdList.length === 0 && selectValue.length === 0) { | ||
1653 | + layer.msg('请选择一个收藏夹!', {icon: 0, time: 3000}); | ||
1654 | + return false; | ||
1655 | + } | ||
1656 | + var favIds = selectValue.join(','); | ||
1657 | + layer.load(2); | ||
1658 | + saveFavs($aDom,favIds,resId,'false',layerIndex); | ||
1659 | + } | ||
1660 | + }); | ||
1661 | + } | ||
1662 | + }) | ||
1663 | + } | ||
1664 | + | ||
1665 | + //移出收藏夹 | ||
1666 | + $('a.layui-icon-rate-solid').unbind('click').on('click',rateSolidClick ); | ||
1667 | + | ||
1668 | + function rateSolidClick() { | ||
1669 | + var $aDom = $(this); | ||
1670 | + var resId = $aDom.data('id'); | ||
1671 | + var favId = ''; | ||
1672 | + saveFavs($aDom,favId,resId,'false'); | ||
1673 | + } | ||
1674 | + | ||
1675 | + //添加收藏夹/移出收藏夹 | ||
1676 | + function saveFavs($aDom,favIds,resId,flag,layerIndex) { | ||
1677 | + admin.req({ | ||
1678 | + url: common.domainName + '/api-web/favorites/save/fav', | ||
1679 | + type: 'POST', | ||
1680 | + data: { | ||
1681 | + favIds: favIds, | ||
1682 | + resId: resId, | ||
1683 | + flag: flag | ||
1684 | + }, | ||
1685 | + error: function () { | ||
1686 | + layer.closeAll('loading'); | ||
1687 | + } | ||
1688 | + }).done(function (response) { | ||
1689 | + layer.closeAll('loading'); | ||
1690 | + if (response.success) { | ||
1691 | + if (favIds != '' || (flag == 'true' && favIds == '')) { | ||
1692 | + $aDom.removeClass('layui-icon-rate'); | ||
1693 | + $aDom.removeClass('hide'); | ||
1694 | + $aDom.addClass('layui-icon-rate-solid'); | ||
1695 | + $aDom.unbind('click').on('click', rateSolidClick); | ||
1696 | + $aDom.attr('lay-tips', '移出收藏夹'); | ||
1697 | + $aDom.css('color','#FEB61E').css('font-size','14px').css('margin-left','10px'); | ||
1698 | + $aDom.data('favid', favIds); | ||
1699 | + } else { | ||
1700 | + $aDom.removeClass('layui-icon-rate-solid'); | ||
1701 | + $aDom.addClass('layui-icon-rate'); | ||
1702 | + $aDom.unbind('click').on('click', rate); | ||
1703 | + $aDom.addClass('hide'); | ||
1704 | + $aDom.attr('lay-tips', '加入收藏夹'); | ||
1705 | + $aDom.css('font-size', '14px'); | ||
1706 | + $aDom.data('favid', ''); | ||
1707 | + } | ||
1708 | + layer.close(layerIndex); | ||
1709 | + } else { | ||
1710 | + layer.msg('保存失败!', {icon: 2, time: 3000}); | ||
1711 | + } | ||
1712 | + }); | ||
1713 | + } | ||
1714 | + } | ||
1715 | + | ||
1716 | + function resTopo() { | ||
1717 | + //绑定鼠标移入移出事件 | ||
1718 | + $('table tr').hover(function (obj) { | ||
1719 | + $(obj.currentTarget).find('.reslist-view-topo').removeClass('hide'); | ||
1720 | + $(obj.currentTarget).find('.reslist-assets-details').removeClass('hide'); | ||
1721 | + }, function (obj) { | ||
1722 | + $(obj.currentTarget).find('.reslist-view-topo').addClass('hide'); | ||
1723 | + $(obj.currentTarget).find('.reslist-assets-details').addClass('hide'); | ||
1724 | + }) | ||
1725 | + | ||
1726 | + // 加入/移出收藏夹 | ||
1727 | + $('a.reslist-view-topo').unbind('click').on('click', function () { | ||
1728 | + common.viewResTopo($(this).data('resid')); | ||
1729 | + }); | ||
1730 | + | ||
1731 | + // 查看资产配置信息 | ||
1732 | + $('a.reslist-assets-details').unbind('click').on('click', function () { | ||
1733 | + var $that = $(this); | ||
1734 | + var resId = $that.data("resid"); | ||
1735 | + var resType = $that.data("restype"); | ||
1736 | + var resName = $that.data("name")?$that.data("name"):''; | ||
1737 | + var ip = $that.data("ip")?$that.data("ip"):''; | ||
1738 | + var name = resName + " " + ip; | ||
1739 | + var url = 'assets/assetsProperty'; | ||
1740 | + var params = { | ||
1741 | + "resId": resId, | ||
1742 | + "resType": resType | ||
1743 | + }; | ||
1744 | + //资产配置信息弹窗大小设置 | ||
1745 | + var AREA_DEFAULT=['80%','80%']; | ||
1746 | + var AREA_DEFAULT_SMALL=['70%','80%']; | ||
1747 | + var AREA_DEFAULT_BIG=['90%','80%']; | ||
1748 | + var area=AREA_DEFAULT_SMALL; | ||
1749 | + // if(resType==''){ | ||
1750 | + // area=AREA_DEFAULT_SMALL; | ||
1751 | + // } | ||
1752 | + common.openWin(url, name, params,null,null,null,area); | ||
1753 | + }); | ||
1754 | + } | ||
1755 | + | ||
1756 | + | ||
1757 | + return {getData: getCheckData}; | ||
1758 | + }); | ||
1759 | +}); |
-
Please register or login to post a comment