Authored by wangtao

即时消息功能增加对于es、influxdb、tdengine的支撑(支持监控数据库的查询操作/文本,es、influxdb、tdengine暂时不支持)

... ... @@ -38,7 +38,26 @@ layui.define(['table', 'form', 'admin', 'layer', 'common', 'sessions', 'treeTabl
noticeTimely.state = noticeTimely.state == 2 ? 1 : 0;
form.val('form-noticeTimely-add', noticeTimely);
$('[name="templates"]').val(noticeTimely.templates);
bloatedSite(noticeTimely.site);
var setting = noticeTimely.msgSetting;
if(setting){
try{
// "[{\"fieldName\":\"noticeType\",\"condition\":\"2\",\"conditionVal\":\"2\",\"msgLevel\":\"3\"}]"
var arr = JSON.parse(setting);
if(arr){
$(arr).each(function (i,v){
addCondition(v);
})
}
}catch (e) {
}
}
//bloatedSite(noticeTimely.site);
bloatedParameter(noticeTimely);
if (response.data) {
$.each(response.data, function (i, v) {
... ... @@ -110,30 +129,60 @@ layui.define(['table', 'form', 'admin', 'layer', 'common', 'sessions', 'treeTabl
player.play();
});
//添加消息状态
$("#editNoticeTimelyParamBtn").on("click",function () {
let testStatus = $('#layui-notice_timely_sql_test').attr('test-status');
if(!testStatus || testStatus != 'success'){
layer.msg('请先测试脚本!', {icon: 7,time:3000});
return;
}
function addCondition(defVal){
var settingItem = $('#notice_timely_param_level');
var html = $("#noticeTimelyParamAddRowHtml").html();
$('#notice_timely_param_level').append(html);
settingItem.append(html);
$('#notice_timely_param_sql').removeClass('hide');
$('#notice_timely_param_level').removeClass('hide');
var number = $('#notice_timely_param_level').find('.notice_time_select_sql_value').length;
settingItem.removeClass('hide');
var number = settingItem.find('.notice_time_select_sql_value').length;
getRowName();
var ht = '';
rowNames.forEach(item => {
ht += '<option value="' + item + '">' + item + '</option>'
})
$('#notice_timely_param_level').find('.notice_time_select_sql_value').eq(number - 1).append(ht);
settingItem.find('.notice_time_select_sql_value').eq(number - 1).append(ht);
if (identifying == 0) {
$('#notice_timely_param_level').find('.notice_time_select_colour').eq(0).val(grade);
settingItem.find('.notice_time_select_colour').eq(0).val(grade);
identifying = 1;
}
settingItem.find('.delete-condition').eq(0).attr('id','id'+(new Date()).getTime());
settingItem.find('.delete-condition').on('click',function (){
var that = $(this);
layer.confirm('确认要删除吗?', {icon: 3}, function (index) {
that.parent().parent().remove();
layer.close(index);
});
})
if(defVal){
// 设置默认值
settingItem.find('.notice_time_select_sql_value').val(defVal.fieldName);
settingItem.find('.notice_time_select_symbol').val(defVal.condition);
settingItem.find('.layui-notice-time-btn').val(defVal.conditionVal);
settingItem.find('.notice_time_select_colour').val(defVal.msgLevel);
setDetailsTags(rowNames);
}
}
//添加消息状态
$("#editNoticeTimelyParamBtn").on("click",function () {
var rowNames = getRowName();
if(rowNames && rowNames.length == 0){
let testStatus = $('#layui-notice_timely_sql_test').attr('test-status');
if(!testStatus || testStatus != 'success'){
layer.msg('请先测试脚本!', {icon: 7,time:3000});
return;
}
}
addCondition();
})
//写入标签内容
function writeTagsInfo(data) {
... ... @@ -348,12 +397,16 @@ layui.define(['table', 'form', 'admin', 'layer', 'common', 'sessions', 'treeTabl
}
//测试按钮点击
$('#layui-notice_timely_sql_test').unbind("click").on("click", function () {
$('#layui-notice_timely_sql_test').unbind("click").on("click", function (e) {
e.preventDefault();
var sql = $('#layui-notice_timely_sql').val();
var type = $('#noticeTimely_type').val();
admin.req({
url: common.domainName + '/api-web/noticeTimely/executeSql'
, data: {
sql: sql
sql: sql,
type:type
}
, success: function (res) {
if (res && res.data && res.data.length > 0) {
... ... @@ -363,23 +416,15 @@ layui.define(['table', 'form', 'admin', 'layer', 'common', 'sessions', 'treeTabl
var list = res.data;
//默认取值第一个
var keys = Object.keys(list[0]);
var details_tags = '';
var html = '';
keys.forEach(item => {
html += '<option value="' + item + '">' + item + '</option>'
//
details_tags += `<span id="tags_span_${item}" class="layui-badge layui-bg-blue" style="margin: 3px;" ><em>${item}</em></span>`;
})
$.each($('.notice_time_select_sql_value'), function (i, v) {
$(this).empty();
$(this).append(html);
})
$('#details_tags').append(details_tags);
$('#details_tags span').on('click',function (){
$('[name="templates"]').val($('[name="templates"]').val() + '#{'+$(this).text() + '}');
});
setDetailsTags(keys);
layer.msg('脚本验证通过!', {icon: 1, time: 3000});
} else {
layer.msg('脚本验证失败,请检查!', {icon: 7, time: 3000});
... ... @@ -388,21 +433,28 @@ layui.define(['table', 'form', 'admin', 'layer', 'common', 'sessions', 'treeTabl
});
});
function setDetailsTags(arr){
$('#details_tags').find('.layui-badge').remove();
var details_tags = '';
arr.forEach(item => {
details_tags += `<span id="tags_span_${item}" class="layui-badge layui-bg-blue" style="margin: 3px;" ><em>${item}</em></span>`;
})
$('#details_tags').append(details_tags);
$('#details_tags span').on('click',function (){
$('[name="templates"]').val($('[name="templates"]').val() + '#{'+$(this).text() + '}');
});
}
//获取配置参数
function getParam() {
debugger
var map = getRowName();
var pa = '';
map.rowNameList.forEach(item => {
pa += '#{' + item + '},';
})
if (pa != '') {
pa = pa.substring(0, pa.length - 1);
}
//获取模板和等级
var obj = {
msgSetting: '',
templates: pa
msgSetting: null,
templates: null
};
var errMsg = '';
... ... @@ -410,7 +462,19 @@ layui.define(['table', 'form', 'admin', 'layer', 'common', 'sessions', 'treeTabl
if (!$('#notice_timely_param_sql').hasClass('hide')) {
// 获取模板信息
var val = $('#notice_timely_param_sql').find('textarea[name="templates"]').eq(0).val();
obj.templates = val ? val : pa;
if(!val || val == '' || val == null){
var map = getRowName();
var pa = '';
map.rowNameList.forEach(item => {
pa += '#{' + item + '},';
})
if (pa != '') {
pa = pa.substring(0, pa.length - 1);
}
val = pa;
}
obj.templates = val;
var arr = [];
// 获取条件行
... ...
... ... @@ -113,7 +113,7 @@ layui.define(['table', 'form', 'admin', 'layer', 'common', 'sessions', 'treeTabl
elem: '#table-noticeTimely-state-list',
url: domainName + '/api-web/noticeTimely/statePage',
where: params,
height: 'full',
height: 'full-450',
limit: common.limit,
limits: common.limits,
page: {
... ... @@ -246,7 +246,7 @@ layui.define(['table', 'form', 'admin', 'layer', 'common', 'sessions', 'treeTabl
layer.open({
title: "已发送消息",
content: $("#noticeTimely-state-html").html(),
area: ['80%', '70%'],
area: ['80%', '670px'],
btns: ['确认', '取消'],
success: function (index) {
loadStateTable(id);
... ...
... ... @@ -441,8 +441,7 @@ layui.extend({
//通过stompClient.subscribe订阅/topic/getResponse 目标(destination)发送的消息
stompClient.subscribe('/alarmQuery/', function (respnose) {
var alarmArr = JSON.parse(respnose.body);
var mp3Name = sessionStorage.getItem('mp3');
var audio = audioPlayer(`../src/style/mp3/${mp3Name}.mp3`)
$.each(alarmArr, function (i, v) {
if (v.alarmContent) {
(function (i) {
... ... @@ -461,7 +460,8 @@ layui.extend({
let isNotify = alarmByUser(v.alarmId, alarmType === 'alarm' ? 'b_alarm' : 'b_alarm_his');
if (isNotify) {
setTimeout(function () {
audio.playclip();
var mp3Name = sessionStorage.getItem('mp3');
audioPlayer(`../src/style/mp3/${mp3Name}.mp3`)
new msgTips({
dom: ".right-bottom-tips",
title: "告警消息",
... ... @@ -551,7 +551,7 @@ layui.extend({
toastType: toastType,
type: 'click',
action: function () {
if (hash) {
if (hash && hash != '' && hash != null) {
if (hash.toLowerCase().indexOf("http://") != -1 && hash.toLowerCase().indexOf("https://") != -1) {
location.hash = hash;
} else {
... ... @@ -621,7 +621,7 @@ layui.extend({
// 订阅实时消息
stompClient.subscribe('/realTime/', function (respnose) {
console.log('实时信息: ' + respnose);
//console.log('实时信息: ' + respnose);
var data = respnose.body;
if (data) {
var obj = JSON.parse(data);
... ... @@ -633,7 +633,7 @@ layui.extend({
// 订阅用户消息
layui.use('element', function () {
stompClient.subscribe("/user/realTime/notifications/", function (respnose) {
console.log('专属信息: ' + respnose);
//console.log('专属信息: ' + respnose);
var data = respnose.body;
if (data) {
var obj = JSON.parse(data);
... ... @@ -648,17 +648,23 @@ layui.extend({
progressHandel(element,obj);
} else {
showTips(obj.content, obj.title, obj.msgType.toLowerCase(), obj.href, 1000, obj.queryResult);
if (typeof (obj.msgType) != "undefined") {
var str = '滑稽';
voiceList.forEach(item => {
if (item.type_ == obj.msgType) {
str = item.voice_;
}
})
var url = '../src/style/mp3/' + str + '.mp3';
var audio = audioPlayer(url);
audio.playclip();
var noticeVoice = '滑稽';
if(obj.voice){
noticeVoice = obj.voice;
}
var mp3Url = `/src/style/mp3/${noticeVoice}.mp3`;
audioPlayer(mp3Url);
// if (typeof (obj.msgType) != "undefined") {
// var str = '滑稽';
// voiceList.forEach(item => {
// if (item.type_ == obj.msgType) {
// str = item.voice_;
// }
// })
// var url = '../src/style/mp3/' + str + '.mp3';
// var audio = audioPlayer(url);
// audio.playclip();
// }
}
}
});
... ... @@ -701,20 +707,27 @@ layui.extend({
//音频播放
function audioPlayer(url) {
var audio = document.createElement('audio')
if (audio.canPlayType) {
var element = document.createElement('source')
element.setAttribute('src', url)
element.setAttribute('type', 'audio/mpeg')
audio.appendChild(element)
audio.load()
audio.playclip = function () {
audio.pause()
audio.currentTime = 0
audio.play()
}
return audio
try{
// var audio = document.createElement('audio')
// if (audio.canPlayType) {
// var element = document.createElement('source')
// element.setAttribute('src', url)
// element.setAttribute('type', 'audio/mpeg')
// audio.appendChild(element)
// audio.load()
// audio.playclip = function () {
// audio.pause()
// audio.currentTime = 0
// audio.play()
// }
// return audio
// }
var player = new Audio(url);
player.play();
}catch (e) {
console.log('已播放!');
}
}
var tryFunc = function () {
... ...
... ... @@ -84,15 +84,15 @@
<label class="layui-form-label">类型</label>
<div class="layui-input-inline">
<select name="type" id="noticeTimely_type" lay-filter="noticeTimely_type">
<option value="sql">监控数据库</option>
<option value="text">文本</option>
<option value="SQL">监控数据库</option>
<option value="TEXT">文本</option>
<!-- <option value="es">es</option>
<option value="influxdb">时序</option>
<option value="tdEngine">tdEngine</option>-->
</select>
<span>
<div style="padding: 3px">
文本支持:#{now} 当前时间格式:yyyy-MM-dd HH:mm:ss
</span>
</div>
</div>
</div>
</div>
... ... @@ -129,7 +129,7 @@
</div>
<div class="layui-form-item hide" id="notice_timely_param_level">
<label class="layui-form-label">展示设置</label>
<span style="color: red">* 列表数据的状态设置办法:获取“第一条”数据的内容进行判断;多条件之间的关系为“且”</span>
<span style="color: red;line-height:36px">* 列表数据的状态设置办法:获取“第一条”数据的内容进行判断</span>
</div>
</div>
</article>
... ... @@ -153,7 +153,7 @@
<option value="2">重要(黄色)</option>
<option value="3">严重(红色)</option>
</select>
<div class="layui-notice-time-lable" style="width: 40px;">测试</div>
<div class="layui-notice-time-lable delete-condition" style="width: 40px;">删除</div>
</div>
</div>
</script>
... ...
... ... @@ -55,4 +55,4 @@
layui.use('noticeTimelyIndex', function (fn) {
fn();
});
</script>
\ No newline at end of file
</script>
... ...