197 lines
8.0 KiB
JavaScript
197 lines
8.0 KiB
JavaScript
|
import { layuiObj } from './index.js';
|
|||
|
import { ajax } from '../api/ajax.js';
|
|||
|
|
|||
|
import { movedeviceurl,stationurl } from '../../../public/js/url.js';
|
|||
|
import { timestampFormatTime } from '../../../public/js/timestamp.js';
|
|||
|
|
|||
|
var notifyIndex=null;
|
|||
|
var notifyTemplate={
|
|||
|
"holiday":'节日期间,人流密集,请各单位组织排查火灾情况,加强巡逻和值班工作。',
|
|||
|
"hightemp":'高温天气预,请各单位组织排查火灾情况,并做好防暑工作。',
|
|||
|
"lightningstorm":'雷电暴雨天气预,请各单位排查建筑物,谨防坠物伤人。'
|
|||
|
};
|
|||
|
|
|||
|
var notifyDeviceArr=null;
|
|||
|
function popNotify(deviceArr){
|
|||
|
notifyDeviceArr=JSON.parse(JSON.stringify(deviceArr));
|
|||
|
if(notifyIndex==null){
|
|||
|
var notifyType="moveDevice";
|
|||
|
if(notifyDeviceArr.length>1){
|
|||
|
var title=`通知群发[${notifyDeviceArr.length}]`;
|
|||
|
}else{
|
|||
|
var title=notifyDeviceArr[0]["showname"];
|
|||
|
}
|
|||
|
notifyIndex=layuiObj["layer"].open({
|
|||
|
type: 1,
|
|||
|
title: false, //不显示标题栏
|
|||
|
closeBtn: false,
|
|||
|
area: ['446px', '430px'],
|
|||
|
shade: 0.4,
|
|||
|
id: new Date().getTime(), //设定一个id,防止重复弹出
|
|||
|
btnAlign: 'c',
|
|||
|
move:'.layui-move',
|
|||
|
moveType: 1, //拖拽模式,0或者1
|
|||
|
content:`<div class="popnotify popWindows">
|
|||
|
<div class="notifyInfo">
|
|||
|
<div class="notifyTitle">
|
|||
|
<span class="layui-move">通知发送</span>
|
|||
|
<img src="./pages/cmddispatch/image/closeInfoWindow.png">
|
|||
|
</div>
|
|||
|
<div class="notifyContent">
|
|||
|
<fieldset class="layui-elem-field layui-field-title">
|
|||
|
<legend class="NotifyStationName">${title}</legend>
|
|||
|
</fieldset>
|
|||
|
<form class="layui-form" action="" lay-filter="sendnotifyForm" id="sendnotifyForm" notifytype='${notifyType}'>
|
|||
|
<div class="layui-form-item">
|
|||
|
<label class="layui-form-label">标题</label>
|
|||
|
<div class="layui-input-block">
|
|||
|
<input type="text" name="title" lay-verify="required" value='' placeholder="请输入标题" autocomplete="off" class="layui-input" id="notifyTitle">
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="layui-form-item">
|
|||
|
<label class="layui-form-label">类型</label>
|
|||
|
<div class="layui-input-block">
|
|||
|
<select name="quiz" lay-filter="notifyType" id="notifyType">
|
|||
|
<option value="">请选择模板</option>
|
|||
|
<option value="holiday">节假日</option>
|
|||
|
<option value="hightemp">高温</option>
|
|||
|
<option value="lightningstorm">雷电暴雨</option>
|
|||
|
</select>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="layui-form-item layui-form-text">
|
|||
|
<label class="layui-form-label">内容</label>
|
|||
|
<div class="layui-input-block notifyTypeFile">
|
|||
|
<textarea placeholder="请输入内容" class="layui-textarea" name="desc" id="notifyContent" autocomplete="off" lay-verify="required" style="resize: none;"></textarea>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="layui-form-item">
|
|||
|
<div class="layui-input-block notifyblockBtn">
|
|||
|
<button type="button" class="layui-btn" lay-submit id="NotifySubmit">发送</button>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</form>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>`,
|
|||
|
success: function(layero){
|
|||
|
sendnotifyEvent();
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
layuiObj.layuiForm.render("select","sendnotifyForm");
|
|||
|
layuiObj.layuiForm.render("checkbox","sendnotifyForm");
|
|||
|
layuiObj.layuiForm.on('select(notifyType)', function(data){
|
|||
|
var value=data["value"];
|
|||
|
value=notifyTemplate[value];
|
|||
|
$("#notifyContent").val(value);
|
|||
|
layuiObj.layuiForm.render("checkbox","sendnotifyForm");
|
|||
|
})
|
|||
|
|
|||
|
//关闭
|
|||
|
$(".notifyTitle>img").click(function(){
|
|||
|
layuiObj["layer"].close(notifyIndex);
|
|||
|
notifyIndex=null;
|
|||
|
})
|
|||
|
}
|
|||
|
|
|||
|
function getnotifyContent(){
|
|||
|
var title=$("#notifyTitle").val();
|
|||
|
var type=$("#notifyType").find("option:selected").text();
|
|||
|
var content=$("#notifyContent").val();
|
|||
|
var timestamp=(new Date().getTime());
|
|||
|
var pts= (new Date()).valueOf();
|
|||
|
var obj={};
|
|||
|
obj["title"]=title;
|
|||
|
obj["content"]=content;
|
|||
|
obj["type"]=type;
|
|||
|
obj["time"]=timestampFormatTime(timestamp),
|
|||
|
obj["timestamp"]=timestamp.toString()
|
|||
|
obj["pts"]=pts
|
|||
|
return obj;
|
|||
|
}
|
|||
|
|
|||
|
function sendnotifyEvent(){
|
|||
|
//发送通知
|
|||
|
$("#NotifySubmit").off('click');
|
|||
|
$("#NotifySubmit").on('click',function(){
|
|||
|
var notifyInfo=getnotifyContent();
|
|||
|
var notifySendALL=[];
|
|||
|
notifyDeviceArr.map((item)=>{
|
|||
|
notifySendALL.push(sendNotifyReq(notifyInfo,item));
|
|||
|
notifySendALL.push(sendNotifyMqttReq(notifyInfo,item));
|
|||
|
})
|
|||
|
Promise.all(notifySendALL).then((res) => {
|
|||
|
layuiObj["layer"].close(notifyIndex);
|
|||
|
notifyIndex=null;
|
|||
|
layuiObj["layer"].msg("发送成功");
|
|||
|
});
|
|||
|
})
|
|||
|
}
|
|||
|
|
|||
|
function sendNotifyReq(notifyInfo,item){
|
|||
|
var nUrl=movedeviceurl+"/mdev/notice/send";
|
|||
|
var unameInfo=JSON.parse(sessionStorage.getItem("unameInfoStr"));//获取用户登录信息
|
|||
|
var deviceid=item.deviceid;
|
|||
|
var obj={
|
|||
|
content:notifyInfo["content"],
|
|||
|
noticeid:notifyInfo["timestamp"],
|
|||
|
receiver:deviceid,
|
|||
|
sender:unameInfo["user_name"],
|
|||
|
sendtype:"toclient",
|
|||
|
title:notifyInfo["title"]
|
|||
|
}
|
|||
|
return ajax(nUrl,obj);
|
|||
|
}
|
|||
|
|
|||
|
function sendNotifyMqttReq(notifyInfo,item){
|
|||
|
var unameInfo=JSON.parse(sessionStorage.getItem("unameInfoStr"));//获取用户登录信息
|
|||
|
var deviceid=item.deviceid;
|
|||
|
var showname=item.showname;
|
|||
|
var station=item.station;
|
|||
|
var messageData={
|
|||
|
"title":"notify",
|
|||
|
"sender":unameInfo.user_name,
|
|||
|
"department":"",
|
|||
|
"scope":"",
|
|||
|
"receiver":[deviceid],
|
|||
|
"video":"",
|
|||
|
"rtm":notifyInfo["timestamp"],
|
|||
|
"data":{
|
|||
|
"number":notifyInfo["timestamp"],
|
|||
|
"title":notifyInfo["title"],
|
|||
|
"content":notifyInfo["content"],
|
|||
|
"sender":unameInfo["user_name"],
|
|||
|
"time":notifyInfo["time"],
|
|||
|
"pts":notifyInfo["timestamp"],
|
|||
|
"receiver":"alone",
|
|||
|
"alias":showname,
|
|||
|
"cid":"",
|
|||
|
"noticeid":notifyInfo["timestamp"]
|
|||
|
},
|
|||
|
"userScope":"",
|
|||
|
"userBragide":"",
|
|||
|
"userDetachchment":"",
|
|||
|
"userBorough":"",
|
|||
|
"name":"web"
|
|||
|
}
|
|||
|
var obj={
|
|||
|
// topic:station+"/ter_cmd",
|
|||
|
topic:deviceid+"_rtmtranfer",
|
|||
|
message:JSON.stringify(messageData)
|
|||
|
}
|
|||
|
if(stationurl=="http://43.15.198.61:8083"){
|
|||
|
var nUrl=stationurl+"/firectrl/client/notice/sendudp";
|
|||
|
}else{
|
|||
|
var nUrl=stationurl+"/firectrl/client/notice/sendmqtt";
|
|||
|
}
|
|||
|
return axios({
|
|||
|
method:'post',
|
|||
|
url:nUrl,
|
|||
|
data:obj
|
|||
|
})
|
|||
|
}
|
|||
|
export {popNotify}
|