-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
1324 lines (1309 loc) · 50.4 KB
/
Copy pathindex.js
File metadata and controls
1324 lines (1309 loc) · 50.4 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
998
999
1000
/*
tnt.js 基于miniui和jquery的高级封装
*/
(function(root, factory) {
// 生成ebapBase
var ebapBase = factory();
root.ebapBase = ebapBase || {};
// umd格式
if (typeof define === 'function' && define.amd) {
define(function () {
return ebapBase;
})
} else if (typeof exports === 'object') {
if (module !== 'undefined' && module.exports) {
exports = module.exports = ebapBase;
}
exports.ebapBase = ebapBase;
}
})(typeof window === 'object' && window, function () {
// 快捷方法
var nativeToString = Object.prototype.toString;
var nativeSlice = Array.prototype.slice;
var nativeHasOwn = Object.prototype.hasOwnProperty;
var ebapBase = (function() {
var ebapModules = {};
var ebapInstance = null;
var isParsed = false;
var winLoc = window.location;
var winLocSearch = winLoc.search;
var guid = 0;
var win = window;
var commonCfg = {
};
var topices = {};
var localCfg = {
'url': '当前页面地址:',
'key': '错误配置的key:',
'modules': '模块详情:'
}
/*
配置文件
* */
var config = {
root: window['ctx'],
injectRules: {
'normal': function() {
rules['mixin'][0][rules.method]();
},
'ifelse': function(rules) {
if (rkFlist.mode = 'line-add') {
rules['mixin'][0][rules.method]();
} else {
rules['mixin'].forEach(function(i, f) {
if (i >= 1) {
f[rules.method]()
}
});
}
},
'combine': function() {
rules['mixin'].forEach(function(i, f) {
f[rules.method]()
});
}
},
uiLib: 'mini',
nameSpace: 'ebap',
enableList: {
open: true,
decode: true,
encode: true,
utils: {
},
lock: ['get', 'created']
},
$$type: '',
openFilterRules: ['onload', 'ondestroy']
};
var _params = {}
// 判断某个环境下是否存在某个库是否支持某个方法
function support(libName,funcName,context) {
var __context = context ? context : window;
return (typeof __context[libName] !=='undefined') && __context[libName][funcName];
}
// 判断miniui是否支持某个方法
function miniSupport(methodName,options) {
if (config.uiLib === 'mini' && support('mini', 'get')) {
if ( methodName === 'form' ) {
return new mini.Form(options.id)
} else if (methodName === 'tooltip') {
return new mini.ToolTip();
} else if (methodName === 'contextMenu') {
return new mini.contextMenu();
}
}
return support(config.uiLib, methodName);
}
/**
* 执行某个对象上的某个方法,也可以注入参数
* @param {node} elm
* @param {string} method
* @returns
*/
function _execute(elm,method) {
var _method = method;
var arg = Array.prototype.slice.call(arguments,2);
return elm[_method] && elm[_method].apply(this,arg);
}
/**
* 判断某个特定的dom元素是否存在
* @param {any} elm
* @param {any} targetInfo
* @returns
*/
function _isExistTarget(elm,targetInfo) {
if (elm.tagName.toUpperCase() === targetInfo.tagName.toUpperCase() && elm.className.indexOf(targetInfo.cls) !== -1 || elm.id === targetInfo.id) {
return true;
}
return false
}
/**
* 事件代理
* @param {domNode} proxyNode
* @param {object} targetInfo
* @param {function} callback
* @param {string} eventType
*/
function _eventProxy(proxyNode, targetInfo, callback, eventType) {
var proxyArgs = [].slice.call(arguments);
var proxyNode = proxyNode;
var targetInfo = targetInfo;
var eventType = eventType || 'click';
var callback = callback;
if (proxyArgs.length === 1 && nativeToString.call(proxyArgs[0]) === '[object Object]') {
proxyNode = proxyArgs[0].context;
targetInfo = {
cls: proxyArgs[0].cls,
tagName: proxyArgs[0].tagName,
id: proxyArgs[0].id
};
eventType = proxyArgs[0].eventType || 'click';
callback = proxyArgs[0].cb;
}
proxyNode.on(eventType, function(e) {
if (e.target.tagName === 'A' && targetInfo.tagName === 'a') {
e.preventDefault();
}
if (_isExistTarget(e.target, targetInfo)) {
targetInfo = $.extend({}, targetInfo, { level: 0, dom: e.target});
callback(targetInfo);
return undefined
}
$(e.target).parents(proxyNode).each(function(idx,elm) {
if (_isExistTarget(elm, targetInfo)) {
targetInfo = $.extend({}, targetInfo, { level: idx+1,dom: e.target});
callback(targetInfo)
//忽略后续的比较 跳出each函数 from http://www.jb51.net/article/50711.htm
return false;
}
});
})
}
/**
* 说明: 自动获取指定区域的input,textarea的值并将其加入到ebapparams
* @param {jquery object} $els
* @param {object} bccparams
**/
function autoInput($els, ebapparams) {
$els.on('input', function(event) {
if (event.target.value.length === 0) {
delete ebapparams[event.target.name];
} else {
ebapparams[event.target.name] = event.target.value;
}
});
if (document.all) {
$els.each(function() {
var that = this;
if (this.attachEvent) {
this.attachEvent('onpropertychange', function(e) {
if (e.propertyName != 'value') return;
$(that).trigger('input');
});
}
});
}
};
/**
* 说明: 对multiselect组件onchange事件的封装
* @param {object} options
* @param {boolean} checked
* @param {element} select
* @param {object} bccparams
**/
function multiChangeHandler(option, checked, key, ebapparams) {
var _multiKey = key
if (checked) {
ebapparams[_multiKey] = option[0].value;
} else {
ebapparams[_multiKey] = '';
}
}
// 初始化设置
function setUp (func) {
typeof func === 'function' && func.apply(null, nativeSlice.call(arguments, 1));
return this;
}
var _cacheEbapIns = null;
/**
* 说明: 项目常用的工具方法
**/
// https://github.com/goatslacker/get-parameter-names/blob/master/index.js
// 看不懂正则的,可以上https://regexper.com
function getParameterNames(fn) {
var COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
var DEFAULT_PARAMS = /=[^,]+/mg;
var FAT_ARROWS = /=>.*$/mg;
var code = fn.toString()
.replace(COMMENTS, '')
.replace(FAT_ARROWS, '')
.replace(DEFAULT_PARAMS, '');
var result = code.slice(code.indexOf('(') + 1, code.indexOf(')'))
.match(/([^\s,]+)/g);
return result === null
? []
: result;
}
// 对object单个或多个key进行分析,分析完成后,执行相应的回调
function getAllOptions(options) {
return function (path, func, defaultOpts) {
var optionsStrToArr = [];
var result = null;
var defaultValue = null;
var oLen = null;
if (path && typeof path === 'string' && path.length > 0) {
if (typeof path === 'string') {
optionsStrToArr = path.split('.');
oLen = optionsStrToArr.length;
}
for (var _index=0;_index< oLen; _index++) {
if (result) {
result = result[optionsStrToArr[_index]];
} else {
result = options[optionsStrToArr[_index]];
}
}
if (func && typeof func === 'function') {;
defaultValue = func.call(null, result, defaultOpts);
} else {
defaultValue = func;
}
return result || defaultValue;
} else if (nativeToString.call(path) === '[object Array]') {
var plen = path.length;
var pstr = '';
var pResult = [];
for (var p = 0; p <plen; p++) {
pstr = path[p];
result = null;
if (typeof pstr === 'string') {
optionsStrToArr = pstr.split('.') || [];
oLen = optionsStrToArr.length || 0;
}
for (var _index = 0;_index< oLen; _index++) {
if (result) {
result = result[optionsStrToArr[_index]];
} else {
result = options[optionsStrToArr[_index]];
}
}
pResult.push(result);
}
pResult.push(defaultOpts, path);
if (func && typeof func === 'function') {
defaultValue = func.apply(null, pResult);
} else {
defaultValue = func;
}
return pResult || defaultValue;
}
}
}
var utilsPool = {};
// pubsub模式消息通信,参考https://github.com/mroderick/PubSubJS
var customEventIndex = -1;
var pubsub = {
_on: function (topic, cb, context) {
if (!topices[topic]) {
topices[topic] = [];
}
// 生成唯一的token,便于后期取消
var token = config.nameSpace + '-uid-' + (customEventIndex++);
topices[topic].push({
context: context,
cb: cb,
token: token
});
return token;
},
_clearAll: function () {
topices = {};
},
_clear: function (topic) {
if (topices[topic]) {
delete topices[topic]
}
},
_off: function (value) {
var descendantTopicExists = function (topic) {
for (var t in topices) {
if (nativeHasOwn.call(topices, t) && t.indexOf(topic) === 0) {
return true;
}
}
return false;
};
var isTopic = typeof value === 'string' && (nativeHasOwn.call(topices, value) || descendantTopicExists(value));
var isToken = !isTopic && typeof value === 'string';
var isFunction = typeof value === 'function';
var t = null;
var result = true;
var topic = null;
if (isTopic) {
pubsub._clear(value);
return;
}
for (t in topices) {
if (nativeHasOwn.call(topices, t)) {
topic = topices[t];
for (var i = 0, tl= topic.length; i < tl; i++) {
if (isToken && topic[i].token === value) {
topic.splice(i, 1);
result = value;
} else if (isFunction && topic[i].cb === value) {
topices[t].splice(i, 1);
result = true;
}
}
}
}
return result;
},
_once: function (topic, cb) {
if (!topices[topic]) {
topices[topic] = [];
}
topices[topic].push({
context: this,
cb: cb,
once: true
})
},
_trigger: function (topic, data, async) {
if (!nativeHasOwn.call(topices, topic)) {
return;
}
function throwException (ex) {
return function rethrowException() {
throw ex;
}
}
function callSubscriberWithExceptions( subscriber, data, async ) {
function emitSubscribe(data) {
if (subscriber.cb) {
subscriber.cb.call(subscriber.context, data);
}
if (subscriber.once) {
subscriber.cb = function () {}
}
}
if (async === true) {
try {
emitSubscribe(data);
} catch (err) {
setTimeout(throwException(err), 0);
}
}
emitSubscribe(data);
}
function distributeMsg () {
if (nativeHasOwn.call(topices, topic)) {
var subscribers = topices[topic];
var cbLen = subscribers.length;
for (var i = 0 ; i < cbLen; i++) {
callSubscriberWithExceptions(subscribers[i], data, async);
}
}
}
if (async === true) {
setTimeout(distributeMsg, 0);
} else {
distributeMsg();
}
return true;
}
}
var utils = {
actionTypes: ['ebap-tbActionAdd','ebap-tbActionDelete','ebap-tbActionModify','ebap-tbActionAssign','ebap-actionType'],
toggleEnable: function(obj) {
$.extend(config['enableList'], obj);
},
// 错误信息提示
invarint: function (info, type) {
for (var i in info) {
console[type || 'error'](localCfg[i], info[i]);
}
},
now: function() {
return new Date();
},
throttle: function (func, wait, options) {
var context = null;
var timeId = null;
var args = null;
var previous = 0;
var result = null;
var later = function () {
previous = options.leading === true ? 0 : utils.now();
timeId = null;
result = func.apply(context, args);
if (!timeId) {
context = args = null;
}
}
return function () {
var now = utils.now();
args = arguments;
if (!previous || options.leading === false) {
previous = utils.now();
}
var remaining = wait - (now - previous);
if (remaining < 0 || remaining> wait) {
if (timeId) {
clearTimeout(timeId);
timeId = null;
}
result = func.apply(context, args);
if (!timeId) {
context = args = null;
}
} else if (!timeId && options.trailing !== false) {
timeId = setTimeout(later, remaining);
}
return result;
}
},
getNormalDate: function (time) {
var startTime = null;
if (typeof startTime === 'number') {
startTime = new Date(time);
} else if (typeof startTime === 'string') {
startTime = new Date(Date.parse(time));
}
return startTime;
},
setParams: function(key, value) {
if (key && nativeToString.call(key) == '[object Object]') {
$.each(key, function(m, ms) {
if (m && ms) {
_params[m] = ms;
}
})
} else {
if (key) {
_params[key] = value;
}
}
},
getParams: function (key) {
if (key && _params[key]) {
return _params[key];
}
},
hasKeys: function (obj) {
if (typeof obj === 'object' && !!obj && nativeToString.call(obj) === '[object Object]') {
for (var o in obj) {
if (nativeHasOwn.call(obj, o)) {
return true;
}
}
}
return false;
},
hasAndReturnGetTime: function (time) {
return time && time.getTime && typeof time.getTime === 'function';
},
computeDelta: function (startTime, endTime) {
var startTime = utils.getNormalDate(startTime);
var endTime = utils.getNormalDate(endTime);
var deltaTime = null;
if (hasAndReturnGetTime(startTime) && hasAndReturnGetTime(endTime)) {
var deltaTime = startTime.getTime() - endTime.getTime();//时间差的毫秒数
}
deltaTime = Math.abs(deltaTime);
//计算出相差天数
var days=Math.floor(deltaTime/(24*3600*1000))
//计算出小时数
var leave1=deltaTime%(24*3600*1000);
//计算天数后剩余的毫秒数
var hours=Math.floor(leave1/(3600*1000))
//计算相差分钟数
var leave2=leave1%(3600*1000);
//计算小时数后剩余的毫秒数
var minutes=Math.floor(leave2/(60*1000))
//计算相差秒数
var leave3=leave2%(60*1000);
//计算分钟数后剩余的毫秒数
var seconds=Math.round(leave3/1000);
return {
days: days,
hours: hours,
minutes: minutes
};
},
/*
生成深层依赖分析函数
*/
genDpo: function (context,opts, options) {
var po = typeof options === 'object' ? utils.getAllOptions(options) : options;
if (context && context.genParseOBK && context['$$type'] === config.nameSpace) {
return context.genParseOBK($.extend(opts || {}, {
parseOBK: po
}))
}
},
// 当获取模块失败时, 提供友好的错误信息提示
safeGetModule: function (modules, options, moduleSettings) {
try {
var moduleIns = utils.getModule(ebapModules, options.key);
var waitInject = {};
moduleIns && typeof moduleIns === 'function' && (waitInject['$$type'] = config.nameSpace);
return $.extend(true, moduleIns($.extend({}, options)), {
setUrls: utils.setUrls,
genParseOBK: utils.genParseOBK,
parseOBK: utils.getAllOptions(options),
getDepsIns: utils.getDepsIns,
extend: utils.extend,
getIns: utils.getIns,
insId: options.key === 'smodules' ? options.id : '',
moduleType: options.mType || options.key,
moduleDeps: options.moduleDeps
}, moduleSettings, waitInject, pubsub);
} catch (e) {
utils.invarint({
url: window.location.href,
key: options.key,
modules: modules
});
return;
}
},
// 从列表数据中生成url后缀
genUrls: function(originData, data, rules) {
var hasIdFlag = data.indexOf('id=') > -1;
var hasSearchFlag = data.indexOf('?') > -1;
var removeInfo = {};
var odLen = originData.length;
for (var i = 0; i < odLen; i++) {
var r = originData[i];
$.each(rules, function(i, dt) {
if (nativeHasOwn.call(r,dt)) {
if (!removeInfo[dt]) {
removeInfo[dt] = dt + '='+ r[dt]
} else {
removeInfo[dt] +=',' + r[dt]
}
}
})
}
hasIdFlag && (data += (hasSearchFlag ? removeInfo['id'].slice(3) : '?'+removeInfo['id'].slice(3)));
for (var rinfo in removeInfo) {
if (nativeHasOwn.call(removeInfo, rinfo)) {
if (hasIdFlag) {
rinfo !== 'id' && (data += ('&'+removeInfo[rinfo]))
} else {
data += (hasSearchFlag ? removeInfo[rinfo] + '&' : '?'+removeInfo[rinfo] + '&');
}
}
}
return data;
},
doDel: function (originData, data, rules) {
var data = utils.genUrls(originData, data, rules);
utils.doListAjax.call(this, data);
},
doListAjax: function (url) {
var self = this;
utils.ajax({
url: url,
success: function (text) {
self.getIns().reload();
},
error: function () {
}
});
},
getAllOptions: getAllOptions,
disable: function (key) {
var _methodName = key;
if (utils[_methodName]) {
config.enableList.utils[_methodName] = false;
}
},
setNameSpace: function (ns) {
if (!ns) return;
return config['nameSpace'] = typeof ns === 'string' ? ns: ns.toString();
},
setPropTrue: function (obj) {
if (!$.isPlainObject(obj)) return;
for (var u in obj) {
if (nativeHasOwn.call(obj, u) && typeof obj[u] == 'function' && $.inArray(u, config.enableList.lock) == -1) {
config.enableList.utils[u] = true;
}
}
},
// 通过id获取某个miniui实例
getInstance: function(options, type) {
var cacheInstance = null;
if (typeof options === 'string') {
var options = {
id: options
}
}
if (type) {
cacheInstance = utils.created(options, String(type));
} else {
cacheInstance = utils.created(options);
}
return cacheInstance;
},
get: get,
genOpenCfg: function(openCfg) {
var _cfg = {};
$.each(openCfg, function(i, cfg) {
if ($.inArray(cfg['filter'] || cfg.openFilterRules, i) > -1) {
if (i === 'onload') {
_cfg[i] = cfg[i];
} else {
_cfg[i] = function(action) {
action ? cfg[i](action) : cfg[i]();
}
}
}
_cfg[i] = cfg[i];
})
return _cfg;
},
open: function(openCfg) {
console.log(":::openCfg", openCfg);
// var newOpenCfg = utils.genOpenCfg(openCfg);
miniSupport('open')(openCfg);
},
genDepsIns: function (deps,flag) {
var _deps = {};
var deps = (deps && deps.length>=0) ? deps : [];
var depsKey = '';
for (var d = 0, dl = deps.length; d < dl; d++) {
depsKey = deps[d].key.split('.').join('');
if (flag) {
_deps[depsKey] = utils.getInstance(deps[d])
} else {
_deps[depsKey] = utils.get(deps[d])
}
}
return _deps;
},
created: function(options, methodName) {
var _cacheEbapIns = null;
if (typeof methodName === 'string' && methodName === 'form') {
_cacheEbapIns = miniSupport('form', options);
} else {
_cacheEbapIns = miniSupport('get')(options.id);
}
if (_cacheEbapIns) {
options['created'] && typeof options['created'] === 'function' && options['created'](_cacheEbapIns, options.moduleDeps)
}
return _cacheEbapIns;
},
seekOptions: function(options, ins) {
for (var o in options) {
if (typeof options[o] === 'function') {
options[o](ins);
}
}
},
isAandHasCls:function(target,clsStr,strategy) {
return target.tagName === 'A' && $(target).hasClass(clsStr) && clsStr === strategy;
},
// 自动绑定事件,并执行相应的策略,用于表格中事件处理
extendInjectRules: function (rule) {
if ($.isPlainObject(rule)) {
for (var r in rule) {
if (nativeHasOwn.call(rule, r)) {
config.injectRules[r] = rule[r]
}
}
return true;
}
return false;
},
// 动态加载脚本
loadScript: function(src, cb, func) {
var spt = null;
if (typeof src === 'string') {
spt = document.createElement('script');
spt.charset="utf-8";
spt.src = src;
spt.onload = spt.onreadystatechange = function(e) {
if (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete') {
cb(e);
spt.onload = spt.onreadystatechange = null;
}
}
func(spt);
} else if (nativeToString.call(src) === '[object Array]') {
var slen = src.length;
var count = slen;
var argsArr = [];
for (var i = 0; i< slen; i++) {
spt = document.createElement('script')
spt.charset="utf-8";
spt.src = src[i];
spt.onload = spt.onreadystatechange = function(e) {
argsArr.push(e);
if (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete') {
count--;
if (!count) {
cb(argsArr);
}
spt.onload = spt.onreadystatechange = null;
}
}
func(spt);
}
}
},
eventProxy: _eventProxy,
autoProxyTrigger: function(cfg) {
for (var icfg in cfg) {
if (nativeHasOwn.call(cfg, icfg)) {
this.eventProxy({
context: cfg[icfg].context,
cls: icfg,
tagName: cfg[icfg].tagName,
eventType: cfg[icfg].eventType,
cb: cfg[icfg].cb
});
}
}
},
getIns: function() {
var insId = this.insId || '';
var moduleType = this.moduleType;
if (!insId) {
return this;
}
return utils.getInstance({ id: insId }, moduleType);
},
setCommonCfg: function(obj, deep) {
var parseOBK = getAllOptions(obj);
var cdArr = null;
var cdLen = null;
$.each(commonCfg.disable, function(index, cd) {{
if (parseOBK(cd) != null) {
cdArr = cd.split('.');
cdLen = cdArr.length;
if (cdLen === 1) {
delete obj[cdArr[0]];
} else if (cdLen === 2) {
delete obj[cdArr[0]][cdArr[1]];
} else if (cdLen === 3) {
delete obj[cdArr[0]][cdArr[1]][cdArr[2]];
}
}
}
});
commonCfg = $.extend(deep ? deep : true,commonCfg, obj);
},
getCommonCfg: function () {
return commonCfg;
},
hackIe: function (verStr, func) {
if ($.inArray(verStr.split(','), document.documentMode.toString()) !== -1) {
func.apply(null, nativeSlice.call(arguments).length>2 && nativeSlice.call(arguments, 2))
}
},
inject: function(options) {
return function() {
config.injectRules[options.rule](options.mixin)
}
},
extend: function () {
var _extendObj = {};
$.each( Array.prototype.slice.call(arguments), function(i, arg) {
_extendObj = $.extend(_extendObj, arg);
})
$.extend(this, _extendObj);
return this;
},
//获取字典标签 ebapBase.utils.getDictLabel
getDictLabel: function getDictLabel(data, value, defaultValue){
for (var i=0; i<data.length; i++){
var ebapDictRows = data[i];
if (ebapDictRows.value == value){
return ebapDictRows.label;
}
}
return defaultValue;
},
genParseOBK: function (opts) {
// 获取当前options分析
var parseOBK = opts.parseOBK;
// 从参数形成新的options
var _parseOBK = ebapUtils.getAllOptions(opts || {});
var parseResult = [];
return function(longPath,defaultValue) {
var _args = [].slice.call(arguments);
// console.clear();
if (typeof longPath === 'string') {
var _key = longPath.split('.').length>=2 ? longPath.split('.').slice(1).join('.') : longPath.split('.').slice()[0] || '';
return _parseOBK(_key, function(result) {
if (result) {
if (typeof defaultValue === 'function') {
defaultValue(result,_args[2]);
}
} else {
return parseOBK(longPath, defaultValue, _args[2]);
}
});
} else if (nativeToString.call(longPath) === '[object Array]') {
var len = longPath.length;
for (var l = 0; l< len; l++) {
var lstr = longPath[l];
var _key = lstr.split('.').length>=2 ? lstr.split('.').slice(1).join('.') : lstr.split('.').slice()[0] || '';
var _result = _parseOBK(_key, function(result) {
if (result) {
return result;
} else {
return parseOBK(lstr);
}
});
parseResult.push(_result);
}
parseResult.push( _args[2], longPath);
if (typeof defaultValue === 'function') {
defaultValue.apply(null, parseResult);
}
return parseResult;
}
}
},
autoInput: autoInput,
// 设置实例的urls
setUrls: function(obj) {
console.log(obj);
if (nativeToString.call(obj) === '[object Object]') {
for ( var ukType in obj) {
if (ukType.toLowerCase().slice(-3) === 'url') {
this.settings && (this.settings[ukType] = utils.prefixPath(obj[ukType]));
} else {
this.settings && (this.settings[ukType + 'Url'] = utils.prefixPath(obj[ukType]));
}
}
}
},
resetRoot: function (root) {
root && (config['root'] = root);
},
// 判断miniui是否支持编码
encode: support('mini', 'encode') ?support('mini', 'encode') : function () {},
// 判断miniui是否支持解码
decode:support('mini', 'decode')? support('mini', 'decode') : function () {},
clone: support('mini', 'clone') ? support('mini', 'clone'): function () {},
// 自动为url加入根路径ctx
prefixPath: function (url, ctx) {
return typeof config.root !== 'undefined' ? config.root + (url || '') : ( url || '')
},
isString: function (str) {
return typeof str === 'string' && str;
},
isSupportStoreByType: function (type) {
var storeMap = {
'session': window.sessionStorage,
'local': window.localStorage,
'cookie': document.cookie
}
return storeMap[utils.isString(type).toLowerCase()];
},
getModule: function (ns, ns_string) {
var parts = ns_string.split('.');
var parent = ns;
var pl = parts.length;
var exportModule = null;
for (var i = 0; i < pl; i++) {
if (!exportModule) {
exportModule = parent[parts[i]];
} else {
exportModule = exportModule[parts[i]];
}
}
return exportModule;
},
// 封装ajax进行更多控制
ajax: function (options) {
var ajaxOpts = $.extend({
contentType: "application/json",
dataType: 'json',
cache: false,
success: function ( data, textStatus, jqXHR ) {
options.success && options.success(data, textStatus, jqXHR);
},
error: function (jqXHR, textStatus, errorThrown) {
options.error && (options.error(jqXHR, textStatus, errorThrown));
}
}, options);
$.ajax(ajaxOpts);
},
// 通用的交互操作
actions: {
close: function (action, ebapFormIns, context ,data) {
if (action == 'close' && ebapFormIns.isChanged()) {
if (confirm("数据被修改了,是否先保存?")) {
return false;
}
}
if (window.CloseOwnerWindow) {
return window.CloseOwnerWindow(action);
} else {
window.close();
}
}
},
support: support,
miniSupport: miniSupport
};
var ebapUtils = utils;
// 如果页面超时,将页面重置到登录页
function loginOut(url) {
if (winLocSearch.length === 0 && win == win.parent) {
win.location.herf = utils.prefixPath(url);
} else if (winLocSearch.length === 0 && win != win.parent) {
win = win.top;
win.location.reload();
}
}
/*
* 登入登出控制
* */
var ebapLogin = function (options) {
var loginUrl = options.url || '/a/login';
var self = {
out: function() {
loginOut(loginUrl);
}
}
return self;
}
// 集合模块
var ebapSameModules = function (options) {
var parseOBK = ebapUtils.getAllOptions(options);
var allModules = {};
var baseFields = {}
parseOBK(['ids', 'count','names', 'mType', 'allOptions'], function(ids, count, names, mType, allOptions) {
if (!ids) {
for (var ic = 0; ic < count; ic++) {
baseFields['id'] = id;
baseFields['key'] = mType;
baseFields = $.extend(true, allOptions && allOptions[i] || $.extend(options,{
created: null,
mounted: null,
deps: []
}), baseFields);
allModules[names[i] || i] = utils.get(baseFields);
baseFields = {};
}
} else {
$.each(ids, function (i,id) {
baseFields['id'] = id;
baseFields['key'] = mType;
baseFields = $.extend(true, allOptions && allOptions[i] || $.extend(options,{
created: null,
mounted: null,
deps: []
}), baseFields);
allModules[names[i] || i] = utils.get(baseFields);
baseFields = {};
});
}
})
var self = {
get: function (name) {