1
81041
2019-06-20 ab3c4acf83f54f8449ca8664c4a2bb79bd30f297
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
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
// 路由的配置
var routers =  [
    {
        path: '/',
        componentUrl: "./pages/main/index.html"
    },
    {    // 登陆
        path: '/login/',
        componentUrl: "./pages/main/login.html"
    },
    {    // 首页
        path:'/home/',
        componentUrl: "./pages/main/home.html",
    },
    {    // 数据分析
        path: '/data/main/',
        componentUrl: "./pages/main/data.html",
    },
    {    // 数据分析
        path: '/chat/',
        componentUrl: "./pages/main/chat.html",
    },
    {
        path: '/monitor/',
        routes:[
            {    // 数据监控
                path: 'main/',
                componentUrl: "./pages/main/monitor.html",
            },
            {    // 电池组列表
                path: 'batt/:province/:city/:county/:home/:homeid/',
                componentUrl: "./pages/monitor/batt.html"
            },
            {    // 电池组功能
                path: 'index/:province/:city/:county/:home/:fbsid/:stationid/:groupid/:groupname/',
                componentUrl: "./pages/monitor/index.html",
            },
            {    // 实时监测
                path: 'control/:province/:city/:county/:home/:fbsid/:stationid/:groupid/:groupname/',
                componentUrl: "./pages/monitor/control.html"
            },
            {    // 核容参数设置
                path: 'nuclear/param/set/:home/:fbsid/:stationid/:groupid/',
                componentUrl: './pages/monitor/nuclear-param-set.html'
            },
            {    // 电池参数设置
                path: 'batt/param/set/:home/:fbsid/:stationid/:groupid/',
                componentUrl: './pages/monitor/batt-param-set.html'
            },
            {    // 系统参数设置
                path: 'sys/param/set/:home/:fbsid/:stationid/:groupid/',
                componentUrl: './pages/monitor/sys-param-set.html'
            },
            {    // 电池参数
                path: 'batt/param/:fbsid/:stationid/',
                componentUrl: './pages/monitor/batt-param.html'
            },
            {    // 系统参数
                path: 'sys/param/:fbsid/:stationid/',
                componentUrl: './pages/monitor/sys-param.html'
            },
            {
                // 单体电压
                path: 'batt/mon/vol/:province/:city/:county/:home/:fbsid/:stationid/:groupid/:groupname/:pagename/',
                componentUrl: './pages/monitor/batt-mon-vol.html'
            },
            {
                // 单体温度
                path: 'batt/mon/tmp/:province/:city/:county/:home/:fbsid/:stationid/:groupid/:groupname/:pagename/',
                componentUrl: './pages/monitor/batt-mon-tmp.html'
            },
            {
                // 单体内阻
                path: 'batt/mon/res/:province/:city/:county/:home/:fbsid/:stationid/:groupid/:groupname/:pagename/',
                componentUrl: './pages/monitor/batt-mon-res.html'
            },
            {
                // 单体电导
                path: 'batt/mon/cond/:province/:city/:county/:home/:fbsid/:stationid/:groupid/:groupname/:pagename/',
                componentUrl: './pages/monitor/batt-mon-cond.html'
            },
            {    // 历史监测
                path: 'history/:province/:city/:county/:home/:fbsid/:stationid/:groupid/:groupname/',
                componentUrl: "./pages/monitor/history.html"
            },
            {    // 历史放电测试数据
                path: 'history/data/:groupid/:groupname/:count/:capstd/:volstd/',
                componentUrl: "./pages/monitor/history-data.html",
                tabs:[
                    {
                        path: '/',
                        id: 'monVol'
                    },
                    {
                        path: '/common-bar/',
                        id: 'commonBar'
                    },
                    
                    {
                        path: '/common-line/',
                        id: 'commonLine'
                    }
                ]
            },
            {    // 电池信息
                path: 'batt/group/info/:groupid/',
                componentUrl: './pages/monitor/batt-group-info.html'
            },
            {
                // 添加机房
                path: 'add/home/:battnum/',
                componentUrl: "./pages/monitor/add-home.html"
            },
            {    // 基站信息
                path: 'home/:stationid/'
            }
        ]
    },
    {
        path: '/data/:province/:city/:county/:home/:fbsid/:stationid/',
        componentUrl: './pages/data/index.html',
        routes: [
            {    // 电池信息统计查询
                path: 'batt-info/',
                componentUrl: './pages/data/batt-info.html'
            },
            {    // 电池组信息统计查询
                path: 'group-info/',
                componentUrl: './pages/data/group-info.html'
            },
            {    // 电池单体统计分析查询
                path: 'mon-info/',
                componentUrl: './pages/data/batt-mon-info.html'
            },
        ]
    },
    {    // 基站信息(style标记的是页面返回类型back或者popup-close)
        path: '/data/home/info/:stationid/:style',
        componentUrl: "./pages/data/home-info.html"
    },
    {
        path: '/warn/:province/:city/:county/:home/:fbsid/:stationid/',
        componentUrl: './pages/warn/index.html',
        routes: [
            {
                path: 'control/',
                componentUrl: './pages/warn/control.html'
            }
        ]
    },
    {
        path: '/panel/left/',
        componentUrl: "./pages/panel/panel-left-page.html"
    },
    {
        path: '/panel/right/',
        componentUrl: "./pages/panel/panel-right-page.html"
    },
    {
        path:'/data/popup/',
        popup: {
            id: 'popupData',
        }
    },
    {
        path: '(.*)',
        url: './pages/404.html',
    },
];
 
var monthNames = monthNamesShort = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月' , '9月' , '10月', '11月', '12月'];
var dayNames = dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
 
// 定义Dom7
var $$ = Dom7;
 
// 根据id和数据获取模板生成的html
function getTplHtml(id, data) {
    var tpl = $$(id).html();
    var compiledTpl = Template7.compile(tpl);
    var tplHtml = compiledTpl(data);
    return tplHtml;
}
 
// 根据数据生成列表
function createList(container, data) {
    container.text("");
    for(var i=0; i<data.length;i++) {
        var _data = data[i];
        var li = $$('<li></li>');
        var a = $$('<a href="#" class="home-item"></a>');
        a.text(_data.text);
        a.data('data', _data);
        li.append(a);
        container.append(li);
    }
}
 
// 在tab中view检测是否被显示
function viewCheckStatus(view) {
    var status = false;
    if($$(view).hasClass("tab-active")) {
        status = true;
    }
    return status;    
}
 
//开启页面是否在运行
function setIsRun(page, id) {
    page.isRun = viewCheckStatus(id);
        // 定义计时器查看当前page所在的view是否显示
    var interval = setInterval(function(){
        page.isRun = viewCheckStatus(id);
    }, 100);
}
 
function PieEcharts(id) {
    this.$el = $("#"+id);
    this.chart="";
    this._init();
};
PieEcharts.prototype._init = function() {
    var graph = this.$el.find('.graph').get(0);
    this.chart = echarts.init(graph);
    this.chart.showLoading();
};
PieEcharts.prototype.resize = function() {
    this.chart.resize();
};
PieEcharts.prototype.setOption = function(props) {
    var defaultPorps = {
        title: "",
        subtitle: "",
        x: "center",
        name: "未知",
        legendData: [],
        seriesData: [],
        color:[]
    };
    
    var data = $.extend({}, defaultPorps, props);
    
    this.chart.hideLoading();    // 关闭等待框
    
    var option = {
        // #008000(绿色), #FF0000(红色),#FFFF00(黄色),#FFC0CB(紫色)
        color: function() {
            var color = ['#c23531','#2f4554', '#61a0a8', '#d48265', '#91c7ae','#749f83',  '#ca8622', '#bda29a','#6e7074', '#546570', '#c4ccd3'];
            for(var i = data.color.length; i>0; i--) {
                var _color = data.color[i-1];
                color.unshift(_color);
            }
            return color;
        }(),
        title : {
            text: data.title,
            subtext: data.subtitle,
            x: data.x
        },
        toolbox: {
            show: true,
            feature : {
                mark : {show: true},
                dataView : {show: true, readOnly: true},
                magicType : {
                    show: true,
                    type: ['pie', 'funnel']
                }
            }
        },
        tooltip : {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
            orient: 'vertical',
            right: 10,
            top: 20,
            bottom: 20,
            //data: data.legendData,
        },
        series : [
            {
                name: data.name,
                type: 'pie',
                radius : '55%',
                center: ['50%', '50%'],
                data: data.seriesData,
                itemStyle: {
                    emphasis: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };
    
    // 生成echarts
    this.chart.setOption(option);
};
 
function BarEcharts(id) {
    this.$el = $("#"+id);
    this.chart="";
    this.props = "";
    this._init();
};
BarEcharts.prototype._init = function() {
    var graph = this.$el.find('.graph').get(0);
    this.chart = echarts.init(graph);
    this.chart.showLoading();
};
BarEcharts.prototype.resize = function() {
    this.chart.resize();
    this.setOption(this.props);
};
BarEcharts.prototype.setOption = function(props) {
    var defaultPorps = {
        title: "",
        subtitle: "",
        x: "center",
        name: "未知",
        legendData: [],
        seriesData: [],
        yData: [],
        color:[]
    };
    
    var data = $.extend({}, defaultPorps, props);
    this.chart.hideLoading();    // 关闭等待框
    this.props = data;
    
    var max = Math.max.apply(null, props.seriesData);
    var min = Math.min.apply(null, props.seriesData);
    var maxflag = true;
    var minflag = true;
    var option = {
        // #008000(绿色), #FF0000(红色),#FFFF00(黄色),#FFC0CB(紫色)
        color: function() {
            var color = ['#c23531','#2f4554', '#61a0a8', '#d48265', '#91c7ae','#749f83',  '#ca8622', '#bda29a','#6e7074', '#546570', '#c4ccd3'];
            for(var i = data.color.length; i>0; i--) {
                var _color = data.color[i-1];
                color.unshift(_color);
            }
            return color;
        }(),
        title : {
            text: data.title,
            subtext: data.subtitle,
            x: data.x
        },
        tooltip : {
             trigger: 'axis',
             axisPointer: {
                 type: 'shadow'
             }
        },
        legend: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: {
            type: 'value',
            max: (max*1.05).toFixed(2),
            min: (min*0.8).toFixed(2),
            boundaryGap: [0, 0.01]
        },
        yAxis: {
            type: 'category',
            inverse: true,
            data: data.yData
        },
        series : [
            {
                name: data.name,
                type: 'bar',
                data: data.seriesData,
                itemStyle: {
                    normal:  {
                        label:{
                            show: false, 
                            position: 'top',
                            fontSize:11
                        },
                        color: function setcolor(value) {
                            if(maxflag==true && value.value==max)
                            {                            
                                maxflag=false;
                                return 'green';
                            }
                            else if(minflag==true && value.value==min)
                            {
                                minflag=false;
                                return 'red';
                            }else
                            {  
                                return '#b4d3fa';                //设置为普通的颜色
                            }    
                        }
                    }
                    
                }
            }
        ]
    };
    this.chart.resize();
    // 生成echarts
    this.chart.setOption(option);
};
 
// 折线图
function LineEcharts(id) {
    this.$el = $("#"+id);
    this.chart="";
    this.props = "";
    this._init();
};
LineEcharts.prototype._init = function() {
    var graph = this.$el.find('.graph').get(0);
    this.chart = echarts.init(graph);
    this.chart.showLoading();
};
LineEcharts.prototype.resize = function() {
    this.chart.resize();
    this.setOption(this.props);
};
LineEcharts.prototype.setOption = function(props, container) {
    // 默认配置项
    var defaultPorps = {
        title: "",
        subtitle: "",
        x: "center",
        name: [],
        legendData: [],
        seriesData: [],
        xData: [],
        color:[]
    };
    
    var data = $.extend({}, defaultPorps, props);
    this.props = data;
    //console.log(data);
    var max = getMaxFromArr(data.seriesData);
    var min = getMinFromArr(data.seriesData);
    
    var option = {
        // #008000(绿色), #FF0000(红色),#FFFF00(黄色),#FFC0CB(紫色)
        color: function() {
            var color = ['#c23531','#2f4554', '#61a0a8', '#d48265', '#91c7ae','#749f83',  '#ca8622', '#bda29a','#6e7074', '#546570', '#c4ccd3'];
            for(var i = data.color.length; i>0; i--) {
                var _color = data.color[i-1];
                color.unshift(_color);
            }
            return color;
        }(),
        tooltip:{
            trigger: 'axis'
        },
        title : {
            text: data.title,
            subtext: data.subtitle,
            x: data.x
        },
        calculable :true,
        grid: {
            left: '1%',
            right: '5%',
            bottom: '2%',
            containLabel: true
        },
        xAxis: {
            data: data.xData
        },
        yAxis: [{
            type: 'value',
            min: Math.floor(min-1),
            max: Math.ceil(max+1),
            precision:2,
            axisLabel:{
                formatter:function(value){
                    //解决原点处带符号问题
                    if(value==0)
                    {
                        return value;
                    }else{
                        return value ;
                    }
                }
            }
        }],
        series: function() {
            var series = [];
            for(var i=0; i<data.name.length; i++) {
                var _name = data.name[i];
                var _data = data.seriesData[i];
                var tmp = {
                    name: _name,
                    type: 'line',
                    symbol:'none',
                    data: _data,
                    itemStyle:{
                        normal:{
                            lineStyle:{
                                width:2
                            }
                        }
                    }
                };
                series.push(tmp);
            }
            return series;
        }()
    };
    //console.log(option);
    this.chart.hideLoading();    // 关闭等待框
    this.chart.resize();
    // 生成echarts
    this.chart.setOption(option);
};
 
// 生成特殊的折线图
function LineEcharts2(id, container) {
    this.$el = $("#"+id);
    this.$cont = '';
    this.chart="";
    this.props = "";
    // 设置外层容器
    if(container) {
        this.$cont = $('#'+container);
        this.$el.height(this.$cont.height());
    }
    this._init();
};
LineEcharts2.prototype._init = function() {
    var graph = this.$el.find('.graph').get(0);
    this.chart = echarts.init(graph);
    this.chart.showLoading();
};
LineEcharts2.prototype.resize = function() {
    this.chart.resize();
    this.setOption(this.props);
};
LineEcharts2.prototype.setOption = function(props, container) {
    // 默认配置项
    var defaultPorps = {
        title: "",
        subtitle: "",
        x: "center",
        name: [],
        legendData: [],
        seriesData: [],
        xData: [],
        lname: [],
        color:[]
    };
    
    var data = $.extend({}, defaultPorps, props);
    this.props = data;
    // 声明临时变量
    var sdata = data.seriesData;
    var xdata = data.xData;
    var lname = data.lname;
    var battname = data.name;
    
    // echarts配置项
    var option={
        tooltip:{
            show:true,
            trigger:'axis',
            formatter:function(params){
                //console.info(params);
                var str = '';
                for(var i=0;i<params.length;i++){
                    str+=params[i].seriesName+'</br>';
                    str+=params[i].marker+params[i].seriesId+':'+params[i].data[0]+','+params[i].data[1]+'AH</br>';
                }
                return str;        
            }
        },
        title : {   
            //text: tname,
            x: "center", //标题水平方向位置
            textStyle: {  
                fontSize:13  
            }
        },
        toolbox:{
            show : true
        },
        calculable : true,
        xAxis:{
            data:xdata
        },
        grid: {
            top:'10%',
            left: '1%',
            right: '5%',
            bottom: '2%',
            containLabel: true
        },
        yAxis:[{
            name:"y(AH)",
            type:'value',
            min:function(){
                var min = Number.POSITIVE_INFINITY;        //正无穷大的数
                var arr = new Array();
                if(sdata.length>0){
                    for(var i=0;i<sdata.length;i++){
                        for(var j=0;j<sdata[i].length;j++){
                            arr.push(sdata[i][j][1]);
                        }                
                    }
                    min = Math.min.apply(null,arr);
                }
                return (Math.floor(min*0.8));
            }(),
            max:function(){
                var max = Number.NEGATIVE_INFINITY;        //负无穷大的数
                var arr = new Array();
                if(sdata.length>0){
                    for(var i=0;i<sdata.length;i++){
                        for(var j=0;j<sdata[i].length;j++){
                            arr.push(sdata[i][j][1]);
                        }                
                    }                
                    max = Math.max.apply(null,arr);
                }else{
                    max = 1;                
                }
                
                return (Math.ceil(max*1.24));                
            }(),
            axisLabel:{
                formatter:function(value){
                    //解决原点处带符号问题
                    if(value==0)
                    {
                        return value;
                    }else{
                        return value ;
                    }
                }
            }
        }],
        series:function(){
            var serie=[];
            for( var i=0;i<sdata.length;i++){
                var item={
                    type:'line',
                    //symbol:'none',
                    id:lname[i],
                    data:sdata[i],
                    name:battname[i]
                }
                serie.push(item);
            }
            return serie;
        }()
    };
    
    // 设置容器的高度
    if(container) {
        var ht = container.height();
        this.$el.height(ht);
    }
    
    this.chart.hideLoading();    // 关闭等待框
    this.chart.resize();
    // 生成echarts
    this.chart.setOption(option);
}
// 自定义查询后台
function ajaxMain(props) {
    
}
 
// 自定义查询后台
function myAjax(props) {
    // 请求后台
    $.ajax({
        type: "post",
        async: true,
        url: props.url,
        data: "json="+JSON.stringify(props.data),
        dataType: "json",
        beforeSend: function(xhr) {
            if(typeof props.beforeSend == "function") {
                props.beforeSend(xhr);
            }
        },
        success: function(res) {
            var rs = JSON.parse(res.result);
            if(typeof props.success == "function") {
                props.success(rs);
            }
        },
        complete: function() {
            if(typeof props.complete == "function") {
                props.complete();
            }
        }
    });
 
//Cookie
function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=")
        if (c_start!=-1)
        { 
            c_start=c_start + c_name.length+1 
            c_end=document.cookie.indexOf(";",c_start)
            if (c_end==-1) c_end=document.cookie.length
            return unescape(document.cookie.substring(c_start,c_end))
        } 
    }
    return ""
}
 
/**
 * 自定义日期
 * @author hdw
 */
var HdwDate = function() {};
 
/**
 * 设置MyDate的原型函数
 */
HdwDate.prototype = {
    /**
     * 获取输入的年份是闰年还是普通年份
     * @return 返回是否为闰年
     */
    isLeapYear: function(year) {
        var isLeap = false;
        // 输入的年份能够被4整除
        if(year%4==0) {
            // 输入的年份不能被100整除
            if(year%100 != 0) {
                isLeap = true;
            }else if(year%400 == 0){
                isLeap = true;
            }
        }
        
        return isLeap;
    },
    /**
     * 根据字符串yyyy-MM获取当前月有几天
     * @return 返回当前月有多少天
     */
    getMonthDay: function(date) {
        var dates = date.split("-");
        var year = Number(dates[0]);
        var month = Number(dates[1]);
        var day = 30;
        // 判断是否为2月
        switch(month) {
            case 2:
                var isLead = this.isLeapYear(year);
                day = isLead?29:28;
                break;
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                day = 31;
                break;
            default:
                day = 30;
                break;
        }
        return day;
    }
    
};
// 实例化对象
var hdwDate = new HdwDate();
 
// 根据对象获取url
function getUrlStr(props) {
    var str = "";
    Object.keys(props).forEach(function(key) {
        str+=props[key]+"/";
    });
    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 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;
    }
    return result;
}
 
// 定义面包屑导航条的点击事件
function breadItemClick(num) {
    var cView = app.views.current;
    var history = cView.router.history;
    var url = history[num];
    cView.router.back(url, {
        force: true
    });
}
 
// 生成表格内容
function createTblBody(tbody, tds, options) {
    tbody.text("");
    var colors = ['green', 'red'];
    // 设置数据的最值
    var errorVal = -999999;
    var max = errorVal;    // 设置默认最大值
    var min = errorVal;    // 设置默认最小值
    var maxinum = false;            // 设置是否开启最值(不开启)
    // 根据options的值复写最值
    if(options) {
        maxinum = (options.maxinum != undefined)?options.maxinum: false;
        max = (options.max !=undefined)?options.max: errorVal;
        min = (options.min !=undefined)?options.min: errorVal;
        colors = (options.colors != undefined)?options.colors: colors;
    }
    var maxColor = colors[0];
    var minColor = colors[1];
    // 遍历tds的值
    for(var i=0; i<tds.length; i++) {
        var $tr = $("<tr></tr>");
        var td = tds[i];
        for(var k=0; k<td.length; k++) {
            var _td = td[k];
            var $td = $('<td></td>');
            $td.text(_td);
            
            // 判断是否设置最值
            if(maxinum) {
                // 当前数据是否为最大值
                if(_td == max) {
                    $td.addClass('tbl-max-val');
                    $td.css('background-color', maxColor);
                }
                if(_td == min) {
                    $td.addClass('tbl-min-val');
                    $td.css('background-color', minColor);
                }
            }
            
            $tr.append($td);
        }
        tbody.append($tr);
    }
}
 
// 自定义面板
function MyModal(id) {
    this.id = id;
    this.elem = $(id);
    this._init();
}
MyModal.prototype._init = function() {
    var showElems = $('.show-my-modal');
    var self = this;
    var id = this.id;
    // 设置显示按钮
    showElems.each(function() {
        var href = $(this).data('href');
        if(href && href==id) {
            $(this).click(function() {
                self.show();
            });
        }
    });
    
    
    var toggleElems = $('.toggle-my-modal');
    // toggle显示按钮
    toggleElems.each(function() {
        var href = $(this).data('href');
        if(href && href==id) {
            $(this).click(function() {
                self.toggle();
            });
        }
    });
    
    // 设置关闭按钮
    var closeElems = this.elem.find('.my-modal-close');
    closeElems.click(function() {
        self.hide();
    });
    
    
};
MyModal.prototype.show = function() {
    if(!this.elem.hasClass('my-modal-show')) {
        this.elem.addClass('my-modal-show');
        setTimeout(function() {
            // 设置内容的高度
            var container = this.elem.find('.my-modal-container');
            var header = this.elem.find('.my-modal-header');
            var content = this.elem.find('.my-modal-content');
            var footer = this.elem.find('.my-modal-footer');
            
            content.height(container.height()-header.height()-footer.height());
        }.bind(this), 400);
    }
};
MyModal.prototype.hide = function() {
    this.elem.removeClass('my-modal-show');
    var modalContent = this.elem.find('.my-modal-content');
};
MyModal.prototype.toggle = function() {
    if(this.elem.hasClass('my-modal-show')) {
        this.hide();
    }else {
        this.show();
    }
}
 
// 加载popup页面的首屏
function loadPopupByRoute(elem) {
    console.log(elem);
    console.log($(elem));
}
 
//定义计时器
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);
};
 
// 封装toast
function Toast() {
    this.toast = '';
}
// 显示
Toast.prototype.open = function(opts) {
    var defaults = {
        text: '',
    };
    
    var options = $.extend({}, defaults, opts);
    // Create center toast
    this.toast = app.toast.create(options);
    this.toast.open();
};
var toast = new Toast();
 
// 根据验证规则校验对象的属性值
function checkObjIsGood(obj, verify, callback) {
    var result = {
        code: 1,
        name: '',
        msg: '',
        data: obj
    };
    Object.keys(verify).forEach(function(key) {
        // 上一笔数据是否有效
        if(result.code && obj[key] != undefined) {
            var valueStatus = checkValueIsGood(obj[key], verify[key]);
            result.code = valueStatus.code;
            result.name = valueStatus.name;
            result.msg = valueStatus.msg;
        }
    });
    
    // 如果code=1设置msg的值
    if(result.code) {
        result.name = '';
        result.msg = '数据匹配成功';
    }
    
    // 执行callback函数
    if(typeof callback == 'function') {
        callback(result);
    }
}
 
// 检测当前数据是否符合要求
function checkValueIsGood(val, option) {
    var result = {
        code: 0,
        name: option.name,
        msg: option.msg
    };
    // 校验数据是否符合匹配规则
    if(option.pattern.test(val)) {
        // 数据存在取值范围的校验
        if(option.regVal) {
            if(val>=option.min && val<=option.max) {
                result.code =1;
            }
        }else {
            result.code =1;
        }
    }
    // 返回结果集
    return result;
}