1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
// 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 = [
          '无','暂停','放电测试','放电等待','限流充电','直流充电','充电等待','测试时间到',
          '测试容量到','单体下限到','组端下限到','市电异常','存储卡不足','负载温度高','电流异常','远程通信坏',
          '负载通信坏','选择通信坏','载模块放电过功率停止','内部程序异常停止','市电恢复停止升压放电','充电过程中市电中断','合路器放电功能组端电压下限','温度上限到','未知'
    ];
    /*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;                //获取参数
    
    //CMD下sys
    gl.namespace('CMD.sys');
    gl.CMD.sys.restart = 0x10;
    gl.CMD.sys.set = 0x81;
    gl.CMD.sys.get = 0x80;
})(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;
}