-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMinQuery.1.0.2.js
More file actions
3933 lines (3747 loc) · 121 KB
/
MinQuery.1.0.2.js
File metadata and controls
3933 lines (3747 loc) · 121 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
/*!
* MinQuery for Wechat Min-App Development JavaScript Library v1.0.2
* https://github.com/JasonDRZ/MinQuery
*
* Copyright 2016, 2017 JasonDRZ.
* Released under the MIT license
*
* Date: 2017-4-15 16.21
*/
// 框架配置项
const $mq_config = {
pageEvents: "onLoad,onReady,onShow,onHide,onUnload,onPullDownRefresh,onReachBottom,onShareAppMessage".split(","),
appEvents: "onLaunch,onShow,onError,onHide".split(","),
inherentStaticKeys: {
"$id": ["$id", "To store element,whitch selected by id!"],
"$cs": ["$cs", "To store element,whitch selected by data-min-class!"],
"$window": ["$window", "To store system infomation."],
"$data": ["$data", "To store custom isolate data!"],
"$servers": ["$servers", "To store global server configuration!"],
// 固有事件处理函数标识
"$bind": ["$bind", "A unified bind[event] handler."],
"$catch": ["$catch", "A unified catch[event] handler."],
// 元素固有操作属性标识
"$class": ["$class", "To manage the element class string! Access method: $id/$cs.elementID/mClass.$class"],
"$hoverClass": ["$hoverClass", "To manage the element hover-class string! Access method: $id/$cs.elementID/mClass.$hoverClass"],
"$attr": ["$attr", "To manage the element multiple attributes value! Access method: $id/$cs.elementID/mClass.$attr.disabled;"],
"$cf": ["$cf", "To manage the Min App View Plugin's configuration! Access method: $id/$cs.elementID/mClass.$attr.disabled;"],
"$style": ["$style", "To manage the element style string! Access method: $id/$cs.elementID/mClass.$style;"],
"$cssAnimation": ["$cssAnimation", "To manage the element css animation string! Access method: $id/$cs.elementID/mClass.$cssAnimation;"],
"$data": ["$data", "To manage the element multiple custom data object! Access method: $id/$cs.elementID/mClass.$data.imageSrc;"],
"$children": ["$children", "To mark children elements,whitch are wraped by this element! Not recommend to access!"],
"$animation": ["$animation", "To manage the element animation object!Access method: $id/$cs.elementID/mClass.$animation;"],
"$text": ["$text", "To manage the element text string! Access method: $id/$cs.elementID/mClass.$text"],
"$events": ["$events", "To manage the element events bank route! Not recommend to access!"],
"$selectorType": "To cache the element selector type!",
"$selectorName": "To cache the element selector name!"
},
selectorsBank: {
// 挂载到data对象上的固有属性选择器
// [selector,hasEvent,eventsString[Separated by commas!]]
"#": ["$id", true, "all"],
".": ["$cs", true, "all"],
"*": ["$all", true, "all"],
"window": ["$window", false],
"data": ["$data", true, "change"],
// 获取当前页面实例对象
"page": ["$page", true, "load,ready,show,hide,unload,pulldownrefresh,reachbottom,shareappmessage"],
// 获取App初始化数据
"app": ["$app", true, "launch,show,error,hide"]
},
// 元素固有操作属性初始化
getElementInitialData() {
// 使用函数进行对象返回,防止页面之间的对象污染
return {
"$selectorType": "",
"$selectorName": "",
"$class": "",
"$hoverClass": "",
"$attr": {},
"$cf": {},
"$style": "",
"$data": {},
"$children": [],
"$cssAnimation": "",
"$animation": undefined,
"$events": {
// "bind": {
// "tap": ["$id.element", "bind.tap"]
// },
// "catch": {
// "tap": ["$id.element", "catch.tap"]
// }
}
}
}
};
const wxLaunchScene = {
'1001': [1001, '发现栏小程序主入口'],
'1005': [1005, '顶部搜索框的搜索结果页'],
'1006': [1006, '发现栏小程序主入口搜索框的搜索结果页'],
'1007': [1007, '单人聊天会话'],
'1008': [1008, '群聊会话'],
'1011': [1011, '扫描二维码'],
'1014': [1014, '小程序模版消息'],
'1020': [1020, '公众号 profile 页相关小程序列表'],
'1022': [1022, '聊天顶部置顶小程序入口'],
'1023': [1023, '安卓系统桌面图标'],
'1024': [1024, '小程序 profile 页'],
'1025': [1025, '扫描一维码'],
'1028': [1028, '我的卡包'],
'1029': [1029, '卡券详情页'],
'1035': [1035, '公众号自定义菜单'],
'1036': [1036, 'App 分享消息卡片'],
'1042': [1042, '添加好友搜索框的搜索结果页'],
'1043': [1043, '公众号模板消息'],
};
// 微信小程序原生接口支持,不支持组件接口
const wxMethodsParamsConfig = [{
name: "request",
param_def: [['url']],
param_nor: [['data', 'object|string'], ['header', 'object', {
'content-type': 'application/json'
}], ['method'], ['dataType', 'string', 'json']],
agent_call: function (wxMethod, options) {
// 用于支持用户小写输入
!!options && !!options.method && (options.method = options.method.toUpperCase());
// 加入设置的apiUrl头
options.url = autoMendServer(options.url, 'ajaxServer');
wxMethod(options);
}
}, {
// 文件上传、下载
// 方法名称
name: 'uploadFile',
// 必填参数,或者说支持快捷设置的参数,最后多一个config参数用于统一设置选填参数
param_def: [['url'], ['filePath'], ['name']],
// 选填参数
param_nor: [['header', 'object'], ['formData', 'object']],
agent_call: function (wxMethod, options) {
// 加入设置的apiUrl头
options.url = autoMendServer(options.url, 'uploadServer');
wxMethod(options);
}
}, {
name: 'downloadFile',
param_def: [['url']],
param_nor: [['header', 'object']],
agent_call: function (wxMethod, options) {
// 加入设置的apiUrl头
options.url = autoMendServer(options.url, 'downloadServer');
wxMethod(options);
}
}, {
// webSocket
name: 'connectSocket',
param_def: [['url']],
param_nor: [['data', 'object'], ['header', 'object'], ['method']],
agent_call: function (wxMethod, options) {
// 加入设置的apiUrl头
options.url = autoMendServer(options.url, 'socketServer');
wxMethod(options);
}
}, {
// 只有名称的则直接返回传入参数后的方法
name: 'onSocketOpen'
}, {
name: 'onSocketError'
}, {
name: 'sendSocketMessage',
// 多类型支持
param_def: [['data', 'string|uint8array']],
param_nor: []
}, {
name: 'onSocketMessage'
}, {
name: 'closeSocket'
}, {
name: 'onSocketClose'
}, {
// 图片
name: 'chooseImage',
param_def: [['count', 'number']],
param_nor: [['sizeType', 'array'], ['sourceType', 'array']]
}, {
name: 'previewImage',
param_def: [['urls', 'array']],
param_nor: [['current']]
}, {
name: 'getImageInfo',
param_def: [['src']],
param_nor: []
}, {
// 录音
name: 'startRecord',
param_def: [],
param_nor: []
}, {
name: 'stopRecord',
param_def: [['delay', 'number']],
agent_call: function (wxMethod, options) {
setTimeout(function () {
delete options.delay;
wxMethod(options);
}, options.delay ? options.delay : 0);
}
}, {
// 音频播放
name: 'playVoice',
param_def: [['filePath']],
param_nor: []
}, {
name: 'pauseVoice'
}, {
name: 'stopVoice',
param_def: [['delay', 'number']],
agent_call: function (wxMethod, options) {
setTimeout(function () {
delete options.delay;
wxMethod(options);
}, options.delay ? options.delay : 0);
}
}, {
// 音乐播放控制
name: 'getBackgroundAudioPlayerState',
param_def: [],
param_nor: []
}, {
name: 'playBackgroundAudio',
param_def: [['dataUrl']],
param_nor: [['title'], ['coverImgUrl']]
}, {
name: 'pauseBackgroundAudio'
}, {
name: 'seekBackgroundAudio',
param_def: [['position']],
param_nor: []
}, {
name: 'stopBackgroundAudio'
}, {
name: 'onBackgroundAudioPlay'
}, {
name: 'onBackgroundAudioPause'
}, {
name: 'onBackgroundAudioStop'
}, {
// 选择视频
name: 'chooseVideo',
param_def: [],
param_nor: [['sourceType', 'array'], ['maxDuration', 'number'], ['camera']]
}, {
// 文件
name: 'saveFile',
param_def: [['tempFilePath']],
param_nor: []
}, {
name: 'getSavedFileList',
param_def: [],
param_nor: []
}, {
name: 'getSavedFileInfo',
param_def: [['filePath']],
param_nor: []
}, {
name: 'removeSavedFile',
param_def: [['filePath']],
param_nor: []
}, {
name: 'openDocument',
param_def: [['filePath']],
param_nor: []
}, {
// 数据缓存
name: 'setStorage',
param_def: [['key'], ['data', 'string|object']],
param_nor: []
}, {
name: 'setStorageSync'
}, {
name: 'getStorage',
param_def: [['key']],
param_nor: []
}, {
name: 'getStorageSync'
}, {
name: 'getStorageInfo',
param_def: [],
param_nor: []
}, {
name: 'getStorageInfoSync'
}, {
name: 'removeStorage',
param_def: [['key']],
param_nor: []
}, {
name: 'removeStorageSync'
}, {
name: 'clearStorage'
}, {
name: 'clearStorageSync'
}, {
// 位置信息
name: 'getLocation',
param_def: [['type']],
param_nor: []
}, {
name: 'chooseLocation',
param_def: [],
param_nor: []
}, {
name: 'openLocation',
param_def: [['latitude', 'number'], ['longitude', 'number']],
param_nor: [['scale', 'number'], ['name'], ['address']]
}, {
// 设备信息
name: 'getSystemInfo',
param_def: [],
param_nor: []
}, {
name: 'getSystemInfoSync'
}, {
name: 'getNetworkType',
param_def: [],
param_nor: []
}, {
name: 'onNetworkStatusChange'
}, {
name: 'onAccelerometerChange'
}, {
name: 'startAccelerometer',
param_def: [],
param_nor: []
}, {
name: 'stopAccelerometer',
param_def: [],
param_nor: []
}, {
name: 'onCompassChange'
}, {
name: 'startCompass',
param_def: [],
param_nor: []
}, {
name: 'stopCompass',
param_def: [['delay', 'number']],
param_nor: [],
agent_call: function (wxMethod, options) {
setTimeout(function () {
delete options.delay;
wxMethod(options);
}, options.delay ? options.delay : 0);
}
}, {
name: 'makePhoneCall',
param_def: [['phoneNumber']],
param_nor: []
}, {
name: 'scanCode',
param_def: [],
param_nor: []
}, {
name: 'setClipboardData',
param_def: [['data']],
param_nor: []
}, {
name: 'getClipboardData',
param_def: [],
param_nor: []
}, {
// 蓝牙设置
name: 'openBluetoothAdapter',
param_def: [],
param_nor: []
}, {
name: 'closeBluetoothAdapter',
param_def: [],
param_nor: []
}, {
name: 'getBluetoothAdapterState',
param_def: [],
param_nor: []
}, {
name: 'onBluetoothAdapterStateChange'
}, {
name: 'startBluetoothDevicesDiscovery',
param_def: [['services', 'array']],
param_nor: []
}, {
name: 'stopBluetoothDevicesDiscovery',
param_def: [],
param_nor: []
}, {
name: 'getBluetoothDevices',
param_def: [['services', 'array']],
param_nor: []
}, {
name: 'onBluetoothDeviceFound'
}, {
name: 'createBLEConnection',
param_def: [['deviceId']],
param_nor: []
}, {
name: 'closeBLEConnection',
param_def: [['deviceId']],
param_nor: []
}, {
name: 'onBLEConnectionStateChanged'
}, {
name: 'getBLEDeviceServices',
param_def: [['deviceId']],
param_nor: []
}, {
name: 'getBLEDeviceCharacteristics',
param_def: [['deviceId'], ['serviceId']],
param_nor: []
}, {
name: 'readBLECharacteristicValue',
param_def: [['deviceId'], ['serviceId'], ['characteristicId']],
param_nor: []
}, {
name: 'writeBLECharacteristicValue',
param_def: [['deviceId'], ['serviceId'], ['characteristicId'], ['value', 'uint8array']],
param_nor: []
}, {
name: 'notifyBLECharacteristicValueChanged',
param_def: [['deviceId'], ['serviceId'], ['characteristicId'], ['state', 'boolean']],
param_nor: []
}, {
name: 'onBLECharacteristicValueChange'
}, {
// 交互反馈
name: 'showToast',
param_def: [['title']],
param_nor: [['icon'], ['image'], ['duration', 'number'], ['mask', 'boolean']]
}, {
name: 'showLoading',
param_def: [['title']],
param_nor: [['mask', 'boolean']]
}, {
name: 'hideToast',
param_def: [['delay', 'number']],
// 使用param_call时,传入的参数将全部传入到该回调中
agent_call: function (wxMethod, options) {
setTimeout(function () {
delete options.delay;
wxMethod(options);
}, options.delay ? options.delay : 0);
}
}, {
name: 'hideLoading',
param_def: [['delay', 'number']],
// 使用param_call时,传入的参数将全部传入到该回调中
agent_call: function (wxMethod, options) {
setTimeout(function () {
delete options.delay;
wxMethod(options);
}, options.delay ? options.delay : 0);
}
}, {
name: 'showModal',
param_def: [['title'], ['content']],
param_nor: [['showCancel', 'boolean'], ['cancelText'], ['cancelColor'], ['confirmText'], ['confirmColor']]
}, {
name: 'showActionSheet',
param_def: [['itemList','array']],
param_nor: [['itemColor']]
}, {
// 设置导航条
name: 'setNavigationBarTitle',
param_def: [['title']],
param_nor: []
}, {
name: 'showNavigationBarLoading'
}, {
name: 'hideNavigationBarLoading'
}, {
// 导航
name: 'navigateTo',
param_def: [['url']],
param_nor: [],
agent_call: function (wxMethod, options) {
// 自动补全本地路径
options.url = smartToCompleteLocalPath(options.url);
wxMethod(options);
}
}, {
name: 'redirectTo',
param_def: [['url']],
param_nor: [],
agent_call: function (wxMethod, options) {
// 自动补全本地路径
options.url = smartToCompleteLocalPath(options.url);
wxMethod(options);
}
}, {
name: 'switchTab',
param_def: [['url']],
param_nor: [],
agent_call: function (wxMethod, options) {
// 自动补全本地路径
options.url = smartToCompleteLocalPath(options.url);
wxMethod(options);
}
}, {
name: 'navigateBack'
}, {
name: 'reLaunch',
param_def: [['url']],
param_nor: [],
agent_call: function (wxMethod, options) {
// 自动补全本地路径
options.url = smartToCompleteLocalPath(options.url);
wxMethod(options);
}
}, {
// 下拉刷新
name: 'stopPullDownRefresh'
}, {
// 登录
name: 'login',
param_def: [],
param_nor: []
}, {
name: 'checkSession',
param_def: [],
param_nor: []
}, {
// 获取用户信息
name: 'getUserInfo',
param_def: [['withCredentials', 'boolean']],
param_nor: []
}, {
// 微信支付
name: 'requestPayment',
param_def: [['timeStamp'], ['nonceStr'], ['package'], ['signType'], ['paySign']],
param_nor: []
}, {
// 收货地址
name: 'chooseAddress',
param_def: [],
param_nor: []
}, {
// 卡券
name: 'addCard',
param_def: [['cardList', 'array']],
param_nor: []
}, {
name: 'openCard',
param_def: [['cardList', 'array']],
param_nor: []
}, {
// 设置
name: 'openSetting',
param_def: [],
param_nor: []
}, {
// Buffer操作
name: 'base64ToArrayBuffer'
}, {
name: 'arrayBufferToBase64'
}];
// MinQuery 工具方法及变量
// 页面数据操作主体
let
// version
version = "2.1.2",
arr = [],
slice = arr.slice,
concat = arr.concat,
push = arr.push,
indexOf = arr.indexOf,
class2type = {},
// 用于初始化某一类型的对象
typeInitial = {},
toString = class2type.toString,
hasOwn = class2type.hasOwnProperty,
rtrim = /\s/g;
// 生成类型字典
let _classTypeInitial = [false, 0, '', function () { }, [], Date.now(), new RegExp(), {}, new Error(), 0];
("Boolean Number String Function Array Date RegExp Object Error Uint8Array".split(" ")).forEach(function (name, i) {
let _l_name = name.toLowerCase();
class2type["[object " + name + "]"] = _l_name;
typeInitial[_l_name] = _classTypeInitial[i];
});
let debugMode = false,errorHandler;
// MinQuery 错误事件捕捉器
const $errorCarry = function (context,fn) {
let _fn_ret,args = [].slice.call(arguments, 2);
if (debugMode) {
try {
_fn_ret = fn.apply(context? context : null, args);
} catch (e) {
typeof errorHandler == 'function' ? errorHandler(e) : console.error(e);
}
} else _fn_ret = fn.apply(context? context : null, args);
return _fn_ret;
}
let _$ = {
error: function (msg) {
console.error(msg);
},
noop: function () { },
isFunction: function (obj) {
return _$.type(obj) === "function";
},
isArraylike: function (obj) {
let length = obj.length,
type = _$.type(obj);
if (type === "function") {
return false;
}
return type === "array" || length === 0 ||
typeof length === "number" && length > 0 && (length - 1) in obj;
},
isArray: Array.isArray,
isNumeric: function (obj) {
// parseFloat NaNs numeric-cast false positives (null|true|false|"")
// ...but misinterprets leading-number strings, particularly hex literals ("0x...")
// subtraction forces infinities to NaN
// adding 1 corrects loss of precision from parseFloat (#15100)
return !_$.isArray(obj) && (obj - parseFloat(obj) + 1) >= 0;
},
isPlainObject: function (obj) {
// Not plain objects:
// - Any object or value whose internal [[Class]] property is not "[object Object]"
if (_$.type(obj) !== "object") {
return false;
}
if (obj.constructor &&
!hasOwn.call(obj.constructor.prototype, "isPrototypeOf")) {
return false;
}
// If the function hasn't returned already, we're confident that
// |obj| is a plain object, created by {} or constructed with new Object
return true;
},
isString: function (str) {
return typeof str === 'string';
},
isEmpty: function (str) {
return typeof str === 'undefined' || str === null || _$.trim(str + "") == "";
},
isUndefined: function (obj) {
return typeof obj === 'undefined';
},
isEmptyObject: function (obj) {
let name;
for (name in obj) {
return false;
}
return true;
},
type: function (obj) {
if (obj == null) {
return obj + "";
}
// Support: Android<4.0, iOS<6 (functionish RegExp)
return typeof obj === "object" || typeof obj === "function" ?
class2type[toString.call(obj)] || "object" :
typeof obj;
},
// 数据镜像:将已有数据镜像还原到某一原状态;
recoveryObject: function (source, mirror, deep) {
let isArray, s;
// 支持对象数据恢复,deep操作时支持数组
if (_$.isPlainObject(source) || (deep && _$.isArray(source))) {
for (s in source) {
// 均存在这恢复镜像数据到源数据
if (!(s in source) && !(s in mirror)) {
if (deep) {
// 进行深度恢复操作
if (_$.isPlainObject(source[s]) || (deep && _$.isArray(source[s]))) {
_$.recoveryObject(source[s], mirror[s], deep);
} else {
// 非对象或数组,则进行赋值操作
source[s] = mirror[s];
}
} else {
// 非深度恢复,则进行赋值操作
source[s] = mirror[s]
}
} else if (!(s in source) && s in mirror) {
// 如果镜像数据不存在,而源数据存在,则删除源数据
delete source[s];
} else {
// 如果镜像数据存在,源数据不存在,则恢复
source[s] = mirror[s];
}
}
}
},
// args is for internal usage only
each: function (obj, callback, args) {
let value,
i = 0,
length = obj.length,
isArray = _$.isArraylike(obj);
if (args) {
if (isArray) {
for (; i < length;) {
value = callback.apply(obj[i++], args);
if (value === false) {
break;
}
}
} else {
for (i in obj) {
value = callback.apply(obj[i], args);
if (value === false) {
break;
}
}
}
// A special, fast, case for the most common use of each
} else {
if (isArray) {
for (; i < length;) {
value = callback.call(obj[i], i, obj[i++]);
if (value === false) {
break;
}
}
} else {
for (i in obj) {
value = callback.call(obj[i], i, obj[i]);
if (value === false) {
break;
}
}
}
}
return obj;
},
trim: function (text) {
return text == null ?
"" :
(text + "").replace(rtrim, "");
},
// results is for internal usage only
makeArray: function (arr, results) {
let ret = results || [];
if (arr != null) {
if (_$.isArraylike(Object(arr))) {
_$.merge(ret,
typeof arr === "string" ? [arr] : arr
);
} else {
push.call(ret, arr);
}
}
return ret;
},
inArray: function (elem, arr, i) {
return arr == null ? -1 : indexOf.call(arr, elem, i);
},
merge: function (first, second) {
let len = +second.length,
j = 0,
i = first.length;
for (; j < len; j++) {
first[i++] = second[j];
}
first.length = i;
return first;
},
grep: function (elems, callback, invert) {
let callbackInverse,
matches = [],
i = 0,
length = elems.length,
callbackExpect = !invert;
// Go through the array, only saving the items
// that pass the validator function
for (; i < length; i++) {
callbackInverse = !callback(elems[i], i);
if (callbackInverse !== callbackExpect) {
matches.push(elems[i]);
}
}
return matches;
},
// arg is for internal usage only
map: function (elems, callback, arg) {
let value,
i = 0,
length = elems.length,
isArray = _$.isArraylike(elems),
ret = [];
// Go through the array, translating each of the items to their new values
if (isArray) {
for (; i < length; i++) {
value = callback(elems[i], i, arg);
if (value != null) {
ret.push(value);
}
}
// Go through every key on the object,
} else {
for (i in elems) {
value = callback(elems[i], i, arg);
if (value != null) {
ret.push(value);
}
}
}
// Flatten any nested arrays
return concat.apply([], ret);
},
// 短横线[或其他连接符]转驼峰
toHump: function (str, symbal) {
let reg = new RegExp((symbal ? symbal : "-") + "(\w)", 'g');
return str.replace(reg, function ($0, $1) {
return $1.toUpperCase();
});
},
// 驼峰转中横线或任意链接符
humpToAny: function (str, symbal) {
return str.replace(/([A-Z])/g, (symbal ? symbal : "-") + "$1").toLowerCase();
},
// 格式化日期,支持时间戳和Date实例
formatDate: function (date, fmt) {
//author: meizz,jason
if (date instanceof Date || typeof date === 'number') {
typeof date === 'number' && (date = new Date(date));
} else {
console.error("The formatDate first param must be an Date() instance or timestamp!");
return date;
}
let o = {
"m+": date.getMonth() + 1, //月份
"d+": date.getDate(), //日
"h+": date.getHours(), //小时
"i+": date.getMinutes(), //分
"s+": date.getSeconds(), //秒
"q+": Math.floor((date.getMonth() + 3) / 3), //季度
"S": date.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
for (let k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
},
// 当前时间戳
now: Date.now
}, _$_proto_ = {
};
// 简易原型继承方法,框架外部使用时仅能做对象浅层继承
const $extend = function () {
let options, name, src, copy, copyIsArray, clone,
target = arguments[0] || {},
i = 1,
length = arguments.length,
deep = false;
// Handle a deep copy situation
if (typeof target === "boolean") {
deep = target;
// Skip the boolean and the target
target = arguments[i] || {};
i++;
}
// Handle case when target is a string or something (possible in deep copy)
if (typeof target !== "object" && !_$.isFunction(target)) {
target = {};
}
// Extend MinQuery itself if only one argument is passed
if (i === length) {
target = this;
i--;
}
for (; i < length; i++) {
// Only deal with non-null/undefined values
if ((options = arguments[i]) != null) {
// Extend the base object
for (name in options) {
src = target[name];
copy = options[name];
// Prevent never-ending loop
if (target === copy) {
continue;
}
// Recurse if we're merging plain objects or arrays
if (deep && copy && (_$.isPlainObject(copy) || (copyIsArray = _$.isArray(copy)))) {
if (copyIsArray) {
copyIsArray = false;
clone = src && _$.isArray(src) ? src : [];
} else {
clone = src && _$.isPlainObject(src) ? src : {};
}
// Never move original objects, clone them
target[name] = $extend(deep, clone, copy);
// Don't bring in undefined values
} else if (copy !== undefined) {
target[name] = copy;
}
}
}
}
// Return the modified object
return target;
};
// 工具方法
// 支持对象设置及单数据键值设置的数据查询引擎
const $analysisDataEngine = function (sourceData, keyString, keyValue) {
// 如果传入的是data 查询的 key 并且使用call方法调用
if (_$.isString(sourceData)) {
sourceData = this[sourceData];
}
if (sourceData) {
// 如果不存在则返回数据源
if (!keyString) {
return sourceData;
}
// 是否获取指定键值
let dataRequire = false, obj = {};
if (_$.isString(keyString) && _$.isUndefined(keyValue)) {
dataRequire = true;
obj[keyString] = {};
}
// 如果关闭获取指定键值下,keyString不是数据对象时,则报错
if ((!dataRequire && _$.isUndefined(keyValue) && !_$.isPlainObject(keyString)) || (!_$.isUndefined(keyValue) && !_$.isString(keyString))) {
console.error(`AnalysisDataEngine params error!`, keyString, keyValue);
return sourceData;
}
// 复制object
if (!dataRequire) {
if (_$.isPlainObject(keyString)) {
obj = keyString;
} else
obj[keyString] = keyValue;
}
// dataRequire模式,不存在则返回false,并终止;
// 非dataRequire模式,将自动初始化对象的值为指定的objInit值
let analyType = function (_data, key, objInit) {
if (!_data[key]) {
if (dataRequire) {
// undefindData(key, _data);
return false;
} else {
_data[key] = objInit
return true;
}
} else {
return true;
}
}
let dotKeys, arrKeys, eackKey, noArrKey, value, l, d;
// 对象循环
dataEach: for (l in obj) {
let _rd = sourceData;
// 优先筛选dot key
dotKeys = l.split(".");
// 存储当前字段数据
value = obj[l];
// 循环查询当前dotkey 和 arrkey对象
// 数组循环
dotKeyEach: for (d = 0; d < dotKeys.length; d++) {
eackKey = dotKeys[d];
// 忽略空键,直接进入下一阶段解析
if (eackKey.replace(/\s/g, "") === "") {
continue dotKeyEach;