const CORS= 'http://192.168.7.120:8080/Device_Manage/'; // 开启跨域请求(调试时开启)
|
//const CORS=''; // 关闭跨域请求(发布时开启)
|
|
//定义计时器
|
function Interval() {
|
this.timer = null;
|
this.time = '';
|
this.callback = '';
|
}
|
// 开启计时器并添加
|
Interval.prototype.start = function(callback, time) {
|
// 先关闭计时器
|
this.stop();
|
// 配置执行函数
|
if(typeof callback == 'function' && typeof time == 'number') {
|
this.callback = callback;
|
this.time = time;
|
callback();
|
this.timer = setInterval(callback, time);
|
}else {
|
console.warn('未完整配置参数!');
|
}
|
};
|
// 开启计时器
|
Interval.prototype.open = function() {
|
var callback = this.callback;
|
var time = this.time;
|
this.start(callback, time);
|
};
|
|
// 关闭计时器
|
Interval.prototype.stop = function() {
|
clearInterval(this.timer);
|
};
|
|
|
// 延时计时器
|
function Timeout() {
|
this.timer = null;
|
this.time = '';
|
this.callback = '';
|
}
|
// 开启计时器并添加
|
Timeout.prototype.start = function(callback, time, exe) {
|
// 先关闭计时器
|
this.stop();
|
// 配置执行函数
|
if(typeof callback == 'function' && typeof time == 'number') {
|
this.callback = callback;
|
this.time = time;
|
if(exe != 'exe') {
|
callback();
|
}
|
this.timer = setTimeout(callback, time);
|
}else {
|
console.warn('未完整配置参数!');
|
}
|
};
|
// 开启计时器
|
Timeout.prototype.open = function() {
|
var callback = this.callback;
|
var time = this.time;
|
this.start(callback, time, 'exe');
|
};
|
|
// 关闭计时器
|
Timeout.prototype.stop = function() {
|
clearTimeout(this.timer);
|
};
|
|
/*从多维数组中获取最大值*/
|
function getMaxFromArr(arr) {
|
var newArray = arr.join(",").split(",");
|
return Math.max.apply({},newArray);
|
}
|
|
/*从多维数组中获取最小值*/
|
function getMinFromArr (arr) {
|
var newArray = arr.join(",").split(",");
|
return Math.min.apply({},newArray);
|
}
|
/*从多维数组中获取和*/
|
function getSumFromArr (arr) {
|
var newArray = arr.join(",").split(",");
|
var sum =0;
|
for(var i=0; i<newArray.length; i++) {
|
var _newArray = newArray[i];
|
sum += Number(_newArray);
|
}
|
return sum;
|
}
|
/*从多维数组中获取平均值*/
|
function getAvgFromArr (arr) {
|
var avg = 0;
|
if(arr.length !=0) {
|
var sum = getSumFromArr(arr);
|
avg = sum/arr.length;
|
}
|
return avg;
|
}
|
|
function ajax(option) {
|
// bui.ajax({
|
// method: 'POST',
|
// async: true,
|
// url: CORS+option.url,
|
// data: option.data,
|
// dataType: 'json',
|
// needNative: true,
|
// }).then(function(res) {
|
// if(typeof(option.success) == 'function') {
|
// option.success(res);
|
// }
|
// if(typeof(option.complete) == 'function') {
|
// option.complete();
|
// }
|
// },
|
// function() {
|
// if(typeof(option.complete) == 'function') {
|
// option.complete();
|
// }
|
// });
|
$.ajax({
|
type: 'post',
|
async: true,
|
url: CORS+option.url,
|
data: option.data,
|
dataType: 'json',
|
success: option.success,
|
error: option.error,
|
complete: option.complete
|
});
|
}
|
|
//将秒转化成时:分:秒
|
function formatSeconds(value) {
|
if(value > 0){
|
|
}else{
|
value = 0;
|
}
|
var theTime = parseInt(value);// 秒
|
var theTime1 = 0;// 分
|
var theTime2 = 0;// 小时
|
// alert(theTime);
|
if(theTime >= 60) {
|
theTime1 = parseInt(theTime/60);
|
theTime = parseInt(theTime%60);
|
//alert(theTime1+"-"+theTime);
|
if(theTime1 >= 60) {
|
theTime2 = parseInt(theTime1/60);
|
theTime1 = parseInt(theTime1%60);
|
}
|
}
|
var result = (theTime<10?"0":"")+parseInt(theTime);
|
if(theTime1 >= 0) {
|
result =(theTime1<10?"0":"")+parseInt(theTime1)+":"+result;
|
}
|
if(theTime2 >= 0) {
|
result =(theTime2<10?"0":"")+parseInt(theTime2)+":"+result;
|
}
|
//console.info(result);
|
return result;
|
}
|
|
// 设置后备时间(续航时间)
|
function sethoubeiTime(value){
|
value = Math.abs(value);
|
var str = "";
|
if(value>0){
|
var hour = parseInt(value);
|
var min = parseInt((parseFloat(value) - hour)*60);
|
if(hour<10){
|
str = "0";
|
}
|
str+=hour+"H";
|
if(min<10){
|
str+="0";
|
}
|
str+=min+"M";
|
}else{
|
str = "00H00M";
|
}
|
return str;
|
}
|
|
// 格式化时间
|
Date.prototype.format =function(format)
|
{
|
var o = {
|
"M+" : this.getMonth()+1, //month
|
"d+" : this.getDate(), //day
|
"h+" : this.getHours(), //hour
|
"m+" : this.getMinutes(), //minute
|
"s+" : this.getSeconds(), //second
|
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
|
"S" : this.getMilliseconds() //millisecond
|
};
|
if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
|
(this.getFullYear()+"").substr(4- RegExp.$1.length));
|
for(var k in o)if(new RegExp("("+ k +")").test(format))
|
format = format.replace(RegExp.$1,
|
RegExp.$1.length==1? o[k] :
|
("00"+ o[k]).substr((""+ o[k]).length));
|
return format;
|
};
|
|
function Title(){
|
this.min=0; //最小值
|
this.max=0; //最大值
|
this.avg=0; //平均值
|
this.sum=0; //总和
|
this.ahight=0; //高告警阀值
|
this.alow=0; //低告警阀值
|
this.clow=0; //次低更换阀值
|
this.lc=0; //低告警单体数
|
this.lp=0; //低告警百分比
|
}
|
|
function createTitle(){
|
var obj=new Object();
|
obj.min=0;
|
obj.max=0;
|
obj.avg=0;
|
obj.sum=0;
|
obj.ahight=0;
|
obj.alow=0;
|
obj.clow=0;
|
obj.lc=0;
|
obj.lp=0;
|
return obj;
|
}
|
|
Title.prototype.setMin=function(min){
|
this.min=min;
|
};
|
|
Title.prototype.getMin=function(){
|
return this.min;
|
};
|
|
Title.prototype.setMax=function(max){
|
this.max=max;
|
};
|
|
Title.prototype.getMax=function(){
|
return this.max;
|
};
|
|
Title.prototype.setAvg=function(avg){
|
this.avg=avg;
|
};
|
|
Title.prototype.getAvg=function(){
|
return this.avg;
|
};
|
|
Title.prototype.setSum=function(sum){
|
this.sum=sum;
|
};
|
|
Title.prototype.getSum=function(){
|
return this.sum;
|
};
|
|
Title.prototype.setAhight=function(ahight){
|
this.ahight=ahight;
|
};
|
|
Title.prototype.getAhight=function(){
|
return this.ahight;
|
};
|
|
Title.prototype.setAlow=function(alow){
|
this.alow=alow;
|
};
|
|
Title.prototype.getAlow=function(){
|
return this.alow;
|
};
|
|
Title.prototype.setClow=function(clow){
|
this.clow=clow;
|
};
|
|
Title.prototype.getClow=function(){
|
return this.clow;
|
};
|
|
Title.prototype.setLc=function(lc){
|
this.lc=lc;
|
};
|
|
Title.prototype.getLc=function(){
|
return this.lc;
|
};
|
|
Title.prototype.setLp=function(lp){
|
this.lp=lp;
|
};
|
|
Title.prototype.getLp=function(){
|
return lp;
|
};
|
|
Title.prototype.getAllTile=function(lname){
|
//alert(this.avg);
|
var title="";
|
var maxText='最大值'; //最大值
|
var minText='最小值'; //最小值
|
var avgText='平均值'; //平均值
|
var lowText='落后值'; //落后值
|
var lcText='落后数量'; //落后数量
|
var lpText='落后数量比'; //落后数量比
|
if("Voltage"==lname){
|
//title=maxText+"="+(parseFloat(this.max).toFixed(3))+"V;"+minText+"="+(parseFloat(this.min).toFixed(3))+"V;"+avgText+"="+(parseFloat(this.avg).toFixed(3))+"V;"+lowText+"="+this.alow+"V;"+lcText+"="+this.lc+";"+lpText+"="+this.lp+"%";
|
title=maxText+"="+(parseFloat(this.max).toFixed(3))+"V;"+minText+"="+(parseFloat(this.min).toFixed(3))+"V;"+avgText+"="+(parseFloat(this.avg).toFixed(3))+"V;累加和="+(parseFloat(this.sum).toFixed(3))+"V";
|
}else if("Resistance"==lname){
|
//title=maxText+"="+(parseFloat(this.max).toFixed(3))+"mΩ;"+minText+"="+(parseFloat(this.min).toFixed(3))+"mΩ;"+avgText+"="+(parseFloat(this.avg).toFixed(3))+"mΩ;"+lowText+"="+this.alow+"mΩ;"+lcText+"="+this.lc+";"+lpText+"="+this.lp+"%";
|
title=maxText+"="+(parseFloat(this.max).toFixed(3))+"mΩ;"+minText+"="+(parseFloat(this.min).toFixed(3))+"mΩ;"+avgText+"="+(parseFloat(this.avg).toFixed(3))+"mΩ";
|
}else if("Temperature"==lname){
|
//title=maxText+"="+(parseFloat(this.max).toFixed(1))+"℃;"+minText+"="+(parseFloat(this.min).toFixed(1))+"℃;"+avgText+"="+(parseFloat(this.avg).toFixed(1))+"℃;"+lowText+"="+this.alow+"℃;"+lcText+"="+this.lc+";"+lpText+"="+this.lp+"%";
|
title=maxText+"="+(parseFloat(this.max).toFixed(1))+"℃;"+minText+"="+(parseFloat(this.min).toFixed(1))+"℃;"+avgText+"="+(parseFloat(this.avg).toFixed(1))+"℃";
|
}else if("Conductance"==lname){
|
//title=maxText+"="+(parseFloat(this.max).toFixed(0))+";"+minText+"="+(parseFloat(this.min).toFixed(0))+";"+avgText+"="+(parseFloat(this.avg).toFixed(0))+";"+lowText+"="+this.alow+";"+lcText+"="+this.lc+";"+lpText+"="+this.lp+"%";
|
title=maxText+"="+(parseFloat(this.max).toFixed(0))+";"+minText+"="+(parseFloat(this.min).toFixed(0))+";"+avgText+"="+(parseFloat(this.avg).toFixed(0));
|
}else if("MonJHCurr"==lname){
|
//title=maxText+"="+(parseFloat(this.max).toFixed(3))+"V;"+minText+"="+(parseFloat(this.min).toFixed(3))+"V;"+avgText+"="+(parseFloat(this.avg).toFixed(3))+"V;"+lowText+"="+this.alow+"V;"+lcText+"="+this.lc+";"+lpText+"="+this.lp+"%";
|
title=maxText+"="+(parseFloat(this.max).toFixed(3))+"mA;"+minText+"="+(parseFloat(this.min).toFixed(3))+"mA;"+avgText+"="+(parseFloat(this.avg).toFixed(3))+"mA";
|
}else if("Serpercent"==lname || "Percent_total_capacity" == lname){
|
//title=maxText+"="+this.max+"%;"+minText+"="+this.min+"%;"+avgText+"="+this.avg+"%;"+lowText+"="+this.alow+"%;"+lcText+"="+this.lc+";"+lpText+"="+this.lp+"%";
|
title=maxText+"="+this.max+"%;"+minText+"="+this.min+"%;"+avgText+"="+this.avg+"%";
|
}else if("Actual_capacity"==lname || "Residual_capacity" == lname){
|
//title=maxText+"="+(parseFloat(this.max).toFixed(0))+"AH;"+minText+"="+(parseFloat(this.min).toFixed(0))+"AH;"+avgText+"="+(parseFloat(this.avg).toFixed(0))+"AH;"+lowText+"="+this.alow+"AH;"+lcText+"="+this.lc+";"+lpText+"="+this.lp+"%";
|
title=maxText+"="+(parseFloat(this.max).toFixed(0))+"AH;"+minText+"="+(parseFloat(this.min).toFixed(0))+"AH;"+avgText+"="+(parseFloat(this.avg).toFixed(0))+"AH";
|
}
|
return title;
|
};
|
|
// 根据设备的id获取设备的基本信息
|
function getDevBaseInfo(dev_id) {
|
var result = {
|
name: '未知',
|
key: '未知',
|
reg: '',
|
workstates: [],
|
stopreasons: [],
|
alarmstates: [],
|
};
|
// 遍历DEVICEINFO
|
for(var i=0; i<DEVICEINFO.length; i++) {
|
var data = DEVICEINFO[i];
|
if(regEquipType(dev_id, data.reg)) {
|
result = data;
|
}
|
}
|
return result;
|
}
|
|
// 验证设备类型
|
function regEquipType(eId, pattern) {
|
if(pattern.test(eId)) {
|
return true;
|
}
|
return false;
|
}
|
|
function getBattstate(state){
|
var str="";
|
switch(state){
|
case 1:str = battstate[1];break;
|
case 2:str = battstate[2];break;
|
case 3:str = battstate[3];break;
|
case 4:str = battstate[4];break;
|
default:str = battstate[0];
|
}
|
return str;
|
}
|