當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
一段javascript告警回放代码
生活随笔
收集整理的這篇文章主要介紹了
一段javascript告警回放代码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/*** 描述 :* 這里是實現播放,快進等功能的js文件* * */var replaySpeed = 1000 * 5;//播放速度 50秒
var alarmReplayTimer = null; // 定義播放定期器
var alarmBackUpTimer = null; // 定義回退播放器
var flag = false; // 播放開關//向前播放的action地址
var alarmForwardUrl = getRootPath() + "/web/alarm/alarmReplayController/alarmForward.do";//向后播放的action地址
var alarmBackupUrl = getRootPath() + "/web/alarm/alarmReplayController/alarmBackup.do";var startOrPause = function() { // (開始/暫停 ) 播放//修改 開始/暫停 播放 按鈕的值var startOrPauseButton = document.getElementById("startOrPause");var startOrPauseButtonValue = startOrPauseButton.innerHTML;if (startOrPauseButtonValue == "開始") {updateTime();startOrPauseButton.innerHTML = "暫停";} else {startOrPauseButton.innerHTML = "開始";}//開始播放或暫停播放if (!flag) { // 未啟動flag = true;alarmReplayTimer = setInterval("forward()", replaySpeed); //定時器定時刷新} else { // 已啟動flag = false;clearTimer();//停止播放}
}
var forward = function() { // 向前var currentTime = document.getElementById("currentTime").value;var currentEndTime = document.getElementById("currentEndTime").value;var compareDate = isBigger(currentTime,currentEndTime);if(compareDate==0){$.ajax( {url:alarmForwardUrl,data:{currentTime:currentTime,currentEndTime:currentEndTime},type:'post',cache:false,dataType:'json', success:function(data) {var time = data[0];var alarmList = data[1]; //告警對象集合initTableHtml(alarmList);// console.info(alarmList);if(time!=null){document.getElementById("currentTime").value = time; }else{document.getElementById("currentTime").value = document.getElementById("currentEndTime").value;}// $("#alarmRelay").html(tableContent); },error: function(XMLHttpRequest, textStatus, errorThrown) {alert("播放異常");},})}else if(compareDate==1){alert("播放完成");clearTimer();}else if(compareDate == null){alert("播放異常");}}var stop = function(){ // 停止clearTimer();
}var backward = function() { // 向后var currentTime = document.getElementById("currentTime").value;var currentStartTime = document.getElementById("currentStartTime").value;var compareDate = isBigger(currentStartTime,currentTime);if(compareDate==0){$.ajax( {url:alarmBackupUrl,data:{currentTime:currentTime,currentStartTime:currentStartTime},type:'post',cache:false,dataType:'json', success:function(data) {var time = data[0];var alarmList = data[1]; //告警對象集合initTableHtml(alarmList);if(time!=null){document.getElementById("currentTime").value = time; }else{document.getElementById("currentTime").value = document.getElementById("currentStartTime").value;}
// document.getElementById("currentTime").value = time;
// $("#alarmRelay").html(tableContent); },error: function(XMLHttpRequest, textStatus, errorThrown) {alert("播放異常");},})}else if(compareDate==1){alert("播放完成");clearTimer();}else if(compareDate == null){alert("播放異常");}}var lastTime = function() { // 上一次clearTimer();backward();
}var nextTime = function() { // 下一次clearTimer();forward();
}var clearAlarmReplayTimer = function(){ // 清除向前定時器if(alarmReplayTimer!=null){clearTimeout(alarmReplayTimer); //清除下一次播放定時器alarmReplayTimer = null;}
}var clearAlarmBackUpTimer = function(){ // 清除向后定時器if(alarmBackUpTimer!=null){clearTimeout(alarmBackUpTimer); //清除上一次播放定時器alarmBackUpTimer = null;} }var backSpace = function() { // 回退// speedUp();clearTimer();alarmBackUpTimer = setInterval("backward()", replaySpeed); //定時器定時刷新
}var fastForward = function() { // 快進// speedUp();clearTimer();alarmReplayTimer = setInterval("forward()", replaySpeed); //定時器定時刷新}var clearTimer = function() { // 清除定時器clearAlarmReplayTimer();clearAlarmBackUpTimer();document.getElementById("startOrPause").innerHTML = "開始";}var speedUp = function(){//加速if(replaySpeed == 1000 * 5){replaySpeed = 1000 * 3;}else if(replaySpeed == 1000 * 3){replaySpeed = 1000 * 1;}else if(replaySpeed == 1000 * 1){replaySpeed = 100 * 5;}else if(replaySpeed == 100 * 5){replaySpeed = 100 * 3;}else if(replaySpeed == 100 * 3){replaySpeed = 100 * 1;}
}
var assignSpeed = function(){ //指定速度倍數//指定倍數var assignSpeedSelect = document.getElementById("assignSpeedSelect").value;if(assignSpeedSelect == "1"){replaySpeed = 1000 * 5;}else if(assignSpeedSelect == "2"){replaySpeed = 1000 * 3;}else if(assignSpeedSelect == "5"){replaySpeed = 1000 * 1;}else if(assignSpeedSelect == "10"){replaySpeed = 100 * 5;}else if(assignSpeedSelect == "20"){replaySpeed = 100 * 3;}else if(assignSpeedSelect == "50"){replaySpeed = 100 * 1;}//重啟定時器if(alarmReplayTimer!=null){clearAlarmReplayTimer();alarmReplayTimer = setInterval("forward()", replaySpeed); //定時器定時刷新}if(alarmBackUpTimer!=null){clearAlarmBackUpTimer();alarmBackUpTimer = setInterval("backward()", replaySpeed); //定時器定時刷新}}function getRootPath() { //得到項目路徑var strFullPath = window.document.location.href; var strPath = window.document.location.pathname; var pos = strFullPath.indexOf(strPath); var prePath = strFullPath.substring(0, pos); var postPath = strPath.substring(0, strPath.substr(1).indexOf('/') + 1); var rootPath = prePath + postPath; return (rootPath);
}
$(window).load(function() {(function($){$(document).ready(function(){jeDate({dateCell:'#currentStartTime',format:'YYYY-MM-DD hh:mm:ss',isTime:true,minDate:'2014-09-19 00:00:00'}),jeDate({dateCell:'#currentEndTime',format:'YYYY-MM-DD hh:mm:ss',isTime:true,minDate:'2014-09-19 00:00:00'})});})(jQuery);})
var updateTime = function(){var currentStartTime = document.getElementById("currentStartTime");var currentTime = document.getElementById("currentTime");currentTime.value = currentStartTime.value;
}/*表格內容*/function initTableHtml(arr){if(arr==null) return ;console.info(arr);var str = '',strNull = '<td><div></div></td>';var getRowHtml = function(alarmList){var subs = '';subs += '<td player="first"><div><input type="checkbox" class="select" value="'+ alarmList.deviceId +'"</div></td>';if(alarmList.alarmLevel) subs += '<td><div>' + alarmList.alarmLevel + '</div></td>';else subs += strNull;if(alarmList.alarmType) subs += '<td><div>' + alarmList.alarmType + '</div></td>';else subs += strNull;if(alarmList.deviceName) subs += '<td><div>' + alarmList.deviceName + '</div></td>';else subs += strNull;if(alarmList.ip) subs += '<td><div>' + alarmList.ip + '</div></td>';else subs += strNull;if(alarmList.area) subs += '<td><div>' + alarmList.area + '</div></td>';else subs += strNull;if(alarmList.ceateTime) subs += '<td><div>' + getLocalTime(alarmList.ceateTime)+ '</div></td>';else subs += strNull;if(alarmList.lastUpdateTime) subs += '<td><div>' + getLocalTime(alarmList.lastUpdateTime) + '</div></td>';else subs += strNull;if(alarmList.alarmNumber) subs += '<td><div>' + alarmList.alarmNumber + '</div></td>';else subs += strNull;if(alarmList.status) subs += '<td><div>' + alarmList.status + '</div></td>';else subs += strNull;return subs;};var len = arr.length;for(var i=0;i<len;i++){str += '<tr class="id'+ arr[i].deviceId +'">';str += getRowHtml(arr[i]);str += '</tr>';}var stationContent = document.querySelector(".stationContent");stationContent.innerHTML = str;document.querySelector(".selectAll").checked = false; //取消表頭的多}function getLocalTime(nS) { return new Date(nS).Format("yyyy-MM-dd HH:mm:ss");
};
總結
以上是生活随笔為你收集整理的一段javascript告警回放代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: (2) java项目中用redis
- 下一篇: 打印功能