"use strict"; // 获取页面的根目录并返回 function getPageRoot(module, parent) { var rs = "#" + module.id + ' .bui-page'; if (parent) { rs = $(rs).parent().get(0); } return rs; } /*从多维数组中获取最大值*/ 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 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; }; //将秒转化成时:分:秒 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 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 HandleData() {}; // 对新旧数据进行对比处理 HandleData.prototype.handle = function (oldData, newData, keys) { // 剔除旧数据 this.del(oldData, newData, keys); // 添加新数据 this.add(oldData, newData, keys); }; // 添加新数据 HandleData.prototype.add = function (oldData, newData, keys) { // 遍历新数据 for (var i = 0; i < newData.length; i++) { var _newData = newData[i]; var isExist = this.checkObjIsExist(_newData, oldData, keys); if (isExist.code == 0) { oldData.push(_newData); } } }; // 提出旧数据 HandleData.prototype.del = function (oldData, newData, keys) { // 遍历旧数据 for (var i = 0; i < oldData.length; i++) { var _oldData = oldData[i]; var isExist = this.checkObjIsExist(_oldData, newData, keys); if (isExist.code == 0) { oldData.splice(i, 1); i--; } } }; // 检测对象是否存在于对象数组中 HandleData.prototype.checkObjIsExist = function (obj, objs, keys) { var result = { code: 0, index: -1, data: {} }; // 遍历数组 for (var i = 0; i < objs.length; i++) { var _objs = objs[i]; var equal = true; // 相等 // 遍历keys for (var k = 0; k < keys.length; k++) { var key = keys[k]; if (_objs[key] == undefined || _objs[key] != obj[key]) { equal = false; break; } } // 存在属性值一致的对象 if (equal) { result.code = 1; result.index = i; result.data = _objs; } } return result; }; 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; }; // 电池告警名称 var battAlarmTypes = [{ value: 119001, text: '组端电压告警', unit: "V" }, { value: 119002, text: '电池电流告警', unit: "A" }, { value: 119003, text: '单体电压告警', unit: 'V' }, { value: 119004, text: '单体温度告警', unit: '℃' }, { value: 119005, text: '单体内阻告警', unit: 'mΩ' }]; // 电池告警类型 var almSignalId = [{ value: 0, text: '无告警' }, { value: 1, text: '下限告警' }, { value: 2, text: '上限告警' }]; // 根据value的值获取文本值 function getTextByVal(value, list) { var rs = "未知"; // 遍历list for (var i = 0; i < list.length; i++) { var _list = list[i]; if (_list.value == value) { rs = _list.text; } } return rs; } // 根据value的值获取单位 function getTextByUnit(value, list) { var rs = ""; // 遍历list for (var i = 0; i < list.length; i++) { var _list = list[i]; if (_list.value == value && _list.unit) { rs = _list.unit; } } return rs; }