// myTbl插件
|
// 定义容器中表格
|
;(function($, window, document, undefined) {
|
/**
|
* @description 表格插件的定义
|
* @param jquery ele jquery选择器选中元素
|
* @param object options 插件的配置项
|
*/
|
var MyTbl = function(ele, options) {
|
this.ele = ele.eq(0);
|
this.opts = options;
|
this.init();
|
};
|
|
MyTbl.prototype = {
|
init: function() {
|
this.regData(); // 验证数据格式
|
this.ele.find('.no-data').remove(); // 清除无数据图标
|
this.ele.addClass('tbl-container');
|
this.ele.find('.tbl-body').fullContainer();
|
},
|
create: function() {
|
var opts = this.formatOpts();
|
|
// 根据数据生成表格元素
|
var table = $('<table></table>');
|
var thead = $('<thead></thead>');
|
var tr = $('<tr></tr>');
|
|
for(var i=0; i<opts.thead.length; i++) {
|
var td = $('<td>'+opts.thead[i]+'</td>');
|
tr.append(td);
|
}
|
|
thead.append(tr);
|
table.append(thead);
|
|
var tbody = $('<tbody></tbody>');
|
for(var i=0; i<opts.tbody.length; i++) {
|
var tr = $('<tr></tr>');
|
for(var k=0; k<opts.tbody[i].length; k++) {
|
var td = $('<td>'+opts.tbody[i][k]+'</td>');
|
tr.append(td);
|
}
|
tr.data().attr = opts.attr[i];
|
|
// 是否全部选中
|
if(opts.isAllActive) {
|
tr.addClass('active');
|
}
|
|
tbody.append(tr);
|
}
|
|
table.append(tbody);
|
|
this.ele.find('.tbl-body').text("");
|
|
this.ele.find('.tbl-body').append(table);
|
this.ele.find('.tbl-header').html(this.ele.find('.tbl-body').html());
|
if(this.opts.tbody.length == 0 && this.opts.noData) {
|
this.ele.append(this.noData());
|
}
|
|
this.resize();
|
var scrollLeft = this.ele.find('.tbl-body').scrollLeft();
|
this.ele.find('.tbl-body').siblings('.tbl-header').find('table').css('left', -scrollLeft+'px');
|
|
this.ele.find('.tbl-body').scroll(function() {
|
var scrollLeft = $(this).scrollLeft();
|
$(this).siblings('.tbl-header').find('table').css('left', -scrollLeft+'px');
|
});
|
},
|
|
// 添加一行数据
|
add: function() {
|
var isOne = true;
|
|
// 判断为二维数组
|
if(typeof this.opts.add[0] == 'object') {
|
isOne = false;
|
}
|
|
// 根据isOne的值执行
|
if(isOne) {
|
this.opts.tbody.push(this.opts.add);
|
this.opts.add = [];
|
}else {
|
for(var i=0; i<this.opts.add.length; i++) {
|
this.opts.tbody.push(this.opts.add[i]);
|
}
|
}
|
|
|
this.create();
|
},
|
// 格式化数据
|
formatOpts: function() {
|
// 将配置项的数据存储到当前元素的
|
var opts = $.extend(true, {}, this.opts);
|
|
// 计算表格的行数
|
opts.rows = opts.tbody.length;
|
|
// 根据表格行数向attr中添加默认对象
|
for(var i=0; i<opts.rows; i++) {
|
var tmp = {
|
lists: i
|
};
|
if(typeof opts.attr[i] != 'object') {
|
opts.attr[i] = $.extend(true, {}, tmp);
|
}else {
|
opts.attr[i] = $.extend(true, {}, opts.attr[i],tmp);
|
}
|
|
}
|
|
this.ele.data().options = opts;
|
|
var rsData = this.getRsData();
|
var rs = $.extend({}, opts, rsData);
|
return rs;
|
},
|
noData: function() {
|
var noData = $('<div class="no-data not-select"><img src="pages/images/nodata.png"></div>');
|
return noData;
|
},
|
resize: function() {
|
var tblWidth = this.ele.find('.tbl-body table').width();
|
this.ele.find('.tbl-header').children('table').width(tblWidth);
|
var tbl = this;
|
},
|
regData: function() { // 格式化表格的状态数组
|
var opts = this.opts;
|
var thead = opts.thead;
|
var status = opts.status;
|
// 遍历thead数据对status的数据进行校验和补齐
|
for(var i=0;i<this.opts.thead.length; i++) {
|
// status[i]没有被定义就用1补齐
|
if(status[i] == undefined) {
|
status[i] = 1;
|
}else {
|
// status[i]的值不是0或1就用1替换
|
if(status[i] != 0 && status[i] != 1) {
|
status[i] = 1;
|
}
|
}
|
}
|
},
|
getRsData:function() { // 根据状态数组修改并返回最终的数据
|
var rs = {
|
thead:[],
|
tbody:[],
|
};
|
|
var opts = this.opts;
|
var thead = opts.thead;
|
var tbody = opts.tbody;
|
var status = opts.status;
|
//console.info(status);
|
// 遍历status的值获取最终的thead数据
|
for(var i=0; i<status.length; i++) {
|
if(status[i] == 1) {
|
// 设置头部数据
|
rs.thead.push(thead[i]);
|
}
|
}
|
|
// 遍历tbody的值根据status值生成最终的tbody
|
for(var i=0; i<tbody.length; i++) {
|
var tmp = [];
|
for(var k=0; k<tbody[i].length; k++) {
|
if(status[k] == 1) {
|
tmp.push(tbody[i][k]);
|
}
|
}
|
rs.tbody.push(tmp);
|
}
|
//console.info(rs);
|
return rs;
|
}
|
};
|
|
// 向jquery中添加表格插件
|
$.fn.myTbl = function(options) {
|
var defaults = {
|
thead: [],
|
tbody: [],
|
attr:[],
|
rows:0,
|
status: [],
|
noData: false,
|
isAllActive: false,
|
event: 'create'
|
};
|
options.ele = this;
|
|
|
// 判断当前传递参数的类型
|
if(options !=undefined ) {
|
if(typeof options == 'string' || options.constructor.name == "Array") {
|
console.log('error options typeof!!!');
|
return this;
|
}
|
}
|
|
var opts = $.extend(true, {}, defaults, options || {});
|
var tbl = new MyTbl(this, opts);
|
|
if(tbl[opts.event]) {
|
tbl[opts.event]();
|
}else {
|
console.log('no '+opts.event+' event');
|
}
|
|
return this;
|
}
|
})(jQuery, window, document);
|
|
//当前容器充满父容器
|
;(function($, window, document) {
|
$.mainChild = [];
|
$.fn.fullContainer = function() {
|
var container = this.parent(); // 父节点
|
var siblings = this.siblings(); // 兄弟节点
|
var cHt = container.height(); // 父节点的高度
|
var sHt = 0; // 兄弟节点的高度总和
|
siblings.each(function(i) {
|
if(!$(this).hasClass('not-select')) {
|
sHt += $(this).outerHeight(true);
|
}
|
});
|
this.height(cHt-sHt);
|
this.addClass('main-child');
|
if(container.hasClass('tbl-container')) {
|
var tblWidth = container.children('.tbl-body').children('table').width();
|
container.children('.tbl-header').children('table').width(tblWidth);
|
}
|
|
// 没有参数传进来就将当前元素添加到$.mainChild中
|
if(arguments.length == 0) {
|
$.mainChild.push(this);
|
}
|
|
return this;
|
};
|
$.resizeMainChild = function() {
|
for(var i=0;i<$.mainChild.length; i++) {
|
$.mainChild[i].fullContainer('resize'); // 不触发插入mainChild的操作
|
}
|
}
|
|
|
// window的窗口大小改变就触发插件fullContainer
|
$(window).resize(function() {
|
$.resizeMainChild();
|
|
setTimeout(function() {
|
$.resizeMainChild();
|
}, 100);
|
});
|
})(jQuery, window, document, undefined);
|
|
// 带表格的页面
|
;(function($, window, document, gl) {
|
gl.namespace('tblPage')
|
//页面表格的配置项
|
var tblOpts = {
|
thead:[], // 表格头部信息
|
tbody:[], // 表格
|
attr: [], // 表格行重要的信息
|
add: [], // 是否添加
|
status:[] // 表格列显示状态
|
};
|
|
gl.tblPage.tblOpts = tblOpts;
|
})(jQuery, window, document, GLOBAL, undefined);
|
|
//存储不同设备的状态信息
|
;(function($, window, document, gl, undefined) {
|
// 61850设备
|
gl.namespace('DEV61850');
|
|
gl.DEV61850.workstates = ["在线浮充","预充电","核容测试","停电放电","内阻测试","K1/D1测试"]; // 设备工作状态
|
gl.DEV61850.alarmstates = ["继电器K1告警","通讯告警","设备过温告警","二极管D1告警"]; // 告警状态
|
gl.DEV61850.stopreasons = [
|
'设备掉电','手动终止', '放电时间到', '放电容量到', '单体电压下限到', '单体温度上限到', '组端电压下限到',
|
'市电中断', '单体模块通信异常', '存储数据满', '机内温度异常', '放电电流异常', '后台通信中断', '内部程序异常',
|
'电源电压高','协议转通信异常','其他'
|
]; // 核容停止原因
|
|
// BTS设备
|
gl.namespace('BTS9100');
|
gl.BTS9100.workstates = ['在线监测','放电测试','充电测试','内阻测试','未知']; // 设备工作状态
|
gl.BTS9100.alarmstates = [
|
'无','暂停','放电测试','放电等待','限流充电','直流充电','充电等待','测试时间到',
|
'测试容量到','单体下限到','组端下限到','市电异常','存储卡不足','负载温度高','电流异常','远程通信坏',
|
'负载通信坏','选择通信坏','负载电流坏','内存申请坏','未知'
|
];
|
|
// LD9设备
|
gl.namespace('LD9');
|
gl.LD9.workstates = ['在线监测','核容测试','测试状态状态暂停','单节测试']; // 设备工作状态
|
gl.LD9.stopreasons = ['无','手动停止','单体下限到','充电完成停止','测试完成停止','远程停止','在线电压低'];
|
|
// 4016设备
|
gl.namespace('LD6');
|
gl.LD6.workstates = ['充电测试', '放电测试']; // 设备工作状态
|
gl.LD6.stopreasons = ['无','手动停止','核容测试时间到','核容测试组端下限到','核容测试单体下限到','核容测试容量低于阀值','应急供电组端下限到'
|
, '应急供电单体下限到', '市电恢复停止应急供电', '停止自动应急供电', '无法启动核容测试', '模块故障', '电池开路故障'];
|
})(jQuery, window, document, GLOBAL);
|
|
// 基站信息
|
;(function($, window, document, gl, undefined) {
|
// 基站异常类型
|
gl.namespace('BaseStation.Abnormal');
|
//1:基站停电 2:基站续航 3:基站发电 4:基站开门 5:基站掉站 6:基站温度上限 7:基站温度下限 8:基站湿度上限 9:基站湿度下限
|
var abnormal = ['全部(异常)', '基站停电', '基站续航', '基站发电', '基站开门', '基站掉站', '基站温度上限', '基站温度下限', '基站湿度上限', '基站湿度下限'];
|
gl.BaseStation.Abnormal = abnormal;
|
|
|
// 根据下标获取基站异常类型的文本值
|
function getAbnormalTxt(num) {
|
var rs = abnormal[num];
|
if(rs == undefined) {
|
alert('基站异常类型'+num+'不存在');
|
rs = abnormal[0];
|
}
|
return rs;
|
}
|
// 将函数绑定到GLOBAL.BaseStation
|
gl.BaseStation.getAbnormalTxt = getAbnormalTxt;
|
|
|
|
})(jQuery, window, document, GLOBAL);
|
|
//页面中计时器的使用
|
;(function($, gl) {
|
gl.namespace('Timer');
|
var timerList = [];
|
|
|
// 定义计时器类
|
var Timer = function(opts) {
|
this.timer = '';
|
this.opts = {};
|
this._setOpts(opts);
|
timerList.push(this);
|
};
|
|
var _prop = Timer.prototype;
|
|
_prop._setOpts = function(opts) {
|
var defaults = {
|
fun: '',
|
params: [],
|
times: 1000
|
};
|
|
this.opts = $.extend({}, defaults, opts);
|
};
|
|
// 启动计时器
|
_prop.start = function() {
|
var opts = this.opts;
|
this.stop();
|
|
opts.fun.apply({}, opts.params);
|
this.timer = setInterval(function() {
|
opts.fun.apply({}, opts.params);
|
}, opts.times);
|
};
|
|
// 停止计时器
|
_prop.stop = function() {
|
clearInterval(this.timer);
|
};
|
|
// 停止所有通过Timer类声明的计时器
|
function stop() {
|
for(var i=0; i<timerList.length; i++) {
|
timerList[i].stop();
|
}
|
}
|
|
// 启动所有通过Timer类声明的计时器
|
function start() {
|
for(var i=0; i<timerList.length; i++) {
|
timerList[i].start();
|
}
|
}
|
|
// 启动/关闭所有所有通过Timer类声明的计时器
|
gl.Timer.startAll = start;
|
gl.Timer.stopAll = stop;
|
// 将计数器添加到全局中
|
gl.Timer.timer = Timer;
|
})(jQuery, GLOBAL);
|
|
//定义设备类型
|
;(function($, window, document, gl, undefined) {
|
// 定义设备类型equipType命名空间
|
gl.namespace('equipType');
|
|
var type = {
|
LD9: /^40190/,
|
equip61850: /^61850/,
|
BTS:/^(9100)|(9600)|(9616)/,
|
BTSSreen: /^9611/,
|
equip4016:/^4016/
|
};
|
|
// 绑定到命名空间equipType中
|
gl.equipType.type = type;
|
|
// 验证类型
|
function regType(id, pattern) {
|
var rs = true;
|
rs = pattern.test(id);
|
return rs;
|
}
|
|
// 绑定到命名空间equipType中
|
gl.equipType.regType = regType;
|
})(jQuery, window, document, GLOBAL);
|
|
//设置充放电参数的名称
|
;(function($, window, document, gl, undefined) {
|
// CMD的命名空间
|
gl.namespace('CMD');
|
|
// CMD下BTS的命名空间
|
gl.namespace('CMD.BTS');
|
gl.CMD.BTS.startDischarge = 37; //容量测试
|
gl.CMD.BTS.startRESTest = 50; //内阻测试
|
gl.CMD.BTS.getDischargeParm = 41; //获取放电参数
|
gl.CMD.BTS.setDischargeParm = 40; //设置放电参数
|
gl.CMD.BTS.start = 81; //启动测试
|
gl.CMD.BTS.stop = 83; //停止测试
|
|
// CMD下的61850命名空间
|
gl.namespace('CMD.e61850');
|
gl.CMD.e61850.startDischarge = 37; //启动核容测试
|
gl.CMD.e61850.startRESTest = 50; //启动内阻测试
|
|
gl.CMD.e61850.start = 81; //启动测试
|
gl.CMD.e61850.stop = 83; //停止测试
|
gl.CMD.e61850.setDischargeParm = 40; //设置参数
|
gl.CMD.e61850.getDischargeParm = 41; //获取参数
|
})(jQuery, window, document, GLOBAL);
|
|
// 地图信息
|
;(function($, window, document, gl, undefined) {
|
// 定义BMap的命名空间
|
gl.namespace('BMap');
|
// 地图可视区域定义
|
var mapViewArea = [
|
{name: '中国',area:'中国', left: {lng:71.3822, lat:0.6212}, right: {lng: 139.526,lat:54.3093}},
|
{name: '中国-广西',area: '广西省' ,left: {lng:104.45675, lat:20.8744}, right: {lng: 112.068,lat:26.391}}
|
];
|
|
// 将变量mapView绑定到GLOBAL.BMap下
|
gl.BMap.mapViewArea = mapViewArea;
|
|
})(jQuery, window, document, GLOBAL);
|
|
|
// 生成阿里图标的元素
|
function create_ali_font(cla, color, data) {
|
var i = $('<i class="icon iconfont"></i>');
|
i.addClass(cla);
|
i.css({
|
'color': color
|
});
|
Object.keys(data).forEach(function(key) {
|
var attr = 'data-'+key
|
i.attr(attr, data[key]);
|
});
|
// 获取字符串
|
var outerHTML = i[0].outerHTML;
|
return outerHTML;
|
}
|
|
//生成阿里图标的元素
|
function create_fa_font(cla, color, data) {
|
var i = $('<i class="fa"></i>');
|
i.addClass(cla);
|
i.css({
|
'color': color
|
});
|
Object.keys(data).forEach(function(key) {
|
var attr = 'data-'+key
|
i.attr(attr, data[key]);
|
});
|
// 获取字符串
|
var outerHTML = i[0].outerHTML;
|
return outerHTML;
|
}
|
|
// 生成跳转的链接
|
function skipUrl(page, province, city, county, home,battid,monnum) {
|
var str = page+'?';
|
if(province){
|
str += '&province='+province;
|
}
|
if(city){
|
str +='&city='+city;
|
}
|
if(county){
|
str += '&county='+county;
|
}
|
if(home){
|
str += '&home='+home;
|
}
|
if(battid){
|
str += '&battid='+battid;
|
}
|
if(monnum){
|
str += '&monnum'+monnum;
|
}
|
//var str = page+'?province='+province+'&city='+city+'&county='+county+'&home='+home;
|
return str;
|
}
|
|
// 检测用户是否有权限
|
function checkUserPermit(permits, name) {
|
var rs = false;
|
// 遍历permits
|
for(var i=0; i<permits.length; i++) {
|
var _permit = permits[i];
|
if(_permit.permit_item_name == name && _permit.permit_item_value==1) {
|
rs = true;
|
break;
|
}
|
}
|
return rs;
|
}
|