123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- io.sails.autoConnect = false;
- io.sails.url="http://"+alarmServiceIP+":"+alarmServicePort+"";
- socketio = io.sails.connect();
- var alarmInfoDialog;
- var alarmData=new Array();
- var alarmLevelDic={};
- var alarmLevelDicName={};
- getAlarmLevels();
- function getAlarmLevels(){
- var reqData = {"method":"GetLevels","param":{}};
- var eventName = "/alarm/doservice";
- var dataTypes=[];
- dataTypes.push("*");
- socketio.post(eventName,reqData,function(data){
- if(data.success="true"){
- var DataType=data.data.data;
- for(var i=0;i<DataType.length;i++){
- alarmId=i+1;
- alarmLevelDic[DataType[i].level]=DataType[i];
- alarmLevelDicName[DataType[i].level_name]=DataType[i];
- dataTypes.push(DataType[i].level_name);
- }
- socketio.post("/alarm/SubscribeNotify", function (data) {
- if (data.success = "true") {
- socketio.on("alarm_notify", function (data) {
-
- var len=alarmData.length;
- alarmData=alarmData.concat(data);
- // console.log(alarmLevelDic["1"]);
- for(var j=0;j<data.length;j++){
- if( alarmLevelDic[data[j].state0].popup==1){
- AlarmInfoShow(alarmData,len);
- }
- }
- })
- }
- });
- }
- });
- return dataTypes;
- }
- function AlarmInfoShow(data,curAlarmIndex) {
-
- if (data.length < 0) {
- return;
- }
- var currentData = data[curAlarmIndex];
- var currentAlarmTime = moment(Number(currentData.alarm_time)).format("YYYY-MM-DD HH:mm:ss");
- var currentAlarmDesc = currentData.message;
- var curAlarmCount = data.length;
- var tagName=currentData.tag_name;
- var alarmDialogPosition = {
- x: document.body.clientWidth - 250,
- y: graphView.getView().clientHeight - 200
- };
- var content = "<div style='margin-top:0px;width:250px;height:180px;'><p style='height:50px;color:#f00;font:15px 微软雅黑;'>" + currentAlarmTime + "</p><p style='height:50px;color:#f00;font:15px 微软雅黑;'>"+tagName+"</p><p style='height:50px;color:#f00;font: 15px 微软雅黑;'>" + currentAlarmDesc + "</p></div>";
- var alarmDialogConfigObj = {
- title: "报警",
- titleAlign: "left",
- titleBackground:'rgb(12,77,85)',
- position:alarmDialogPosition,
- closable: true,
- draggable: true,
- contentPadding: 5,
- width: 250,
- height: 200,
- content: content,
- buttons: [{
- label: "<<"
- },
- {
- label: "<"
- },
- {
- label: "第" + (curAlarmIndex+1)+ "/" + curAlarmCount + "页"
- },
- {
- label: ">"
- },
- {
- label: ">>"
- },
- {
- label: "确认",
- className: "button-yes"
- }
- ],
- buttonsAlign: "center",
- action: function (item, e) {
- if (item["label"] == "<") {
- if (curAlarmIndex == 0) {
- return;
- }else{
- curAlarmIndex=curAlarmIndex-1;
- }
- }
- if (item["label"] == "<<") {
- if (curAlarmIndex == 0) {
- return;}
- curAlarmIndex = 0;
- }
- if (item["label"] == ">") {
-
- // curAlarmIndex = curAlarmIndex + 1
- if (curAlarmIndex !=curAlarmCount-1) {
- curAlarmIndex = curAlarmIndex + 1
- //return;
- }
- }
- if (item["label"] == ">>") {
- curAlarmIndex = curAlarmCount-1;
-
- }
-
- if (item["label"] == "确认") {
-
- data.removeArr(curAlarmIndex);
- curAlarmIndex=curAlarmIndex-1;
- var EnsureUser = currentData.ensure_info;
- var Ensuretag = currentData.tag_name;
- tagobj = {
- "tag_name": Ensuretag,
- "ensure_info": EnsureUser
- };
-
- ensureAlarm([tagobj]);
- if(data.length<=0){
- alarmInfoDialog.hide();
- // getRealAlarmInfos(realdataModelReal,tablePaneReal,pageinputReal.value,rowssizeReal.getValue(),pageCountReal,dataAreaNameReal,alarmGroupValueReal,alarmLevelValueReal);
- return;
- } else {
- if (curAlarmIndex >= curAlarmCount) {
- curAlarmIndex = curAlarmCount;
- }
- }
- }
-
-
- AlarmInfoShow(data,curAlarmIndex);
-
- }
- }
- var tabViewConfig = [
- {
- name: 'scada',
- view: content,
- selected: true
- }
- ]
- if (typeof (alarmInfoDialog) == "undefined"){
- // alarmInfoDialog = new ht.widget.Dialog();
- alarmInfoDialog = createDialogWithTabView(alarmDialogConfigObj, tabViewConfig);
- }
- // alarmInfoDialog.setConfig(alarmDialogConfigObj);
- alarmInfoDialog.setModal(false);
- if(alarmInfoDialog.isShowing()){
- //alarmInfoDialog.hide();
- }else{
- alarmInfoDialog.show();
- }
- getAlarmSound(data);
- }
- //获取报警铃声
- function getAlarmSound(data){
- var minlevel=1000;
- var alarmInfos=data;
- var wavfilename="";
- for(var i=0;i<alarmInfos.length;i++){
- var levelId=i+1;
- var levelValue=alarmLevelDic[levelId].level;
- if(levelValue<=minlevel){
- minlevel=levelValue;
- wavfilename=alarmLevelDic[levelId].wave_file;
- }
- }
- var audio = new Audio(wavFile+wavfilename);
- audio.play();
- }
- /*确认报警信息*/
- function ensureAlarm(tagnames){
- var arr=tagnames;
- var eventName = "/alarm/ensure";
- socketio.post(eventName,arr,function(data){
- });
- }
|