common.js
33.5 KB
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
/*
* @Copyright (c) 2018 缪聪(mcg-helper@qq.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//最大可视高度
var screenMaxHeight = $(window).height();
//最大可视宽度
var screenMaxWidth = $(window).width();
//ace编辑器的属性性,目前用于全屏功能记录其改变的高宽值
var acePropertyMap = new Map();
/*
* 消息类,用于前端展示流程日志和通知消息
* */
var Message = function(param){
this.continer = "";
this.msg = param.msg;
}
/* 前端展示日志和通知
* 流程日志输出方法
* 通知展示
* */
Message.prototype.output = function() {
var self = this;
var log = {
"info" : {
html:"暂无内容",
value:"暂无内容",
execute:function(){
this.value = self.msg.body.content;
this.html = self.build();
}
},
"success" : {
html:"暂无内容",
value:"暂无内容",
execute:function(){
this.value = self.msg.body.content;
this.html = self.build();
}
},
"error" : {
html:"暂无内容",
value:"暂无内容",
execute:function(){
this.value = self.msg.body.content;
this.html = self.build();
Messenger().post({
message: "发生异常",
type: "error",
hideAfter: 5,
showCloseButton: true
});
}
}
};
var textEditor = {
"make" : {
"options" : {
},
execute:function(container, param) {
$("#" + container).html('<pre style="background:#fff;border-radius:0px;border:0px solid #ccc;"><code><xmp>' + param + '</xmp></code></pre>');
}
}
};
var linuxEditor = {
"make" : {
"options" : {
},
execute:function(container, param) {
var length = param.split("\n").length;
var screenRows = 25;
if(length < 24) {
screenRows = length + 1;
}
var term = new Terminal({
cols: 120,
rows: screenRows
});
term.open(document.getElementById(container));
term.write(param);
}
}
};
var jsonEditor = {
"make" : {
"options" : {
mode: 'view',
modes: ['view','code']
},
execute:function(container, param) {
if(param != null || !"" == param) {
var result = {};
try {
result = JSON.parse(param);
var editor = new JSONEditor(document.getElementById(container), this.options, result);
// editor.setMode("code");
} catch (e) {
$("#" + container).html('<pre style="background:#fff;border-radius:0px;border:0px solid #ccc;"><code><xmp>' + param + '</xmp></code></pre>');
/*
Messenger().post({
message: "控制台接收到非JSON数据,异常:" + e,
type: "error",
hideAfter: 5,
showCloseButton: true
});
*/
}
}
}
}
};
var notify = {
execute:function(){
Messenger().post({
message: self.msg.body.content,
type: self.msg.body.type,
hideAfter: 5,
showCloseButton: true
});
}
};
var wonton = {
};
if(self.msg.header.mesType == "FLOW") {
/*
* 将子流程中的控件日志过滤,不在当流程图中显示次序号
* 每个控件第一次输出日志时,因为第一次才会有次序号orderNum
* */
if(!self.msg.body.subFlag && self.msg.body.orderNum != undefined && self.msg.body.orderNum > 0) {
if(baseMap.get("runnerFlowElementId") == null) {
baseMap.put("runnerFlowElementId", self.msg.body.eleId);
} else {
$("#name_" + baseMap.get("runnerFlowElementId")).removeClass("run_flicker");
baseMap.put("runnerFlowElementId", self.msg.body.eleId);
}
var elementName = elementMap.get(self.msg.body.eleId).getName();
var nameHtml = $("#name_" + self.msg.body.eleId).html();
var orderNumLength = $("#name_" + self.msg.body.eleId).children("span").length; //当前控件上显示次序号的个数
// 当由于循环功能,一个控件上的次序号显示超出5个后,就显示“...”,不再追加次序号
if(orderNumLength < 5) {
var appendHtml = '<span class="badge" style="background-color:green">' + self.msg.body.orderNum + '</span>';
$("#name_" + self.msg.body.eleId).html(nameHtml.substring(0, nameHtml.length - elementName.length) + appendHtml + elementName);
} else if(orderNumLength == 5){
var appendHtml = '<span class="badge" style="background-color:green">...</span>';
$("#name_" + self.msg.body.eleId).html(nameHtml.substring(0, nameHtml.length - elementName.length) + appendHtml + elementName);
}
$("#name_" + self.msg.body.eleId).addClass("run_flicker");
}
log[self.msg.body.logType].execute();
var html = '';
html = log[self.msg.body.logType].html;
$(self.continer).append(html);
//控制台日志输出
if(this.msg.body.eleType != "finish") {
console.log(self.msg.body.eleType + "--" + self.msg.body.logOutType);
if(self.msg.body.eleType == "linux" && self.msg.body.logOutType == "ssh") {
linuxEditor["make"].execute(self.msg.id, log[self.msg.body.logType].value);
} else if(self.msg.body.eleType == "text" && self.msg.body.logOutType == "text") {
textEditor["make"].execute(self.msg.id, log[self.msg.body.logType].value);
} else {
jsonEditor["make"].execute(self.msg.id, log[self.msg.body.logType].value);
}
}
if(self.msg.body.logType == "error") {
baseMap.put("selector", self.msg.body.eleId);
baseMap.put("highlight", "highlight" + self.msg.body.eleId); //把当前被高亮标记div的id放入缓存
$("#highlight" + baseMap.get("selector")).addClass("highlight");
$("#flowStopBtn span").removeClass("text-danger"); //控制台执行状态去掉红色,变为默认灰色
var pos = $("#log" + baseMap.get("selector")).offset().top;
$("#mcg_flow").animate({scrollTop: pos - 10}, 100);
}
} else if(self.msg.header.mesType == "NOTIFY") {
notify.execute();
} else if(self.msg.header.mesType == "WONTON") {
for(var i=0;i<self.msg.body.dataList.length; i++) {
var wontonListTable = $("#wontonListTable");
var wontonHeart = wontonListTable.bootstrapTable('getRowByUniqueId', self.msg.body.dataList[i].host);
if(wontonHeart == null) {
wontonListTable.bootstrapTable('append', self.msg.body.dataList[i]);
} else {
wontonListTable.bootstrapTable('updateByUniqueId', {
id: self.msg.body.dataList[i].host,
row: self.msg.body.dataList[i]
});
}
}
}
};
Message.prototype.build = function() {
var html = "";
if (this.msg.header.mesType == "FLOW") {
// console.log(this); 输出日志
/* 控件初次产生的日志 */
if($("#console").children("#log" + this.msg.body.eleId).length <= 0) {
html += '<div id="log' + this.msg.body.eleId + '" class="alert alert-info alert-dismissible" role="alert">';
html += '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button><br/>';
html += '<ul style="margin-top:21px;background:#fff;" class="messenger messenger-theme-air"><li class="messenger-message-slot"><div class="messenger-message message alert alert-' + this.msg.body.logType + ' "><div id="highlight' + this.msg.body.eleId + '" class="messenger-message-inner">' + this.msg.body.logTypeDesc + '--》' + this.msg.body.eleTypeDesc + '--》' + this.msg.body.comment + '</div></div></li></ul>';
// 流程或子流程正常执行完毕,控制台最后追加“文件列表”以及“控制台停止按钮”更正状态颜色
if(this.msg.body.eleType == "finish" || this.msg.body.eleType == "subFinish") {
if(this.msg.body.content != null && this.msg.body.content != "none") {
html += '<div style="height:auto;background:#fff;">';
var filesData = JSON.parse(this.msg.body.content);
for (var key in filesData.availableFileMap) {
html += ' ' + filesData.availableFileMap[key] + ' <a href="#" onClick="downFlowGenFile(this)" eleId="' + key + '" path="' + filesData.availableFileMap[key] + '">下载</a></br>';
}
html += '</div>';
}
if(this.msg.body.eleType == "finish") {
$("#flowStopBtn span").removeClass("text-danger");
if(!this.msg.body.subFlag) {
$("#name_" + baseMap.get("runnerFlowElementId")).removeClass("run_flicker");
}
}
} else if(this.msg.body.eleType == "interrupt") { //流程主动中断操作,且已停止后,“控制台停止按钮”更正状态颜色
$("#flowStopBtn span").removeClass("text-danger");
}
html += '<div style="height:auto;" id="' + this.msg.id + '"></div>';
html += '</div>';
this.continer = "#console";
} else { /* 同一控件第二次及后续产生的日志 */
html += '<ul style="background:#fff;margin-top:13px;" class="messenger messenger-theme-air"><li class="messenger-message-slot"><div class="messenger-message message alert alert-' + this.msg.body.logType + ' "><div class="messenger-message-inner">' + this.msg.body.logTypeDesc + '--》' + this.msg.body.comment + '</div></div></li></ul>';
html += '<div style="height:auto;" id="' + this.msg.id + '"></div>';
this.continer = "#log" + this.msg.body.eleId;
}
}
return html;
}
/* 下载流程中“文本控件”生成的文件 */
function downFlowGenFile(obj) {
var eleId = $(obj).attr("eleId");
var path = $(obj).attr("path");
if(eleId != null && eleId != "" && path != null && path != "") {
var form = $("<form>");
form.attr("style", "display:none");
form.attr("target", "");
form.attr("method", "post");
form.attr("action", baseUrl + "/tool/downFlowGenFile");
var eleIdInput = $("<input>");
eleIdInput.attr("type","hidden");
eleIdInput.attr("name","eleId");
eleIdInput.attr("value", eleId);
form.append(eleIdInput);
var pathInput = $("<input>");
pathInput.attr("type","hidden");
pathInput.attr("name","path");
pathInput.attr("value", path);
form.append(pathInput);
$("body").append(form);
form.submit();
form.remove();
webSocket = new WebSocket(websocketUrl);
webSocket.onerror = function(event) {
};
webSocket.onopen = function(event) {
};
webSocket.onmessage = function(event) {
var message = new Message({
msg : JSON.parse(event.data)
});
message.output();
};
webSocket.onclose = function(event) {
};
}
}
/*
* websocket
* param : {"operation":"init", "mcgWebScoketCode":"xxxx-xxxx-xxxx-xxxx"}
*/
var WSSHClient = function(param) {
}
WSSHClient.prototype._generateEndpoint = function () {
var endPoint = "ws:" + baseUrl.replace("http:", "") + "/wssh";
return endPoint;
};
WSSHClient.prototype.connect = function (options) {
var endpoint = this._generateEndpoint();
this._connection = new WebSocket(endpoint);
this._connection.onopen = function () {
options.onConnect();
};
this._connection.onmessage = function (evt) {
var data = evt.data.toString();
options.onData(data);
};
this._connection.onclose = function (evt) {
options.onClose();
};
};
WSSHClient.prototype.send = function (data) {
this._connection.send(JSON.stringify(data));
};
WSSHClient.prototype.sendInitData = function (options) {
this._connection.send(JSON.stringify(options));
}
WSSHClient.prototype.sendClientData = function (data) {
this._connection.send(JSON.stringify({"operation": "shell", "shell":data}))
}
//消息通知提示框插件
Messenger.options = {
extraClasses: 'messenger-fixed messenger-on-bottom messenger-on-right',
theme: 'air'
}
Date.prototype.format = function (format) {
var o = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"h+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() + 3) / 3),
"S": this.getMilliseconds()
}
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 common = function(){
var doResult = function (data, url, failureCallBack) {
if (failureCallBack)
failureCallBack(data);
return data;
};
return {
ajax : function(option, ajaxCallBack){
$.ajax({
url: baseUrl + option.url + (option.url.indexOf("?") == -1 ? "?" : "&") + "_R=" + Math.random(),
type: option.type,
data: option.data,
contentType: option.contentType,
async: option.async == undefined ? true : option.async,
dataType : option.dataType,
jsonp : option.jsonp,
success: function (data) {
var result = doResult(data, option.url, option.failureCallBack || function () { });
if(ajaxCallBack)
ajaxCallBack(result);
},
error: function (a, b, c) {
Messenger().post({
message: "非常抱歉, 发生异常!",
type: "error",
hideAfter: 5,
showCloseButton: true
});
},
beforeSend: function() {
if(option.isLoading) {
$.bootstrapLoading.end();
}
}
});
},
ajax : function(option, ajaxCallBack, errorCallBack){
$.ajax({
url: baseUrl + option.url + (option.url.indexOf("?") == -1 ? "?" : "&") + "_R=" + Math.random(),
type: option.type,
data: option.data,
contentType: option.contentType,
async: option.async == undefined ? true : option.async,
dataType : option.dataType,
jsonp : option.jsonp,
success: function (data) {
var result = doResult(data, option.url, option.failureCallBack || function () { });
if(ajaxCallBack)
ajaxCallBack(result);
},
beforeSend: function() {
if(option.isLoading) {
$.bootstrapLoading.end();
}
},
error: errorCallBack
});
},
ready : function(){},
showAjaxModal : function(url, data, callback, closeCallback, param){
var me = this;
this.ajax({
url: url,
type: 'GET',
"dataType":"html",
"async":false,
"data":param
}, function(html) {
var m = $(html).modal({ backdrop: "static", show: false });
m.returnValue = "";
var clientHeight = $(window).height();
m.find(".modal-body").css("max-height", clientHeight - 100);
m.find(".modal-body").css("overflow-y", 'auto');
m.modal("show").css({
/* "margin-top": function () {
return "5%"; //($(window).height() / 2)
}*/
});
m.on('shown.bs.modal', function () {
/* m.draggable({
cursor: "move",
handle: '.modal-header'
});
$(".modal-backdrop").remove();
*/
if(callback) {
callback(param);
}
me.ready.call(m, data);
});
m.on('hidden.bs.modal', function () {
if (m.returnValue) {
if (closeCallback)
closeCallback(m.returnValue);
}
m.remove();
});
});
},
showAjaxDialog : function(url, btns, callback, closeCallback, param){
if($("#dialog"+param.modalId).length > 0) {
return ;
}
var me = this;
this.ajax({
url: url,
type: 'GET',
"dataType":"html",
"async":false,
"data":param
}, function(html) {
var parentdiv=$('<div></div>');
parentdiv.attr('id', "dialog"+param.modalId);
$(parentdiv).html(html);
$(parentdiv).dialog({
title: param.option.title,
autoOpen: false,
closeOnEscape: false,
width: param.option.width,
height: "auto",
buttons: btns,
position: {
my: "center top",
at: "center top",
of: window,
collision: "flip"/*,
using: function( pos ) {
$(this).css({
"position":"fix", //absolute
"margin":"auto",
"left": 0,
"right": 0,
"top":"20px"
});
}*/
}
}).on( "dialogclose", function( event, ui ) {
$(this).dialog( "destroy" );
});
$(parentdiv).dialog("open");
if(callback) {
param["dialog"] = this;
callback(param);
}
});
},
formUtils : {
setValues : function(formId, data) {
var form = $("#" + formId)[0];
if (form != null){
for(var i = 0;i < form.elements.length;i++){
var oField = form.elements[i];
if (oField.type != "button"){
if(oField.name.indexOf("[") > 0) {
var key = oField.name.substring(0, oField.name.indexOf("["));
var obj = data[key];
var valueName = oField.name.substring(oField.name.indexOf("[") + 1, oField.name.indexOf("]"));
var value = obj[valueName];
// console.log("oField.name="+ oField.name + "---key =" +key + "---valueName=" + valueName + "---value=" + value);
if(typeof (value) == "undefined") {
continue ;
}
if(oField.type == "checkbox" || oField.type == "radio"){
if (value == null || value == "" || value == "0" || value == "false"){
oField.checked = false;
}else{
oField.checked = true;
}
} else if(oField.type == "text"
|| oField.type == "number"
|| oField.type == "password"
|| oField.type == "hidden"
|| oField.type == "textarea"){
oField.value = value;
} else if(oField.type == "select" || oField.type == "select-one") {
$(oField).val(value);
$(oField).selectpicker('refresh');
$(oField).selectpicker('val', value + "");
} else{
//其它的表单就不用设置了,比如image,reset,submit
oField.value = value;
}
oField.value = obj[valueName];
}
} else {
//暂不处理button
}
}
} else{
Messenger().post({
message: "表单不存在, 初始化值失败!",
type: "error",
hideAfter: 5,
showCloseButton: true
});
}
}
},
dateUtils : {
/**
*转换日期对象为日期字符串
* @param date 日期对象
* @param isFull 是否为完整的日期数据,
* 为true时, 格式如"2000-03-05 01:05:04"
* 为false时, 格式如 "2000-03-05"
* @return 符合要求的日期字符串
*/
getSmpFormatDate : function(date, isFull) {
var pattern = "";
if (isFull == true || isFull == undefined) {
pattern = "yyyy-MM-dd hh:mm:ss";
} else {
pattern = "yyyy-MM-dd";
}
return this.getFormatDate(date, pattern);
},
/**
*转换当前日期对象为日期字符串
* @param date 日期对象
* @param isFull 是否为完整的日期数据,
* 为true时, 格式如"2000-03-05 01:05:04"
* 为false时, 格式如 "2000-03-05"
* @return 符合要求的日期字符串
*/
getSmpFormatNowDate : function(isFull) {
return this.getSmpFormatDate(new Date(), isFull);
},
/**
*转换long值为日期字符串
* @param l long值
* @param isFull 是否为完整的日期数据,
* 为true时, 格式如"2000-03-05 01:05:04"
* 为false时, 格式如 "2000-03-05"
* @return 符合要求的日期字符串
*/
getSmpFormatDateByLong : function(l, isFull) {
return this.getSmpFormatDate(new Date(l), isFull);
},
/**
*转换long值为日期字符串
* @param l long值
* @param pattern 格式字符串,例如:yyyy-MM-dd hh:mm:ss
* @return 符合要求的日期字符串
*/
getFormatDateByLong : function(l, pattern) {
return this.getFormatDate(new Date(l), pattern);
},
/**
*转换日期对象为日期字符串
* @param date
* @param pattern 格式字符串,例如:yyyy-MM-dd hh:mm:ss
* @return 符合要求的日期字符串
*/
getFormatDate : function(date, pattern) {
if (date == undefined) {
date = new Date();
}
if (pattern == undefined) {
pattern = "yyyy-MM-dd hh:mm:ss";
}
return date.format(pattern);
}
}
};
}();
/*===========定义生成uuid函数开始
用法:Math.uuid()
==============*/
(function() {
var CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
.split('');
Math.uuid = function(len, radix) {
var chars = CHARS, uuid = [], i;
radix = radix || chars.length;
if (len) {
for (i = 0; i < len; i++)
uuid[i] = chars[0 | Math.random() * radix];
} else {
var r;
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '_';
uuid[14] = '4';
for (i = 0; i < 36; i++) {
if (!uuid[i]) {
r = 0 | Math.random() * 16;
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
}
}
}
return uuid.join('');
};
Math.uuidFast = function() {
var chars = CHARS, uuid = new Array(36), rnd = 0, r;
for (var i = 0; i < 36; i++) {
if (i == 8 || i == 13 || i == 18 || i == 23) {
uuid[i] = '_';
} else if (i == 14) {
uuid[i] = '4';
} else {
if (rnd <= 0x02)
rnd = 0x2000000 + (Math.random() * 0x1000000) | 0;
r = rnd & 0xf;
rnd = rnd >> 4;
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
}
}
return uuid.join('');
};
Math.uuidCompact = function() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
function(c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r
: (r & 0x3 | 0x8);
return v.toString(16);
});
};
})();
/*===========定义生成uuid函数结束==============*/
/*=================定义Map开始==================
用法 : baseMap.put("key", value);
baseMap.remove("key");
var array = map.keySet();
for(var i in array) {
console.log("key:(" + array[i] +") value: ("+map.get(array[i])+")");
}
=================================================*/
function Map() {
this.container = new Object();
}
Map.prototype.put = function(key, value) {
this.container[key] = value;
}
Map.prototype.get = function(key) {
return this.container[key];
}
Map.prototype.keySet = function() {
var keyset = new Array();
var count = 0;
for ( var key in this.container) {
// 跳过object的extend函数
if (key == 'extend') {
continue;
}
keyset[count] = key;
count++;
}
return keyset;
}
Map.prototype.size = function() {
var count = 0;
for ( var key in this.container) {
// 跳过object的extend函数
if (key == 'extend') {
continue;
}
count++;
}
return count;
}
Map.prototype.remove = function(key) {
delete this.container[key];
}
/*===============定义Map结束=============*/
/*===============定义loading开始=============
* 用法 $.bootstrapLoading.start({ loadingTips: "正在处理数据,请稍候..." });
* $.bootstrapLoading.end();
* */
jQuery.bootstrapLoading = {
start : function(options) {
var defaults = {
opacity : 1,
//loading页面透明度
backgroundColor : "#fff",
//loading页面背景色
borderColor : "#bbb",
//提示边框颜色
borderWidth : 1,
//提示边框宽度
borderStyle : "solid",
//提示边框样式
loadingTips : "Loading, please wait...",
//提示文本
TipsColor : "#666",
//提示颜色
delayTime : 1000,
//页面加载完成后,加载页面渐出速度
zindex : 9999999,
//loading页面层次
sleep : 0
//设置挂起,等于0时则无需挂起
}
var options = $.extend(defaults, options);
//获取页面宽高
var _PageHeight = document.documentElement.clientHeight, _PageWidth = document.documentElement.clientWidth;
//在页面未加载完毕之前显示的loading Html自定义内容
var _LoadingHtml = '<div id="loadingPage" style="position:fixed;left:0;top:0;_position: absolute;width:100%;height:'
+ _PageHeight
+ 'px;background:#cccccc;'
// + options.backgroundColor
+ ';opacity:'
+ options.opacity
+ ';filter:alpha(opacity='
+ options.opacity * 100
+ ');z-index:'
+ options.zindex
+ ';"><div id="loadingTips" class="pacman" style="position: absolute; cursor1: wait; width: auto;border-color:'
+ options.borderColor
+ ';border-style:'
+ options.borderStyle
+ ';border-width:'
+ options.borderWidth
+ 'px; background: #cccccc;'
// + options.backgroundColor
// + ' url(<%=basePath %>/library/images/loading.gif) no-repeat 5px center; color:'
+ options.TipsColor
+ ';font-size:20px;">'
+ '<div></div><div></div><div></div><div></div><div></div></div></div>';
//呈现loading效果
$("#mcg_header").append(_LoadingHtml);
//获取loading提示框宽高
var _LoadingTipsH = document.getElementById("loadingTips").clientHeight, _LoadingTipsW = document
.getElementById("loadingTips").clientWidth;
//计算距离,让loading提示框保持在屏幕上下左右居中
var _LoadingTop = _PageHeight > _LoadingTipsH ? (_PageHeight - _LoadingTipsH) / 2
: 0, _LoadingLeft = _PageWidth > _LoadingTipsW ? (_PageWidth - _LoadingTipsW) / 2
: 0;
$("#loadingTips").css({
"left" : _LoadingLeft + "px",
"top" : _LoadingTop + "px"
});
},
end : function() {
$("#loadingPage").remove();
}
}
/*===============定义loading结束=============*/
$(document).ajaxStart(function(){
$.bootstrapLoading.start({ "loadingTips": "正在处理数据,请稍候...", "borderWidth":0, "opacity":0.5 });
});
$(document).ajaxStop(function(){
$.bootstrapLoading.end();
});
$(document).ajaxError(function(){
Messenger().post({
message: "非常抱歉,发生异常!",
type: "error",
hideAfter: 5,
showCloseButton: true
});
$.bootstrapLoading.end();
});
var Tools = function(param){
}
//将带下划线的字符转换为驼峰命名
Tools.prototype.convertHumpName = function(name) {
var reg = /_(\w)/g;
return name.toLowerCase().replace(reg, function (a,b){
return b.toUpperCase();
});
}
//将带下划线的字符转换为驼峰命名,且首字符为大写
Tools.prototype.convertClassName = function(name) {
var reg = /\b(\w)|\s(\w)/g;
return this.convertHumpName(name).replace(reg, function (data){
return data.toUpperCase();
});
}
var tools = new Tools({});
/*
* 自适应布局 计算并设置所有autoHeight元素的高度(参数为父元素)
*/
function setAutoHeight($pe,min_height){
if ($pe != null) {
// 获取父元素的高度
var parent_h = 0;
//if ($pe.attr("id")=="body"){
if ($pe.get(0).tagName=="BODY"){
parent_h = getTotalHeight(); // body元素获取窗口的高度
//alert("0-"+parent_h);
min_height = (parseInt(min_height) == "NaN") ? 400 : min_height; // 默认最小高度为500
parent_h = (parent_h<min_height) ? min_height : parent_h;
// 动态设置body的
$pe.css("overflow","hidden");
} else {
parent_h = $pe.height();
}
// 遍历父元素子级元素中样式类名 包含"autoHeight"但不包含"gridTable"的元素,计算并设置其高度
$pe.children(".autoHeight").each(function(i){
var $e1 = $(this);
if ($e1.hasClass("autoHeight") && (! $e1.hasClass("gridTable")) && ($e1.css("display") != "none") ) {
// 该元素的纵向的边线宽度及外边距(从边线(border)开始至margin-top或margin-bottom之间的距离
//(含border线宽度和padding高度))
var border_outer_h = $e1.outerHeight()-$e1.height();
//alert($e1.attr("id")+" : "+border_outer_h);
// 遍历该元素的所有 非autoHeight 和 非隐藏 的兄弟元素并合计实际高度(siblings())
var sibling_h = 0;
$e1.siblings().each(function(j){
if (!($(this).hasClass("autoHeight") || ($(this).css("display") == "none"))) {
// 获取本元素
sibling_h = sibling_h+$(this).outerHeight(true);
//alert($(this).attr("id")+" : "+sibling_h);
};
});
// 遍历父元素的所有子元素, 排除 浮动 的子元素,处理
// 纵向上的外边距值(maring)之间重叠互吃的问题(两个以上兄弟元素才计算)
var margin_height_1 = 0; // 垂直方向的理论外边距(包含margin-top和margin-bottom)
var margin_height_2 = 0; // 元素的margin-bottom 与相邻下一个元素间的 margin-top 之间互吃后的实际边距
if ($pe.children().size()>1) {
$pe.children().each(function(k){
$e2 = $(this);
if (!(($e2.css("float")=="left") || ($e2.css("float")=="right"))) {
// 垂直方向的理论外边距合计
margin_height_1 = margin_height_1 + $e2.outerHeight(true) - $e2.outerHeight(false);
// 计算元素的margin-bottom 与相邻下一个元素间的 margin-top
// 之间互吃被吃掉的外边距
// 当前元素下边距值(只考虑了单位是px的情况,其他单位会出错)
var v_m_bottom=$e2.css("margin-bottom");
var index = v_m_bottom.indexOf("px");
if (index>0) {
v_m_bottom = v_m_bottom.substring(0,index);
} else {
alert("不合乎要求的下外边距设置,计算出的高度可能会有误差:"+v_m_bottom);
v_m_bottom = 0;
};
v_m_bottom = parseInt(v_m_bottom);
// 下一个元素上边距值(只考虑了单位是px的情况,其他单位会出错)
var v_m_top = 0;
if (k<$pe.children().size()-1) {
v_m_top=$e2.next().css("margin-top");
var index = v_m_top.indexOf("px");
if (index>0) {
v_m_top = v_m_top.substring(0,index);
} else {
alert("不合乎要求的上外边距设置,计算出的高度可能会有误差:"+v_m_top);
v_m_top = 0;
};
v_m_top = parseInt(v_m_top);
};
// 实际被吃掉的那一部分边距(小的那一个被吃掉了,等于的时候吃掉任意一个)
margin_height_2 = margin_height_2 + ((v_m_bottom<v_m_top) ? v_m_bottom : v_m_top);
//alert($e2.attr("id")+" : "+ margin_height_1 + " | " + margin_height_2 );
};
});
};
// 设置该元素的高度值
var h=parent_h-sibling_h-border_outer_h-margin_height_1+margin_height_2-1;
//alert($e1.attr("id") +" ::: "+$pe.attr("id")+" : "+parent_h +"|" +sibling_h+"|" +border_outer_h+"|" +margin_height_1+ "|" +margin_height_2);
//alert("h-"+h);
$e1.height(h);
// 递归调用,计算该元素下所有自动高度元素的高度
setAutoHeight($e1);
};
});
}
}
/*
* 计算窗口的有效高度
*/
function getTotalHeight(){
//alert(document.compatMode);
//alert($(document).height()+" "+$("body").height());
//alert(document.documentElement.clientHeight+" "+document.body.clientHeight);
//leadingWhitespace: 如果在使用innerHTML的时候浏览器会保持前导空白字符,则返回true,目前在IE 6-8中返回false。
if($.support.leadingWhitespace){
//compatMode 文档渲染方式:CSS1Compat-标准兼容模式模式开启,BackCompat-标准兼容模式关闭(怪异模式)
_h = document.compatMode == "CSS1Compat"? document.documentElement.clientHeight :
document.body.clientHeight;
}else{
_h = document.compatMode == "CSS1Compat"? document.documentElement.clientHeight :
document.body.clientHeight;
//return self.innerHeight;
}
//alert(_h + " | " +self.innerHeight);
return _h-2;
}
/*
* 计算窗口的有效宽度
*/
function getTotalWidth(){
if($.support.leadingWhitespace){
return document.compatMode == "CSS1Compat"? document.documentElement.clientWidth :
document.body.clientWidth;
}else{
return self.innerWidth;
}
}