alarmwindow.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. io.sails.autoConnect = false;
  2. io.sails.url="http://"+alarmServiceIP+":"+alarmServicePort+"";
  3. socketio = io.sails.connect();
  4. var alarmInfoDialog;
  5. var alarmData=new Array();
  6. var alarmLevelDic={};
  7. var alarmLevelDicName={};
  8. getAlarmLevels();
  9. function getAlarmLevels(){
  10. var reqData = {"method":"GetLevels","param":{}};
  11. var eventName = "/alarm/doservice";
  12. var dataTypes=[];
  13. dataTypes.push("*");
  14. socketio.post(eventName,reqData,function(data){
  15. if(data.success="true"){
  16. var DataType=data.data.data;
  17. for(var i=0;i<DataType.length;i++){
  18. alarmId=i+1;
  19. alarmLevelDic[DataType[i].level]=DataType[i];
  20. alarmLevelDicName[DataType[i].level_name]=DataType[i];
  21. dataTypes.push(DataType[i].level_name);
  22. }
  23. socketio.post("/alarm/SubscribeNotify", function (data) {
  24. if (data.success = "true") {
  25. socketio.on("alarm_notify", function (data) {
  26. var len=alarmData.length;
  27. alarmData=alarmData.concat(data);
  28. // console.log(alarmLevelDic["1"]);
  29. for(var j=0;j<data.length;j++){
  30. if( alarmLevelDic[data[j].state0].popup==1){
  31. AlarmInfoShow(alarmData,len);
  32. }
  33. }
  34. })
  35. }
  36. });
  37. }
  38. });
  39. return dataTypes;
  40. }
  41. function AlarmInfoShow(data,curAlarmIndex) {
  42. if (data.length < 0) {
  43. return;
  44. }
  45. var currentData = data[curAlarmIndex];
  46. var currentAlarmTime = moment(Number(currentData.alarm_time)).format("YYYY-MM-DD HH:mm:ss");
  47. var currentAlarmDesc = currentData.message;
  48. var curAlarmCount = data.length;
  49. var tagName=currentData.tag_name;
  50. var alarmDialogPosition = {
  51. x: document.body.clientWidth - 250,
  52. y: graphView.getView().clientHeight - 200
  53. };
  54. 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>";
  55. var alarmDialogConfigObj = {
  56. title: "报警",
  57. titleAlign: "left",
  58. titleBackground:'rgb(12,77,85)',
  59. position:alarmDialogPosition,
  60. closable: true,
  61. draggable: true,
  62. contentPadding: 5,
  63. width: 250,
  64. height: 200,
  65. content: content,
  66. buttons: [{
  67. label: "<<"
  68. },
  69. {
  70. label: "<"
  71. },
  72. {
  73. label: "第" + (curAlarmIndex+1)+ "/" + curAlarmCount + "页"
  74. },
  75. {
  76. label: ">"
  77. },
  78. {
  79. label: ">>"
  80. },
  81. {
  82. label: "确认",
  83. className: "button-yes"
  84. }
  85. ],
  86. buttonsAlign: "center",
  87. action: function (item, e) {
  88. if (item["label"] == "<") {
  89. if (curAlarmIndex == 0) {
  90. return;
  91. }else{
  92. curAlarmIndex=curAlarmIndex-1;
  93. }
  94. }
  95. if (item["label"] == "<<") {
  96. if (curAlarmIndex == 0) {
  97. return;}
  98. curAlarmIndex = 0;
  99. }
  100. if (item["label"] == ">") {
  101. // curAlarmIndex = curAlarmIndex + 1
  102. if (curAlarmIndex !=curAlarmCount-1) {
  103. curAlarmIndex = curAlarmIndex + 1
  104. //return;
  105. }
  106. }
  107. if (item["label"] == ">>") {
  108. curAlarmIndex = curAlarmCount-1;
  109. }
  110. if (item["label"] == "确认") {
  111. data.removeArr(curAlarmIndex);
  112. curAlarmIndex=curAlarmIndex-1;
  113. var EnsureUser = currentData.ensure_info;
  114. var Ensuretag = currentData.tag_name;
  115. tagobj = {
  116. "tag_name": Ensuretag,
  117. "ensure_info": EnsureUser
  118. };
  119. ensureAlarm([tagobj]);
  120. if(data.length<=0){
  121. alarmInfoDialog.hide();
  122. // getRealAlarmInfos(realdataModelReal,tablePaneReal,pageinputReal.value,rowssizeReal.getValue(),pageCountReal,dataAreaNameReal,alarmGroupValueReal,alarmLevelValueReal);
  123. return;
  124. } else {
  125. if (curAlarmIndex >= curAlarmCount) {
  126. curAlarmIndex = curAlarmCount;
  127. }
  128. }
  129. }
  130. AlarmInfoShow(data,curAlarmIndex);
  131. }
  132. }
  133. var tabViewConfig = [
  134. {
  135. name: 'scada',
  136. view: content,
  137. selected: true
  138. }
  139. ]
  140. if (typeof (alarmInfoDialog) == "undefined"){
  141. // alarmInfoDialog = new ht.widget.Dialog();
  142. alarmInfoDialog = createDialogWithTabView(alarmDialogConfigObj, tabViewConfig);
  143. }
  144. // alarmInfoDialog.setConfig(alarmDialogConfigObj);
  145. alarmInfoDialog.setModal(false);
  146. if(alarmInfoDialog.isShowing()){
  147. //alarmInfoDialog.hide();
  148. }else{
  149. alarmInfoDialog.show();
  150. }
  151. getAlarmSound(data);
  152. }
  153. //获取报警铃声
  154. function getAlarmSound(data){
  155. var minlevel=1000;
  156. var alarmInfos=data;
  157. var wavfilename="";
  158. for(var i=0;i<alarmInfos.length;i++){
  159. var levelId=i+1;
  160. var levelValue=alarmLevelDic[levelId].level;
  161. if(levelValue<=minlevel){
  162. minlevel=levelValue;
  163. wavfilename=alarmLevelDic[levelId].wave_file;
  164. }
  165. }
  166. var audio = new Audio(wavFile+wavfilename);
  167. audio.play();
  168. }
  169. /*确认报警信息*/
  170. function ensureAlarm(tagnames){
  171. var arr=tagnames;
  172. var eventName = "/alarm/ensure";
  173. socketio.post(eventName,arr,function(data){
  174. });
  175. }