Authored by 王涛

删除浙江工程依赖,将文件拷贝过来

Too many changes to show.

To preserve performance only 8 of 8+ files are displayed.

... ... @@ -18,7 +18,7 @@
<dependencies>
<dependency>
<groupId>com.honggroup</groupId>
<artifactId>hg-monitor-web-zj</artifactId>
<artifactId>hg-monitor-web-base</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
... ...
//活动告警
layui.define(['table', 'form', 'laydate', 'admin', 'layer', 'laytpl', 'common', 'sessions','commonDetail','soulTable', 'treeTable'], function (exports) {
var $ = layui.$;
var form = layui.form;
var layer = layui.layer;
var admin = layui.admin;
var table = layui.table;
var laydate = layui.laydate;
var laytpl = layui.laytpl;
var treeTable = layui.treeTable;
var common = layui.common;
var commonDetail=layui.commonDetail;
var domainName = common.domainName;
var todayStr = '';
//对外暴露的接口
exports('activewarning', function () {
var sessions = layui.sessions;
var accessToken = sessions.getToken()['access_token'];
var router = layui.router();
var alarmLevel = router.search.level; //告警级别
var checkList = common.checkPermission(accessToken);
var resId = router.search.resId;//资源Id
var kpiId = router.search.kpiId;//指标Id
var bizId = router.search.bizId;//业务Id
var alarmNo = router.search.alarmNo;//告警编号
var busIdSelect;
var busTypeList = [];
if(!bizId){
bizId='';
}
if (resId) {
resId = decodeURIComponent(resId);
}
if (alarmNo) {
$("#activewarningkw").val(alarmNo);
}
var netFlag = router.search.netFlag;//网络标识
var resType = router.search.restype ? router.search.restype : '';//资源类型
var soulTable = layui.soulTable;
var sortKey = '';
if ($("#alarmLevelSearchBox").val()) {
alarmLevel = $("#alarmLevelSearchBox").val()
}
//回显告警级别
$("#alarmLevelSearchBox").val(alarmLevel);
form.render("select");
function initDate() {
let startMin = {};
let endMax = {};
//开始时间
var start = laydate.render({
elem: '#activewarningStartdate'
, trigger: 'click'
,ready: function(date){
startMin=start.config.min;
}
, done: function (value, date) {
date.month--;
end.config.min = date;
if(value === ''){//点击清空
end.config.min = startMin;
}
form.render();
reloadTable()
}
});
//结束时间
var end = laydate.render({
elem: '#activewarningEnddate'
, trigger: 'click'
,ready: function(date){
endMax=end.config.max;
}
, done: function (value, date) {
date.month--;
start.config.max = date;
if(value === ''){//点击清空
start.config.max = endMax;
}
form.render();
reloadTable();
}
});
//绑定业务下拉选择数据
admin.req({
url: domainName + '/api-web/home/business/findUserBusTypeAll?table=',
success: function (response) {
if (response && response.success) {
busTypeList = response.data;
var bizList = response.data.map(item => {
return {
name: item.busTypeName,
value: item.busId,
parentId: item.parentId
}
});
var bizTree=common.pidToChildren(bizList, 'value', 'parentId');
// 影响业务下拉框
busIdSelect = xmSelect.render({
el: '#bisTypeSearchBox',
name: 'bizId',
tips: '=所属业务=',
//开启搜索
filterable: true,
clickClose: true,
initValue: [bizId.split(',')[0]],
toolbar: {
show: true,
list: ['ALL', 'REVERSE', 'CLEAR']
},
height: '170px',
tree: {
show: true,
showFolderIcon: true,
showLine: true,
strict: true,
//间距
indent: 20,
},
model: {
label: {
type: 'text'
}
},
data: bizTree,
on: function (data) {
if (data.arr.length != 0) {
var str='';
$.each(data.arr,function (i,v) {
str+=v.value+',';
})
bizId = str.substring(0,str.length-1);
} else {
bizId = '';
}
form.render();
reloadTable();
}
});
if(busIdSelect){
//追加样式
$('#bisTypeSearchBox').find('.xm-body').eq(0).css("width","230px");
}
} else {
layer.msg('获取业务失败', {icon: 2});
}
},
error: function () {
layer.msg('获取业务失败', {icon: 2});
}
});
$.ajax({
url: common.domainName + '/api-web/manage/kpi/findKpiInAlarm?access_token='+accessToken+'&tableName=b_alarm',
type: "get",
success:function (res) {
var kpis = res.data;
var html = '<option value="">=指标名称=</option>'
$.each(kpis,function (i,e) {
html+='<option value="'+e.kpiId+'">'+e.kpiName+'</option>'
})
$("#alarmKpiSearchBox").html('');
$("#alarmKpiSearchBox").append(html);
form.render();
}
})
$.ajax({
url: `${common.domainName}/api-web/manage/restype/list?access_token=${accessToken}`,
method: 'GET',
success: function (res) {
// 资源类型下拉框
var resTypeList = res.data.map(item => {
return {
name: item.resTypeName,
value: item.resTypeCode,
parentId: item.parentId
}
});
var resTypeTree = treeTable.pidToChildren(resTypeList, "value", "parentId");
xmSelect.render({
el: '#resTypeSearchBox',
name: "resType",
tips: '=资源类型=',
filterable: true,
radio: true,
clickClose: true,
initValue: [resType],
toolbar: {
show: true,
list: ['CLEAR']
},
tree: {
show: true,
showFolderIcon: true,
showLine: true,
strict: false,
indent: 20
},
model: {
label: {
type: 'text'
}
},
height: '200px',
data: resTypeTree,
on: function (data) {
if(data.isAdd){
if (data.arr.length != 0) {
resType = data.arr[0].value;
} else {
resType = '';
}
reloadTable();
}
}
});
}
});
}
//回车搜索
$('#activewarningkw, input[name="durationVal"]').keydown(function (e) {
if (e.keyCode === 13) {
reloadTable();
}
});
//选择框搜索事件
bindSelectEvent();
initDate();
function initToolBarClickEvent() {
//告警消除
$("#clearBtn").unbind('click').on('click', function () {
if ($.inArray('app:alarm:clear', checkList) == -1) {
layer.msg('暂无权限!', {icon: 7, time: 3000});
return;
}
var ids = [];
var data = table.checkStatus('activewarningTable').data;
if (data.length == 0) {
layer.msg('请最少选择一项数据', {icon: 7, time: 2000});
return;
}
//选中的告警ID放到集合中
$.each(data, function (i, obj) {
ids.push(obj.id)
});
//获取以往告警消除意见
admin.req({
url: common.domainName + '/api-web/home/alarm/clear/reason',
type: "get",
data:{
alarmId: ids.toString()
},
done:function (data) {
var clearReson = "暂无参考处理方案,请输入处理方案";
var hisReason = "";
var reasonlist = data.reason;
if(reasonlist && reasonlist.length > 0){
hisReason = "参考方案:\n";
$.each(reasonlist,function (i,v) {
var idx = i + 1;
hisReason += idx +":"+v +"\n";
});
}
layer.prompt({id: "alarms_clear_id", title: '告警消除', area: ['400px'], formType: 2,value: hisReason}, function (text, index) {
admin.req({
url: common.domainName + '/api-web/home/alarm/clear'
, type: "post"
, data: {
ids: ids.toString(),
reason: text,
access_token: accessToken,
noticeFlag: $('input[name="noticeFlag"]:checked').val()
}
, done: function (res) {
//如果消除成功,关闭弹出框然后重新加载页面
if (res.success) {
layer.close(index);
layer.msg('告警已消除!', {icon: 1, time: 2000});
reloadTable();
} else {
layer.msg('告警消除失败,请与管理员联系!', {icon: 7, time: 3000});
}
}
});
});
$("#alarms_clear_id").find('textarea.layui-layer-input').attr("placeholder", clearReson);
$("#alarms_clear_id").append('<div style="padding-top: 15px;"><span>是否通知:</span> ' +
'<input type="radio" name="noticeFlag" value="true" title="是" >&nbsp;是' +
'<input type="radio" name="noticeFlag" value="false" title="否" checked="" style="margin-left: 20px;">&nbsp;否</div> ');
}
});
});
//告警关闭
$("#closeBtn").unbind('click').on("click", function () {
if ($.inArray('app:alarm:close', checkList) == -1) {
layer.msg('暂无权限!', {icon: 7, time: 3000});
return;
}
var ids = [];
var data = table.checkStatus('activewarningTable').data;
var alarmStatus = true;
if (data.length == 0) {
layer.msg('请最少选择一项数据', {icon: 7, time: 2000});
return;
}
//选中的告警ID放到集合中
$.each(data, function (i, obj) {
var status = JSON.stringify(obj.alarmStatus);
if (status && status == '1') {
alarmStatus = false;
}
ids.push(obj.id)
});
if (!alarmStatus) {
layer.msg('已关闭的告警不可重复关闭!', {icon: 7, time: 3000});
return;
}
layer.prompt({
id: "alarms_cloes_id",
formType: 2,
title: '告警关闭',
area: ['400px']
},
function (value, index) {
if (value === "") {
layer.msg('请填写关闭意见', {icon: 7, time: 3000});
}
if ($('#closeDuration').val() === "") {
layer.msg('请填写关闭时长', {icon: 7, time: 3000});
return;
}
admin.req({
url: common.domainName + '/api-web/home/alarm/close'
, type: "post"
, data: {
ids: ids.toString(),
reason: value,
duration: $('#closeDuration').val() * 60,
closeType: $('input[name="closeType"]:checked').val(),
noticeFlag: $('input[name="noticeFlag"]:checked').val(),
kpiAllFlag: $('input[name="kpiAllFlag"]:checked').val(),
access_token: accessToken
}
, done: function (res) {
if (res.success) {
layer.close(index);
layer.msg('关闭成功', {icon: 1, time: 2000}, function () {
reloadTable();
});
} else {
layer.msg('告警关闭失败,请与管理员联系!', {icon: 7, time: 3000});
}
}
});
});
$("#alarms_cloes_id").find('textarea.layui-layer-input').attr("placeholder", "请输入关闭意见(必填)");// /[^(\d||/.)]/g,''
$("#alarms_cloes_id").append('<br/>' +
'<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="输入关闭时长,单位小时(必填)"/>');
$("#alarms_cloes_id").append('<br/><div style="line-height: 38px;"><span>关闭类型:</span> ' +
'<input type="radio" name="closeType" value="0" title="关闭告警" checked="">&nbsp;关闭告警' +
'<input type="radio" name="closeType" value="1" title="关闭通知" style="margin-left: 20px;">&nbsp;关闭通知</div> ');
$("#alarms_cloes_id").append('<div style="line-height: 38px;"><span>是否关闭该指标所有告警/通知:</span> ' +
'<input type="radio" name="kpiAllFlag" value="true" title="是">&nbsp;是' +
'<input type="radio" name="kpiAllFlag" value="false" title="否" checked="" style="margin-left: 20px;">&nbsp;否</div> ');
$("#alarms_cloes_id").append('<div style="line-height: 38px;"><span>是否通知:</span> ' +
'<input type="radio" name="noticeFlag" value="true" title="是">&nbsp;是' +
'<input type="radio" name="noticeFlag" value="false" title="否" checked="" style="margin-left: 20px;">&nbsp;否</div> ');
});
//告警确认
$("#confirmBtn").unbind('click').on("click", function () {
if ($.inArray('app:alarm:confirm', checkList) == -1) {
layer.msg('暂无权限!', {icon: 7, time: 3000});
return;
}
var ids = [];
var data = table.checkStatus('activewarningTable').data;
if (data.length == 0) {
layer.msg('请最少选择一项数据', {icon: 7, time: 2000});
return;
}
$.each(data, function (i, obj) {
ids.push(obj.id)
});
layer.prompt({
id: "alarms_confirm_id",
formType: 2,
title: '告警确认',
area: ['400px']
},
function (value, index) {
if (value === "") {
layer.msg('请填确认意见', {icon: 7, time: 3000});
}
admin.req({
url: common.domainName + '/api-web/home/alarm/confirm'
, type: "post"
, data: {
ids: ids.toString(),
reason: value,
level: $('input[name="confrimlevel"]:checked').val(),
access_token: accessToken
}
, done: function (res) {
if (res.success) {
layer.close(index);
layer.msg('告警确认成功', {icon: 1, time: 2000}, function () {
reloadTable();
});
} else {
layer.msg('告警确认失败,请与管理员联系!', {icon: 7, time: 3000});
}
}
});
});
$("#alarms_confirm_id").find('textarea.layui-layer-input').attr("placeholder", "请输入意见(必填)");
$("#alarms_confirm_id").append('<br/> ' +
'<input type="radio" name="confrimlevel" value="0" title="紧急" checked="">&nbsp;紧急' +
'<input type="radio" name="confrimlevel" value="1" title="非常紧急" style="margin-left: 20px;">&nbsp;非常紧急' +
'<input type="radio" name="confrimlevel" value="2" title="不紧急" style="margin-left: 20px;">&nbsp;不紧急');
});
//告警恢复
$("#resumeBtn").unbind('click').on("click", function () {
if ($.inArray('app:alarm:resume', checkList) == -1) {
layer.msg('暂无权限!', {icon: 7, time: 3000});
return;
}
var ids = [];
var closeIds = [];
var data = table.checkStatus('activewarningTable').data;
var resumeStatus = true;
if (data.length == 0) {
layer.msg('请最少选择一项数据', {icon: 7, time: 2000});
return;
}
var msg = "";
//选中的告警ID放到集合中
$.each(data, function (i, obj) {
var alarmStatus = JSON.stringify(obj.alarmStatus);
//已关闭的告警才可以恢复,告警状态,0告警,1关闭
if (alarmStatus && alarmStatus == '0') {
resumeStatus = false;
msg = '只能恢复已关闭状态的告警,请重新选择!';
}
ids.push(obj.id);
closeIds.push(obj.closeId);
});
if (!resumeStatus) {
layer.msg(msg, {icon: 7, time: 3000});
return;
}
layer.prompt({title: '恢复说明(必填)', formType: 2}, function (text, index) {
admin.req({
url: common.domainName + '/api-web/home/alarm/resume'
, type: "post"
, data: {
ids: ids.toString(),
reason: text,
closeId: closeIds.toString(),
resumeType: '0',//0告警关闭,1历史告警
access_token: accessToken
}
, done: function (res) {
//如果消除成功,关闭弹出框然后重新加载页面
if (res.success) {
layer.close(index);
layer.msg('告警已恢复!', {icon: 1, time: 3000}, function () {
reloadTable();
});
} else {
layer.msg('告警恢复失败,请与管理员联系!', {icon: 7, time: 3000});
}
}
});
})
});
//导出
$("#exportAarmBtn").unbind('click').on("click", function () {
if ($.inArray('app:alarm:export', checkList) == -1) {
layer.msg('暂无权限!', {icon: 7, time: 3000});
return;
}
var data = table.checkStatus('activewarningTable').data;
if (data.length == 0) {
//确认提示框
layer.confirm('当前没选择告警,将全量导出数据,请确认', {
btn: ['确定', '取消'] //按钮
}, function () {
var url = common.domainName + '/api-web/home/alarm/exportExcel/condition?access_token=' + accessToken;
url += '&kpiName=' + $("#activewarningkw").val();
url += '&busId=' + (bizId && bizId!='undefined' ? bizId : '');
url += '&resId=' + (resId && resId!='undefined' ? bizId : '');
url += '&kpiId=' + (kpiId && kpiId!='undefined' ? bizId : '');
url += '&alarmStatus=' + $("#alarmStatusSearchBox").val();
url += '&alarmLevel=' + $("#alarmLevelSearchBox").val();
url += '&confirmStatus=' + $("#alarmConfirmSearchBox").val();
url += '&beginTime=' + $("#activewarningStartdate").val();
url += '&endTime=' + $("#activewarningEnddate").val();
url += '&sortKey=' + sortKey;
url += '&alarmKpi=' + ($("#alarmKpiSearchBox").val() != 'KPI97B835A4' ? $("#alarmKpiSearchBox").val() : '');
url += '&isBus=' + ($("#alarmKpiSearchBox").val() == 'KPI97B835A4' ? 'Y' : '');
url += '&durationVal=' + ($('#inline-condition-duration input[name="durationVal"]').val());
url += '&durationUnit=' + ($('#inline-condition-duration select[name="durationUnit"]').val());
url += '&alarmTimeDay=' + todayStr;
url += '&resType=' + resType;
url += '&page=1&limit=999999';
window.open(url);
layer.closeAll();
});
} else {
var ids = [];
//讲选中的告警ID放到集合中
$.each(data, function (i, obj) {
ids.push(obj.id);
});
ids = ids.toString();
var url = common.domainName + '/api-web/home/alarm/exportExcel?alarmIds=' + ids + "&access_token=" + accessToken;
window.open(url)
}
});
//发送通知
$("#sendNoticeBtn").unbind('click').on("click", function () {
if ($.inArray('app:alarm:sendnotice', checkList) == -1) {
layer.msg('暂无权限!', {icon: 7, time: 3000});
return;
}
var ids = [];
var resIds = [];
var data = table.checkStatus('activewarningTable').data;
if (data.length == 0) {
layer.msg('请最少选择一项数据', {icon: 7, time: 2000});
return;
}
if (data.length > 1) {
layer.msg('请最多选择一项数据', {icon: 7, time: 2000});
return;
}
//将选中的告警ID放到集合中
$.each(data, function (i, obj) {
ids.push(obj.id);
resIds.push(obj.resId);
});
admin.req({
url: common.domainName + '/api-web/home/alarm/subscribe/user/' + resIds.toString()
, done: function (res) {
if (res.data && res.data.length > 0) {
var username = '';
var begin = '<div style="padding: 0 5px 0 5px;"><table class="layui-table"><thead>' +
'<tr><th></th><th>名称</th><th>电话</th><th>邮箱</th></tr></thead><tbody>';
var end = '</tbody></table></div>';
$.each(res.data, function (i, v) {
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>';
});
//获取告警通知接收人
var reciveUsers = begin + username + end;
layer.open({
type: 1
, title: "通知接收人"
, shade: 0.8
, area: ['600px', '390px']
, id: 'lay_users' //设定一个id,防止重复弹出
, content: reciveUsers
, btn: ['发送', '关闭']
, yes: function () {
var names = [];
$("input[class='userName']:checked").each(function(i){
names.push($(this).attr("data-name"));
});
if(names.length<1){
layer.msg('请最少选择一个用户', {icon: 7, time: 2000});
return;
}
admin.req({
url: common.domainName + '/api-web/home/alarm/sendnotice'
, type: "post"
, data: {
ids: ids.toString(),
names:names.toString(),
access_token: accessToken
}
, done: function (res) {
layer.closeAll();
if (res.success) {
layer.msg('发送成功', {icon: 1, time: 2000});
} else {
layer.msg('发送失败,稍后再试', {icon: 7, time: 2000});
}
}
});
}
});
} else {
layer.msg('未获取到接收所选通知的用户!', {icon: 7, time: 2000});
}
}
});
});
}
//告警处理及时率
getAlarmCount();
var activeAlarmTable;
//获取配置的列
common.getTableCols({
domId: 'activewarningTable',
moduleId: 'activewarning',
resType: ''
},function (retCols) {
var cols = [
{type: 'checkbox', fixed: 'left'}
, {
field: 'alarmLevel', title: '级别', align: 'center', width: 120, sort: true,
templet: `
<div>
{{# if (d.alarmLevel == 3) {
}} <span class="layui-table-warn" style="width: 100%;">严重</span> {{#
} else if (d.alarmLevel == 2) {
}} <span class="layui-table-close" style="width: 100%;">重要</span> {{#
} else if (d.alarmLevel == 1) {
}} <span class="layui-table-normal" style="width: 100%;">一般</span> {{#
} }}
</div>
`
}
, {
field: 'alarmNo', title: '告警编号', align: 'center', width: 140, sort: true,
}
, {
field: 'resName', title: '资源名称', width: 230, sort: true,
templet:`
<div>
<div style="display: flex;align-items: center;">
{{# if (d.confirmStatus == 0 || d.confirmStatus == null) { }}
<i lay-tips="新的告警未确认,告警确认后消失!" class="shake iconfont" style="color: red;font-size: 28px;">&#xe68b;</i>
{{# } }}
{{# if(d.isBus == 'N'){ }}
<span lay-tips="{{ d.resName }}" style="margin:0 5px;max-width: 160px;overflow: hidden; text-overflow: ellipsis; white-space: nowrap;display: inline-block;" data-isBus="{{d.isBus}}" data-resid="{{d.resId}}" data-restype="{{d.resType}}" data-warn-zymc="{{d.id}}" data-ip="{{d.ip}}"
data-resname="{{d.resName}}" data-pingenable="{{d.pingEnable}}" class="layui-table-link">{{d.resName}}</span>
{{# }else{ }}
<span lay-tips="{{ d.resName }}" style="margin:0 5px;max-width: 160px;overflow: hidden; text-overflow: ellipsis; white-space: nowrap;display: inline-block;" data-isBus="{{d.isBus}}" data-resid="{{d.resId}}" data-restype="{{d.resType}}" data-warn-zymc="{{d.id}}" data-ip="{{d.ip}}"
data-resname="{{d.resName}}" data-pingenable="{{d.pingEnable}}" >{{d.resName}}</span>
{{# } }}
<a class="layui-icon reslist-view-topo hide" data-resid="{{d.resId}}" lay-tips="查看资源拓扑"><i class="iconfont" style="font-size: 20px;
color: #FEB61E;"></i></a>
</div>
</div>
`
}
, {
field: 'kpiName', title: '指标名称', align: 'center', width: 120, sort: true,
templet: `
<div>
{{#
var kpiName = d.kpiName == 'TYPE'?'ERRPT':d.kpiName;
if (d.kpiIdent != 1) {
if(d.isWarning != 1) {
}} <div>{{kpiName}}</div> {{#
} else { }}
<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>
{{# }
} else { }}
<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>
{{# }
}}
</div>`
}
, {field: 'alarmContent', title: '告警内容', align: 'center', width: 500}
, {
field: 'alarmResource', title: '告警来源', align: 'center', minWidth: 120, templet: `<div>
{{# if (d.alarmResource == 1) { }}
<div>华为告警</div>
{{# } else { }}
<div>监控系统</div>
{{# } }}
</div>`
}
, {field: 'updateTime', title: '告警时间', align: 'center', minWidth: 180, sort: true}
, {field: 'alarmTime', title: '首次告警时间', align: 'center', minWidth: 180, sort: true}
, {field: 'durationStr', title: '持续时间', align: 'center', width: 190}
, {field: 'alarmRepeatCnt', title: '告警次数', align: 'center', width: 180}
, {field: 'nickName', title: '通知人', align: 'center', width: 180}
, {field: 'adminName', title: '负责人', align: 'center', width: 180}
, {field: 'noticeTime', title: '通知时间', align: 'center', width: 180, hide: true}
, {
title: '操作', align: 'center', minWidth: 100,
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>'
}
];
if (retCols) {
cols = retCols;
}
//渲染表格
activeAlarmTable = table.render({
elem: '#activewarningTable'
, url: domainName + '/api-web/home/alarm/alarmListPage'
, id: 'activewarningTable'
, toolbar: '#activeAlarmtoolbar' //开启头部工具栏,并为其绑定左侧模板
, defaultToolbar: ['filter']
, where: {
access_token: accessToken,
kpiName: $("#activewarningkw").val(),
busId: bizId,
resId: resId,
kpiId: kpiId,
alarmStatus: $("#alarmStatusSearchBox").val(),
alarmLevel: alarmLevel,
confirmStatus: $("#alarmConfirmSearchBox").val(),
beginTime: $("#activewarningStartdate").val(),
endTime: $("#activewarningEnddate").val(),
sortKey: sortKey,
alarmKpi: $("#alarmKpiSearchBox").val()!='KPI97B835A4'?$("#alarmKpiSearchBox").val():'',
isBus:$("#alarmKpiSearchBox").val()=='KPI97B835A4'?'Y':'',
durationVal: $('#inline-condition-duration input[name="durationVal"]').val(),
durationUnit: $('#inline-condition-duration select[name="durationUnit"]').val(),
netFlag: netFlag,
resType:resType
}
, height: 'full-245'
, cellMinWidth: 80
, page: {
layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
, theme: '#1E9FFF'
}
, even: true
, drag: {toolbar: false}
, cols: [cols],
done: function (res, curr, count) {
soulTable.render(this)
var groupurl = domainName + '/api-web/home/alarm/countAlarmNumByAlarmLevel?alarmTimeDay=' + todayStr + '&access_token=' + accessToken;
$.ajax({
url: groupurl,
type: 'get',
data: {
access_token: accessToken,
kpiName: $("#activewarningkw").val(),
busId: bizId,
resId: resId,
kpiId: kpiId,
alarmStatus: $("#alarmStatusSearchBox").val(),
alarmLevel: alarmLevel,
confirmStatus: $("#alarmConfirmSearchBox").val(),
beginTime: $("#activewarningStartdate").val(),
endTime: $("#activewarningEnddate").val(),
sortKey: sortKey,
//alarmKpi: $("#alarmKpiSearchBox").val(),
alarmKpi: $("#alarmKpiSearchBox").val()!='KPI97B835A4'?$("#alarmKpiSearchBox").val():'',
isBus:$("#alarmKpiSearchBox").val()=='KPI97B835A4'?'Y':'',
durationVal: $('#inline-condition-duration input[name="durationVal"]').val(),
durationUnit: $('#inline-condition-duration select[name="durationUnit"]').val(),
netFlag: netFlag,
resType:resType
},
success: function (res) {
var map = res.map;
if (map) {
layui.use('laytpl', function () {
var laytpl = layui.laytpl;
var getTpl = document.getElementById("alarm-count-id-tpl").innerHTML;
laytpl(getTpl).render(map, function (html) {
$('#alarm-count-id').html(html);
});
//告警升级量 悬浮提示
var alarmUpRate, alarmDealRate;
$("#alarm_level_up_area_id").hover(function () {
alarmUpRate = layer.tips("活动告警中升级的告警总量及占比",
'#alarm_level_up_area_id', {tips: [1]});
}, function () {
layer.close(alarmUpRate);
});
//告警处理及时率
$("#alarm_deal_rate_area_id").hover(function () {
alarmDealRate = layer.tips("活动告警中及时处理的告警量占比",
'#alarm_deal_rate_area_id', {tips: [1]});
}, function () {
layer.close(alarmDealRate);
});
$('[data-warn-zymc]').unbind('click').on('click', function () {
//先去查找资源有没有权限
var resId = $(this).data("resid");
var resType = $(this).data("restype");
var ip = $(this).data("ip") ? $(this).data("ip") : "";
var resName = $(this).data("resname");
var pingEnable = $(this).data("pingenable"); //获取pingEnable的值 joke add 20200619
var resTypeName = '';
var adminName = '';
var manageIp = '';
var collProtocol = '';
var sign='false';
$.ajax({
url: common.domainName + "/api-web/home/resource/findById?resId="+resId + '&access_token='+ accessToken,
async: false,
type:'get',
success: function (res) {
sign=res.str;
var data = res.object;
resType = data.resType;
adminName = data.adminName;
manageIp = data.manageIp;
collProtocol = data.collProtocol;
resTypeName = data.resTypeName;
}
})
if(sign=='false'){
layer.msg('当前用户暂无此资源权限!', {icon: 7, time: 3000});
return false;
}
let title = resName;
if (title && title !== '') {
title += '|';
}
if (resTypeName && resType !== 'HOST_X86SERVER') {
title += resTypeName + '|';
}
if (ip) {
if (resType === 'HOST_X86SERVER') {
if (collProtocol && (collProtocol.split(",").length > 1 || collProtocol === 'SSH')) {
title += '应用IP-' + ip + '|';
}
} else {
title += ip + '|';
}
}
if (resType === 'HOST_X86SERVER' && collProtocol && collProtocol.indexOf('SNMP') !== -1 ) {
if (manageIp) {
title += '管理IP-' + manageIp + '|';
}
}
if (adminName) {
title += adminName + '|';
}
if (title.length > 0) {
title = title.substr(0, title.length - 1);
}
if (pingEnable == '2') { //如果pingEnable为2,则进入ping状态详情页面
commonDetail.openNewWin('template/detail/pingIndex', title, {'resId': resId}, false);
} else { //否则进入监控详情页面
commonDetail.openDetail(resId, resType, title);
}
});
//指标名称点击事件
$('[data-warn-zbmc]').unbind("click").on('click', function () {
var name = $(this).data("name");
var params = {
resId: $(this).data("resid"),
kpiId: $(this).data("kpi"),
flag: $(this).data("flag"),
name: name,
warning: $(this).data("warning"),
ident: $(this).data("ident"),
trend: $(this).data("trend")
};
common.openLineChart(name, params);
});
//告警操作日志
$('[data-warn-view]').unbind('click').on('click', function () {
admin.req({
url: common.domainName + '/api-web/home/alarm/info'
, data: {
alarmId: $(this).data('warn-view'),
access_token: accessToken
}
}).done(function (res) {
laytpl($('#warnViewWinTpl').html()).render(res.obj, function (html) {
layer.open({
area: '750px',
title: ['告警操作信息', 'font-size:18px;'],
type: 1,
content: html
});
});
});
});
//告警轨迹
$('[data-warn-path]').unbind('click').on('click', function () {
var id = $(this).attr('data-warn-path');
var view = layui.view;
var params = {
"warnId": id
};
view('commonViewModel').render("template/detail/warn_gj").then(function (res) {
layer.open({
title: ['告警轨迹', 'font-size:18px;'],
type: 1,
area: ['900px', '650px'],
content: laytpl(res.body).render(JSON.stringify(params))
});
});
});
});
//点击严重重要一般统计告警
$("#alarm-count-id").find(".warn-count-item").unbind('click').on("click", function () {
var alarmLevel = $(this).attr("alarm-level");
if (alarmLevel != '' && alarmLevel != null && alarmLevel != undefined) {
$("#alarmLevelSearchBox").val(alarmLevel)
layui.form.render('select');
reloadTable();
} else {
$("#alarmLevelSearchBox").val("");
layui.form.render('select');
if (alarmLevel === '') {
reloadTable();
}
}
});
initToolBarClickEvent();
//表格排序监听 joke add 20200408
table.on('sort(activewarningTable)', function (obj) {
//有些时候,你可能需要根据当前排序的字段,重新向服务端发送请求,从而实现服务端排序,如:
if (obj.type != null) {
sortKey = obj.field + ' ' + obj.type;
} else {
sortKey = '';
}
reloadTable('sort');
})
//更改告警级别颜色
setColourLevel();
}
}
})
//触发拖动列事件,参数为保存按钮的id
common.dragCols("activewarning_cols_save");
//保存列顺序
$("#activewarning_cols_save").unbind("click").on("click", function () {
var params = {
domId: 'activewarningTable',
moduleId: 'activewarning',
resType: '',
cols: JSON.stringify(activeAlarmTable.config.cols)
}
common.saveTableCols(params,0);
});
resTopo();
}
});
});
//更改告警级别颜色
function setColourLevel() {
//获取告警等级
let alarmLevel = $("#alarmLevelSearchBox").val();
$('#alarm_serious').css("color","#666");
$('#alarm_important').css("color","#666");
$('#alarm_commonly').css("color","#666");
switch (alarmLevel) {
case "3"://严重告警
$('#alarm_serious').css("color","#D81E06");
break;
case "2"://重要告警
$('#alarm_important').css("color","#FF7E00");
break;
case "1"://一般告警
$('#alarm_commonly').css("color","#1e9fff");
break;
default://其他 空或无
break;
}
}
//绑定下拉搜索事件
function bindSelectEvent() {
//选择业务搜索
form.on('select(bisTypeSearch)', function (data) {
bizId = data.value;
reloadTable();
});
//选择业务搜索
form.on('select(alarmKpiSearch)', function (data) {
reloadTable();
});
// 告警状态
form.on('select(alarmStatusSearch)', function (data) {
reloadTable();
});
//告警级别
form.on('select(alarmLevelSearch)', function (data) {
reloadTable();
});
// 告警确认
form.on('select(alarmConfirmSearch)', function (data) {
reloadTable();
});
}
$("#todayOrAllBtn").unbind().on("click",function () {
var $that = $(this);
var str = $(this).text();
if(str.indexOf("今日") > -1){
$that.text("全部告警")
todayStr = common.getToday('day');
}else{
todayStr = ''
$that.text("今日告警")
}
reloadTable();
})
//刷新表格
function reloadTable(type) {
if (type != 'sort'){
sortKey = '';
}
activeAlarmTable.reload({
page: {
curr: 1
}
,where: {
access_token: accessToken,
kpiName: $("#activewarningkw").val(),
busId: bizId,
resId: resId,
kpiId: kpiId,
alarmStatus: $("#alarmStatusSearchBox").val(),
alarmLevel: $("#alarmLevelSearchBox").val(),
confirmStatus: $("#alarmConfirmSearchBox").val(),
beginTime: $("#activewarningStartdate").val(),
endTime: $("#activewarningEnddate").val(),
sortKey: sortKey,
//alarmKpi: $("#alarmKpiSearchBox").val(),
alarmKpi: $("#alarmKpiSearchBox").val()!='KPI97B835A4'?$("#alarmKpiSearchBox").val():'',
isBus:$("#alarmKpiSearchBox").val()=='KPI97B835A4'?'Y':'',
durationVal: $('#inline-condition-duration input[name="durationVal"]').val(),
durationUnit: $('#inline-condition-duration select[name="durationUnit"]').val(),
alarmTimeDay:todayStr,
resType:resType
}
});
}
//获取告警统计信息
function getAlarmCount() {
admin.req({
url: common.domainName + "/api-web/home/alarm/countByAlarmLevel"
, type: "get"
, done: function (data) {
var alarms = data.data;
if (data.code == 0) {
$.each(alarms, function (i, v) {
if (v.alarmLevel == 5) {//及时率
$("#alarm_dealRate").html(v.alarmNum + "%");
}
});
} else {
console.error("接口请求失败")
console.log(data.msg);
}
}
})
}
form.render(null, 'activewarning-form');
//60秒倒计时
(function () {
var autoBtn = $('#activewarningAutoFlush');
var timer = null;
function autoFlush(target) {
var el = target.find('span');
var checked = target.find('input').prop('checked');
localStorage.setItem('alarm_auto__flush', checked);
function fn() {
var second = el.data('second');
var checked = target.find('input').prop('checked');
if (!checked) {
return;
}
--second;
el.data('second', second);
el.html(second + '秒');
timer = setTimeout(fn, 1000);
if (second <= 0) {
clearTimeout(timer);
reloadTable()
$(el).data('second', 60);
$(el).text("60秒");
fn();
}
}
if (checked) {
timer = setTimeout(fn, 1000);
} else {
clearTimeout(timer);
}
}
form.on("checkbox(warnActiveAutoFlush)",function (data) {
autoFlush(autoBtn);
})
/*autoBtn.change(function () {
autoFlush(autoBtn);
});*/
var auto = localStorage.getItem('alarm_auto__flush')
auto = auto ? auto : false;
autoBtn.find('input').prop('checked', auto);
autoFlush(autoBtn);
admin.on('hash(*)', function (router) {
if (router.href === '/activewarning') {
autoFlush(autoBtn);
} else {
clearTimeout(timer);
}
});
})();
function resTopo() {
//绑定鼠标移入移出事件
$('table tr').hover(function (obj) {
$(obj.currentTarget).find('.reslist-view-topo').removeClass('hide');
}, function (obj) {
$(obj.currentTarget).find('.reslist-view-topo').addClass('hide');
})
// 加入/移出收藏夹
$('a.reslist-view-topo').unbind('click').on('click', function () {
common.viewResTopo($(this).data('resid'));
});
}
});
});
\ No newline at end of file
... ...
layui.define(['commonDetail','common', 'admin'], function (exports) {
var $ = layui.$;
var commonDetail = layui.commonDetail;
var common = layui.common;
var admin = layui.admin;
//对外暴露的接口
exports('arms', function (data) {
var resId = '';
var resType = '';
var os = '';
var domainName = common.domainName;
var showFlag = common.getUrlParam("show");
if(showFlag && showFlag == '0'){
resId = common.getUrlParam("resId");
resType = common.getUrlParam("resType");
os = common.getUrlParam("os");
}else{
resId = data.resId;
resType = data.resType;
os = data.os;
}
//基本信息
var jbxxKpi = "KPIE13DD9A3,KPIF74D9D2B";
commonDetail.bindTips();
renderPageInfo()
//渲染页面
function renderPageInfo() {
//资源状态
commonDetail.renderResHealth("arms_health_state", resId);
//基本信息
commonDetail.renderText("arms_baseinfo", resId, jbxxKpi, null, null, null, "true");
//GC瞬时次数/每分钟
dataRenderingBase("arms_frequency_lineChart", resId, "KPIB30309CF,KPI6AFFCBDB", "GC瞬时次数/每分钟", null);
// //GC瞬时耗时/每分钟
dataRenderingBase("arms_elapsed_lineChart", resId, "KPI5769F327,KPI8B2CCCCF", "GC瞬时耗时/每分钟", null);
// //堆内存详情/每分钟
dataRenderingBase("arms_JVM_memory_lineChart", resId, "KPI5C214A8F,KPI14BD24A7,KPI206706E5", "堆内存详情/每分钟", null);
// //非堆内存/每分钟
dataRenderingBase("arms_NOJVN_memory_lineChart", resId, "KPIA751DDD7,KPIB0C32458,KPIBEA62DAA,KPID346BB6F", "非堆内存/每分钟", null);
// //直接缓冲区/每分钟
dataRenderingBase("arms_cacheRegion_lineChart", resId, "KPIBAD64951,KPIA80D93D8", "直接缓冲区/每分钟", null);
// //JVM线程数/每分钟
dataRenderingBase("arms_JVM_threadCount_lineChart", resId, "KPI7C4BEB26,KPI97B71BAA,KPI15EC2627,KPIA9E2E4DE,KPI068D9FA5,KPI6ECA9036,KPI328E5AFE,KPI8F8FAD7F", "JVM线程数/每分钟", null, 1);
//响应时间/每分钟
dataRenderingBase("arms_time_lineChart", resId, "KPI678F9FC3", "响应时间/每分钟", null);
// Start Wang 2022/2/24 9:29 解决:arms采集结果展示(详情页面开发)
// 节点详情
commonDetail.renderTable("arms_node_detail",false,resId,"KPI452C0F78,KPI5769F327,KPI8B2CCCCF,KPI678F9FC3,KPI649E288B,KPI8DC835B1,KPI4D6871EA,KPICC063E40,KPIFC03301B",'节点详情',`detail`,'KPIFC03301B','desc');
// End Wang 2022/2/24 9:30
//活动告警
commonDetail.renderActiveAlarms("arms_active_alram", resId);
}
//折线图数据渲染及页面设置
function dataRenderingBase(id, resId, kpiId, title, flag) {
var dataList = {};
var item = {};
var other = {};
item.legend = {};
item.x = {};
item.y = {};
//获取数据
admin.req({
url: domainName + '/api-web/details/getBase',
data: {
resId: resId,
kpiIds: kpiId,
}
}).done(function (response) {
if (response.success && !response.msg) {//有数据
dataList.legend = response.map.legend;
dataList.x = response.map.x;
if (response.map.y != null) {
var series = [];
$.each(response.map.y, function (i, v) {
var item = {
name: dataList.legend[i],
stack: 'Total',
type: 'line',
emphasis: {
focus: 'series'
},
itemStyle: {
normal: {
color: common.colorsArr[i%6].start
}
},
data: v,
};
series.push(item);
});
other["series"]=series;
}
initLinChart(id, resId, kpiId, title, flag, dataList, other);
} else {//无数据
//初始化数据
}
});
//页面渲染
return {item, other}
}
//初始化折线图
function initLinChart(id, resId, kpiId, title, flag, data, other) {
//初始化echarts
var myChart = echarts.init(document.getElementById(id));
//初始化配置option
var option;
option = {
legend: {//设置图表图例
data: data.legend,
},
tooltip: {
trigger: 'axis',
},
toolbox: {
feature: {
saveAsImage: {}
}
},
xAxis: {//X轴数据
type: 'category',
boundaryGap: false,
data: data.x,
},
yAxis: {//设置提示
type: 'value'
},
grid: { //直角坐标系内绘图网格
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
series: [//y轴数据
{
data: data.y?data.y:{},
type: 'line',
smooth: true
}
]
};
//获取传入option对象
var keys = Object.keys(other);
//替换option属性
keys.forEach(item => {
option[item]=other[item];
});
option && myChart.setOption(option);
}
//定时任务
var timer = setInterval(function () {
renderPageInfo()
},commonDetail.timerTime);
commonDetail.detailTimer.push(timer);
});
});
... ...
layui.define(['tree', 'laypage', 'laytpl', 'admin', 'form', 'table', 'commonCols', 'echarts', 'sessions',"commonDetail",'tableTree','soulTable'], function (exports) {
var $ = layui.$;
var laytpl = layui.laytpl;
var tree = layui.tree;
var form = layui.form;
var view = layui.view;
var table = layui.table;
var admin = layui.admin;
var commonCols = layui.commonCols;
var soulTable = layui.soulTable;
var tableTree = layui.tableTree;
var common = layui.common;
var commonDetail = layui.commonDetail;
var busId = '';//当前业务Id
var appId = '';
var curTreeNode = '';
var curBizResType = '';//当前业务所在的资源类型
var sortKey = '';
function autoHeight(el) {
// var height = el.parents('.layui-card').height();
// el.css('min-height', height - 75);
}
// 隐藏左侧菜单
$('#LAY_app_flexible').click();
//对外暴露的接口
exports('bizindex', function () {
var sessions = layui.sessions;
var accessToken = sessions.getToken()['access_token'];
var router = layui.router();
// 资源视图父级表格
var bizParentList;
// 资源视图表格
var bizListTable;
//点击卡片
$('#bizindexTable').unbind('click').on('click', '[data-biz-card]', function () {
var resType = $(this).data("biz-card");
var isLeaf = $(this).data("biz-leaf");
//过滤业务卡片
if (isLeaf =='1') {
//回选树节点
selectedBizTreeNode('[data-id="' + resType + '"]', "biz");
renderBizResTypeCard(resType);
} else if(isLeaf == '0'){
selectedBizTreeNode('[data-id="' + resType + '"]', "biz");
renderSecondIndex(resType);
}else{
//curBizResType = resType;
$("div[data-id='"+busId+"']").find("div[data-id='"+resType+"'] .layui-tree-entry:first span.layui-tree-txt").trigger("click")
}
});
// 查看拓扑
$('#bizindexTable').on('click', '.bizcard-view-topo', function () {
common.viewBizTopo($(this).data('busid'));
return false;
});
//回车搜索
$('#bizindex_keyword').keydown(function (e) {
if (e.keyCode === 13) {
// renderList(busId, curBizResType);
reloadTable();
return false;
}
});
var loading = layer.load(2);
// 树收缩事件
$('#bizindex-leftree-shrink').on('click', function () {
$(".bizIndexLeft").animate({width:0,minWidth:0,marginLeft:0},300,function () {
$("#bizindex-leftree_btn").show();
$("#bizindex-leftree-shrink").hide();
});
});
//树展开事件
$("#bizindex-leftree_btn").on("click",function () {
$("#bizindex-leftree_btn").hide();
$("#bizindex-leftree-shrink").show();
$(".bizIndexLeft").animate({minWidth:250,marginLeft:10},300);
});
//this
loadBizTree();
function renderIndex(busId, resType) {
$('#bizIndexContent').show();
$('#bizListContent').hide();
$('#biztreeTableContent').hide();
$('#bizDetailContent').empty();
$('#bizDetailContent').hide();
var bizindexTable = $('#bizindexTable');
autoHeight(bizindexTable);
window.setResizeEvents('autoHeight', autoHeight);
bizindexTable.html('<div class="loading"></div>');
admin.req({
url: common.domainName + '/api-web/home/resource/healthByResType?pResType=' + resType + '&busId=' + busId,
}).done(function (res) {
laytpl($('#bizindexTpl').html()).render({list: res.data}, function (html) {
bizindexTable.html(html);
});
});
}
function renderDefaultIndex() {
$('#bizIndexContent').show();
$('#bizListContent').hide();
$('#biztreeTableContent').hide();
$('#bizDetailContent').empty();
$('#bizDetailContent').hide();
var bizindexTable = $('#bizindexTable');
autoHeight(bizindexTable);
window.setResizeEvents('autoHeight', autoHeight);
admin.req({
url: common.domainName + '/api-web/home/resource/countResourceGroupByBusType',
}).done(function (res) {
layer.close(loading);
laytpl($('#bizindexTpl').html()).render({list: res.data, isBiz: true}, function (html) {
bizindexTable.html(html);
});
});
}
function renderSecondIndex(parentId) {
$('#bizIndexContent').show();
$('#bizListContent').hide();
$('#biztreeTableContent').hide();
$('#bizDetailContent').empty();
$('#bizDetailContent').hide();
var bizindexTable = $('#bizindexTable');
autoHeight(bizindexTable);
window.setResizeEvents('autoHeight', autoHeight);
admin.req({
url: common.domainName + '/api-web/home/resource/countSecondNum?parentId='+parentId,
}).done(function (res) {
layer.close(loading);
laytpl($('#bizindexTpl').html()).render({list: res.data, isBiz: true}, function (html) {
bizindexTable.html(html);
});
});
}
//详细页面
function renderDetail(resId, resType) {
$('#bizIndexContent').hide();
$('#bizListContent').hide();
$('#biztreeTableContent').hide();
$('#bizDetailContent').show();
var url = common.detailPath(resType);
view('commonViewModel').render(url).then(function (res) {
var params = {
"resId": resId,
"resType": resType
};
laytpl(res.body).render(JSON.stringify(params), function (html) {
$("#bizDetailContent").html(html);
});
});
}
//加载树节点
function loadBizTree(val) {
//获取树节点数据
$("#bizindextree").empty();
if (val == '' || val == null || val == undefined) {
val = '';
}
admin.req({
url: common.domainName + '/api-web/home/business/getBusTree?keyword=' + val + '&notExist=machineroom',
sync: true,
done: function (res) {
$('.layui-form layui-card-header')
if (res.success) {
var data = res.data;
tree.render({
elem: '#bizindextree',
showLine: false,
data: data,
click: function (node) {
if (node && node.data && node.data.children && node.data.children.length == 1) {
$('[data-id="' + node.data.children[0].id + '"]').find('.layui-tree-iconClick:first').click()
}
curTreeNode = node;
curBizResType = node.data.id;
if (node.data.code) {
busId = JSON.parse(node.data.code)["busId"];
appId = JSON.parse(node.data.code)["appId"];
}
var el = null;
if (node.data.children) {
el = $(node.elem[0]).find('>.layui-tree-entry .layui-tree-txt');
} else {
el = $(node.elem[0]).find('.layui-tree-txt');
}
var action = 'removeClass';
if (!el.hasClass('tree-node-select') && node.state === 'open') {
action = 'addClass';
el.parents('.layui-tree').find('.tree-node-select').removeClass('tree-node-select');
}
el[action]('tree-node-select');
// 决定显示那个视图
var optionsStr = '';
if (node.data.code) {
optionsStr = JSON.parse(node.data.code)['options'];
}
if (optionsStr && optionsStr != "") {
options = JSON.parse(optionsStr);
var callback = options.bizCallBack;
var fun = eval(callback);
// 获取回调方法
if ($.isFunction(fun)) {
fun.call(this, data, node.data, options);
}
} else if (node.data.code && JSON.parse(node.data.code).isLeaf == '0') {
renderSecondIndex(node.data.id);
} else {
if (node.data && node.data.system) {
//操作系统
if (node.data.system.length > 0) {
renderSystem(node.data.system);
}
} else {
renderBizResTypeCard(node.data.id);
}
}
}
});
$("#bizTotal").html(res.count);
loadParamSelect();
resTopo();
}
}
}).error(function () {
layer.close(loading);
var data = new Array();
tree.render({
elem: '#bizindextree',
showLine: false,
data: data
});
$("#bizTotal").html('0')
laytpl($('#bizindexTpl').html()).render({list: new Array()}, function (html) {
$('#bizindexTable').html(html);
});
});
renderDefaultIndex();
}
$("#bizTotal").parent().on("click",function () {
renderDefaultIndex();
})
$(".layui-input-search").keyup(function (e) {
if (e.keyCode === 13) {
loadBizTree($(this).val())
}
});
//资源详细页面
function loadResDetailInfo(parentNode, data, node, options) {
var resId = data.id;
var resType = data.pid;
renderDetail(resId, resType);
}
function loadChildResTypeCount(parentNode, data, node, options) {
var resId = data.id;
for (var i = 0; i < parentNode.length; i++) {
if (parentNode.id == data.id) {
resId = '';
break;
}
}
var code = JSON.parse(data.code);
renderIndex(code.busId, resId);
}
function loadChildBusCount(parentNode, data, node, options) {
var resId = data.id;
for (var i = 0; i < parentNode.length; i++) {
if (parentNode.id == data.id) {
resId = '';
break;
}
}
var code = JSON.parse(data.code);
renderSecondIndex(code.busId);
}
function openResourceView(parentNode, data, node, options) {
var code = JSON.parse(data.code);
renderList(code.busId, data.id);
}
//资源视图父级列表
function openParentResourceView(parentNode, data, node, options) {
var code = JSON.parse(data.code);
renderParentList(code.busId, data.id);
}
//加载虚拟化数据(平台、资源池、物理机、虚拟机)
function loadVirtualizationView(parentNode, data, node, options) {
renderTreeTable(busId, data.id);
}
//加载weblogic
function loadWeblogicView(parentNode, data, node, options) {
renderParentList(busId, data.id);
}
//资源状态
form.on('select(biz_resStatus)', function (data) {
// renderList(busId, curBizResType)
reloadTable();
});
//集群选择事件
form.on('select(biz_res_cluster)', function (data) {
// renderList(busId, curBizResType);
reloadTable();
});
//资源池选择事件
form.on('select(biz_res_colony)', function (data) {
// renderList(busId, curBizResType);
reloadTable();
});
//资源连接状态选择事件
form.on('select(biz_state)', function (data) {
// renderList(busId, curBizResType);
reloadTable();
});
//资源连接状态选择事件
form.on('select(biz_platform)', function (data) {
// renderList(busId, curBizResType);
reloadTable();
});
//连接状态
form.on('select(bizlink_state)', function (data) {
// renderList(currentResType);
reloadTable();
});
//连接状态
form.on('select(bizlink_state)', function (data) {
// renderList(currentResType);
reloadTable();
});
//资源池选择事件
form.on('select(biz_sub_restype)', function (data) {
// renderList(currentResType);
if (data.value) {
bizLoadRightResTypeSelectEvent(busId, data.value, 'normal')
} else {
bizLoadRightResTypeSelectEvent(busId, curTreeNode.data.id, 'normal')
}
reloadTable();
});
//操作系统
function renderSystem(system) {
$('#bizIndexContent').hide();
$('#bizListContent').show();
$('#bizDetailContent').empty();
$('#bizDetailContent').hide();
$('#biztreeTableContent').hide();
//清除查询条件
$("#bizindex_keyword").val("");
$("#biz_resStatus").val("");
$("#biz_res_colony").val("");
$("#biz_res_cluster").val("");
$("#bizlink_state").val("");
$("#biz_state").val("");
busId="";
//隐藏资源类型
$("#biz_sub_restype").parent().parent().addClass("hide");
form.render('select');
form.render(null, 'biz-list-form');
var cols = commonCols.resTypeCls["OperatingSystem"];
var resTypeList=[];
$.each(system, function (i, v) {
resTypeList.push(v.value);
busId=v.pid;
});
//获取配置的列
common.getTableCols({
domId: 'bizListTable',
moduleId: 'bizIndex',
resType: 'OperatingSystem'
},function (retCols) {
if (retCols) {
cols = retCols;
}
bizListTable = table.render({
elem: '#bizListTable'
// //, toolbar: '<div><button id="bizIndex_cols_save" class="layui-btn layui-btn-primary layui-btn-xs toolbar-btn" lay-tips="保存列顺序"><i class="iconfont">&#xe633;</i></button></div>' //开启头部工具栏,并为其绑定左侧模板
, toolbar: '#bizList-top-head-info-tpl' //开启头部工具栏,并为其绑定左侧模板
, defaultToolbar: ['filter']
, drag: {toolbar: false}
, url: common.domainName + '/api-web/home/res-list/' + resTypeList.toString()
, where: {
access_token: accessToken,
resName: $("#bizindex_keyword").val(),
resHealth: $("#biz_resStatus").val(),
busId: busId,
colonlyId: $("#biz_res_colony").val(),
parentId: $("#biz_res_cluster").val(),
linkState: $("#bizlink_state").val(),
state: $("#biz_state").val(),
resCategory: 'resources',
}
, height: 'full-165'
, cellMinWidth: 80
, page: {
layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
, theme: '#1E9FFF'
}
, autoSort: false
, cols: [cols]
, done: function (res) {
soulTable.render(this);
getResCount(busId, resTypeList.toString());
commonCols.colsClickEvent();
bizLoadRightResTypeSelectEvent(busId, 'OperatingSystem', 'normal', res.obj);
//表格排序监听 joke add 20200408
table.on('sort(bizListTable)', function (obj) {
//有些时候,你可能需要根据当前排序的字段,重新向服务端发送请求,从而实现服务端排序,如:
if (obj.type != null) {
sortKey = obj.field + ' ' + obj.type;
} else {
sortKey = '';
}
reloadTable();
})
//触发拖动列事件,参数为保存按钮的id
common.dragCols("bizIndex_cols_save");
//保存列顺序
$("#bizIndex_cols_save").unbind("click").on("click", function () {
var params = {
domId: 'bizListTable',
moduleId: 'bizIndex',
resType: 'OperatingSystem',
cols: bizListTable.config.cols
}
common.saveTableCols(params);
});
resTopo();
}
});
});
}
//获取业务下的资源类型健康统计
function renderBizResTypeCard(bizId) {
busId = bizId;
$('#bizIndexContent').show();
$('#bizListContent').hide();
$('#biztreeTableContent').hide();
$('#bizDetailContent').empty();
$('#bizDetailContent').hide();
var bizindexTable = $('#bizindexTable');
autoHeight(bizindexTable);
window.setResizeEvents('autoHeight', autoHeight);
admin.req({
url: common.domainName + "/api-web/datavis/getResTotal/?busId=" + bizId
, done: function (res) {
laytpl($('#bizindexTpl').html()).render({list: res.data}, function (html) {
bizindexTable.html(html);
});
}
});
}
function renderParentList(busId, resType) {
$('#bizIndexContent').hide();
$('#bizListContent').show();
$('#bizDetailContent').empty();
$('#bizDetailContent').hide();
$('#biztreeTableContent').hide();
renderBizSerach(resType, busId, true);
form.render(null, 'biz-list-form');
var cols = commonCols.resTypeCls[resType];
//获取配置的列
common.getTableCols({
domId: 'bizParentList',
moduleId: 'bizIndex',
resType: resType
},function (retCols) {
if (retCols) {
cols = retCols;
}
bizParentList = table.render({
elem: '#bizListTable'
, url: common.domainName + '/api-web/home/res-list/' + resType
, toolbar: '#bizList-top-head-info-tpl' //开启头部工具栏,并为其绑定左侧模板
, defaultToolbar: ['filter']
, drag: {toolbar: false}
, where: {
access_token: accessToken,
resName: $("#bizindex_keyword").val(),
resHealth: $("#biz_resStatus").val(),
busId: busId,
colonlyId: $("#biz_res_colony").val(),
parentId: $("#biz_res_cluster").val(),
linkState: $("#bizlink_state").val(),
state: $("#biz_state").val(),
resCategory: 'resources'
}
, height: 'full-165'
, cellMinWidth: 80
, page: {
layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
, theme: '#1E9FFF'
}
, autoSort: false
, cols: [cols]
, done: function (res) {
soulTable.render(this)
getResCount(busId, resType)
commonCols.colsClickEvent();
//表格排序监听 joke add 20200408
table.on('sort(bizListTable)', function (obj) {
//有些时候,你可能需要根据当前排序的字段,重新向服务端发送请求,从而实现服务端排序,如:
if (obj.type != null) {
sortKey = obj.field + ' ' + obj.type;
} else {
sortKey = '';
}
reloadTable();
})
//触发拖动列事件,参数为保存按钮的id
common.dragCols("bizIndex_cols_save");
bizLoadRightResTypeSelectEvent(busId, resType, 'normal', res.obj);
//保存列顺序
$("#bizIndex_cols_save").unbind("click").on("click", function () {
var params = {
domId: 'bizParentList',
moduleId: 'bizIndex',
resType: resType,
cols: bizParentList.config.cols
}
common.saveTableCols(params);
});
resTopo();
}
});
});
}
//资源列表
function renderList(busId, resType) {
$('#bizIndexContent').hide();
$('#bizListContent').show();
$('#bizDetailContent').empty();
$('#bizDetailContent').hide();
$('#biztreeTableContent').hide();
renderBizSerach(resType, busId);
form.render(null, 'biz-list-form');
var cols = commonCols.resTypeCls[resType];
//获取配置的列
common.getTableCols({
domId: 'bizListTable',
moduleId: 'bizIndex',
resType: resType
},function (retCols) {
if (retCols) {
cols = retCols;
}
bizListTable = table.render({
elem: '#bizListTable'
//, toolbar: '<div><button id="bizIndex_cols_save" class="layui-btn layui-btn-primary layui-btn-xs toolbar-btn" lay-tips="保存列顺序"><i class="iconfont">&#xe634;</i></button></div>' //开启头部工具栏,并为其绑定左侧模板
, toolbar: '#bizList-top-head-info-tpl' //开启头部工具栏,并为其绑定左侧模板
, defaultToolbar: ['filter']
, drag: {toolbar: false}
, url: common.domainName + '/api-web/home/res-list/' + resType
, where: {
access_token: accessToken,
resName: $("#bizindex_keyword").val(),
resHealth: $("#biz_resStatus").val(),
busId: busId,
colonlyId: $("#biz_res_colony").val(),
parentId: $("#biz_res_cluster").val(),
linkState: $("#bizlink_state").val(),
state: $("#biz_state").val(),
resCategory: 'resources'
}
, height: 'full-165'
, cellMinWidth: 80
, page: {
layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
, theme: '#1E9FFF'
}
, autoSort: false
, cols: [cols]
, done: function (res) {
soulTable.render(this)
getResCount(busId, resType)
commonCols.colsClickEvent();
//表格排序监听 joke add 20200408
table.on('sort(bizListTable)', function (obj) {
//有些时候,你可能需要根据当前排序的字段,重新向服务端发送请求,从而实现服务端排序,如:
if (obj.type != null) {
sortKey = obj.field + ' ' + obj.type;
} else {
sortKey = '';
}
reloadTable();
})
//触发拖动列事件,参数为保存按钮的id
common.dragCols("bizIndex_cols_save");
bizLoadRightResTypeSelectEvent(busId, resType, 'normal', res.obj);
//保存列顺序
$("#bizIndex_cols_save").unbind("click").on("click", function () {
var params = {
domId: 'bizListTable',
moduleId: 'bizIndex',
resType: resType,
cols: bizListTable.config.cols
}
common.saveTableCols(params);
});
resTopo();
}
});
});
}
//树表格
function renderTreeTable(busId, resType) {
$('#bizIndexContent').hide();
$('#bizListContent').hide();
$('#bizDetailContent').empty();
$('#bizDetailContent').hide();
$('#biztreeTableContent').show();
$(".top-head-info").removeClass("hide");
layer.load(2); //加载层。
//非平台才有以下三个指标信息
if (resType != 'VIRTUALIZATION_VMWARE') {
//绑定虚拟化平台
common.virtualPlatFormSelect("biz_virtual_platForm_select", busId, function () {
form.render("select");
});
if(resType == 'MIDDLEWARE_WEBLOGIC'){
$("#biz_virtual_platform_div_id").hide();
}
} else {
$("#biz_virtual_platform_div_id").hide();
}
var cols = commonCols.resTypeCls[resType];
admin.req({
url: common.domainName + "/api-web/home/virtual-res-list/" + resType
, data: {
ptId: $("#biz_virtual_platForm_select").val(),
health: $("#biz_treetable_resStatus").val(),
busId: busId,
keyWords: $("#biz_treetable_keyword").val(),
state: $("#biz_treetable_res_state").val()
}
, done: function (res) {
if (res.code == 0) {
var bizTableTreeVirtual;
//获取配置的列
common.getTableCols({
domId: 'bizTableTreeVirtual',
moduleId: 'bizIndex',
resType: resType
},function (retCols) {
if (retCols) {
cols = retCols;
}
bizTableTreeVirtual = table.render({
elem: '#biz_virtual_platform_treeTable',
data: res.data,
treeConfig: { //表格树所需配置
showField: 'resName' //表格树显示的字段
, treeid: 'resId' //treeid所对应字段的值在表格数据中必须是唯一的,且不能为空。
, treepid: ''//父级id字段名称
, iconClass: 'layui-icon-triangle-r' //小图标class样式 窗口图标 layui-icon-layer
},
tree: {
iconIndex: 1
},
page: false,
limit: 9999,
autoColumnWidth: false,
cols: [cols]
, height: 'full-220',
done: function (res){
soulTable.render(this);
common.treeTableDragCols('#biz_virtual_platform_treeTable', '#bizTreeList-top-head-info-tpl');
bizLoadRightResTypeSelectEvent(busId, resType, 'tree', res.obj);
// 保存列顺序
$('#biz_virtual_platform_treeTable').next().find('.btn_save_cols').unbind('click').on('click', function (){
common.saveTableCols({
domId: 'bizTableTreeVirtual',
moduleId: 'bizIndex',
resType: resType,
cols: bizTableTreeVirtual.config.cols
});
});
commonCols.colsClickEvent();
resTopo();
}
});
/*bizTableTreeVirtual.on('tool(tableEvent)',function (obj) {
if(!obj.data.treeList){
var field = obj.field; //单元格字段
var value = obj.value; //修改后的值
var data = obj.data; //当前行数据
var event = obj.event; //当前单元格事件属性值
var subResType = '';
if(data.resType == 'VIRTUALIZATION_VMWARE' || data.resType == 'VIRTUALIZATION_HUAWEI'){
subResType = data.resType=='VIRTUALIZATION_VMWARE'?'VIRTUALIZATION_VMWARE_CLUSTER':'VIRTUALIZATION_HUAWEI_CLUSTER';
}else if(data.resType.indexOf('CLUSTER')>-1){
subResType = data.resType=='VIRTUALIZATION_VMWARE_CLUSTER'?'VIRTUALIZATION_VMWARE_PHYSICSHOST':'VIRTUALIZATION_HUAWEI_PHYSICSHOST';
}else if(data.resType.indexOf('PHYSICSHOST')>-1){
subResType = data.resType=='VIRTUALIZATION_VMWARE_PHYSICSHOST'?'VIRTUALIZATION_VMWARE_VHOST':'VIRTUALIZATION_HUAWEI_VHOST';
}else{
subResType = data.resType
}
if(event === 'loadChildren'){
$.ajax({
url: common.domainName + "/api-web/home/virtual-res-list/" + subResType
, type: "get"
, data: {
ptId: $("#biz_virtual_platForm_select").val(),
health: $("#treetable_resStatus").val(),
busId: busId,
keyWords: $("#biz_treetable_keyword").val(),
state: $("#biz_treetable_state").val(),
access_token:accessToken,
parentId:data.resId
}
, success: function (res) {
if (res.data.length > 0) {
obj.loadChildren(res.data);
commonCols.colsClickEvent();
}
}
})
}
}
});*/
//统计总数
// $('#biz_virtual_platform_treeTable').next().find('.layui-table-box').after(laytpl($('#biz-treetable-countTpl').html()).render(res.data.length));
});
} else {
console.log(data.msg);
}
layer.closeAll();
//关键字回车事件
$('#biz_treetable_keyword').keydown(function (e) {
if (e.keyCode === 13) {
renderTreeTable(busId, curTreeNode.data.id)
return false;
}
});
//选择资源状态
form.on('select(biz_treetable_resStatus)', function (data) {
renderTreeTable(busId, curTreeNode.data.id);
});
//选择业务
form.on('select(treetableBizTypes)', function (data) {
renderTreeTable(busId, curTreeNode.data.id);
});
//选择业务
form.on('select(biz_treetable_res_state)', function (data) {
renderTreeTable(busId, curTreeNode.data.id);
});
//选择平台
form.on('select(biz_virtual_platForm_select)', function (data) {
renderTreeTable(busId, curTreeNode.data.id);
});
//资源连接状态选择时间
form.on('select(biz_treetable_state)', function (data) {
renderTreeTable(busId, curTreeNode.data.id);
});
}
}).error(function () {
layer.closeAll();
});
}
//获取资源统计
function getResCount(busId, resType) {
admin.req({
url: common.domainName + "/api-web/home/res-list/count/" + resType + "?busId=" + busId
, done: function (data) {
var rest = data.map;
if (data.code === 0) {
$("#resGoodCount").text("优:" + rest.good);
$("#resWorseCount").text("良:" + rest.worse);
$("#resWorstCount").text("中:" + rest.worst);
} else {
console.log(data.msg);
}
}
});
}
//回选树节点
function selectedBizTreeNode(target, type) {
$(".layui-tree-txt").removeClass("tree-node-select")
if (type == 'biz') { //如果是业务,默认展开第一节点
$(target).addClass("layui-tree-spread");
$(target).find(".layui-tree-entry").find('.layui-tree-txt').eq(0).addClass("tree-node-select");
$(target).parent().show();
$(target).find(".layui-tree-pack").eq(0).show();
} else if (type == 'select') {
$(target).parent().show();
$(target).find(".layui-tree-txt:first").addClass("tree-node-select");
} else {
var el = $('[data-id="' + busId + '"]').find(target);
$(target).parent().show();
el.find(".layui-tree-txt").addClass("tree-node-select")
}
}
//加载资源池、集群等查询条件
function renderBizSerach(resType, busId, subflag) {
//清空查询条件 joke add 20200409 开始
$('#bizindex_keyword').val('');
$('#biz_resStatus').val('');
$('#biz_res_colony').val('');
$('#biz_res_cluster').val('');
form.render('select');
//清空查询条件 joke add 20200409 开始
var targetId = '';
var searchType = "";
var optons = "";
//华为云物理机,加载华为云集群查询条件
if (resType == 'HUAWEI_CLOUD_PHYSICSHOST') {
optons = "<option value=''>=所属集群=</option>"
searchType = "HUAWEI_CLOUD_CLUSTER";
targetId = "biz_res_cluster";
$("#biz_res_cluster_id").show();
} else if ("MIDDLEWARE_WEBLOGIC" == resType) {
optons = "<option value=''>=所属控制台=</option>"
searchType = "MIDDLEWARE_WEBLOGIC";
targetId = 'biz_res_cluster'
$("#biz_res_cluster_id").show();
} else {
$("#biz_res_cluster_id").hide();
}
//华为云的集群、虚拟化物理机,查询条件绑定资源池
if (resType == 'HUAWEI_CLOUD_CLUSTER' || resType == 'VIRTUALIZATION_VMWARE_PHYSICSHOST') {
optons = "<option value=''>=所属资源池=</option>"
if (resType == 'VIRTUALIZATION_VMWARE_PHYSICSHOST') {
searchType = "VIRTUALIZATION_VMWARE_CLUSTER";
}
if (resType == 'HUAWEI_CLOUD_CLUSTER') {
searchType = "HUAWEI_CLOUD_COLONY";
}
targetId = "biz_res_colony";
$("#biz_res_colony_id").show();
} else {
$("#biz_res_colony_id").hide();
}
if ("MIDDLEWARE_WEBLOGIC" == resType) {
$("#biz_platform_id").hide()
}
if (resType == 'VIRTUALIZATION_VMWARE' || resType == 'VIRTUALIZATION_HUAWEI' || resType == 'MIDDLEWARE_WEBLOGIC') {
$("#biz_virtual_platform_div_id").hide();
}
if (targetId && searchType) {
var url = "/api-web/home/res-list/" + searchType + "?page=1&limit=50&busId=" + busId;
if(searchType == 'MIDDLEWARE_WEBLOGIC'){
url += '&parentId=null'
}
admin.req({
url: common.domainName + url
}).done(function (res) {
if (res.data) {
$.each(res.data, function (i, v) {
optons += '<option value="' + v.resId + '">' + v.resName + '</option>';
});
}
$('#' + targetId).html(optons);
form.render("select");
})
}
//vmware虚拟机 joke add 20200528
if (resType == 'VIRTUALIZATION_VMWARE_VHOST') {
$("#biz_platform_id").show();
//绑定虚拟化平台
common.virtualPlatFormSelect("biz_platform", "", function () {
form.render("select");
});
} else {
$("#biz_platform_id").hide();
}
if(subflag){
$("#biz_sub_restype").parent().parent().removeClass("hide");
$("#bizListContent").find(".top-head-info").removeClass("hide");
var url = `${common.domainName}/api-web/bResource/finsResTypeListByParentId?resType=${resType}`
admin.req({
url: url
}).done(function (res) {
var subhtml = '<option value="">=资源类型=</option>';
if (res.data) {
$.each(res.data, function (i, v) {
subhtml += '<option value="' + v.name + '">' + v.val + '</option>';
});
}
$('#biz_sub_restype').html(subhtml);
form.render("select");
})
} else {
if (!$("#bizListContent").find(".top-head-info").hasClass("hide")) {
$("#bizListContent").find(".top-head-info").addClass("hide")
}
if (!$("#biz_sub_restype").parent().parent().hasClass("hide")) {
$("#biz_sub_restype").parent().parent().addClass("hide");
}
}
}
function bizLoadRightResTypeSelectEvent(busId, resType, type, obj) {
var str = '';
var domStr = 'bizListContent'
var fun = reloadTable;
if (type == 'tree') {
str = 'tree_'
domStr = 'biztreeTableContent'
fun = renderTreeTable
}
var map = obj;
$.each(map, function (key, values) {
$("#" + str + key + "_biz").html(map[key])
});
//清除筛选条件
$("#" + domStr).find(".info-box-count .num span").unbind().on("click", function () {
var val = $(this).data("value"), target = $(this).data("target");
if (val && target) {
$("#" + target).val(val);
form.render("select")
fun(busId, resType);
} else {
//清除查询条件
$('#bizindex_keyword').val('');
$('#biz_res_colony').val('');
$('#biz_res_cluster').val('');
$('#biz_resStatus').val('');
$('#bizlink_state').val('');
$('#biz_state').val('');
$('#biz_sub_restype').val('');
$("#biz_virtual_platForm_select").val('');
$("#biz_treetable_resStatus").val('');
$("#biz_treetable_keyword").val('');
$("#biz_treetable_res_state").val('');
$('#biz_platform').val('');
form.render("select")
fun(busId, resType);
}
})
}
//重新load表格
function reloadTable() {
var platform = $("#biz_platform").find("option:selected").text();
if (platform == '=所属平台=') {
platform = '';
}
bizListTable = bizParentList = table.reload('bizListTable', {
page: {
curr: 1
}
,where: { //请求参数(注意:这里面的参数可任意定义,并非下面固定的格式)
access_token: accessToken,
resName: $("#bizindex_keyword").val(),
resHealth: $("#biz_resStatus").val(),
busId: busId,
colonlyId: $("#biz_res_colony").val(),
parentId: $("#biz_res_cluster").val(),
sortKey: sortKey,
state: $("#biz_state").val(),
linkState: $("#bizlink_state").val(),
platform: platform,
subResType:$("#biz_sub_restype").val()
}
})
}
function loadParamSelect() {
if (router.search.busId) {
busId = router.search.busId;
var type = router.search.type ? router.search.type : 'select';
//回选树节点
selectedBizTreeNode('[data-id="' + busId + '"]', type);
renderBizResTypeCard(busId);
}
}
function resTopo() {
//绑定鼠标移入移出事件
$('table tr').hover(function (obj) {
$(obj.currentTarget).find('.reslist-view-topo').removeClass('hide');
}, function (obj) {
$(obj.currentTarget).find('.reslist-view-topo').addClass('hide');
})
// 加入/移出收藏夹
$('a.reslist-view-topo').unbind('click').on('click', function () {
common.viewResTopo($(this).data('resid'));
});
}
});
});
\ No newline at end of file
... ...
// 业务类型管理
layui.define(['table', 'form', 'admin', 'layer', 'laytpl', 'common', 'view', 'sessions', 'commonDetail', 'treeTable', 'xmSelect', 'userlist', 'reslist'], function (exports) {
var $ = layui.$;
var form = layui.form;
var layer = layui.layer;
var admin = layui.admin;
var table = layui.table;
var treeTable = layui.treeTable;
var xmSelect = layui.xmSelect;
var laytpl = layui.laytpl;
var view = layui.view;
var common = layui.common;
var commonDetail = layui.commonDetail;
var domainName = common.domainName;
// 业务类型展示表格
var busTypeTable;
// 对外暴露的接口
exports('bustype', function (data) {
var sessions = layui.sessions;
var accessToken = sessions.getToken()['access_token'];
var cutoverId = '', targetType = '';
if (data && data.cutoverId) {
cutoverId = data.cutoverId;
targetType = data.targetType;
}
var mode = (data && data.mode) ? data.mode : '';
var username = (data && data.username) ? data.username : '';
//展示类型
var showTypeList=[];
var dataBusType=[];
initShowType();
// 查询条件
var conditions = {busTypeName: ''};
// 加载遮罩
var loading;
var checkList = common.checkPermission(accessToken);
loadBusTypeTable();
// 查询条件框回车查询事件
$('#condition-bustype-name').keydown(function (e) {
if (e.keyCode === 13) {
loadBusTypeTable();
return false;
}
});
//查询按钮点击事件 joke add 20210428
$('#bustypeQueryBtn').on('click',function () {
loadBusTypeTable();
});
// 删除按钮删除事件
$('#btn-bustype-delete').click(function () {
var checks = busTypeTable.checkStatus(false);
var busId = $.map(checks, function (item) {
return item.busId;
});
deleteBusTypeByIds(busId);
});
//授权按钮事件
$("#btn-bustype-authorization").click(function () {
var checks = busTypeTable.checkStatus(false);
var busId = [];
var j = 0;
var number = 0;
for (var i = 0; i < checks.length; i++) {
if (checks[i].children != null) {
j++;
number = checks[i].children.length;
}
}
if (j = 1 && checks.length - number == 1) {
busId = checks[0].busId;
} else {
busId = $.map(checks, function (item) {
return item.busId;
});
}
if (busId.length == 0) {
layer.msg('请先选择数据', {icon: 0, timeout: 3000});
return;
} else if (busId.length == 1) {
busId = busId[0];
} else {
busId = busId.toString();
}
authorizationIndex(busId)
})
var cols = []
if (!mode) {
cols.push({
type: 'checkbox'
})
}
cols = cols.concat([{
type: 'numbers', title: '序号', align: 'center', width: 70
}, {
field: 'busTypeName', title: '名称', align: 'left',
templet:
'<div>' +
' <span' +
' data-code="{{d.busTypeCode}}"' +
' class="layui-table-link btn-bustype-edit">{{d.busTypeName}}' +
' </span>' +
'</div>'
}, {
field: 'nickname', title: '负责人', align: 'center'
}, {
field: 'busTypeDesc', title: '业务类型描述', align: 'left'
}, {
field: 'isOps', title: '乙方运维', align: 'center',width: 120,
templet: function (d) {
if(d.isOps==0){
return '否';
}else{
return '是';
}
}
}, {
field: 'isUse', title: '是否使用', align: 'center',width: 120,
templet: function (d) {
switch (d.isUse) {
case 0:
return '否';
case 1:
return '是';
default:
return '';
}
}
}, {
field: 'important', title: '重要程度', align: 'center', width: 120,
templet: function (d) {
switch (d.important) {
case 1:
return '核心';
case 2:
return '重要';
case 3:
return '一般';
case 9:
return '虚拟业务';
default:
return '';
}
}
}, {
field: 'sort', title: '排序', align: 'right', width: 120,
}])
if (!mode) {
cols.push({
title: '操作', align: 'center', fixed: 'right', width: '10%',
templet: function (d) {
if (d.isLeaf) {
return '' +
'<div>' +
'<button data-id="' + d.busId + '" lay-tips="删除" type="button" class="layui-btn layui-btn-xs layui-btn-normal btn-bustype-delete"><i class="layui-icon layui-icon-delete"></i></button>' +
'<button data-id="' + d.busId + '" lay-tips="资源分配" type="button" class="layui-btn layui-btn-xs layui-btn-normal btn-bustype-res-config"><i class="layui-icon layui-icon-menu-fill"></i></button>' +
'<button data-id="' + d.busId + '" lay-tips="授权" type="button" class="layui-btn layui-btn-xs layui-btn-normal btn-bustype-authorize"><i class="layui-icon layui-icon-auz"></i></button>' +
// '<button data-id="' + d.busId + '" data-code="'+ d.busTypeCode +'" lay-tips="乙方运维配置" type="button" class="layui-btn layui-btn-xs layui-btn-normal btn-bustype-yf-config"><i class="layui-icon layui-icon-set-fill"></i></button>' +
'</div>'
} else {
return '' +
'<div class="layui-row">' +
'<button data-id="' + d.busId + '" lay-tips="删除" type="button" class="layui-btn layui-btn-xs layui-btn-normal btn-bustype-delete"><i class="layui-icon layui-icon-delete"></i></button>' +
'<button data-id="' + d.busId + '" lay-tips="授权" type="button" class="layui-btn layui-btn-xs layui-btn-normal btn-bustype-authorize"><i class="layui-icon layui-icon-auz"></i></button>' +
'</div>'
}
}
});
} else {
cols.push({field: 'showType', title: '展示类型', align: 'center',sort:true,width:210,
templet: function (d) {
if(d.parentId == '0' && dataBusType.indexOf(d.busId)>-1){
return '';
}else{
//初始化select内容
var html='<div><select lay-ignore data-index="99" name="showType" class="layui-input resourceType_showType" style="min-width: 150px;display:inline">';
$.each(showTypeList,function (i,v) {
if(d.showType == v.value){
html += '<option value="' + v.value + '" selected>' + v.name + '</option> '
}else{
html += '<option value="' + v.value + '">' + v.name + '</option> '
}
});
html+='</select></div>';
return html;
}
}
});
cols.push({
title: '操作', align: 'center', fixed: 'right', width: '10%',
templet: function (d) {
if (d.userCount) {
return '' +
'<div class="layui-row">' +
'<button data-id="' + d.busId + '" type="button" class="layui-btn layui-btn-xs btn-bustype-bind hide" lay-tips="未授权,点击授权"><i class="layui-icon layui-icon-link"></i> 添加授权</button>' +
'<button data-id="' + d.busId + '" type="button" style="margin-left: 0" class="layui-btn layui-btn-xs layui-btn-danger btn-bustype-unbind" lay-tips="已授权,点击解除授权"><i class="layui-icon layui-icon-unlink"></i> 解除授权</button>' +
'</div>';
} else {
return '' +
'<div class="layui-row">' +
'<button data-id="' + d.busId + '" type="button" class="layui-btn layui-btn-xs btn-bustype-bind" lay-tips="未授权,点击授权"><i class="layui-icon layui-icon-link"></i> 添加授权</button>' +
'<button data-id="' + d.busId + '" type="button" style="margin-left: 0" class="layui-btn layui-btn-xs layui-btn-danger btn-bustype-unbind hide" lay-tips="已授权,点击解除授权"><i class="layui-icon layui-icon-unlink"></i> 解除授权</button>' +
'</div>';
}
}
});
}
/**
* 加载业务类型表格
*/
function loadBusTypeTable() {
conditions = {
busTypeName: $('#condition-bustype-name').val() ? $('#condition-bustype-name').val().trim() : '',
access_token: accessToken,
cutoverId: cutoverId,
targetType: targetType,
username: username,
page: -1,
limit: -1
};
conditions.limit = -1;
admin.req({
url: domainName + '/api-web/manage/bustype/page',
data: conditions
}).done(function (response) {
$.each(response.data,function (i,v) {
dataBusType.push(v.parentId);
})
// 设置总数
$('#span-bustype-total').html('共 ' + response.data.length + ' 个业务');
// 渲染表格
busTypeTable = treeTable.render({
elem: '#bustype-table',
data: response.data,
page: {
layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'],
theme: '#1E9FFF'
},
tree: {
iconIndex: mode ? 1 : 2, // 折叠图标显示在第几列
isPidData: true, // 是否是id、pid形式数据
idName: 'busId', // id字段名称
pidName: 'parentId', // pid字段名称
onlyIconControl: true // 仅允许点击图标折叠
},
cols: cols
});
//回填数据
if (data && data.username) {
if (data.username.length == 1) {
$.ajax({
type: "get",
url: domainName + "/api-web/manage/bustype/getBusTypeByUser?access_token=" + accessToken + "&username=" + data.username[0],
success: function (res) {
if (res && res.success) {
var busTypeData = res.data;
busTypeTable.setChecked(busTypeData.map(item => item.busId))
}
},
})
}
}
// 点击编号编辑事件
$('.btn-bustype-edit').click(function () {
if ($.inArray('back:bustype:update', checkList) == -1) {
layer.msg('暂无权限!', {icon: 7, time: 3000});
return;
}
var busTypeCode = $(this).data('code');
saveBusType(busTypeCode);
});
// 删除事件
$('.btn-bustype-delete').click(function () {
var busId = $(this).data('id');
deleteBusTypeByIds([busId]);
});
// 授权事件
$('.btn-bustype-authorize').click(function () {
loading = layer.load(2);
var busId = $(this).data('id')
authorizationIndex(busId)
});
// 乙方运维配置
$('.btn-bustype-yf-config').click(function () {
var busId = $(this).data('id');
var busTypeCode = $(this).data('code');
layer.open({
type: 2
,title: "乙方运维配置"
,closeBtn: false
,area: ['50%', '70%']
,btn: ['关闭']
,shade: 0.8
,id: 'operationMaintenance-config' //设定一个id,防止重复弹出
,content:`/vue3/index.html#/operationMaintenance/config?id=${busId}&code=${busTypeCode}`
, success: function (layero, index) {
}
,yes: function(index, layero){
layer.closeAll();
return false;
}
});
$(document).on("closeBusWindow", function(){
layer.closeAll();
});
});
$('.btn-bustype-bind').unbind('click').on('click', function () {
var $this = $(this);
var busId = $this.data('id')
layer.load(2);
admin.req({
url: domainName + '/api-web/manage/bustype/bindUser/' + busId,
data: {username},
success(response) {
layer.closeAll('loading');
if (response && response.success) {
$this.addClass('hide');
$this.parent().find('.btn-bustype-unbind').removeClass('hide')
var $child = $('tr[data-pid="' + busId + '"] .btn-bustype-bind');
$child.addClass('hide')
$child.parent().find('.btn-bustype-unbind').removeClass('hide')
} else {
layer.msg('授权失败!', {icon: 2});
}
},
error() {
layer.closeAll('loading');
}
})
});
$('.btn-bustype-unbind').unbind('click').on('click', function () {
var $this = $(this);
var busId = $this.data('id')
layer.load(2);
admin.req({
url: domainName + '/api-web/manage/bustype/unBindUser/' + busId,
data: {username},
success(response) {
layer.closeAll('loading');
if (response && response.success) {
$this.addClass('hide');
$this.parent().find('.btn-bustype-bind').removeClass('hide')
} else {
layer.msg('取消授权失败!', {icon: 2});
}
},
error() {
layer.closeAll('loading');
}
})
});
// 资源分配事件
// $('.btn-bustype-res-config').click(function () {
// var busId = $(this).data('id');
// var bustypeReslist = layui.reslist({busId: busId, idSuffix: 1})
// // 展示资源页面layerindex
// var bustypeReslayerIndex;
// common.openWin("template/res/reslist", "当前绑定的资源", {busId: busId, idSuffix: 1}, ["完成", "取消"], function () {
// layer.close(bustypeReslayerIndex);
// }, null, ['80%', '90%'],
// function (layero, layerIndex) {
// bustypeReslayerIndex = layerIndex;
// // 新增按钮
// $("#bustype-reslist-add").click(function () {
// var reslist = layui.reslist();
// // 添加绑定页面的layerindex
// var addResLayerIndex;
// common.openWin("template/res/reslist", "添加绑定", {}, ["添加", "取消"], function () {
// loading = layer.load(2);
// // 当前选中的资源
// var checks = reslist.getData();
// // 之前已经选择过的资源
// var oldResIdList = [];
// admin.req({
// url: domainName + '/api-web/manage/bustype/resourceList/' + busId,
// async: false,
// error: function () {
// layer.close(loading);
// }
// }).done(function (response) {
// $.each(response.data, function (index, value) {
// oldResIdList.push(value.resId);
// });
// });
// // 需要进行插入的资源
// var inserts = [];
// var insertCount = 0;
// var isExistCount = 0;
// $.each(checks, function (index, value) {
// if (oldResIdList.indexOf(value.resId) === -1) {
// inserts.push(value.resId);
// insertCount++;
// } else {
// isExistCount++;
// }
// });
// if (inserts.length === 0) {
// layer.msg('所选的都已存在,无需重复添加!', {icon: 7, time: 5000});
// layer.close(loading);
// return;
// }
// // 发送请求添加绑定
// admin.req({
// url: domainName + '/api-web/manage/bustype/addResource/' + busId + '?access_token=' + accessToken,
// type: 'POST',
// contentType: 'application/json',
// data: JSON.stringify(inserts),
// error: function () {
// layer.close(loading);
// }
// }).done(function (response) {
// layer.close(loading);
// if (response.success) {
// layer.msg('添加绑定成功!此次添加了' + insertCount + '个新资源' + (isExistCount > 0 ? ',有' + isExistCount + '个已经存在。' : ''), {icon: 1, time: 5000});
// layer.close(addResLayerIndex);
// bustypeReslist.reloadResTable();
// } else {
// layer.msg('添加绑定失败!', {icon: 2, time: 3000});
// }
// });
// }, null, ['90%', '80%'], function (layero, layerIndex) {
// addResLayerIndex = layerIndex
// });
// });
// // 取消绑定按钮
// $("#bustype-reslist-unbind").click(function () {
// // 需要取消绑定的资源id集合
// var deletes = [];
// $.each(bustypeReslist.getData(), function (index, value) {
// deletes.push(value.resId);
// });
// admin.req({
// url: domainName + '/api-web/manage/bustype/deleteResource/' + busId + '?access_token=' + accessToken,
// type: 'POST',
// contentType: 'application/json',
// data: JSON.stringify(deletes)
// }).done(function (response) {
// if (response.success) {
// layer.msg('取消绑定成功!', {icon: 1, time: 3000});
// bustypeReslist.reloadResTable();
// } else {
// layer.msg('取消绑定失败!', {icon: 2, time: 3000});
// }
// });
// });
// });
// });
//资源分配
$('.btn-bustype-res-config').click(function () {
if ($.inArray('back:bustype:resource', checkList) == -1) {
layer.closeAll();
layer.msg('暂无权限!', {icon: 7, time: 3000});
return;
}
var busId = $(this).data('id');
layer.open({
title: '当前绑定的资源',
type: 1,
content: $('#bustype-reslist-table').html(),
btn: ['完成'],
area: ['80%', '90%'],
success: function () {
// 表格
var resType = 'all';
$("#bustype_reslist_resListBizTypes").attr("disabled",true);
form.render();
//绑定业务下拉选择数据
common.bizTypeSelect("bustype_reslist_resListBizTypes",function () {
$("#bustype_reslist_resListBizTypes").val(busId);
form.render("select");
});
//绑定资源类型下拉选择
common.resTypeSelect("bustype_reslist_restype",function () {
form.render("select");
});
//回车搜索
$('#bustype_reslist_keyword').keydown(function (e) {
if (e.keyCode === 13) {
reloadTable(resType);
}
});
//选择框搜索事件
bindSelectEvent();
//渲染表格
table.render({
elem: '#bustype_reslist_resListTable'
, url: common.domainName + '/api-web/home/res-list/' + resType
, where: {
access_token: accessToken,
resName: $("#bustype_reslist_keyword").val(),
busId: busId,
resHealth: $("#bustype_reslist_resStatus").val()
}
, height: 'full-300'
, cellMinWidth: 80
, page: {
layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
, theme: '#1E9FFF'
}
, limit: common.limit
, limits: common.limits
, cols: [[
{type: 'checkbox'},
{type: 'numbers', title: '序号', align: 'center'}
, {field: 'resName', title: '资源名称', minWidth: 300, align: 'center'}
, {field: 'ip', title: 'IP地址', align: 'center'}
, {field: 'admin', title: '负责人', align: 'center'}
, {field: 'resTypeName', title: '资源类型', align: 'center'}
, {field: 'healthDesc', title: '资源状态', align: 'center'}
]]
});
//绑定下拉搜索事件
function bindSelectEvent() {
// 资源状态
form.on('select(bustype_reslist_resStatus)', function(data){
reloadTable(resType);
});
// 资源类型
form.on('select(bustype_reslist_restype)', function(data){
resType = data.value;
reloadTable(resType);
});
}
//刷新表格
function reloadTable(resType) {
table.reload('bustype_reslist_resListTable', {
url: common.domainName + '/api-web/home/res-list/' + (resType ? resType : 'all'),
where: {
access_token: accessToken,
resName: $("#bustype_reslist_keyword").val(),
busId: busId,
resHealth: $("#bustype_reslist_resStatus").val()
}
});
}
// 新增按钮
$("#bustype-reslist-add").click(function () {
var reslist = layui.reslist();
// 添加绑定页面的layerindex
var addResLayerIndex;
common.openWin("template/res/reslist", "添加绑定", {}, ["添加", "取消"], function () {
loading = layer.load(2);
// 当前选中的资源
var checks = reslist.getData();
if (checks.length ==0) {
layer.msg('请先选择资源后,再进行添加!', {icon: 7, time: 3000});
layer.close(loading);
return;
}
// 之前已经选择过的资源
var oldResIdList = [];
admin.req({
url: domainName + '/api-web/manage/bustype/resourceList/' + busId,
async: false,
error: function () {
layer.close(loading);
}
}).done(function (response) {
$.each(response.data, function (index, value) {
oldResIdList.push(value.resId);
});
});
// 需要进行插入的资源
var inserts = [];
var insertCount = 0;
var isExistCount = 0;
var resTypes=[];
var parentIds=[];
$.each(checks, function (index, value) {
if (oldResIdList.indexOf(value.resId) === -1) {
resTypes.push(value.resType);
parentIds.push(value.parentId);
inserts.push(value.resId);
insertCount++;
} else {
isExistCount++;
}
});
if (inserts.length === 0) {
layer.msg('所选的都已存在,无需重复添加!', {icon: 7, time: 5000});
layer.close(loading);
return;
}
var ArrIndex=[];
if(resTypes.length>0){
var identify=0;
$.each(resTypes,function (i,v) {
if(v=='MIDDLEWARE_WEBLOGIC' && parentIds[i]==''){
identify=1;
ArrIndex.push(i);
}
});
if(identify==1){
//询问框
layer.confirm('选择的资源中包含weblogic控制台,是否将控制台下的服务一起分配到当前业务下?', {
btn: ['是','否'] //按钮
}, function(){//是
//获得控制台下所有服务的resID
//如果选择将控制台下的服务一起分配到当前业务下
var arrResIds=[];
$.each(ArrIndex,function (i,v) {
arrResIds.push(inserts[v]);
})
var map={
resIds: arrResIds.toString()
};
admin.req({
url: common.domainName + '/api-web/bResource/resourceByResId?access_token='+accessToken,
type:'post',
data:JSON.stringify(map),
contentType: "application/json;charset=utf-8",
async:false,
error: function () {
layer.msg('获取控制台下所有服务失败', {icon: 2});
layer.close(layer.index);
}
}).done(function (response) {
if(response.success && response.data && response.data.length>0){
$.each(response.data,function (i,v) {
inserts.push(v.resId);
insertCount++;
});
}
inserts=Array.from(new Set(inserts));
isExistCount = insertCount-inserts;
add(addResLayerIndex,inserts,busId,insertCount,isExistCount,resType);
layer.close(layer.index);
})
}, function(){//否
add(addResLayerIndex,inserts,busId,insertCount,isExistCount,resType);
layer.close(layer.index);
});
}else{
add(addResLayerIndex,inserts,busId,insertCount,isExistCount,resType);
}
}
}, null, ['90%', '80%'], function (layero, layerIndex) {
addResLayerIndex = layerIndex
});
});
// 取消绑定按钮
$("#bustype-reslist-unbind").click(function () {
// 需要取消绑定的资源id集合
var deletes = [];
var resTypes=[];
var parentIds=[];
$.each(table.checkStatus('bustype_reslist_resListTable').data, function (index, value) {
deletes.push(value.resId);
resTypes.push(value.resType);
parentIds.push(value.parentId);
});
if(deletes.length<1){
layer.msg('请选择要解除绑定的数据!', {icon: 7, time: 3000});
layer.close(loading);
return;
}
var ArrIndex=[];
if(resTypes.length>0){
var identify=0;
$.each(resTypes,function (i,v) {
if(v=='MIDDLEWARE_WEBLOGIC' && parentIds[i]==''){
identify=1;
ArrIndex.push(i);
}
});
if(identify==1){
//询问框
layer.confirm('选择的资源中包含weblogic控制台,是否将控制台下的服务一起取消?', {
btn: ['是','否'] //按钮
}, function(){//是
//获得控制台下所有服务的resID
//如果选择将控制台下的服务一起取消
var arrResIds=[];
$.each(ArrIndex,function (i,v) {
arrResIds.push(deletes[v]);
})
var map={
resIds: arrResIds.toString()
};
admin.req({
url: common.domainName + '/api-web/bResource/resourceByResId?access_token='+accessToken,
type:'post',
data:JSON.stringify(map),
contentType: "application/json;charset=utf-8",
async:false,
error: function () {
layer.msg('获取控制台下所有服务失败', {icon: 2});
layer.close(layer.index);
}
}).done(function (response) {
if(response.success && response.data && response.data.length>0){
$.each(response.data,function (i,v) {
deletes.push(v.resId);
});
}
deletes=Array.from(new Set(deletes));
del(busId,deletes,resType);
layer.close(layer.index);
})
}, function(){//否
del(busId,deletes,resType);
layer.close(layer.index);
});
}else{
del(busId,deletes,resType);
}
}
});
},
yes: function (index) {
layer.close(index);
}
});
});
});
}
//授权页面
function authorizationIndex(busId) {
if ($.inArray('back:bustype:impower', checkList) == -1) {
layer.closeAll();
layer.msg('暂无权限!', {icon: 7, time: 3000});
return;
}
var params = {
oldUsers: [],
bindUrl: '/api-web/manage/bustype/bindUser/' + busId,
unBindUrl: '/api-web/manage/bustype/unBindUser/' + busId
};
// 获取当前资源类型的权限用于回显
admin.req({
url: domainName + '/api-web/manage/bustype/getUsersByBusId',
async: false,
data: {
busId: busId
}
}).done(function (response) {
$.each(response.data, function (index, value) {
params.oldUsers.push(value.userAccount);
})
return false;
});
layer.close(loading);
var userlist;
layer.open({
title: '授权',
id: 'busType-role-config-layer',
type: 1,
area: ['80%', '90%'],
btn: ['关闭'],
scrollbar: false,
success: function () {
view(this.id).render('/template/user/userlist').done(function () {
userlist = layui.userlist(params);
});
},
yes: function (index, layero) {
layer.close(index);
}
});
}
// 新增按钮
$('#bustype-create').click(function () {
if ($.inArray('back:bustype:save', checkList) == -1) {
layer.msg('暂无权限!', {icon: 7, time: 3000});
return;
}
saveBusType();
});
// 刷新表格按钮
$('#btn-bustype-reload-table').click(function () {
loadBusTypeTable();
});
/**
* 新增或者编辑业务类型
*
* @param busTypeCode 业务类型编号
*/
function saveBusType(busTypeCode) {
// 打开(新增/编辑)窗口
common.openWin('/baseconfig/bustype/add', '<a class="layui-icon layui-icon-edit win_title_icon"></a>' + busTypeCode ? '编辑' : '新增',
{busTypeCode: busTypeCode}, ['保存', '取消'], function () {
$('#btn-bustype-submit').click();
}, null, ['40%', 'auto']);
}
function deleteBusTypeByIds(busIds) {
if ($.inArray('back:bustype:delete', checkList) == -1) {
layer.msg('暂无权限!', {icon: 7, time: 3000});
return;
}
if (busIds.length == 0) {
layer.msg('请先选择数据,再点击删除。', {icon: 0, timeout: 3000});
return;
}
layer.confirm('确认要删除吗?', {icon: 3, title: '提示'}, function () {
loading = layer.load(2);
admin.req({
url: domainName + '/api-web/manage/bustype/deleteByIds?access_token=' + accessToken,
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(busIds),
success: function () {
layer.close(loading);
},
error: function () {
layer.close(loading);
}
}).done(function (response) {
if (response.success) {
layer.msg('删除成功!', {icon: 1, time: 3000});
loadBusTypeTable();
} else {
layer.msg('删除失败!', {icon: 2, time: 3000});
}
});
});
}
//添加绑定
function add(addResLayerIndex,inserts,busId,insertCount,isExistCount,resType) {
// 发送请求添加绑定
admin.req({
url: domainName + '/api-web/manage/bustype/addResource/' + busId + '?access_token=' + accessToken,
type: 'POST',
async: false,
contentType: 'application/json',
data: JSON.stringify(inserts),
error: function () {
layer.close(layer.index);
}
}).done(function (response) {
layer.close(loading);
if (response.success) {
layer.msg('添加绑定成功!此次添加了' + insertCount + '个新资源(父资源)' + (isExistCount > 0 ? ',有' + isExistCount + '个已经存在。' : ''), {icon: 1, time: 5000});
layer.close(addResLayerIndex);
reloadTable(resType,busId);
} else {
layer.msg('添加绑定失败!', {icon: 2, time: 3000});
}
});
}
//取消绑定
function del(busId,deletes,resType) {
admin.req({
url: domainName + '/api-web/manage/bustype/deleteResource/' + busId + '?access_token=' + accessToken,
type: 'POST',
async: false,
contentType: 'application/json',
data: JSON.stringify(deletes)
}).done(function (response) {
if (response.success) {
layer.msg('取消绑定成功!', {icon: 1, time: 3000});
reloadTable(resType,busId);
} else {
layer.msg('取消绑定失败!', {icon: 2, time: 3000});
}
});
}
//获取展示类型的字典数据
function initShowType(){
if(mode){//如果不展示字段就不去请求
admin.req({
url: domainName + '/api-web/manage/ddic/findSucDdics/DETAILS_POWER'
, method: 'POST'
, async: false
, success: function (res) {
$.each(res.data, function (i, v) {
showTypeList.push({
name: v.ddicName
,value: v.ddicCode.substring(v.ddicCode.lastIndexOf("_")+1,v.ddicCode.length)
})
});
}
});
}
}
//刷新表格
function reloadTable(resType,busId) {
table.reload('bustype_reslist_resListTable', {
url: common.domainName + '/api-web/home/res-list/' + (resType ? resType : 'all'),
where: {
access_token: accessToken,
resName: $("#bustype_reslist_keyword").val(),
busId: busId,
resHealth: $("#bustype_reslist_resStatus").val()
}
});
}
//获取选中的数据
function getCheckData() {
if(mode){
//获取改变的值
var str='';
var $tr=$('#bustype-table').next().find('tbody tr');
$.each($tr,function (i,v) {
var $btn=$(this).find('.btn-bustype-unbind');
var showType=$(this).find('.resourceType_showType') && $(this).find('.resourceType_showType').eq(0) && $(this).find('.resourceType_showType').eq(0).val() ? $(this).find('.resourceType_showType').eq(0).val():'<';
if(!$btn.hasClass('hide')){
str += $btn.attr("data-id")+'_'+showType+',';
}
});
if(str!=''){
str=str.substring(0,str.length-1);
}
return str;
}else{
return busTypeTable.checkStatus(false);
}
}
return {getData: getCheckData};
});
});
... ...
// 业务类型管理
layui.define(['table', 'form', 'admin', 'layer', 'laytpl', 'common', 'view', 'sessions', 'commonDetail', 'treeTable', 'xmSelect', 'userlist', 'reslist'], function (exports) {
var $ = layui.$;
var form = layui.form;
var layer = layui.layer;
var admin = layui.admin;
var table = layui.table;
var treeTable = layui.treeTable;
var xmSelect = layui.xmSelect;
var laytpl = layui.laytpl;
var view = layui.view;
var common = layui.common;
var commonDetail = layui.commonDetail;
var domainName = common.domainName;
// 对外暴露的接口
exports('bustypeAdd', function (data) {
var sessions = layui.sessions;
var accessToken = sessions.getToken()['access_token'];
var userSelect = {}
var opsSelect={}
initUserSelect();
//渲染运维负责人
initUserSelectOps();
// 加载遮罩
var loading;
var oldBusTypeCode = data && data.busTypeCode ? data.busTypeCode : '';
var busType;
// 父业务下拉框
admin.req({
url: domainName + '/api-web/manage/bustype/page',
data: {
page: -1,
limit: -1,
parentId: '0'
}
}).done(function (response) {
var options = '';
$.each(response.data, function (i, v) {
options += ' <option value="' + v.busId + '">' + v.busTypeName + '</option> '
});
$('select[name="parentId"]').append(options);
// 如果是新增,就对busType进行初始化
if (!oldBusTypeCode) {
busType = {
busTypeCode: '',
busTypeName: '',
busTypeDesc: '',
admin: '',
isUse: '',
important: '',
sort: '',
isLeaf: '1'
}
form.render();
} else {
// 如果是编辑模式,回写数据
admin.req({
url: domainName + '/api-web/manage/bustype/page',
data: {
page: 1,
limit: 10,
busTypeCode: oldBusTypeCode
}
}).done(function (response) {
busType = response.data[0];
form.val('form-bustype-edit', busType);
$('form[lay-filter="form-bustype-edit"] input[name="busTypeCode"]').attr('readonly', true);
setTimeout(function (){
userSelect.setValue([busType.admin]);
},2000)
let principal = busType.principal;
let principalLi = principal ? principal.split(",") : [];
setTimeout(function (){
opsSelect.setValue(principalLi);
},2000)
//是否启用 1启用 0不启用
let isUse = busType.isUse || busType.isUse == 0 ? busType.isUse : 1;
if (isUse != 1) {//不启用
layui.jquery('input[name="isUse"]').removeAttr('checked'); //改变开关为 关
}
//是否是乙方运维 1是,0不是
let system_type = busType.isOps || busType.isOps == 0 ? busType.isOps : 1;
if (system_type != 1) {//不是乙方运维 隐藏项目 是否虚拟不能点击
layui.jquery('input[name="system_type"]').removeAttr('checked'); //改变开关为 关
$('#select_principalName').addClass("hide");
//layui.jquery('input[name="isvirtual"]').removeAttr('disabled');//可以点击
layui.jquery('input[name="isvirtual"]').attr("disabled", true)//不能点击
}
//是否是虚拟 0是,1不是
let isvirtual = busType.isvirtual || busType.isvirtual == 0 ? busType.isvirtual : 0;
if (isvirtual != 0) {//不是虚拟
layui.jquery('input[name="isvirtual"]').removeAttr('checked'); //改变开关为 关
}
form.render();
});
}
});
// 业务类型编号改变判断是否已经存在
$('#txt-bustype-code').change(function () {
if (checkBusTypeCodeExist($(this).val())) {
$(this).val(oldBusTypeCode);
layer.msg('该编码已存在,请重新输入!', {icon: 2, time: 3000});
}
});
//设置乙方运维项目
form.on('switch(system_type)', function (obj) {
//sign=fale 不是乙方运维项目 sign=true 是乙方运维项目
var sign = obj.elem.checked;
if (!sign) {//不是乙方运维 下拉框隐藏 是否是虚拟项目可以点击
$('#select_principalName').addClass("hide");
opsSelect.setValue([]);
//layui.jquery('input[name="isvirtual"]').removeAttr('disabled');//可以点击
//删除原来的组件 新加dom
$('#isvirtual_ops_switch').empty();//删除子元素
let html = '<input type="checkbox" lay-skin="switch" name="isvirtual" lay-filter="switch_isVirtual" value="0" lay-text="是|否" disabled/>';
$('#isvirtual_ops_switch').append(html);//追加子元素
//重新渲染
form.render();
} else {//是乙方运维 下拉框展示 只能是虚拟项目 不能更改是否是虚拟项目
$('#select_principalName').removeClass('hide');
//layui.jquery('input[name="isvirtual"]').attr("checked", true);//改变状态为开
//layui.jquery('input[name="isvirtual"]').attr("disabled", true)//不能点击
layui.jquery('input[name="isvirtual"]').removeAttr('disabled');//可以点击
//渲染下拉框
initUserSelectOps();
//重新渲染
form.render();
}
});
// 绑定表单提交事件
form.on('submit(bus-type-submit)', function (data) {
loading = layer.load(2);
busType = Object.assign(busType, data.field);
//是否启用 1启用 0不启用
if (!data.field.isUse) {
busType.isUse = '0'
}
//是否是乙方运维 1是,0不是
if (!data.field.system_type) {
busType.system_type = '0'
}
//是否是虚拟业务 0是,1不是
if (!data.field.isvirtual) {
busType.isvirtual = '1'
}
if (busType.parentId == busType.busId) {
// 防止循环引用
busType.parentId = '0';
}
//获取业务负责人信息
busType.nickname = userSelect.getValue("name")[0];
busType.admin = userSelect.getValue("value")[0];
//获取业务运维负责人
busType.principalName = opsSelect.getValue("nameStr");
busType.principal = opsSelect.getValue("valueStr");
delete busType.select
admin.req({
url: domainName + '/api-web/manage/bustype/save?access_token=' + accessToken,
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(busType),
error: function () {
layer.close(loading);
}
}).done(function (response) {
layer.close(loading);
if (response.success) {
layer.msg('保存成功!', {icon: 1, time: 3000});
layer.closeAll('page');
$('#btn-bustype-reload-table').click();
} else {
layer.msg('保存失败!', {icon: 2, time: 3000});
}
});
return false;
});
/**
* 判断该业务类型编号是否已经存在
*
* @param busTypeCode 业务类型编号
* @returns {boolean} 存在: true,不存在: false
*/
function checkBusTypeCodeExist(busTypeCode) {
var result = true;
admin.req({
url: domainName + '/api-web/manage/bustype/page',
async: false,
data: {
page: 1,
limit: 10,
busTypeCode: busTypeCode
}
}).done(function (response) {
if (response.data.length === 0) {
result = false;
}
});
return result;
}
//初始化用户下拉列表框
function initUserSelect() {
$.ajax({
url: domainName + '/api-user/users/getAll?access_token=' + accessToken,
sync: false,
success: function (res) {
userSelect = xmSelect.render({
el: '.adminUser',
radio: true,
clickClose: true,
prop: {
name: 'nickname',
value: 'username'
},
filterable: true,
layVerify: 'required',
layVerType: 'msg',
data: res,
})
}
})
}
//初始化用户下拉列表框
function initUserSelectOps() {
$.ajax({
url: domainName + '/api-user/users/getAll?access_token=' + accessToken,
sync: false,
success: function (res) {
opsSelect = xmSelect.render({
el: '#opsProject-username-select',
prop: {
name: 'nickname',
value: 'username'
},
data: res,
})
}
})
}
//添加表单验证方法
form.verify({
sort: function (t) {
if (t.length >= 7) {
return '排序必须小于100万';
}
}
});
});
});
... ...
layui.define(['table', 'form', 'laydate', 'admin', 'layer', 'laytpl', 'common', 'sessions',"commonDetail",'soulTable'], function (exports) {
var $ = layui.$;
var form = layui.form;
var layer = layui.layer;
var admin = layui.admin;
var table = layui.table;
var laydate = layui.laydate;
var laytpl = layui.laytpl;
var common = layui.common;
var commonDetail = layui.commonDetail;
var domainName = common.domainName;
var soulTable = layui.soulTable;
//对外暴露的接口
exports('historywarning', function () {
var sessions = layui.sessions;
var router = layui.router();
var accessToken = sessions.getToken()['access_token'];
var sortKey = '';
var checkList = common.checkPermission(accessToken);
var alarmNo = router.search.alarmNo;//告警编号
var bizId='';//业务Id
var busIdSelect;
var busTypeList = [];
if (alarmNo) {
$("#historywarningkw").val(alarmNo);
}
function initDate() {
let startMin = {};
let endMax = {};
var start = laydate.render({
elem: '#historywarningStartdate'
, trigger: 'click'
,ready: function(date){
startMin=start.config.min;
}
, done: function (value, date) {
date.month--;
end.config.min = date;
if(value === ''){//点击清空
end.config.min = startMin;
}
form.render();
reloadTable();
}
});
var end = laydate.render({
elem: '#historywarningEnddate'
, trigger: 'click'
,ready: function(date){
endMax=end.config.max;
}
, done: function (value, date) {
date.month--;
start.config.max = date;
if(value === ''){//点击清空
start.config.max = endMax;
}
form.render();
reloadTable();
}
});
//绑定业务下拉选择数据
admin.req({
url: domainName + '/api-web/home/business/findUserBusTypeAll?table=b_alarm_his',
success: function (response) {
if (response && response.success) {
busTypeList = response.data;
var bizList = response.data.map(item => {
return {
name: item.busTypeName,
value: item.busId,
parentId: item.parentId
}
});
var bizTree=common.pidToChildren(bizList, 'value', 'parentId');
// 影响业务下拉框
busIdSelect = xmSelect.render({
el: '#historyBisTypeSearchBox',
name: 'bizId',
tips: '=所属业务=',
//开启搜索
filterable: true,
clickClose: true,
initValue: [bizId.split(',')[0]],
toolbar: {
show: true,
list: ['ALL', 'REVERSE', 'CLEAR']
},
height: '170px',
tree: {
show: true,
showFolderIcon: true,
showLine: true,
strict: true,
//间距
indent: 20,
},
model: {
label: {
type: 'text'
}
},
data: bizTree,
on: function (data) {
if (data.arr.length != 0) {
var str='';
$.each(data.arr,function (i,v) {
str+=v.value+',';
})
bizId = str.substring(0,str.length-1);
} else {
bizId = '';
}
form.render();
reloadTable();
}
});
if(busIdSelect){
//追加样式
$('#historyBisTypeSearchBox').find('.xm-body').eq(0).css("width","230px");
}
} else {
layer.msg('获取业务失败', {icon: 2});
}
},
error: function () {
layer.msg('获取业务失败', {icon: 2});
}
});
$.ajax({
url: common.domainName + '/api-web/manage/kpi/findKpiInAlarm?access_token='+accessToken+'&tableName=b_alarm_his',
type: "get",
success:function (res) {
var kpis = res.data;
var html = '<option value="">=指标名称=</option>'
$.each(kpis,function (i,e) {
html+='<option value="'+e.kpiId+'">'+e.kpiName+'</option>'
})
$("#alarmKpiHisSearchBox").html('');
$("#alarmKpiHisSearchBox").append(html);
form.render();
}
})
}
//回车事件
$('#historywarningkw, input[name="durationVal"]').keydown(function (e) {
if (e.keyCode === 13) {
reloadTable();
}
});
//选择框搜索事件
bindSelectEvent();
initDate();
function initHistoryBtnCLick() {
//告警恢复
$("#historyResumeBtn").unbind("click").on("click", function () {
if ($.inArray('app:alarm:resume', checkList) == -1) {
layer.msg('暂无权限!', {icon: 7, time: 3000});
return;
}
var ids = [];
var closeIds = [];
var data = table.checkStatus('historywarningTable').data;
var resumeStatus = true;
if (data.length == 0) {
layer.msg('请最少选择一项数据', {icon: 7, time: 2000});
return;
}
var msg = "";
//选中的告警ID放到集合中
$.each(data, function (i, obj) {
ids.push(obj.id);
closeIds.push(obj.closeId);
});
if (!resumeStatus) {
layer.msg(msg, {icon: 7, time: 3000});
return;
}
layer.prompt({title: '恢复说明(必填)', formType: 2}, function (text, index) {
admin.req({
url: common.domainName + '/api-web/home/alarm/resume'
, type: "post"
, data: {
ids: ids.toString(),
reason: text,
closeId: closeIds.toString(),
resumeType: '1',//0告警关闭,1历史告警
access_token: accessToken
}
, done: function (res) {
//如果消除成功,关闭弹出框然后重新加载页面
if (res.success) {
layer.close(index);
layer.msg('告警已恢复!', {icon: 1, time: 3000}, function () {
reloadTable();
});
} else {
layer.msg('告警恢复失败,请与管理员联系!', {icon: 7, time: 3000});
}
}
});
})
});
}
//渲染表格
var historywarningTable;
//获取配置的列
common.getTableCols({
domId: 'historywarningTable',
moduleId: 'historywarning',
resType: ''
}, function (retCols) {
var cols;
if (retCols) {
cols = retCols;
} else {
cols = [
{type: 'checkbox', fixed: 'left'}
, {
field: 'alarmLevel', title: '级别', align: 'center', width: 120, sort: true,
templet: `<div>
{{# if (d.alarmLevel == 3) { }}
<span class="layui-table-warn" style="width: 100%;">严重</span>
{{# } else if (d.alarmLevel == 2) { }}
<span class="layui-table-close" style="width: 100%;">重要</span>
{{# } else if (d.alarmLevel == 1) { }}
<span class="layui-table-normal" style="width: 100%;">一般</span>
{{# } }}
</div>`
}
, {
field: 'alarmNo', title: '告警编号', align: 'center', width: 140, sort: true,
}
, {
field: 'resName', title: '资源名称', width: 230, sort: true,
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>'
}
, {
field: 'kpiName', title: '指标名称', align: 'center', width: 150, sort: true,
templet: '#historywarngingKpiNameTpl'
}
, {field: 'alarmContent', title: '告警内容', align: 'center', width: 500}
, {
field: 'alarmResource', title: '告警来源', align: 'center', minWidth: 100, templet: `<div>
{{# if (d.alarmResource == 1) { }}
<div>华为告警</div>
{{# } else { }}
<div>监控系统</div>
{{# } }}
</div>`
}
, {field: 'updateTime', title: '告警时间', align: 'center', minWidth: 180, sort: true}
, {field: 'alarmTime', title: '首次告警时间', align: 'center', minWidth: 180, sort: true}
, {field: 'durationStr', title: '持续时间', align: 'center', width: 190}
, {
title: '操作', align: 'center', minWidth: 100,
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>'
}
];
}
historywarningTable = table.render({
elem: '#historywarningTable'
, url: domainName + '/api-web/home/alarm/alarmListPage'
, toolbar: '#hisAlarmtoolbar' //开启头部工具栏,并为其绑定左侧模板
, defaultToolbar: ['filter']
, where: {
access_token: accessToken,
hisFlag: true,
kpiName: $("#historywarningkw").val(),
busId: bizId,
alarmStatus: $("#historyAlarmStatusSearchBox").val(),
alarmLevel: $("#historyAlarmLevelSearchBox").val(),
confirmStatus: $("#historyAlarmConfirmSearchBox").val(),
beginTime: $("#historywarningStartdate").val(),
endTime: $("#historywarningEnddate").val(),
durationVal: $('#his_inline-condition-duration input[name="durationVal"]').val(),
durationUnit: $('#his_inline-condition-duration select[name="durationUnit"]').val(),
sortKey: sortKey,
//alarmKpi: $("#alarmKpiHisSearchBox").val(),
alarmKpi: $("#alarmKpiHisSearchBox").val()!='KPI97B835A4'?$("#alarmKpiHisSearchBox").val():'',
isBus:$("#alarmKpiHisSearchBox").val()=='KPI97B835A4'?'Y':'',
}
, height: 'full-245'
, cellMinWidth: 80
, page: {
layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
, theme: '#1E9FFF'
}
, even: true
, drag: {toolbar: false}
, cols: [cols],
done: function (res, curr, count) {
soulTable.render(this)
initHistoryBtnCLick();
var groupurl = domainName + '/api-web/home/alarm/countAlarmNumByAlarmLevel?access_token=' + accessToken;
$.ajax({
url: groupurl,
type: 'get',
data: {
access_token: accessToken,
hisFlag: true,
kpiName: $("#historywarningkw").val(),
busId: bizId,
alarmStatus: $("#historyAlarmStatusSearchBox").val(),
alarmLevel: '',
confirmStatus: $("#historyAlarmConfirmSearchBox").val(),
beginTime: $("#historywarningStartdate").val(),
endTime: $("#historywarningEnddate").val(),
durationVal: $('#his_inline-condition-duration input[name="durationVal"]').val(),
durationUnit: $('#his_inline-condition-duration select[name="durationUnit"]').val(),
sortKey: sortKey,
//alarmKpi: $("#alarmKpiHisSearchBox").val(),
alarmKpi: $("#alarmKpiHisSearchBox").val()!='KPI97B835A4'?$("#alarmKpiHisSearchBox").val():'',
isBus:$("#alarmKpiHisSearchBox").val()=='KPI97B835A4'?'Y':'',
},
success: function (res) {
var map = res.map;
if (!isEmptyObject(map)) {
layui.use('laytpl', function () {
var laytpl = layui.laytpl;
var getTpl = document.getElementById("his-alarm-count-id-tpl").innerHTML;
laytpl(getTpl).render(map, function (html) {
$('#his-alarm-count-id').html(html);
});
});
}
//告警操作日志
$('[history-data-warn-view]').unbind("click").on('click', function () {
admin.req({
url: common.domainName + '/api-web/home/alarm/info'
, data: {
alarmId: $(this).attr('history-data-warn-view'),
access_token: accessToken
}
}).done(function (res) {
laytpl($('#warnViewWinTpl').html()).render(res.obj, function (html) {
layer.open({
area: ['80%', '90%'],
title: ['告警操作信息', 'font-size:18px;'],
type: 1,
content: html
});
});
});
});
//告警轨迹
$('[history-data-warn-path]').unbind("click").on('click', function () {
var id = $(this).attr('history-data-warn-path');
var view = layui.view;
var params = {
"warnId": id
};
view('commonViewModel').render("template/detail/warn_gj").then(function (res) {
layer.open({
title: ['告警轨迹', 'font-size:18px;'],
type: 1,
area: ['80%', '90%'],
content: laytpl(res.body).render(JSON.stringify(params))
});
});
});
//资源名称,查看详细
$('[data-hiswarn-zymc]').unbind("click").on('click', function () {
var resId = $(this).data("resid");
var resType = $(this).data("restype");
var ip = $(this).data("ip") ? $(this).data("ip") : "";
var resName = $(this).data("resname");
var pingEnable = $(this).data("pingenable"); //获取pingEnable的值 joke add 20200619
var resTypeName = '';
var adminName = '';
var manageIp = '';
var collProtocol = '';
var sign='false';
$.ajax({
url: common.domainName + "/api-web/home/resource/findById?resId="+resId + '&access_token='+ accessToken,
async: false,
type:'get',
success: function (res) {
sign=res.str;
var data = res.object;
resType = data.resType;
adminName = data.adminName;
manageIp = data.manageIp;
collProtocol = data.collProtocol;
resTypeName = data.resTypeName;
}
})
if(sign=='false'){
layer.msg('当前用户暂无此资源权限!', {icon: 7, time: 3000});
return false;
}
let title = resName;
if (title && title !== '') {
title += '|';
}
if (resTypeName && resType !== 'HOST_X86SERVER') {
title += resTypeName + '|';
}
if (ip) {
if (resType === 'HOST_X86SERVER') {
if (collProtocol && (collProtocol.split(",").length > 1 || collProtocol === 'SSH')) {
title += '应用IP-' + ip + '|';
}
} else {
title += ip + '|';
}
}
if (resType === 'HOST_X86SERVER' && collProtocol && collProtocol.indexOf('SNMP') !== -1 ) {
if (manageIp) {
title += '管理IP-' + manageIp + '|';
}
}
if (adminName) {
title += adminName + '|';
}
if (title.length > 0) {
title = title.substr(0, title.length - 1);
}
if (pingEnable == '2') { //如果pingEnable为2,则进入ping状态详情页面
commonDetail.openNewWin('template/detail/pingIndex', title, {'resId': resId}, false);
} else { //否则进入监控详情页面
commonDetail.openDetail(resId, resType, title);
}
});
//指标性能曲线图
$(' [data-warn-zbmc]').unbind("click").on('click', function () {
var name = $(this).data("name");
var params = {
resId: $(this).data("resid"),
kpiId: $(this).data("kpi"),
flag: $(this).data("flag"),
name: name,
warning: $(this).data("warning"),
ident: $(this).data("ident"),
trend: $(this).data("trend")
};
common.openLineChart(name, params);
});
//表格排序监听 joke add 20200408
table.on('sort(historywarningTable)', function (obj) {
//有些时候,你可能需要根据当前排序的字段,重新向服务端发送请求,从而实现服务端排序,如:
if (obj.type != null) {
sortKey = obj.field + ' ' + obj.type;
} else {
sortKey = '';
}
reloadTable('sort');
})
//点击严重重要一般统计告警
$("#his-alarm-count-id").find(".warn-count-item").unbind("click").on("click", function () {
var alarmLevel = $(this).attr("alarm-level");
if (alarmLevel != '' && alarmLevel != null && alarmLevel != undefined) {
$("#historyAlarmLevelSearchBox").val(alarmLevel)
layui.form.render('select');
reloadTable();
} else {
$("#historyAlarmLevelSearchBox").val("");
layui.form.render('select');
reloadTable();
}
});
//更改告警级别颜色
setColourLevel();
}
});
//触发拖动列事件,参数为保存按钮的id
common.dragCols("historywarning_cols_save");
//保存列顺序
$("#historywarning_cols_save").unbind("click").on("click", function () {
var params = {
domId: 'historywarningTable',
moduleId: 'historywarning',
resType: '',
cols: JSON.stringify(historywarningTable.config.cols)
}
common.saveTableCols(params,0);
});
}
});
});
//更改告警级别颜色
function setColourLevel() {
//获取告警等级
let alarmLevel = $("#historyAlarmLevelSearchBox").val();
$('#his_alarm_serious').css("color","#666");
$('#his_alarm_important').css("color","#666");
$('#his_alarm_commonly').css("color","#666");
switch (alarmLevel) {
case "3"://严重告警
$('#his_alarm_serious').css("color","#D81E06");
break;
case "2"://重要告警
$('#his_alarm_important').css("color","#FF7E00");
break;
case "1"://一般告警
$('#his_alarm_commonly').css("color","#1e9fff");
break;
default://其他 空或无
break;
}
}
function isEmptyObject(e) {
var t;
for (t in e)
return !1;
return !0
}
//绑定下拉搜索事件
function bindSelectEvent() {
form.on('select(alarmKpiHisSearch)', function (data) {
reloadTable();
});
// 告警状态
form.on('select(historyAlarmStatusSearch)', function (data) {
reloadTable();
});
//告警级别
form.on('select(historyAlarmLevelSearch)', function (data) {
reloadTable();
});
// 告警确认
form.on('select(historyAlarmConfirmSearch)', function (data) {
reloadTable();
});
}
//刷新表格
function reloadTable(type) {
if (type != 'sort'){
sortKey = '';
}
historywarningTable.reload({
page: {
curr: 1
}
,where: {
access_token: accessToken,
kpiName: $("#historywarningkw").val(),
busId: bizId,
alarmStatus: $("#historyAlarmStatusSearchBox").val(),
alarmLevel: $("#historyAlarmLevelSearchBox").val(),
confirmStatus: $("#historyAlarmConfirmSearchBox").val(),
beginTime: $("#historywarningStartdate").val(),
endTime: $("#historywarningEnddate").val(),
durationVal: $('#his_inline-condition-duration input[name="durationVal"]').val(),
durationUnit: $('#his_inline-condition-duration select[name="durationUnit"]').val(),
sortKey: sortKey,
//alarmKpi: $("#alarmKpiHisSearchBox").val(),
alarmKpi: $("#alarmKpiHisSearchBox").val()!='KPI97B835A4'?$("#alarmKpiHisSearchBox").val():'',
isBus:$("#alarmKpiHisSearchBox").val()=='KPI97B835A4'?'Y':'',
}
});
}
/* //获取告警统计信息
function getAlarmCount() {
admin.req({
url: common.domainName + "/api-web/home/alarm/countByAlarmLevel?hisFlag=true"
, type: "get"
, done: function (data) {
var alarms = data.data;
if (data.code === 0) {
let total = 0;
$.each(alarms,function (i,v) {
if(v.alarmLevel<4){
total+=v.alarmNum;
}
if(v.alarmLevel == 3){//严重告警
$("#history_alarm_serious").text(v.alarmNum);
}
if(v.alarmLevel == 2){//重要告警
$("#history_alarm_important").text(v.alarmNum);
}
if(v.alarmLevel == 1){//一般告警
$("#history_alarm_commonly").text(v.alarmNum);
}
});
$("#history_alarm_total").text(total);
} else {
console.log(data.msg);
}
}
});
}*/
form.render(null, 'historywarning-form');
(function () {
var autoBtn = $('#historywarningAutoFlush');
var timer = null;
function autoFlush(target) {
var el = target.find('span');
var checked = target.find('input').prop('checked');
localStorage.setItem('auto__flush', checked);
function fn() {
var second = el.data('second');
var checked = target.find('input').prop('checked');
if (!checked) {
return;
}
--second;
el.data('second', second);
el.html(second + '秒');
timer = setTimeout(fn, 1000);
if (second <= 0) {
clearTimeout(timer);
reloadTable()
$(el).data('second', 60);
$(el).text("60秒")
fn();
//layui.index.render();
}
}
if (checked) {
timer = setTimeout(fn, 1000);
} else {
clearTimeout(timer);
}
}
/*autoBtn.change(function () {
autoFlush(autoBtn);
});*/
form.on("checkbox(hisWarnActiveAutoFlush)",function (data) {
autoFlush(autoBtn);
})
var auto = localStorage.getItem('auto__flush')
auto = auto ? auto : false;
autoBtn.find('input').prop('checked', auto);
autoFlush(autoBtn);
admin.on('hash(*)', function (router) {
if (router.href === '/historywarning') {
autoFlush(autoBtn);
} else {
clearTimeout(timer);
}
});
})();
});
});
\ No newline at end of file
... ...
/**
* @desc 华为云网络设备(防火墙、交换机)
* @author wangfeng
* @date 2020/2/4 14:36
**/
layui.define(['commonDetail','common'], function (exports) {
var commonDetail = layui.commonDetail;
var common = layui.common;
//对外暴露的接口
exports('huawei_cloud_nethardware', function (data) {
var resId = '';
var resType = '';
var showFlag = common.getUrlParam("show");
if(showFlag && showFlag == '0'){
resId = common.getUrlParam("resId");
resType = common.getUrlParam("resType");
}else{
resId = data.resId;
resType = data.resType;
}
commonDetail.bindTips();
//基本信息
//2020-02-07 xwx屏蔽:设备序列号,IPV6地址 与李腾飞确认采集不到,屏蔽
var jbxxKpi = "KPIE13DD9A3,KPIF74D9D2B,KPIFABFD741,KPIB718ADEC,KPI5858832B,KPI2DC9105C,KPI7E81DFB5,KPI6F17667E, KPIF21A9F60, KPI81BAB2C4, KPI5364695E, KPI14E5F9B4, KPIC70A1E3D";
reload()
//渲染页面
function reload() {
//基本信息
commonDetail.renderTextCols("hauwei_cloude_nethardware_baseinfo",resId,jbxxKpi,2);
//维保信息 joke add 20200528
commonDetail.renderMaintenanceInfo('hauwei_cloude_nethardware_wbinfo',resId,resType);
//CPU平均使用率
commonDetail.renderGauge("hauwei_cloude_nethardware_cpurate",resId,"KPI961A9688");
//内存平均使用率
commonDetail.renderGauge("hauwei_cloude_nethardware_memrate",resId,"KPIE78B29FF");
// commonDetail.renderCircular("hauwei_cloude_nethardware_memrate",resId,"KPIE78B29FF","内存平均使用率","%");
//响应时长
commonDetail.renderLineCharat("hauwei_cloude_nethardware_responestimes",resId,"KPI7480987F","响应时长","");
//活动告警
commonDetail.renderActiveAlarms("hauwei_cloude_nethardware_activealarms",resId);
}
//定时任务
var timer = setInterval(function () {
reload()
},commonDetail.timerTime);
commonDetail.detailTimer.push(timer);
});
});
\ No newline at end of file
... ...