arisu.js 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/arisu.js ADDED
@@ -0,0 +1,4668 @@
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if(typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory();
4
+ else if(typeof define === 'function' && define.amd)
5
+ define([], factory);
6
+ else if(typeof exports === 'object')
7
+ exports["a"] = factory();
8
+ else
9
+ root["a"] = factory();
10
+ })(globalThis, () => {
11
+ return /******/ (() => { // webpackBootstrap
12
+ /******/ "use strict";
13
+ /******/ // The require scope
14
+ /******/ var __webpack_require__ = {};
15
+ /******/
16
+ /************************************************************************/
17
+ /******/ /* webpack/runtime/define property getters */
18
+ /******/ (() => {
19
+ /******/ // define getter functions for harmony exports
20
+ /******/ __webpack_require__.d = (exports, definition) => {
21
+ /******/ for(var key in definition) {
22
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
23
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
24
+ /******/ }
25
+ /******/ }
26
+ /******/ };
27
+ /******/ })();
28
+ /******/
29
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
30
+ /******/ (() => {
31
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
32
+ /******/ })();
33
+ /******/
34
+ /******/ /* webpack/runtime/make namespace object */
35
+ /******/ (() => {
36
+ /******/ // define __esModule on exports
37
+ /******/ __webpack_require__.r = (exports) => {
38
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
39
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
40
+ /******/ }
41
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
42
+ /******/ };
43
+ /******/ })();
44
+ /******/
45
+ /************************************************************************/
46
+ var __webpack_exports__ = {};
47
+ // ESM COMPAT FLAG
48
+ __webpack_require__.r(__webpack_exports__);
49
+
50
+ // EXPORTS
51
+ __webpack_require__.d(__webpack_exports__, {
52
+ b: () => (/* reexport */ utils),
53
+ "default": () => (/* binding */ main),
54
+ m: () => (/* binding */ Main),
55
+ u: () => (/* reexport */ utils_namespaceObject)
56
+ });
57
+
58
+ // NAMESPACE OBJECT: ./src/js/utils.js
59
+ var utils_namespaceObject = {};
60
+ __webpack_require__.r(utils_namespaceObject);
61
+ __webpack_require__.d(utils_namespaceObject, {
62
+ AeLoader: () => (AeLoader),
63
+ BtnEf: () => (BtnEf),
64
+ Flash: () => (Flash),
65
+ GoTop: () => (GoTop),
66
+ HoverDir: () => (HoverDir),
67
+ IAccordion: () => (IAccordion),
68
+ IList: () => (IList),
69
+ IPagination: () => (IPagination),
70
+ ItemCount: () => (ItemCount),
71
+ LineEffect: () => (LineEffect),
72
+ NiceSelect: () => (NiceSelect),
73
+ PopoverSearch: () => (PopoverSearch),
74
+ SubmitFlag: () => (SubmitFlag),
75
+ b: () => (base),
76
+ "default": () => (utils)
77
+ });
78
+
79
+ ;// CONCATENATED MODULE: ./src/js/base.js
80
+
81
+ /* ========================================================================
82
+ * 常用JS方法
83
+ * 2024年6月4日 21:41:04
84
+ * ========================================================================
85
+
86
+ // 导入
87
+ import b from './base'
88
+
89
+ // 1.1 基础方法
90
+ // 添加class
91
+ b("#id").addClass('test')
92
+ // 是否包含某个class
93
+ console.log(b("#id").hasClass('test'))//true
94
+ // 删除class
95
+ b("#id").removeClass('test');
96
+ // 切换class
97
+ b('.myclass').toggleClass('hi').toggleClass('hi')//加入再删除
98
+ // 选择不包含某个选择器的标签
99
+ console.log(b('div').not('.myclass')); //选择除了.myclass的div
100
+ // 判断当前选择器是否为某种标签,或者某状态如, :disabled
101
+ console.log(b('#movetest').is('button'))
102
+ console.log(b('#movetest').is(':disabled'))
103
+ // 返回祖节点,不传参数返回自己
104
+ console.log(b('.myspan').closest('div.myclass').html())
105
+ // 当前标签的下一个标签,如果是class多个标签则则包含第一个class开始到最后一个class的下一个标签
106
+ console.log(b('.myclass').next());
107
+ // 当前标签之后的所有标签,如果是class则从第一个class开始算
108
+ console.log($('.myclass').nextAll())
109
+ // 当前标签的上一个标签,如果是class多个标签则则包含倒数第二个class开始到第一个class的上一个标签
110
+ console.log(b('.myclass').prev());
111
+ // 当前标签之前的所有标签,如果是class则从最后一个class开始算
112
+ console.log($('.myclass').prevAll())
113
+ // 返回只包含第一个元素的base类
114
+ console.log($('.myclass').first());
115
+ // 查询当前对象下的元素
116
+ console.log(b('body').find('.myclass'))
117
+ // 查找父类标签
118
+ b.l(b("#id").parent());
119
+ // 查找祖先标签
120
+ b.l(b("#id").parents("div"));
121
+ // 返回兄弟节点
122
+ console.log(b("#id").siblings());
123
+ // 返回一级子元素,多个对象则为多个子元素
124
+ b.l(b(".ce-txt").children());
125
+ // 返回元素下标
126
+ console.log(b("#id").index());
127
+ // 事件绑定
128
+ b("#id").on("focus", () => {...
129
+ // 点击事件
130
+ b(".e2").click(function() { ...
131
+ // 焦点事件
132
+ b(".e2").focus(function() { ...
133
+ // 用于监听<input>、<select>和<textarea>元素值的变化
134
+ b('.myInput').change((e) => { console.log(e.currentTarget.value); })
135
+ // 主动触发事件
136
+ trigger('click', { message: 'Hello, World!' });
137
+ // 删除标签
138
+ b("#id").remove();
139
+ // data属性绑定设置
140
+ <div id="id" data-name="arisu">data测试</div>
141
+ b("#id").data('age', '99');
142
+ console.log(b("#id").data('age')); //99
143
+ console.log(b("#id").data('name')); //arisu
144
+ // attr、removeAttr页面标签属性增删
145
+ b("#id").attr('sex', 'man').removeAttr('data-name');
146
+ // 当前元素坐标,eg:{ 3633, 180 }
147
+ b("#id").offset();
148
+ // 获取滚动条位置距离页面顶部的长度
149
+ console.log(b(window).scrollTop());
150
+ // 获取当前页面真实高度
151
+ b(window).height()
152
+ // 获取或者设置输入框下拉框等标签中的值
153
+ b('.myInput').val('test').attr('data-c', 'd')
154
+ // 样式修改
155
+ b("#id").css('font-size','2rem').text('hhh')
156
+ // 获取变更dom文本信息
157
+ console.log(b("#id").text());
158
+ console.log(b("#id").text('载入中...'));
159
+ // 设置或获取html代码
160
+ console.log(b('.myclass').html('<h3>这是一个h3标签</h3>').html());
161
+ // 在当前选择器后插入代码
162
+ b('.myclass').after('<p>after加入P</p>');
163
+ // 在当前选择器内尾部加入代码
164
+ b('.myclass').append('<p>append加入P</p>').append('<span>append加入span</span>');
165
+ // 在当前选择器内起始位置加入代码
166
+ b("#id").prepend('<p>插入到内部头部</p>')
167
+ // 隐藏元素
168
+ b('.myclass').hide().css('font-size', '3rem');
169
+ // 显示元素
170
+ b('.myclass').show()
171
+ // 标签消失高度变0的关闭动画
172
+ b('.myElement').slideUp(500, function() { console.log('动画完成'); });
173
+ // 标签显示高度变复原的打开动画
174
+ b('.myElement').slideDown(500, function() { console.log('动画完成'); });
175
+ // 标签打开关闭切换
176
+ b('.myElement').slideToggle(500, function() { console.log('动画完成'); });
177
+
178
+ // 1.2 页面基础方法扩展
179
+ // 全选全清,<input type="checkbox" class="myCheckbox"><input type="checkbox" class="test">
180
+ b(".myCheckbox").checkAll('.test');
181
+ // 反选
182
+ b('#be-reverse-check').checkReverse('.be-check')
183
+ // 数字特效递增动画
184
+ b("#f").numStep({...
185
+ // 背景滚动动画
186
+ b(".ce-bg-ef").scrollBG({speed: 6});
187
+ // 点击切换激活项
188
+ b(".my-btn").setActive();
189
+ // 全屏loading
190
+ b('body').loading();
191
+ b("body").loading("complete");
192
+
193
+
194
+ // 2. 静态方法
195
+ // 2.1 基础静态方法
196
+ // 参数继承覆盖
197
+ b.extend( newOptions, defaults )
198
+ // 四舍五入,保留n位
199
+ b.toRound(3.14159, 2); //3.14
200
+ // 判断变量是否为空
201
+ if(b.isNull(变量)) {
202
+ // 如果为空设置默认值
203
+ b.setDefault(data.id, 0);
204
+ // 获取两个数组中的相同值
205
+ b.same([1,2], [7,9,4,2,5,6,1]) //[1, 2]
206
+ // 获取两个数组中的不相同值
207
+ b.different([1,2], [7,9,4,2,5,6,1]) //[7, 9, 4, 5, 6]
208
+ // 判断字符串是否为html标签,如<li></li><div></div><img/>返回true
209
+ console.log(b.isHtmlTag('<img />')); // true
210
+ // 判断变量是否为对象
211
+ console.log(b.isObject(custom));
212
+ // 允许插件扩展plugin静态方法
213
+ // 普通方法
214
+ function test(p1, p2) { console.log(this, p1, p2) } //Base... 3 4
215
+ Base.plugin('test', test);
216
+ b(".myclass").test(3,4)
217
+ // 插件,支持扩展插件,声明的插件或者方法调用不方便:new Base("#id").myPlugin(),直接使用b['test'] = test;绑定
218
+ +function(b) {
219
+ function myPlugin(options) {
220
+ this.each((element) => { b.l(element); });
221
+ return this;
222
+ }
223
+ b.fn.myPlugin = myPlugin;
224
+ }(Base);
225
+ // ajax异步请求
226
+ b.ajax({ url: "/data.json", success: (data) => { b.l(data) } })
227
+
228
+ // 2.2 页面常用方法
229
+ // 获取URL中的参数,rg: ..url?name=arisu
230
+ b.getParam("name"); //arisu
231
+ // 页面内缓慢移动,样式:html { scroll-behavior: smooth; }
232
+ b("#movetest").click((e) => { b.move("#id"); });
233
+ //字符串复杂度验证,表单验证
234
+ b.strValidation('abc123#', 3, 12);//8
235
+ // b.keys 常用键盘按钮
236
+ b.keys.enter //回车
237
+ // 常用快捷键事件绑定
238
+ b.hotkey(b.keys.enter, () => { b.l('你点击了enter') })
239
+ b.hotkey('Delete', () => { b.l('你点击了Delete') }) //b.keys没有预制的可以直接填键盘KEY
240
+ // 设置cookie
241
+ b.setCookie('username', 'JohnDoe');
242
+ // 获取cookie
243
+ console.log(b.getCookie('username')); // 输出: JohnDoe
244
+ // 删除cookie
245
+ b.removeCookie('username'); //b.getCookie('username')为null
246
+ // 数据库菜单数据生成ul列表树
247
+ const html = b.menu(data.trees, true); b('#nav-accordion').html(html) //<ul class="ce-accordion" id="nav-accordion"></ul>
248
+ // 数据库普通的数据列表转换成有层次的数组
249
+ b.l(b.menu2Tree(data.trees, 1, 1));
250
+ // 包含搜索按钮删除按钮的搜索框
251
+ b.search(function(txt) { if (txt) console.log(txt); });// 输入框文本
252
+
253
+
254
+ // 3. 其他常用方法、原生JS方法重写等
255
+ // 时间格式化
256
+ new Date().format("yyyy-MM-dd hh:mm:ss")//'2024-06-10 10:47:06'
257
+ // 数组根据下标删除扩展,返回执行完数组长度
258
+ ['a', 'b', 'c', 'd'].remove(-1);//删除最后一个元素返回3,数组为['a', 'b', 'c']
259
+ // 数组删除重复元素
260
+ [1, 2, 3, 1].unique() //[1, 2, 3]
261
+
262
+
263
+
264
+ * ======================================================================== */
265
+
266
+ class Base {
267
+
268
+ //支持new Base("div:eq(2)", ".container")、new Base(" > div", ".container")等格式选择器
269
+ constructor(selector, context) {
270
+ context = (context instanceof Base) ? context.elements[0] : (context || document);
271
+
272
+ if (typeof selector === 'string') {
273
+ if (context && typeof context === 'string') {
274
+ context = document.querySelector(context);
275
+ }
276
+ if (Base.isEqSelector(selector)) {
277
+ const ss = selector.split(':'),
278
+ htmlTag = ss[0],
279
+ eqIndexMatch = selector.match(/:eq\((\d+)\)/),
280
+ htmlIndex = parseInt(eqIndexMatch[1]);
281
+ const list = Base.contextQuerySelector(">" + htmlTag, context);
282
+ if (list.length > 0) {
283
+ this.elements = [ list[htmlIndex] ]
284
+ } else {
285
+ this.elements = [];
286
+ }
287
+ } else {
288
+ this.elements = Base.contextQuerySelector(selector, context);
289
+ }
290
+ } else if (selector instanceof NodeList || selector instanceof HTMLElement) {
291
+ this.elements = [ selector ];
292
+ } else if (selector instanceof Window) {
293
+ this.elements = [ window ];
294
+ } else if (selector !== null && typeof selector === 'object' && 'documentElement' in selector) {
295
+ this.elements = [ context ];
296
+ } else if (selector instanceof Array) {
297
+ this.elements = selector;
298
+ } else {
299
+ this.elements = [];
300
+ }
301
+ this.length = this.elements.length;
302
+ }
303
+
304
+ // length = 0
305
+
306
+ // 选择器遍历
307
+ each(callback) {
308
+ this.elements.forEach((element) => {
309
+ let index;
310
+ if (Array.isArray(this.elements)) {
311
+ index = this.elements.indexOf(element);
312
+ } else if (this.elements instanceof NodeList) {
313
+ index = Array.from(this.elements).indexOf(element);
314
+ } else {
315
+ index = -1;
316
+ }
317
+ callback(element, index);
318
+ });
319
+ return this;
320
+ }
321
+
322
+ /* ========================================================================
323
+ * 1 基础常用方法
324
+ * ======================================================================== */
325
+
326
+ // 1.1 基础方法
327
+
328
+ // 是否包含某个class
329
+ hasClass( className ) {
330
+ let result = false;
331
+ this.each((element) => {
332
+ result = element.classList.contains(className);
333
+ });
334
+ return result;
335
+ }
336
+
337
+ // 添加class
338
+ addClass(className) {
339
+ return this.each((element) => {
340
+ if (/\s/.test(className)) {
341
+ const classes = className.split(' ');
342
+ for (let i = 0; i < classes.length; i++) {
343
+ if (classes[i])
344
+ element.classList.add(classes[i]);
345
+ }
346
+ } else {
347
+ if (className)
348
+ element.classList.add(className);
349
+ }
350
+ });
351
+ }
352
+
353
+ // 删除class
354
+ removeClass(className) {
355
+ return this.each((element) => {
356
+ if (className === undefined) {
357
+ element.className = '';
358
+ } else if (className || className.length !== 0) {
359
+ if (/\s/.test(className)) {
360
+ const classes = className.split(' ');
361
+ for (let i = 0; i < classes.length; i++) {
362
+ if (classes[i])
363
+ element.classList.remove(classes[i].trim());
364
+ }
365
+ } else {
366
+ element.classList.remove(className.trim());
367
+ }
368
+ }
369
+ });
370
+ }
371
+
372
+ // 切换class
373
+ toggleClass(className) {
374
+ return this.each((element) => {
375
+ if (element.classList) {
376
+ element.classList.toggle(className);
377
+ } else {
378
+ let classes = element.className.split(/\s+/);
379
+ let existingIndex = classes.indexOf(className);
380
+ if (existingIndex >= 0) {
381
+ classes.splice(existingIndex, 1);
382
+ } else {
383
+ classes.push(className);
384
+ }
385
+ element.className = classes.join(' ');
386
+ }
387
+ })
388
+ }
389
+
390
+ // 选择不包含某个选择器的标签
391
+ not(selector) {
392
+ let excludedElements = (selector instanceof Base) ? selector.elements : Array.from(document.querySelectorAll(selector));
393
+ // if (selector instanceof Base) {
394
+ // let excludedElements = selector.elements;
395
+ // this.elements = Array.from(this.elements).filter((element) => {
396
+ // return !excludedElements.includes( element );
397
+ // });
398
+ // } else {
399
+ // let excludedElements = Array.from(document.querySelectorAll(selector));
400
+ this.elements = Array.from(this.elements).filter((element) => {
401
+ return !excludedElements.includes( element );
402
+ });
403
+ // }
404
+ return this;
405
+ }
406
+
407
+ // 判断当前选择器是否为某种标签,或者某状态如, :disabled
408
+ is(selector) {
409
+ let element = this.elements[0];
410
+ if (selector === ':visible') {
411
+ if (element.style.display === 'none' || element.style.visibility === 'hidden' ||
412
+ getComputedStyle(element).opacity === '0') {
413
+ return false;
414
+ }
415
+ } else if (selector === ':first-child') {
416
+ return element.parentNode.firstChild === element;
417
+ } else if (selector === ':last-child') {
418
+ // const parent = element.parentNode;
419
+ // for (let i = 0; i < parent.childNodes.length; i++) {
420
+ // const sibling = parent.childNodes[i];
421
+ // if (sibling.nodeType === Node.ELEMENT_NODE && sibling !== element) {
422
+ // return false; // 存在更后的兄弟元素,不是最后一个子元素
423
+ // }
424
+ // }
425
+ // return true;
426
+ const parent = element.parentNode,
427
+ children = parent.children;
428
+ return children[children.length - 1] === element;
429
+ } else {
430
+ return element.matches(selector);
431
+ }
432
+ }
433
+
434
+ // 返回父亲节点
435
+ closest(selector) {
436
+ let element = this.elements[0];
437
+
438
+ // 匹配传入的selector
439
+ const matchesSelector = element.matches || element.webkitMatchesSelector;//|| element.msMatchesSelector
440
+
441
+ // 如果元素本身匹配selector,则返回元素本身
442
+ if (matchesSelector.call(element, selector)) {
443
+ return this;
444
+ }
445
+ // 如果没有匹配,则向上遍历DOM树
446
+ let parent;
447
+ while ((parent = element.parentElement)) {
448
+ if (matchesSelector.call(parent, selector)) {
449
+ return new Base(parent);
450
+ }
451
+ element = parent;
452
+ }
453
+ return this;
454
+ }
455
+
456
+ // 当前标签的下一个标签,如果是class多个标签则则包含第一个class开始到最后一个class的下一个标签
457
+ next() {
458
+ if (this.elements.length === 1) {
459
+ return new Base(this.elements[0].nextElementSibling);
460
+ } else if (this.elements.length > 1) {
461
+ let b = new Base(this.elements[0].nextElementSibling);
462
+ this.each((element, i) => {
463
+ if (i > 1) {
464
+ b.elements.push(element)
465
+ if (i === this.elements.length - 1) {
466
+ b.elements.push( element.nextElementSibling )
467
+ }
468
+ }
469
+ })
470
+ return b;
471
+ } else {
472
+ return null;
473
+ }
474
+ }
475
+
476
+ // 当前标签之后的所有标签,如果是class则从第一个class开始算 console.log($('.myclass').nextAll())
477
+ nextAll(selector) {
478
+ // 创建一个数组来存储所有之后的兄弟节点
479
+ const nextElements = [];
480
+ let element = this.elements[0],
481
+ nextSibling = element.nextSibling,
482
+ parentElement = element.parentElement;
483
+ while (nextSibling) {
484
+ if (nextSibling.nodeType === 1) {
485
+ // 如果没有提供选择器,或者nextSibling匹配给定的选择器
486
+ if (!selector || nextSibling.matches(selector)) {
487
+ nextElements.unshift(nextSibling); // 使用unshift将元素添加到数组开头,以保持顺序
488
+ }
489
+ }
490
+ nextSibling = nextSibling.nextSibling;
491
+ if (nextSibling === null && nextElements.length === 0 && parentElement.firstChild === element) {
492
+ break;
493
+ }
494
+ }
495
+ this.elements = nextElements;
496
+ this.length = this.elements.length;
497
+ return this;
498
+ }
499
+
500
+ // 当前标签的上一个标签,如果是class多个标签则则包含第一个class开始到最后一个class的下一个标签
501
+ prev() {
502
+ if (this.elements.length === 1) {
503
+ return new Base(this.elements[0].previousElementSibling);
504
+ } else if (this.elements.length > 1) {
505
+ let b = new Base(this.elements[0].previousElementSibling);
506
+ this.each((element, i) => {
507
+ if (i > 1) {
508
+ b.elements.push(element)
509
+ if (i === this.elements.length - 1) {
510
+ b.elements.push( element.previousElementSibling )
511
+ }
512
+ }
513
+ })
514
+ return b;
515
+ } else {
516
+ return null;
517
+ }
518
+ }
519
+
520
+ // 当前标签之前的所有标签,如果是class则从最后一个class开始算
521
+ prevAll(selector) {
522
+ // 创建一个数组来存储所有之前的兄弟节点
523
+ const prevElements = [];
524
+ let element = this.elements[this.elements.length - 1],
525
+ prevSibling = element.previousSibling,
526
+ parentElement = element.parentElement;
527
+ while (prevSibling) {
528
+ if (prevSibling.nodeType === 1) {
529
+ // 如果没有提供选择器,或者prevSibling匹配给定的选择器
530
+ if (!selector || prevSibling.matches(selector)) {
531
+ prevElements.unshift(prevSibling); // 使用unshift将元素添加到数组开头,以保持顺序
532
+ }
533
+ }
534
+ prevSibling = prevSibling.previousSibling;
535
+ if (prevSibling === null && prevElements.length === 0 && parentElement.firstChild === element) {
536
+ break;
537
+ }
538
+ }
539
+ this.elements = prevElements;
540
+ this.length = this.elements.length;
541
+ return this;
542
+ }
543
+
544
+ // 返回只包含第一个元素的base类
545
+ first() {
546
+ return new Base([ this.elements[0] ]);
547
+ }
548
+
549
+ // 查询当前对象下的元素
550
+ find(context) {
551
+ if (context && context.trim() === "option:selected") {
552
+ this.each((element) => {
553
+ if (element.type === 'select-one' || element.type === 'select-multiple') {
554
+ return new Base(element.options[element.selectedIndex]);
555
+ }
556
+ });
557
+ // selectElement.options[selectElement.selectedIndex];
558
+ } else {
559
+ return new Base(context, this.elements[0]);
560
+ }
561
+ // let element = this.elements[0],
562
+ // ctx = element.querySelectorAll( context );
563
+ // if (ctx.length > 0) {
564
+ // this.elements = ctx;
565
+ // } else {
566
+ // this.elements = [ ];
567
+ // }
568
+ // return this;
569
+ //
570
+ }
571
+
572
+ // 查找父类标签
573
+ parent() {
574
+ let element = this.elements[0];
575
+ return element ? new Base(element.parentNode) : new Base();
576
+ }
577
+
578
+ // 查找祖先标签
579
+ parents(selector) {
580
+ const parents = [];
581
+ let element = this.elements[0],
582
+ parent = element.parentNode;
583
+ while (parent && parent !== document) {
584
+ if (!selector || parent.matches(selector)) {
585
+ parents.push(parent);
586
+ }
587
+ parent = parent.parentNode;
588
+ }
589
+ return new Base(parents);
590
+ }
591
+
592
+ // 返回兄弟节点console.log(b("#id").siblings());
593
+ siblings() {
594
+ let element = this.elements[0];
595
+ if (!element || !(element.nodeType === 1)) {
596
+ return new Base();
597
+ } else {
598
+ // 获取元素的父元素
599
+ let parent = element.parentNode;
600
+ if (parent) {
601
+ let siblingsArray = [];
602
+ // 遍历父元素的子节点
603
+ for (let i = 0; i < parent.childNodes.length; i++) {
604
+ let child = parent.childNodes[i];
605
+ if (child.nodeType === 1 && child !== element) {
606
+ siblingsArray.push(child);
607
+ }
608
+ }
609
+ return new Base(siblingsArray);
610
+ } else {
611
+ // 没有父元素
612
+ return new Base();
613
+ }
614
+ }
615
+ }
616
+
617
+ // 返回一级子元素
618
+ children() {
619
+ let children = [];
620
+ this.each((element) => {
621
+ for (const child in element.children) {
622
+ if (element.children.hasOwnProperty(child)) {
623
+ children.push(element.children[child]);
624
+ }
625
+ }
626
+ })
627
+ return new Base(children);
628
+ }
629
+
630
+ // 返回元素下标
631
+ index() {
632
+ const element = this.elements[0],
633
+ siblings = element.parentNode.children;
634
+ for (let i = 0; i < siblings.length; i++) {
635
+ if (siblings[i] === element) {
636
+ return i;
637
+ }
638
+ }
639
+ return -1;
640
+ }
641
+
642
+ size() {
643
+ return this.elements ? this.elements.length : 0;
644
+ }
645
+
646
+ // 事件绑定,相当于bind
647
+ on(eventType, handler) {
648
+ return this.each(function(element) {
649
+ element.addEventListener(eventType, handler);
650
+ });
651
+ }
652
+
653
+ // 事件解除绑定,只能删除指定方法
654
+ off(eventName, callback) {
655
+ return this.each(function(element) {
656
+ if (element.removeEventListener) {
657
+ if (callback) {
658
+ element.removeEventListener(eventName, callback);
659
+ } else {
660
+ }
661
+ }
662
+ });
663
+ }
664
+
665
+ // 点击事件
666
+ click(handler) {
667
+ if (typeof handler === 'function') {
668
+ this.on('click', handler);
669
+ } else {
670
+ // 如果没有参数传入,则触发元素的点击事件
671
+ this.each((el) => {
672
+ const event = new MouseEvent('click', {
673
+ bubbles: true,
674
+ cancelable: true,
675
+ view: window
676
+ });
677
+ el.dispatchEvent(event);
678
+ });
679
+ }
680
+ return this;
681
+ }
682
+
683
+ // 焦点事件
684
+ focus(handler) {
685
+ if (typeof handler === 'function') {
686
+ this.on('focus', handler);
687
+ }
688
+ return this;
689
+ }
690
+
691
+ // 用于监听<input>、<select>和<textarea>元素值的变化b('.myInput').change((e) => { console.log(e.currentTarget.value); })
692
+ change(handler) {
693
+ if (typeof handler === 'function') {
694
+ let element = this.elements[0];
695
+ if (element.addEventListener) {
696
+ // 对于现代浏览器
697
+ return this.each(function(element) {
698
+ element.addEventListener('change', handler, false);
699
+ });
700
+ } else if (element.attachEvent) {
701
+ // 对于老版本的IE浏览器
702
+ return this.each(function(element) {
703
+ element.attachEvent('onchange', callback);
704
+ });
705
+ } else {
706
+ return this.each(function(element) {
707
+ element.onchange = handler;
708
+ });
709
+ }
710
+ }
711
+ }
712
+
713
+ // 主动触发事件,trigger('click', { message: 'Hello, World!' });
714
+ trigger(eventName, eventData) {
715
+ this.each(function(element) {
716
+ let event;
717
+ try {
718
+ // 对于现代浏览器
719
+ event = new CustomEvent(eventName, {
720
+ detail: eventData,
721
+ bubbles: true,
722
+ cancelable: true
723
+ });
724
+ } catch (e) {
725
+ // 对于旧版浏览器
726
+ event = document.createEvent('CustomEvent');
727
+ event.initCustomEvent(eventName, true, true, eventData);
728
+ }
729
+ element.dispatchEvent(event);
730
+ });
731
+ }
732
+
733
+ // 删除标签
734
+ remove() {
735
+ return this.each((element) => {
736
+ element.parentNode.removeChild(element);
737
+ });
738
+ }
739
+
740
+ // data属性绑定设置
741
+ data( key, value ) {
742
+ if ( key === undefined ) {
743
+ throw new Error('读取的或设置的键值不能为空');
744
+ }
745
+
746
+ let cache,
747
+ elem = this.elements[0],
748
+ // 获取与元素关联的缓存对象
749
+ id = Base.expando,
750
+ isCache = id && Base.cache[ id ];
751
+
752
+ if ( value !== undefined ) {
753
+ // 如果尚未创建缓存对象,则创建它
754
+ if ( !isCache ) {
755
+ cache = {};
756
+ // 生成唯一的缓存键
757
+ elem[ Base.expando ] = cache[ Base.expando ] = id;
758
+ // 将缓存对象存储在全局 Base.cache 中
759
+ Base.cache[ id ] = isCache = cache;
760
+ }
761
+ // 存储数据到缓存对象中
762
+ isCache[ Base.camelCase( key ) ] = value;
763
+ return this;
764
+ } else {
765
+ if (!isCache) return undefined; else
766
+ return isCache[ Base.camelCase( key ) ] ? isCache[ Base.camelCase( key ) ] : Base.dataAttr( elem, Base.camelCase( key ) )
767
+ }
768
+ }
769
+
770
+ // 清除data属性绑定的值
771
+ removeData( key ) {
772
+ delete Base.cache[ Base.expando ][ key ];
773
+ }
774
+
775
+ // attr 方法实现
776
+ attr(attributeName, value) {
777
+ let element = this.elements[0];
778
+ if (value === undefined) {
779
+ return element.getAttribute(attributeName);
780
+ } else {
781
+ return this.each((element) => {
782
+ element.setAttribute(attributeName, value);
783
+ });
784
+ }
785
+ }
786
+
787
+ // removeAttr 方法实现
788
+ removeAttr(attributeName) {
789
+ return this.each((element) => {
790
+ if (typeof element.removeAttribute === 'function') {
791
+ element.removeAttribute(attributeName);
792
+ }
793
+ });
794
+ }
795
+
796
+ // 当前元素坐标,eg:{ 3633, 180 }
797
+ offset() {
798
+ let rect = this.elements[0].getBoundingClientRect(),
799
+ scrollTop = window.pageYOffset || document.documentElement.scrollTop,
800
+ scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
801
+ return {
802
+ top: rect.top + scrollTop,
803
+ left: rect.left + scrollLeft
804
+ };
805
+ }
806
+
807
+ // 获取滚动条位置距离页面顶部的长度
808
+ scrollTop() {
809
+ let element = this.elements[0];
810
+ if (element instanceof Window) {
811
+ return (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;
812
+ } else {
813
+ return document.documentElement.scrollTop;
814
+ }
815
+ }
816
+
817
+ // 获取当前选择器第一个元素真实高度
818
+ height() {
819
+ let element = this.elements[0];
820
+ if (element === window) {
821
+ return window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
822
+ }
823
+ return element.offsetHeight ;
824
+ }
825
+
826
+ // 获取当前选择器第一个元素真实宽度
827
+ width() {
828
+ let element = this.elements[0];
829
+ // 如果传入的是window对象,直接返回视口宽度
830
+ if (element === window) {
831
+ return window.innerWidth || document.documentElement.clientWidth;
832
+ }
833
+ return element.offsetWidth;
834
+ }
835
+
836
+ // 获取或者设置输入框下拉框等标签中的值
837
+ val(newValue) {
838
+ let element = this.elements[0];
839
+ if (element.type === 'select-multiple') {
840
+ // 对于多选select元素
841
+ if (newValue !== undefined) {// 设置值
842
+ for (let i = element.options.length - 1; i >= 0; i--) {
843
+ element.options[i].selected = element.options[i].value === newValue;
844
+ }
845
+ return this;
846
+ } else {// 获取值
847
+ let selectedValues = [];
848
+ for (let i = 0; i < element.options.length; i++) {
849
+ if (element.options[i].selected) {
850
+ selectedValues.push(element.options[i].value);
851
+ }
852
+ }
853
+ return selectedValues;
854
+ }
855
+ } else {
856
+ if (newValue !== undefined) {// 设置值
857
+ element.value = newValue;
858
+ return this;
859
+ } else {// 获取值
860
+ return element.value;
861
+ }
862
+ }
863
+ }
864
+
865
+ // 样式修改
866
+ css(propertyName, value) {
867
+ if (this.elements.length === 0) return false;
868
+
869
+ if (value === undefined) {
870
+ if (Base.isObject(propertyName)) {
871
+ // 当propertyName为对象时表示需要设置多个属性
872
+ return this.each(element => {
873
+ for (const key in propertyName) {
874
+ if (propertyName.hasOwnProperty(key)) {
875
+ element.style[key] = propertyName[key];
876
+ }
877
+ }
878
+ });
879
+ } else {
880
+ // 获取值
881
+ return this.elements[0].style[propertyName];
882
+ }
883
+ } else {// 设置值
884
+ return this.each(element => {
885
+ element.style[propertyName] = value;
886
+ });
887
+ }
888
+ }
889
+
890
+ // 文字写入
891
+ text(content) {
892
+ let element = this.elements[0];
893
+ if (content === undefined) {
894
+ let textContent = '';
895
+ let childNodes = element.childNodes;
896
+ for (let i = 0; i < childNodes.length; i++) {
897
+ let node = childNodes[i];
898
+ if (node.nodeType === Node.TEXT_NODE || node.nodeType === Node.ELEMENT_NODE) {
899
+ textContent += node.textContent || node.innerText || '';
900
+ }
901
+ }
902
+ return textContent;
903
+ } else {
904
+ return this.each((element) => {
905
+ while (element.firstChild) {
906
+ element.removeChild(element.firstChild);
907
+ }
908
+ element.appendChild(document.createTextNode(content));
909
+ });
910
+ }
911
+ }
912
+
913
+ // 设置或者或者html代码
914
+ html(content) {
915
+ if (content !== undefined) {
916
+ return this.each((element) => {
917
+ if (element && element.nodeType === 1) {
918
+ element.innerHTML = content;
919
+ }
920
+ })
921
+ } else {
922
+ let element = this.elements[0];
923
+ if (element && element.nodeType === 1) {
924
+ return element.innerHTML;
925
+ }
926
+ }
927
+ }
928
+
929
+ // 在当前选择器后插入代码
930
+ after(html) {
931
+ return this.each((element) => {
932
+ // 插入html方法,参数为'beforeBegin', 'afterBegin', 'beforeEnd', 'afterEnd'
933
+ element.insertAdjacentHTML('afterend', html);
934
+ })
935
+ }
936
+
937
+ // 在当前选择器内尾部加入代码
938
+ append(content) {
939
+ return this.each((element) => {
940
+ // 创建一个临时的div元素用于包装HTML字符串
941
+ let tempDiv = document.createElement('div');
942
+ // content放入tempDiv
943
+ if (typeof content === 'string') {
944
+ tempDiv.innerHTML = content;
945
+ } else if (content instanceof Node) {
946
+ tempDiv.appendChild(content); // Node直接可以使用
947
+ } else if (content instanceof NodeList) {
948
+ for (let i = 0; i < content.length; i++) {
949
+ tempDiv.appendChild(content[i]);// NodeList 遍历使用
950
+ }
951
+ }
952
+ // 将tempDiv中的所有子节点移动到element中
953
+ while (tempDiv.firstChild) {
954
+ element.appendChild(tempDiv.firstChild);
955
+ }
956
+ return element;
957
+ })
958
+ }
959
+
960
+ // 在当前选择器内起始位置加入代码
961
+ prepend(content) {
962
+ return this.each((element) => {
963
+ // 创建一个临时的div元素用于包装HTML字符串
964
+ let tempDiv = document.createElement('div');
965
+ // content放入tempDiv
966
+ if (typeof content === 'string') {
967
+ tempDiv.innerHTML = content;
968
+ } else if (content instanceof Node) {
969
+ tempDiv.appendChild(content); // Node直接可以使用
970
+ } else if (content instanceof NodeList) {
971
+ for (let i = 0; i < content.length; i++) {
972
+ tempDiv.appendChild(content[i]);// NodeList 遍历使用
973
+ }
974
+ }
975
+ // 将tempDiv中的所有子节点移动到element中
976
+ while (tempDiv.firstChild) {
977
+ element.insertBefore(tempDiv.firstChild, element.firstChild);
978
+ }
979
+ return element;
980
+ })
981
+ }
982
+
983
+ // 隐藏元素
984
+ // hide() {
985
+ // return this.each((element) => {
986
+ // if (element && element.nodeType === 1) {
987
+ // element.style.display = 'none';
988
+ // }
989
+ // });
990
+ // }
991
+ hide(duration, callback) {
992
+ return this.each((element) => {
993
+ element.style.display = 'block';
994
+ if (duration) {
995
+ setTimeout(() => {
996
+ element.style.display = 'none';
997
+ if (callback && typeof callback === 'function') {
998
+ callback(element);
999
+ }
1000
+ }, duration);
1001
+ } else {
1002
+ element.style.display = 'none';
1003
+ if (callback && typeof callback === 'function') {
1004
+ callback(element);
1005
+ }
1006
+ }
1007
+ });
1008
+ }
1009
+
1010
+ // 显示元素
1011
+ show(duration, callback) {
1012
+ return this.each((element) => {
1013
+ element.style.display = 'block';
1014
+ if (duration) {
1015
+ setTimeout(() => {
1016
+ element.style.display = 'block';
1017
+ if (callback && typeof callback === 'function') {
1018
+ callback(element);
1019
+ }
1020
+ }, duration);
1021
+ } else {
1022
+ element.style.display = 'block';
1023
+ if (callback && typeof callback === 'function') {
1024
+ callback(element);
1025
+ }
1026
+ }
1027
+ });
1028
+ }
1029
+
1030
+ // 标签消失高度变0的关闭动画,300MS刚刚好
1031
+ slideUp(duration, callback) {
1032
+ const options = b.extend({ duration: duration, callback: callback }, { duration: 300, callback: false })
1033
+ return this.each((element) => {
1034
+ const computedStyle = window.getComputedStyle(element),
1035
+ height = element.offsetHeight;
1036
+
1037
+ let paddingTop = computedStyle.getPropertyValue('padding-top'),
1038
+ paddingBottom = computedStyle.getPropertyValue('padding-bottom'),
1039
+ marginTop = computedStyle.getPropertyValue('margin-top'),
1040
+ marginBottom = computedStyle.getPropertyValue('margin-bottom');
1041
+ if (paddingTop && paddingTop.includes('px'))
1042
+ paddingTop = paddingTop.replace(/px/g, '');
1043
+ if (paddingBottom && paddingBottom.includes('px'))
1044
+ paddingBottom = paddingBottom.replace(/px/g, '');
1045
+ if (marginTop && marginTop.includes('px'))
1046
+ marginTop = marginTop.replace(/px/g, '');
1047
+ if (marginBottom && marginBottom.includes('px'))
1048
+ marginBottom = marginBottom.replace(/px/g, '');
1049
+
1050
+ // element.style.transition = 'height ' + options.duration + 'ms ease-in-out';
1051
+ element.style.transition = 'none';
1052
+ element.style.overflow = 'hidden'; // 隐藏超出元素的内容
1053
+
1054
+ function step(startTime) {
1055
+ const now = performance.now(),
1056
+ timeElapsed = now - startTime,
1057
+ newHeight = Math.max(0, height - (timeElapsed / options.duration) * height),// 计算当前应该设置的高度
1058
+ newPaddingTop = Math.max(0, paddingTop - (timeElapsed / options.duration) * paddingTop),
1059
+ newPaddingBottom = Math.max(0, paddingBottom - (timeElapsed / options.duration) * paddingBottom),
1060
+ newMarginTop = Math.max(0, marginTop - (timeElapsed / options.duration) * marginTop),
1061
+ newMarginBottom = Math.max(0, marginBottom - (timeElapsed / options.duration) * marginBottom);
1062
+ element.style.height = newHeight + `px`;
1063
+ element.style.paddingTop = newPaddingTop + `px`;
1064
+ element.style.paddingBottom = newPaddingBottom + `px`;
1065
+ element.style.marginTop = newMarginTop + `px`;
1066
+ element.style.marginBottom = newMarginBottom + `px`;
1067
+ // 如果还没到达目标高度,则继续下一帧
1068
+ if (timeElapsed < options.duration) {
1069
+ requestAnimationFrame(step.bind(null, startTime));
1070
+ } else {
1071
+ // 过渡完成后清除过渡效果,以便后续操作
1072
+ element.style.transition = '';
1073
+ element.style.height = '';
1074
+ element.style.display = 'none';
1075
+ options.callback && options.callback();
1076
+ }
1077
+ }
1078
+ requestAnimationFrame(step);
1079
+ });
1080
+ }
1081
+
1082
+ // 标签显示高度变复原的打开动画
1083
+ slideDown(duration, callback) {
1084
+ const options = b.extend({ duration: duration, callback: callback }, { duration: 300, callback: false })
1085
+ return this.each((element) => {
1086
+ // 获取元素当前的高度和初始的 display 状态
1087
+ let startHeight = element.offsetHeight,
1088
+ display = element.style.display,
1089
+ mainDuration = options.duration * 7 / 10,
1090
+ pmDuration = options.duration * 3 / 10;
1091
+ if (display === 'none') {
1092
+ element.style.display = '';
1093
+ startHeight = 0; // 如果元素是隐藏的,则从 0 开始
1094
+ }
1095
+
1096
+ let endHeight = element.scrollHeight, // 目标高度是元素的 scrollHeight
1097
+ changeHeight = endHeight - startHeight,
1098
+ startTime = null;
1099
+
1100
+ // 动画函数
1101
+ function step(timestamp) {
1102
+ if (!startTime) startTime = timestamp;
1103
+ let progress = timestamp - startTime;
1104
+ if (progress > mainDuration) progress = mainDuration;
1105
+ let newHeight = ease(progress, startHeight, changeHeight, mainDuration);
1106
+ element.style.height = newHeight + 'px';
1107
+
1108
+ if (progress < mainDuration) {
1109
+ window.requestAnimationFrame(step);
1110
+ } else {
1111
+ element.style.transition = 'padding ' + pmDuration + 'ms ease, margin ' + pmDuration + 'ms ease';
1112
+ // element.style.transition = 'all ' + pmDuration + 'ms ease';
1113
+ element.style.margin = '';
1114
+ element.style.padding = '';
1115
+ element.style.height = '';
1116
+ options.callback && options.callback();
1117
+ }
1118
+ }
1119
+ // 线性缓动函数
1120
+ function ease(t, b, c, d) {
1121
+ t /= d / 2;
1122
+ if (t < 1) return c / 2 * t * t + b;
1123
+ t--;
1124
+ return -c / 2 * (t * (t - 2) - 1) + b;
1125
+ }
1126
+ window.requestAnimationFrame(step);
1127
+ });
1128
+ }
1129
+
1130
+ // 标签打开关闭切换
1131
+ slideToggle(duration, callback) {
1132
+ const target = this,
1133
+ options = b.extend({ duration: duration, callback: callback }, { duration: 500, callback: false })
1134
+ let isOpen = true;
1135
+ this.each((element) => {
1136
+ if (element.style.display === 'none') {
1137
+ isOpen = false;
1138
+ }
1139
+ });
1140
+ if (isOpen) {
1141
+ target.slideUp(options.duration, options.callback);
1142
+ } else {
1143
+ target.slideDown(options.duration, options.callback);
1144
+ }
1145
+ }
1146
+
1147
+ // 1.2 页面常用方法扩展
1148
+
1149
+ // 全选全清
1150
+ checkAll(checkboxes) {
1151
+ const options = Base.extend({ checkboxes: checkboxes }, { checkboxes: '.be-check' });
1152
+ return this.each((element) => {
1153
+ let iCheckboxes = document.querySelectorAll(options.checkboxes);
1154
+
1155
+ element.addEventListener('change', function() {
1156
+ iCheckboxes.forEach(function(checkbox) {
1157
+ checkbox.checked = element.checked;
1158
+ })
1159
+ })
1160
+ })
1161
+ }
1162
+
1163
+ /**
1164
+ * 反选
1165
+ <pre>
1166
+ <a href="javascript:" id="be-reverse-check">反选</a>
1167
+ <label><input type="checkbox" className="be-check" checked="checked"/>选项一</label>
1168
+ <label><input type="checkbox" className="be-check"/>选项二</label>
1169
+
1170
+ b('#be-reverse-check').checkReverse('.be-check')
1171
+ </pre>
1172
+ **/
1173
+ checkReverse(checkboxes) {
1174
+ const options = Base.extend({ checkboxes: checkboxes }, { checkboxes: '.be-check' });
1175
+ return this.each((element) => {
1176
+ let iCheckboxes = document.querySelectorAll(options.checkboxes);
1177
+ element.addEventListener('click', function() {
1178
+ iCheckboxes.forEach(function(checkbox) {
1179
+ checkbox.checked = !checkbox.checked;
1180
+ })
1181
+ })
1182
+ })
1183
+ }
1184
+
1185
+ /**
1186
+ * 数字特效递增动画
1187
+ <pre>
1188
+ b("#btn").click(() => {
1189
+ b("#f").numStep({
1190
+ start: 0, //开始数字
1191
+ end: 100, //结束数字
1192
+ duration: 1500, //持续时间
1193
+ callback: function() {
1194
+ b.l('动画完成')
1195
+ }
1196
+ });
1197
+ })
1198
+ </pre>
1199
+ **/
1200
+ numStep(options) {
1201
+ const defaults = {
1202
+ start: 0, //开始数字
1203
+ end: 100, //结束数字
1204
+ duration: 1500, //持续时间
1205
+ callback: false //回调方法
1206
+ }
1207
+ options = b.extend(options, defaults);
1208
+ return this.each((element) => {
1209
+ let startTime = null;
1210
+ function numStepAnimation(currentTime) {
1211
+ if (startTime === null) startTime = currentTime;
1212
+ const progress = Math.min((currentTime - startTime) / options.duration, 1);
1213
+ const value = Math.floor(progress * (options.end - options.start) + options.start);
1214
+
1215
+ b(element).text(value);
1216
+
1217
+ if (progress < 1) {
1218
+ requestAnimationFrame(numStepAnimation);
1219
+ } else {
1220
+ if (typeof options.callback === 'function') {
1221
+ options.callback();
1222
+ }
1223
+ }
1224
+ }
1225
+ requestAnimationFrame(numStepAnimation);
1226
+ })
1227
+ }
1228
+
1229
+ /**
1230
+ * 背景滚动动画
1231
+ <pre>
1232
+ .ce-bg-ef {
1233
+ width: 100%;
1234
+ height: 400px;
1235
+ background: url("//arisu.cn/file/images/tools/bg/a10076f5-9649-43bb-877c-79615ced7536.png");
1236
+ transition: all 0.7s ease-in-out;
1237
+ }
1238
+
1239
+ <div class="ce-bg-ef"></div>
1240
+ b(".ce-bg-ef").scrollBG({speed: 6});
1241
+ </pre>
1242
+ **/
1243
+ scrollBG(options) {
1244
+ const defaults = { speed: 0 } //speed滚动速度,越小越快
1245
+ options = b.extend(options, defaults);
1246
+ return this.each((element) => {
1247
+ b( element ).css( "background-position", "50% 0px" );
1248
+ b( window ).on("scroll", () => {
1249
+ const myElement = b(element),
1250
+ y = myElement.offset().top,
1251
+ h = myElement.height(),
1252
+ windowY = myElement.scrollTop(),
1253
+ windowH = myElement.height();
1254
+ if (windowH + windowY > y && windowH + windowY < y + windowH + h) {
1255
+ const bgY = (y + h - windowY) / options.speed;
1256
+ myElement.css( "background-position", "50% -" + bgY + "px" );
1257
+ }
1258
+ });
1259
+ })
1260
+ }
1261
+
1262
+
1263
+ /**
1264
+ * 点击切换激活项(添加active class),已经激活则取消(删除active class)
1265
+ <pre>
1266
+ <button type="button" className="my-btn btn btn-success">我的按钮1</button>
1267
+ <button type="button" className="my-btn btn btn-success">我的按钮2</button>
1268
+
1269
+ b(".my-btn").setActive();
1270
+ </pre>
1271
+ **/
1272
+ setActive(options) {
1273
+ options = b.extend(options, { className: "active" });
1274
+ b(this.elements).click((e) => {
1275
+ const myTarget = b(e.currentTarget);
1276
+ if (myTarget.hasClass(options.className)) {
1277
+ myTarget.removeClass(options.className)
1278
+ } else {
1279
+ b(this.elements).removeClass(options.className);
1280
+ myTarget.addClass(options.className)
1281
+ }
1282
+ })
1283
+ }
1284
+
1285
+ /**
1286
+ * 全屏loading,
1287
+ <pre>
1288
+ import "istyle/src/css/loading/do-pr-loader.css";
1289
+ b('#c').click(() => {
1290
+ b('body').loading(); //开始loading
1291
+ setTimeout(function() {
1292
+ b("body").loading("complete"); //结束loading
1293
+ }, 3000);
1294
+ })
1295
+ </pre>
1296
+ **/
1297
+ loading(options) {
1298
+ let isComplete = false;
1299
+ if (typeof options !== 'undefined' && typeof options !== 'object') {
1300
+ isComplete = true;
1301
+ options = {};
1302
+ }
1303
+ options = b.extend(options, {
1304
+ isFull: true,
1305
+ loadingClass: '.do-preloader',
1306
+ template: '<div class="do-preloader"><span class="do-pr-loader"><span class="do-pr-lr"></span></span></div>'
1307
+ });
1308
+
1309
+ return this.each((element) => {
1310
+ if (isComplete) {
1311
+ b("> *", element).removeClass("be-blur-2");
1312
+ b(options.loadingClass).addClass("oy-0");
1313
+ setTimeout(() => {
1314
+ b("> *", element).removeClass("be-ts");
1315
+ b(options.loadingClass).remove();
1316
+ }, 300);
1317
+ } else {
1318
+ b(element).prepend(options.template);
1319
+ b("> *", element).addClass("be-ts").addClass("be-blur-2");
1320
+ if (options.template) {
1321
+ b(options.loadingClass).css('position', 'fixed').css('height', '100vh').css('width', '100vw')
1322
+ }
1323
+ }
1324
+ });
1325
+ }
1326
+
1327
+ /* ========================================================================
1328
+ * 2. 够外部直接调用的静态方法
1329
+ * ======================================================================== */
1330
+
1331
+ // 2.1 基础静态方法
1332
+ // 参数继承覆盖默认参数值
1333
+ // import b from './base'
1334
+ // let defaults = { name: 'arisu' }
1335
+ // let newOptions = { name: 'movss' }
1336
+ // console.log( b.extend( newOptions, defaults ) ); //{name: 'movss'}
1337
+ static extend = function( custom, defaults ) {
1338
+ if (custom) {
1339
+ let key, value;
1340
+ for (key in defaults) {
1341
+ if (defaults.hasOwnProperty(key)) {
1342
+ value = defaults[key];
1343
+ if (custom[key] == null) {
1344
+ custom[key] = value;
1345
+ }
1346
+ }
1347
+ }
1348
+ } else {
1349
+ return defaults;
1350
+ }
1351
+ return custom;
1352
+ }
1353
+
1354
+ // 字符串装换为驼峰格式
1355
+ static camelCase = function(str) {
1356
+ return str.replace(/-([a-z])/g, function(all, letter) {
1357
+ return letter.toUpperCase();
1358
+ });
1359
+ }
1360
+
1361
+ // 打印简写
1362
+ static l = function(...message) {
1363
+ if (window.console && window.console.log && message)
1364
+ console.log(...message);
1365
+ }
1366
+
1367
+ // 四舍五入,保留n位,eg: b.toRound(3.14159, 2); //3.14
1368
+ static toRound = function(number, save) {
1369
+ let result = parseFloat(number);
1370
+ if (result) result = Math.round(number * Math.pow(10, save)) / Math.pow(10, save); else result = 0;
1371
+ return result;
1372
+ }
1373
+
1374
+ // 判断变量是否为空,eg: if(b.isNull(变量)) {
1375
+ static isNull = function(target) {
1376
+ let result = true;
1377
+ if (target == null || target === "" || target === "undefined" || target === "null")
1378
+ result = false;
1379
+ return result;
1380
+ }
1381
+
1382
+ // 如果变量为空设置默认值,eg: setDefault(data.id, 0);
1383
+ static setDefault = function(target, defaultVal) {
1384
+ if (target == null || target === "" || target === "undefined" || target === "null")
1385
+ target = defaultVal;
1386
+ return target;
1387
+ }
1388
+
1389
+ // 获取两个数组中的相同值,eg: b.same([1,2], [7,9,4,2,5,6,1]) //[1, 2]
1390
+ static same = function(arr1, arr2) {
1391
+ return arr1.filter(function(v) {
1392
+ return arr2.indexOf(v) !== -1;
1393
+ });
1394
+ }
1395
+
1396
+ // 获取两个数组中的不相同值,eg: b.different([1,2], [7,9,4,2,5,6,1]) //[7, 9, 4, 5, 6]
1397
+ static different = function(arr1, arr2) {
1398
+ return arr1.concat(arr2).filter(function (v) {
1399
+ return arr1.indexOf(v) === -1 || arr2.indexOf(v) === -1;
1400
+ })
1401
+ }
1402
+
1403
+ // 判断字符串是否为html标签,如<li></li><div></div><img/>返回true
1404
+ static isHtmlTag(str) {
1405
+ const regex = /^<([a-z][a-z0-9]*)\b[^>]*>(.*?)<\/\1>$|^<([a-z][a-z0-9]*)\b[^>]*\/>$/i;
1406
+ return regex.test(str);
1407
+ }
1408
+
1409
+ // 判断变量是否为对象
1410
+ static isObject(item) {
1411
+ return (item) ? (item && typeof item === 'object' && !Array.isArray( item ) && true) : false;
1412
+ }
1413
+
1414
+ // 允许插件扩展
1415
+ static plugin(pluginName, pluginFunction) {
1416
+ // Base.fn[pluginName] = pluginFunction;
1417
+ Base.fn[pluginName] = function() {
1418
+ pluginFunction()
1419
+ }
1420
+ }
1421
+
1422
+ // 创建一个新的临时html标签
1423
+ static createElement(htmlString) {
1424
+ // 创建一个新的临时div元素
1425
+ let tempDiv = document.createElement('div');
1426
+ // 将传入的HTML字符串设置为临时div的innerHTML
1427
+ tempDiv.innerHTML = htmlString.trim();
1428
+ // 获取临时div的第一个子元素,这就是我们创建的元素
1429
+ let newElement = tempDiv.firstChild;
1430
+ // 如果传入的HTML字符串包含多个元素,我们需要返回所有的子元素
1431
+ if (newElement.nodeType === Node.TEXT_NODE) {
1432
+ // 如果第一个节点是文本节点,那么真正的元素可能是它的下一个兄弟节点
1433
+ newElement = newElement.nextSibling;
1434
+ // 如果存在多个元素,我们需要收集它们并返回
1435
+ let fragment = document.createDocumentFragment();
1436
+ while (newElement) {
1437
+ fragment.appendChild(newElement);
1438
+ newElement = newElement.nextSibling;
1439
+ }
1440
+
1441
+ return fragment;
1442
+ }
1443
+ // 如果只创建了一个元素,直接返回它
1444
+ return newElement;
1445
+ }
1446
+
1447
+ // 异步请求
1448
+ static ajax(options) {
1449
+ const defaults = {
1450
+ url: '',
1451
+ method: 'GET',
1452
+ async: true,
1453
+ headerMap: { },// 'Content-Type': 'application/json'
1454
+ cache: 'default',
1455
+ dataType: 'json',
1456
+ data: null, // 可以是字符串、FormData 或 URLSearchParams
1457
+ // jsonp: options.jsonp,
1458
+ // jsonpCallback: options.jsonp,
1459
+ success: function() {},
1460
+ error: function() {},
1461
+ }
1462
+ options = b.extend(options, defaults);
1463
+ if (options.method === 'get') {
1464
+ if (!options.url.includes("?")) {
1465
+ let params = new URLSearchParams();
1466
+ for (let key in options.data) {
1467
+ if (options.data.hasOwnProperty(key)) {
1468
+ params.append(key, options.data[key]);
1469
+ }
1470
+ }
1471
+ options.url = options.url + '?' + params.toString();
1472
+ }
1473
+ options.data = null;
1474
+ }
1475
+
1476
+ if (fetch) {
1477
+ fetch(options.url, {
1478
+ method: options.method, // GET, POST, PUT, DELETE 等
1479
+ headers: new Headers(options.headerMap),
1480
+ cache: options.cache,
1481
+ body: options.data ? JSON.stringify(options.data) : null, // 如果需要发送 JSON 数据
1482
+ }).then(function(response) {
1483
+ if (!response.ok) {
1484
+ return Promise.reject(new Error('Failed to fetch resource'));
1485
+ }
1486
+ return (options.dataType === 'json') ? response.json() : response.text();
1487
+ }).then(function(data) {
1488
+ // 请求成功,调用 success 回调函数
1489
+ options.success(data);
1490
+ }).catch(function(error) {
1491
+ options.error(error);
1492
+ });
1493
+ } else {
1494
+ let xhr = new XMLHttpRequest();
1495
+ xhr.onload = function() {
1496
+ if (xhr.status >= 200 && xhr.status < 300) {
1497
+ let response;
1498
+ switch (options.dataType) {
1499
+ case 'json':
1500
+ try {
1501
+ response = JSON.parse(xhr.responseText);
1502
+ } catch (e) {
1503
+ options.error(e);
1504
+ return;
1505
+ }
1506
+ break;
1507
+ case 'text':
1508
+ response = xhr.responseText;
1509
+ break;
1510
+ default:
1511
+ response = xhr.responseText || xhr.response; // 假设是其他格式的数据
1512
+ }
1513
+ options.success(response, xhr.status, xhr);
1514
+ } else {
1515
+ let error = new Error('Request failed. Status: ' + xhr.status);
1516
+ // error.xhr = xhr;
1517
+ options.error(error);
1518
+ }
1519
+ };
1520
+ xhr.onerror = function() {
1521
+ options.error(new Error('Network Error'));
1522
+ };
1523
+ xhr.open(options.method, options.url, options.async); // 第三个参数表示异步
1524
+ // 设置请求头
1525
+ // xhr.setRequestHeader('Content-Type', 'application/json'); // 示例
1526
+ for (let key in options.headerMap) {
1527
+ if (options.headerMap.hasOwnProperty(key)) {
1528
+ xhr.setRequestHeader(key, options.headerMap[key]);
1529
+ }
1530
+ }
1531
+
1532
+ // 如果需要发送请求体(如 POST 请求),则发送数据
1533
+ if (options.data) {
1534
+ // xhr.send(JSON.stringify(options.data));
1535
+ // 或者如果是 FormData 或 URLSearchParams,直接发送
1536
+ xhr.send(options.data);
1537
+ } else {
1538
+ xhr.send(); // 对于 GET 请求或没有数据的 POST 请求
1539
+ }
1540
+ }
1541
+ }
1542
+
1543
+ // 2.2 页面常用方法
1544
+
1545
+ // 获取URL中的参数,eg: ..url?name=arisu,调用b.getParam("name"); //arisu
1546
+ static getParam = function(key) {
1547
+ let reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)", "i");
1548
+ let r = window.location.search.substr(1).match(reg);
1549
+ if (r != null) return unescape(r[2]); else return null;
1550
+ }
1551
+
1552
+ // 页面内缓慢移动,需要CSS3支持特效,html { scroll-behavior: smooth; }
1553
+ static move = function(target) {
1554
+ const t = document.querySelector(target);
1555
+ if (t) {
1556
+ let offset = new Base(t).offset();
1557
+ scrollTo( offset.left, offset.top );
1558
+ }
1559
+ }
1560
+
1561
+ /**
1562
+ * 字符串复杂度验证,表单验证
1563
+ * <pre>
1564
+ let lenMin = 3;
1565
+ let lenMax = 12;
1566
+ let result = b.strValidation('abc123#', lenMin, lenMax);//8
1567
+ if (result == 1) {
1568
+ console.log("字符串必须小于等于" + lenMin + ",或者大于等于" + lenMax);
1569
+ } else if (result == 2) {
1570
+ console.log("不能全部为数字");
1571
+ } else if (result == 3) {
1572
+ console.log("不能全部为字母");
1573
+ } else if (result == 4) {
1574
+ console.log("不能只有数字字母,必须包含特殊字符");
1575
+ } else if (result == 5) {
1576
+ console.log("不能只使用特殊字符");
1577
+ } else if (result == 8) {
1578
+ console.log("通过,包含字母数字及特殊字符");
1579
+ } else {
1580
+ console.log("没有可以匹配的,必须包含英文字母数字及键盘上的特殊字符");
1581
+ }
1582
+ * </pre>
1583
+ **/
1584
+ static strValidation = function(str, lenMin, lenMax) {
1585
+ let result = 0;
1586
+ let d1 = /^[^\u4e00-\u9fa5a-zA-Z\d,.,。]{0,32}$/;//全部为特殊字符
1587
+ let d4 = /^(?=.*\d)(?=.*[a-zA-Z])(?=.*[~!@#$%^&*])[\da-zA-Z~!@#$%^&*]*$/;//包含字母数字及特殊字符
1588
+ let medium = /^[0-9a-zA-z]{0,32}$/;//包含字母数字
1589
+ let e1 = /^[0-9]{0,32}$/;//全部为数字
1590
+ let e2 = /^[a-zA-z]{0,32}$/;//全部为字母
1591
+
1592
+ if (str.length <= lenMin || str.length >= lenMax) {
1593
+ //字符串小于等于lenMin或者大于等于lenMax
1594
+ result = 1;
1595
+ } else if (e1.test(str)) {
1596
+ result = 2;
1597
+ } else if (e2.test(str)) {
1598
+ result = 3;
1599
+ } else if (medium.test(str)) {
1600
+ result = 4;
1601
+ } else if (d1.test(str)) {
1602
+ result = 5;
1603
+ // } else if (d2.test(str)) {
1604
+ // result = 6;
1605
+ // } else if (d3.test(str)) {
1606
+ // result = 7;
1607
+ } else if (d4.test(str)) {
1608
+ result = 8;
1609
+ }
1610
+ return result;
1611
+ }
1612
+
1613
+ // 常用快捷键事件绑定
1614
+ static keys = {
1615
+ 'esc': 'Escape',
1616
+ 'backspace': 'Backspace',
1617
+ 'space': ' ',
1618
+ 'enter': 'Enter',
1619
+ 'up': 'ArrowUp',
1620
+ 'down': 'ArrowDown',
1621
+ 'left': 'ArrowLeft',
1622
+ 'right': 'ArrowRight'
1623
+ };
1624
+ static hotkey(key, callback) {
1625
+ document.addEventListener('keydown', function(event) {
1626
+ if (key === event.key) {
1627
+ callback();
1628
+ }
1629
+ });
1630
+ }
1631
+
1632
+ // 设置cookie
1633
+ static setCookie(name, value, options = {}) {
1634
+ let expires = '',
1635
+ path = options.path || '/',
1636
+ domain = options.domain,
1637
+ secure = options.secure ? '; Secure' : '';
1638
+
1639
+ if (options.expires) {
1640
+ let date;
1641
+ if (typeof options.expires === 'number') {
1642
+ date = new Date();
1643
+ date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
1644
+ } else {
1645
+ date = options.expires;
1646
+ }
1647
+ expires = `; expires=${date.toUTCString()}`;
1648
+ }
1649
+ document.cookie = `${name}=${encodeURIComponent(value)}${expires}; path=${path}; domain=${domain || ''}${secure}`;
1650
+ }
1651
+
1652
+ // 获取cookie
1653
+ static getCookie(name) {
1654
+ let nameEQ = `${name}=`,
1655
+ ca = document.cookie.split(';');
1656
+ for (let i = 0; i < ca.length; i++) {
1657
+ let c = ca[i];
1658
+ while (c.charAt(0) === ' ') c = c.substring(1, c.length);
1659
+ if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length));
1660
+ }
1661
+ return null;
1662
+ }
1663
+
1664
+ // 删除cookie
1665
+ static removeCookie(name, options = {}) {
1666
+ this.setCookie(name, '', { ...options, expires: -1 });
1667
+ }
1668
+
1669
+ // 数据库菜单数据生成html ul列表树
1670
+ // const data = { trees: [ { "tid": 6, "id": 1, "name": "管理后台菜单", "open": true, "isParent": true, "isPublic": false, "checked": false }, { "tid": 14, "id": 277,...
1671
+ static menu(trees, isIgnoreTop) {
1672
+ let html = "";
1673
+ const build = function(trees, level, pid) {
1674
+ let result = "";
1675
+ ++level;
1676
+ for ( let i = 0; i < trees.length; i++) {
1677
+ const tree = trees[i];
1678
+
1679
+ let link = "#";
1680
+ if (tree.link)
1681
+ link = tree.link;
1682
+ // link = "../" + tree.link;
1683
+ if (!tree.pId && level === 0) {
1684
+ if (isIgnoreTop) {
1685
+ //不显示第一层菜单
1686
+ result = build(trees, level, tree.id);
1687
+ } else {
1688
+ let html = build(trees, level, tree.id),
1689
+ hash = tree.hash ? " data-hash='" + tree.hash + "' " : " ",
1690
+ actionId = tree.actionId ? " id='" + tree.actionId + "' " : " ";
1691
+
1692
+ if (html) {
1693
+ html = "<ul class='sub'>" + html + "</ul>";
1694
+ }
1695
+ result += "<li class='sub-menu'>" +
1696
+ "<a" + hash + actionId + "href='" + link + "'><span>" + tree.name + "</span></a>" +
1697
+ html + "</li>";
1698
+
1699
+ }
1700
+ } else if (tree.pId === pid) {
1701
+ let html = "";
1702
+ if (tree.isParent) {//返回数据为节点即不再遍历
1703
+ html = build(trees, level, tree.id);
1704
+ if (html)
1705
+ html = "<ul class='sub'>" + html + "</ul>";
1706
+ }
1707
+
1708
+ let icon = "";//第二层名称前加一个图标
1709
+ if (level === 1)
1710
+ icon = "<i class='" + tree.icon + "'></i>";
1711
+
1712
+ let hash = tree.hash ? " data-hash='" + tree.hash + "' " : " ",
1713
+ actionId = tree.actionId ? " id='" + tree.actionId + "' " : " ";
1714
+
1715
+ result += "<li class='sub-menu'>" +
1716
+ "<a" + hash + actionId + "href='" + link + "'>" +
1717
+ icon +
1718
+ "<span>" + tree.name + "</span>" +
1719
+ "</a>" +
1720
+ html +
1721
+ "</li>";
1722
+ }
1723
+ }
1724
+ return result;
1725
+ }
1726
+ let h = "";
1727
+ if (trees)
1728
+ h = build(trees, -1);
1729
+ return html + h;
1730
+ }
1731
+
1732
+ /**
1733
+ * 数据库普通的数据列表转换成有层次的数组
1734
+ * <pre>
1735
+ //菜单数据节点,如:
1736
+ //a ----------------
1737
+ //b ----------------
1738
+ //根据子父字段数据 形成 节点嵌套,如:
1739
+ //a ------------
1740
+ // b ---------------
1741
+ // c ---------------
1742
+ //d ----------------
1743
+ //e ----------------
1744
+ // f ------------
1745
+
1746
+ b.l(menu2Tree(data.trees, 1, 1)); //数据和上一个方法相同
1747
+ * </pre>
1748
+ **/
1749
+ static menu2Tree(menus, pid, activeid) {
1750
+ let children = [];
1751
+ let m = menus;
1752
+ menus.forEach(function(value) {
1753
+ if (value.pId === pid) {
1754
+ value.isactive = ("a" + value.id) === activeid;
1755
+ children.push(value);
1756
+ if (value.isParent) {
1757
+ value.children = b.menu2Tree(m, value.id);
1758
+ }
1759
+ }
1760
+ });
1761
+ return children;
1762
+ }
1763
+
1764
+ /**
1765
+ * 包含搜索按钮删除按钮的搜索框
1766
+ * <pre>
1767
+ <div class="fm-search">
1768
+ <span class="bi bi-search"></span>
1769
+ <input type="text" placeholder="检索你想找的内容">
1770
+ <span class="bi bi-trash3"></span>
1771
+ </div>
1772
+
1773
+ import 'istyle/src/css/form/form.css'
1774
+ b.search(function(txt) {
1775
+ if (txt) console.log(txt);
1776
+ });
1777
+ * </pre>
1778
+ **/
1779
+ static search(fun) {
1780
+ const mySearch = b(".fm-search"),
1781
+ myInput = b("input", mySearch),
1782
+ myFind = b("span:eq(0)", mySearch),
1783
+ myClear = b("span:eq(1)", mySearch);
1784
+ myInput.on("change",(e) => {
1785
+ const myTarget = b(e.currentTarget);
1786
+ if (myTarget.val() !== "")
1787
+ myTarget.next().css("opacity", "1").css("visibility", "visible");
1788
+ else
1789
+ myTarget.next().css("opacity", "0").css("visibility", "hidden");
1790
+ });
1791
+ if (myInput.val() !== "")
1792
+ myInput.next().css("opacity", "1").css("visibility", "visible");
1793
+ myClear.on("click", (e) => {
1794
+ const myTarget = b(e.currentTarget);
1795
+ myTarget.css("opacity", "0").css("visibility", "hidden");
1796
+ myTarget.prev().val("");
1797
+ });
1798
+ myFind.on("click", (e) => {
1799
+ const myTarget = b(e.currentTarget);
1800
+ if(fun)
1801
+ fun(myTarget.next().val());
1802
+ });
1803
+ }
1804
+
1805
+ // static plugin(pluginName, pluginFunction) {
1806
+ // // 确保 Base.fn 是一个对象,如果不是,你可能需要修正这一点
1807
+ // if (typeof Base.fn === 'object' && Base.fn !== null) {
1808
+ // // 使用 Object.defineProperty 添加属性到 Base.fn
1809
+ // Object.defineProperty(Base.fn, pluginName, {
1810
+ // value: pluginFunction, // 设置属性的值为插件函数
1811
+ // enumerable: false, // 默认情况下,我们可能不希望这个属性是可枚举的
1812
+ // writable: false, // 我们可能不希望这个属性被重写
1813
+ // configurable: false // 我们可能不希望这个属性被删除或重新配置
1814
+ // // 注意:writable 和 configurable 设置为 false 可能会导致在严格模式下无法删除该属性
1815
+ // });
1816
+ // } else {
1817
+ // throw new Error('Base.fn is not an object or is null');
1818
+ // }
1819
+ // }
1820
+
1821
+ // 2.3 私有静态方法
1822
+
1823
+ // 用于从 data-* 属性中获取数据
1824
+ static dataAttr = function(elem, key) {
1825
+ let name = "data-" + key;
1826
+ return elem.getAttribute(name) ? elem.getAttribute(name) : undefined;
1827
+ }
1828
+
1829
+ // console.log(b("> div", ".container")); 模式选择器
1830
+ static contextQuerySelector(selector, context) {
1831
+ if (selector.startsWith('>')) {
1832
+ return Array.from(context.querySelectorAll(selector.substring(1))).filter(function(e) {
1833
+ return e.parentNode === context;
1834
+ });
1835
+ // } else if (selector && selector.trim() === "option:selected") {
1836
+ // selectElement.options[selectElement.selectedIndex];
1837
+ } else {
1838
+ const nodes = context.querySelectorAll( selector );
1839
+ if (nodes.length === 0) {
1840
+ return Array.from( document.querySelectorAll( selector ) )
1841
+ } else {
1842
+ return Array.from( nodes )
1843
+ }
1844
+ }
1845
+ }
1846
+
1847
+ // 判断是否为 html标签:eq(数字) 格式
1848
+ static isEqSelector(str) {
1849
+ const regex = /^[\w-]+:eq\((\d+)\)$/;
1850
+ const match = str.match(regex);
1851
+ return match !== null && match[1] !== undefined;
1852
+ }
1853
+
1854
+
1855
+ // 2.4 静态属性
1856
+ // 生成缓存随机名称
1857
+ static expando = "base" + ("" + Math.random()).replace(/\D/g, "");
1858
+ static cache = { };
1859
+
1860
+ static build(selector, context) {
1861
+ return new Base(selector, context);
1862
+ }
1863
+
1864
+ }
1865
+
1866
+
1867
+ Base.build.extend = Base.extend;//参数继承
1868
+ Base.build.camelCase = Base.camelCase;//字符串驼峰化
1869
+ Base.build.l = Base.l;//打印
1870
+ Base.build.getParam = Base.getParam;//获取url参数
1871
+ Base.build.toRound = Base.toRound;//四舍五入
1872
+ Base.build.isNull = Base.isNull;//是否为空判断
1873
+ Base.build.setDefault = Base.setDefault;//默认值设置
1874
+ Base.build.same = Base.same;//获取两个数组中的相同值
1875
+ Base.build.different = Base.different;//获取两个数组中的不同值
1876
+ Base.build.strValidation = Base.strValidation;//表单字符串验证
1877
+ Base.build.move = Base.move;//页面内缓慢移动
1878
+ Base.build.keys = Base.keys;//常用键盘按键
1879
+ Base.build.hotkey = Base.hotkey;//常用快捷键事件绑定
1880
+ Base.build.isHtmlTag = Base.isHtmlTag;//常用快捷键事件绑定
1881
+ Base.build.isObject = Base.isObject;//判断变量是否为对象
1882
+ Base.build.plugin = Base.plugin;//支持扩展插件,声明的插件或者方法有有警告不提示,直接使用b['test'] = test;绑定
1883
+ Base.build.ajax = Base.ajax;//ajax异步请求
1884
+ Base.build.setCookie = Base.setCookie;//设置cookie
1885
+ Base.build.getCookie = Base.getCookie;//获取cookie
1886
+ Base.build.removeCookie = Base.removeCookie;//删除cookie
1887
+ Base.build.menu = Base.menu;//数据库菜单数据生成ul列表树
1888
+ Base.build.menu2Tree = Base.menu2Tree;//数据库普通的数据列表转换成有层次的数组
1889
+ Base.build.search = Base.search;//包含搜索按钮删除按钮的搜索框
1890
+ const b = Base.build;
1891
+
1892
+ Base.fn = Base.prototype; // 简化对原型的引用,eg:Base.fn.extend('testFun', testFun);
1893
+ // Base.prototype.constructor = Base;
1894
+ // Base.fn.plugin = function(pluginName, pluginFunction) {
1895
+ // Base.fn[pluginName] = pluginFunction;
1896
+ // };
1897
+
1898
+ /* ========================================================================
1899
+ * 其他常用方法,原生JS方法重写等
1900
+ * ======================================================================== */
1901
+
1902
+ /**
1903
+ * 时间格式化
1904
+ * <pre>
1905
+ new Date().format("yyyy-MM-dd hh:mm:ss")
1906
+ * </pre>
1907
+ **/
1908
+ Date.prototype.format = function(fmt) {
1909
+ let o = {
1910
+ "M+" : this.getMonth() + 1,
1911
+ "d+" : this.getDate(),
1912
+ "h+" : this.getHours(),
1913
+ "m+" : this.getMinutes(),
1914
+ "s+" : this.getSeconds(),
1915
+ "q+" : Math.floor((this.getMonth() + 3) / 3),
1916
+ "S" : this.getMilliseconds()
1917
+ };
1918
+ if (/(y+)/.test(fmt))
1919
+ fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
1920
+ for ( let k in o)
1921
+ if (new RegExp("(" + k + ")").test(fmt))
1922
+ fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
1923
+ return fmt;
1924
+ }
1925
+
1926
+ /**
1927
+ * 数组根据下标删除扩展,返回执行完数组长度
1928
+ * <pre>
1929
+ let array = ['a', 'b', 'c', 'd']
1930
+ eg1: array.remove(0);//删除第一个元素
1931
+ eg2: array.remove(-1);//删除倒数第一个元素
1932
+ eg3: array.remove(0, 2);///删除数组中下标为0-2的元素(3个)
1933
+ * </pre>
1934
+ **/
1935
+ Array.prototype.remove = function(from, to) {
1936
+ let rest = this.slice((to || from) + 1 || this.length);
1937
+ this.length = from < 0 ? this.length + from : from;
1938
+ return this.push.apply(this, rest);
1939
+ }
1940
+
1941
+ /**
1942
+ * 删除重复元素
1943
+ * <pre>
1944
+ let arr = [1,2];
1945
+ let arr2 = arr.concat(1,2,3,1)
1946
+ arr2.unique()
1947
+ * </pre>
1948
+ **/
1949
+ Array.prototype.unique = function () {
1950
+ let temp = [];
1951
+ this.sort();
1952
+ for(let i = 0; i < this.length; i++) {
1953
+ if(this[i] === this[i+1]) {
1954
+ continue;
1955
+ }
1956
+ temp[temp.length]=this[i];
1957
+ }
1958
+ return temp;
1959
+ }
1960
+
1961
+
1962
+
1963
+ /* harmony default export */ const base = (b);
1964
+ ;// CONCATENATED MODULE: ./src/js/utils.js
1965
+
1966
+
1967
+ /* ========================================================================
1968
+ * 常用JS插件组件
1969
+ * 2024年6月7日 15:50:36
1970
+ * ========================================================================
1971
+ //使用范例
1972
+ import b, * as u from 'ilib/utils'
1973
+ let sf = new u.SubmitFlag(".e2")
1974
+ or
1975
+ import b, { SubmitFlag } from 'ilib/utils'
1976
+ let sf = new SubmitFlag(".e2")
1977
+
1978
+ 1. SubmitFlag防用户多次点击:new u.SubmitFlag(".e2")
1979
+ 2. 底部按钮快速移动到顶部:new u.GoTop({
1980
+ 3. 数字增加减少,购物数量控制:new u.ItemCount({
1981
+ 4. niceSelect自定义下拉框:new u.NiceSelect('#ns2')
1982
+ 5. 按钮动画:new u.BtnEf(".bn-btn-5")
1983
+ 6. 局部loading动画:new u.AeLoader()...
1984
+ 7. 分页:new u.IPagination({ target: '#ipagination'...
1985
+ 8. 列表查询分页封装插件:const ilist = new u.IList({ target: '#test-list' ..
1986
+ 9. 手风琴导航菜单:new u.IAccordion({ speed: 300, showCount: true });
1987
+ 10. 弹框搜索面板:new u.PopoverSearch('#ipopover', {
1988
+ 11. 文字切换动画特效:new u.Flash("#ce-flash", {
1989
+ 12. 绘制点线背景动画:new u.LineEffect("#canvas-warp", {
1990
+
1991
+ * ======================================================================== */
1992
+ /**
1993
+ * 自定义组件初始化参数
1994
+ * @param iclass 自定义组件
1995
+ * @param selector 选择器
1996
+ * @param custom 自定义参数
1997
+ * @param callback 回调方法
1998
+ */
1999
+ const defaultConstructor = (iclass, selector, custom, callback) => {
2000
+ // if (typeof custom === 'string') {
2001
+ // iclass.elements = document.querySelectorAll( custom );
2002
+ // iclass.options = b.extend( { target: custom }, iclass.options )
2003
+ // iclass.selector = custom;
2004
+ // } else {
2005
+ // if (typeof custom.target === 'string') {
2006
+ // iclass.elements = document.querySelectorAll( custom.target );
2007
+ // } else
2008
+ // if (custom.target instanceof NodeList || custom.target instanceof HTMLElement) {
2009
+ // iclass.elements = [ custom.target ];
2010
+ // } else {
2011
+ // iclass.elements = document.querySelectorAll( iclass.options.target );
2012
+ // }
2013
+ // }
2014
+ if (typeof selector === 'string') {
2015
+ iclass.elements = document.querySelectorAll( selector );
2016
+ } else if (selector instanceof NodeList || selector instanceof HTMLElement) {
2017
+ iclass.elements = [ selector ];
2018
+ } else {
2019
+ iclass.elements = document.querySelectorAll( selector );
2020
+ }
2021
+ iclass.options = base.extend( custom, iclass.options )
2022
+ callback(iclass);
2023
+
2024
+ // if (iclass.elements.length !== 1) {
2025
+ // throw new Error('未正确设置生效标签,请确保传入"#id"或唯一的".class"');
2026
+ // }
2027
+ }
2028
+
2029
+
2030
+ //普通方法
2031
+ // function test(p1, p2) {
2032
+ // console.log(this, p1, p2)
2033
+ // }
2034
+ // b['test'] = test;
2035
+ // // 插件
2036
+ // +function(b) {
2037
+ // function myPlugin(options) {
2038
+ // b.l(options);
2039
+ // this.each((index, element) => {
2040
+ // b.l(index);
2041
+ // b.l(element);
2042
+ // });
2043
+ // return this;
2044
+ // }
2045
+ // b.plugin('myPlugin', myPlugin);
2046
+ // 废弃直接使用:
2047
+ // b['plugin'] = plugin;
2048
+ // }(Base);
2049
+
2050
+
2051
+
2052
+
2053
+ // 自定义组件
2054
+
2055
+ /* ========================================================================
2056
+ * 1. 提交后台过程中让按钮不可用,防止用户多次点击
2057
+ * 2016年6月26日10:08:11
2058
+ * ========================================================================
2059
+ * <pre>
2060
+ <button href="#" class="e2 btn btn-danger">发送请求a</button>
2061
+ <button href="#" class="e2 btn btn-danger">发送请求b</button>
2062
+ <button id="stopSF" href="#" class="btn btn-danger">停止发送请求</button>
2063
+
2064
+ // let sf = new u.SubmitFlag(".e2")
2065
+ // 或者
2066
+ let sf = new u.SubmitFlag(".e2", {
2067
+ text: "数据请求中..",
2068
+ useText: true
2069
+ })
2070
+ b("#stopSF").click(() => {
2071
+ sf.complete();
2072
+ })
2073
+ * </pre>
2074
+ * ======================================================================== */
2075
+ class SubmitFlag {
2076
+ constructor(selector, custom) {
2077
+ this.selector = selector;
2078
+ defaultConstructor(this, selector, custom, (target) => {
2079
+ target.elements.forEach((element) => {
2080
+ let myElems = base(element);
2081
+ if (!myElems.data("be.submitflag"))
2082
+ myElems.data("be.submitflag", target);
2083
+
2084
+ target.init(element);
2085
+ });
2086
+ });
2087
+ }
2088
+
2089
+ options = {
2090
+ text: "处理中..",
2091
+ useText: true
2092
+ };
2093
+
2094
+ init(element) {
2095
+ let myElems = base(element),
2096
+ data = myElems.data("be.submitflag");
2097
+ myElems.data("text", myElems.text()).click((e) => {
2098
+ data.request(e.currentTarget);
2099
+ })
2100
+ }
2101
+
2102
+ request(element) {
2103
+ let myElems = base(element);
2104
+ myElems.addClass("submit-flag-request").data("text", myElems.text()).attr("disabled", "disabled");
2105
+ myElems.text(this.options.text);
2106
+ };
2107
+
2108
+ complete(element) {
2109
+ let myElems = (element) ? base(element) : base(this.selector);
2110
+ myElems.removeClass("submit-flag-request").removeAttr("disabled");
2111
+ if (myElems.data("text") && this.options.useText)
2112
+ myElems.text(myElems.data("text"));
2113
+ };
2114
+
2115
+ destroy() {
2116
+ base(this.selector).removeData("be.submitflag");
2117
+ }
2118
+ }
2119
+
2120
+ /* ========================================================================
2121
+ * 2. 底部按钮快速移动到顶部,按钮出现/消失需要用到animate.css v4,缓动需要样式html { scroll-behavior: smooth; }
2122
+ * 2018年7月3日11:55:06
2123
+ * ========================================================================
2124
+ * <pre>
2125
+ <a class="ce-gotop" href="javascript:">
2126
+ <i class="bi bi-chevron-up"></i>
2127
+ </a>
2128
+
2129
+ import 'istyle/src/css/case/ce-gotop.css';
2130
+ new u.GoTop(".ce-gotop", {
2131
+ position: {
2132
+ bottom: "15px",
2133
+ right: "15px"
2134
+ },
2135
+ showEffect: " animate__zoomIn ",
2136
+ hideEffect: " animate__zoomOut ",
2137
+ type: "fixed",
2138
+ offsetTop: "400"
2139
+ });
2140
+ * </pre>
2141
+ * ======================================================================== */
2142
+ class GoTop {
2143
+ constructor(selector, custom) {
2144
+ this.selector = selector;
2145
+ defaultConstructor(this, selector, custom, (target) => {
2146
+ target.elements.forEach((element) => {
2147
+ let myElems = base(element);
2148
+ if (!myElems.data("be.gotop"))
2149
+ myElems.data("be.gotop", target);
2150
+
2151
+ target.init(element);
2152
+ });
2153
+ });
2154
+ }
2155
+
2156
+ options = {
2157
+ position: {
2158
+ bottom: "15px",
2159
+ right: "15px"
2160
+ },
2161
+ showEffect: " animate__zoomIn ",
2162
+ hideEffect: " animate__zoomOut ",
2163
+ type: "fixed",
2164
+ offsetTop: "400"
2165
+ };
2166
+
2167
+ init(element) {
2168
+ let t = this,
2169
+ myElem = base(element),
2170
+ type = t.options.type,
2171
+ showEffect = t.options.showEffect,
2172
+ position = t.options.position,
2173
+ offsetTop = t.options.offsetTop,
2174
+ hideEffect = t.options.hideEffect;
2175
+
2176
+ myElem.addClass("animate__animated").css({
2177
+ "display": "inline-block",
2178
+ "position": type,
2179
+ "opacity": 0
2180
+ });
2181
+
2182
+ if (type === "fixed" || type === "absolute") {
2183
+ myElem.css(position);
2184
+ }
2185
+
2186
+ myElem.on("click", (e) => {
2187
+ e.preventDefault();
2188
+ scrollTo(0, 0);
2189
+ });
2190
+
2191
+ if (!offsetTop && !myElem.hasClass("animated-running")) {
2192
+ if (myElem.offset().top <= base(window).height()) {
2193
+ myElem.addClass("animated-running " + showEffect).css({
2194
+ "opacity": ""
2195
+ });
2196
+ }
2197
+ }
2198
+
2199
+ base(window).on("scroll", function () {
2200
+ if (offsetTop) {
2201
+ if (base(window).scrollTop() >= offsetTop && !myElem.hasClass("animated-running")) {
2202
+ myElem.addClass("animated-running " + showEffect).css({
2203
+ "opacity": ""
2204
+ });
2205
+ myElem.removeClass(hideEffect);
2206
+ } else if (base(window).scrollTop() <= offsetTop && myElem.hasClass("animated-running")) {
2207
+ myElem.removeClass("animated-running " + showEffect).css({
2208
+ "opacity": 0
2209
+ });
2210
+ myElem.addClass(hideEffect);
2211
+ }
2212
+ } else {
2213
+ let thisOffsetTop = myElem.offset().top;
2214
+
2215
+ if (!myElem.hasClass("animated-running")) {
2216
+ if (base(window).scrollTop() >= thisOffsetTop - base(window).height()) {
2217
+ myElem.addClass("animated-running " + showEffect).css({
2218
+ "opacity": ""
2219
+ });
2220
+ myElem.removeClass(hideEffect);
2221
+ }
2222
+ }
2223
+ }
2224
+ });
2225
+
2226
+ base(window).trigger("scroll");
2227
+ }
2228
+ }
2229
+
2230
+ /* ========================================================================
2231
+ * 3. 数字增加减少,购物数量控制
2232
+ * 2018年1月20日22:14:46
2233
+ * ========================================================================
2234
+ * <pre>
2235
+ <div class="fm-count fmc1">
2236
+ <input class="form-control fm-result" type="text" value="1" readonly="">
2237
+ <div class="fm-btns">
2238
+ <i class="fm-plus bi bi-chevron-up"></i>
2239
+ <i class="fm-minus bi bi-chevron-down"></i>
2240
+ </div>
2241
+ </div>
2242
+
2243
+ import 'istyle/src/css/form/fm-count.css';
2244
+ new u.ItemCount(".fmc1", {
2245
+ num: 1
2246
+ })
2247
+ * </pre>
2248
+ * ======================================================================== */
2249
+ class ItemCount {
2250
+ constructor(selector, custom) {
2251
+ this.selector = selector;
2252
+ defaultConstructor(this, selector, custom, (target) => {
2253
+ this.value = 0;
2254
+ target.elements.forEach((element) => {
2255
+ let myElems = base(element);
2256
+ if (!myElems.data("be.itemcount"))
2257
+ myElems.data("be.itemcount", target);
2258
+
2259
+ target.init(element);
2260
+ });
2261
+ });
2262
+ }
2263
+
2264
+ options = {
2265
+ num: 1
2266
+ };
2267
+
2268
+ init(element) {
2269
+ let t = this,
2270
+ myElem = base(element),
2271
+ options = this.options,
2272
+ myPlus = myElem.find(".fm-plus"),
2273
+ myMinus = myElem.find(".fm-minus"),
2274
+ myResult = myElem.find(".fm-result"),
2275
+ resultVal = parseInt(myResult.val());
2276
+
2277
+ myPlus.on("click", function (e) {
2278
+ e.preventDefault();
2279
+ resultVal += options.num;
2280
+ myResult.val(resultVal);
2281
+ t.value = resultVal;
2282
+ });
2283
+
2284
+ myMinus.on("click", function (e) {
2285
+ e.preventDefault();
2286
+ if (resultVal - options.num >= 0) {
2287
+ resultVal -= options.num;
2288
+ myResult.val(resultVal);
2289
+ t.value = resultVal;
2290
+ } else {
2291
+ return false;
2292
+ }
2293
+ });
2294
+ }
2295
+
2296
+ getValue() {
2297
+ return this.value;
2298
+ }
2299
+ }
2300
+
2301
+ /* ========================================================================
2302
+ * 4. niceSelect下拉框
2303
+ * 2022年8月14日 21:41:21
2304
+ * ========================================================================
2305
+ * <pre>
2306
+ <div style="height: 5rem;">
2307
+ <select id="ns2" class="ns-select mx-auto">
2308
+ <option value="1">All Category</option>
2309
+ <option value="2">HTML Template</option>
2310
+ <option value="3">WP Theme</option>
2311
+ <option value="4">Graphic Design</option>
2312
+ </select>
2313
+ </div>
2314
+ <button id="nsBtn" href="#" class="btn btn-danger">获取下拉框值</button>
2315
+
2316
+ import 'istyle/src/css/case/ce-nice-select.css';
2317
+ let ns = new u.NiceSelect('#ns2');
2318
+ b("#nsBtn").click(() => {
2319
+ b.l(ns.getValue())//选中下拉框value的值
2320
+ b.l(ns.getText()) //选中下拉框文本
2321
+ })
2322
+ * </pre>
2323
+ * ======================================================================== */
2324
+ class NiceSelect {
2325
+ constructor(selector, custom) {
2326
+ this.selector = selector;
2327
+ defaultConstructor(this, selector, custom, (target) => {
2328
+ this.selector = target.selector;
2329
+ target.elements.forEach((element) => {
2330
+ let myElems = base(element);
2331
+ if (!myElems.data("be.niceselect"))
2332
+ myElems.data("be.niceselect", target);
2333
+
2334
+ target.init(element);
2335
+ });
2336
+ });
2337
+ }
2338
+
2339
+ options = {}
2340
+
2341
+ create(element) {
2342
+ let t = this,
2343
+ mySelect = base(element),
2344
+ myDropdown = mySelect.after('<div></div>').next()
2345
+ .addClass('ce-nice-select')
2346
+ .addClass(mySelect.attr('class') || '')
2347
+ .addClass(mySelect.attr('disabled') ? 'disabled' : '')
2348
+ .attr('tabindex', mySelect.attr('disabled') ? null : '0')
2349
+ .html('<span class="current"></span><ul class="list"></ul>');
2350
+
2351
+ let myOptions = mySelect.find('option');
2352
+ let mySelected = base(element.options[element.selectedIndex]);
2353
+
2354
+ t.text = mySelected.data('display') || mySelected.text();
2355
+ myDropdown.find('.current').html(t.text);
2356
+
2357
+ myOptions.each(function(element) {
2358
+ let myOption = base(element),
2359
+ display = myOption.data('display'),
2360
+ isDisplay = (display !== null && display !== undefined ? display : ""),
2361
+ isSelect = mySelected.text() === myOption.text() ? 'selected' : '';
2362
+ myDropdown.find('ul').append("<li data-value=\"" + myOption.val() + "\" data-display=\"" + isDisplay +
2363
+ "\" class=\"option " + isSelect + "\">" + myOption.text() + "</li>");
2364
+ });
2365
+ }
2366
+
2367
+ init(element) {
2368
+ let t = this,
2369
+ mySelector = base(t.selector),
2370
+ myElement = base(element);
2371
+ myElement.hide();
2372
+ t.create(element);
2373
+ let myNS = mySelector.next();
2374
+ myNS.on('click', function() {
2375
+ let myDropdown = myElement.next();
2376
+ myDropdown.toggleClass('open');
2377
+ if (myDropdown.hasClass('open')) {
2378
+ myDropdown.find('.option');
2379
+ myDropdown.find('.focus').removeClass('focus');
2380
+ myDropdown.find('.selected').addClass('focus');
2381
+ } else {
2382
+ myDropdown.focus();
2383
+ }
2384
+ });
2385
+
2386
+ base('.option', myNS).on('click', function(e) {
2387
+ let myOption = base(e.currentTarget);
2388
+ let myDropdown = myNS;
2389
+ myDropdown.find('.selected').removeClass('selected');
2390
+ myOption.addClass('selected');
2391
+
2392
+ t.text = myOption.data('display') || myOption.text();
2393
+ myDropdown.find('.current').text(t.text);
2394
+ t.value = myOption.data('value');
2395
+ myDropdown.prev('select').val(t.value).trigger('change');
2396
+ });
2397
+
2398
+ return this;
2399
+ }
2400
+
2401
+ getText() {
2402
+ return this.text;
2403
+ }
2404
+ getValue() {
2405
+ return this.value;
2406
+ }
2407
+ }
2408
+
2409
+
2410
+ /* ========================================================================
2411
+ * 5. 按钮动画
2412
+ * 2023年8月30日 10:41:03
2413
+ * ========================================================================
2414
+ * <pre>
2415
+ <a href="#" class="bn-btn-5">
2416
+ <span>了解更多</span>
2417
+ </a>
2418
+
2419
+ import 'istyle/src/css/button/bn-btn-5.css';
2420
+ new u.BtnEf(".bn-btn-5");
2421
+ * </pre>
2422
+ * ======================================================================== */
2423
+ class BtnEf {
2424
+ constructor(selector, custom) {
2425
+ this.selector = selector;
2426
+ defaultConstructor(this, selector, custom, (target) => {
2427
+ this.value = 0;
2428
+ target.elements.forEach((element) => {
2429
+ let myElems = base(element);
2430
+ if (!myElems.data("be.btnef"))
2431
+ myElems.data("be.btnef", target);
2432
+
2433
+ target.init(element);
2434
+ });
2435
+ });
2436
+ }
2437
+
2438
+ options = {};
2439
+
2440
+ init(element) {
2441
+ base(element).append('<b></b>');
2442
+ base(element).on('mouseenter', function (e) {
2443
+ let parentOffset = base(this).offset(),
2444
+ relX = e.pageX - parentOffset.left,
2445
+ relY = e.pageY - parentOffset.top;
2446
+ base(this).find('b').css({
2447
+ 'top': relY + 'px',
2448
+ 'left': relX + 'px'
2449
+ });
2450
+ }).on('mouseout', function (e) {
2451
+ let parentOffset = base(this).offset(),
2452
+ relX = e.pageX - parentOffset.left,
2453
+ relY = e.pageY - parentOffset.top;
2454
+ base(this).find('b').css({
2455
+ 'top': relY + 'px',
2456
+ 'left': relX + 'px'
2457
+ });
2458
+ });
2459
+ // b("." + b(element).attr('class') + "[href='#']").click(function (e) {
2460
+ // e.preventDefault()
2461
+ // });
2462
+ }
2463
+ }
2464
+
2465
+
2466
+ /* ========================================================================
2467
+ * 6. 局部loading动画
2468
+ * 2023年8月5日 10:55:51
2469
+ * ========================================================================
2470
+ * <pre>
2471
+ <div class="do-load-warp mx-auto" style="text-align: left; width: 620px;">
2472
+ <p class="mb-3 ae-test-target" data-ae-load>
2473
+ 在线客服正在为您服务
2474
+ </p>
2475
+ <h2 class="mb-3 ae-test-target" data-ae-load>
2476
+ 欢迎!我们能为您提供什么帮助?
2477
+ </h2>
2478
+ <div class="mb-5 " data-ae-load>
2479
+ <img src="//arisu.cn/file/images/res/anime/anime1470402086147.jpg" class="img-fluid mx-auto d-block"/>
2480
+ </div>
2481
+ </div>
2482
+
2483
+ <a id="ae-load-loading" class="btn btn-primary" href="#">显示loading动画</a>
2484
+ <a id="ae-load-done" class="btn btn-primary" href="#">loading动画完成,显示数据</a>
2485
+ <a id="ae-load-start" class="btn btn-primary" href="#">不需要加载数据,完整的loading动画</a>// let al = new u.AeLoader();//建议使用这个,在根据情况指定触发
2486
+
2487
+ import 'istyle/src/css/loading/ae-load.css';
2488
+ // let al = new u.AeLoader();//建议使用这个,在根据情况指定触发
2489
+ let al = new u.AeLoader('.ae-test-target', {
2490
+ time: 1000 //默认1秒,修改需要同时也需要修改CSS动画
2491
+ });
2492
+
2493
+ // 不需要加载数据,完整的loading动画
2494
+ b("#ae-load-start").click(function(e) {
2495
+ e.preventDefault();
2496
+ //全部触发
2497
+ al.start();
2498
+ // 指定触发,如果初始化有指定则不需要
2499
+ // al.start(".ae-test-target");
2500
+ });
2501
+ // 显示loading动画
2502
+ b("#ae-load-loading").click(function(e) {
2503
+ e.preventDefault();
2504
+ //全部触发
2505
+ al.loading();
2506
+ // 指定触发,如果初始化有指定则不需要
2507
+ // al.loading(".ae-test-target");
2508
+ });
2509
+ // loading动画完成,显示数据
2510
+ b("#ae-load-done").click(function(e) {
2511
+ e.preventDefault();
2512
+ //全部触发
2513
+ al.done();
2514
+ // 指定触发,如果初始化有指定则不需要
2515
+ // al.done(".ae-test-target");
2516
+ });
2517
+ * </pre>
2518
+ * ======================================================================== */
2519
+ class AeLoader {
2520
+ constructor(selector, custom) {
2521
+ this.selector = selector;
2522
+ this.options = base.extend( custom, this.options )
2523
+ base("[data-ae-load]").addClass("ae-load");
2524
+ }
2525
+
2526
+ options = {
2527
+ target: '',
2528
+ //默认1秒,修改需要同时也需要修改CSS动画
2529
+ time: 1000
2530
+ }
2531
+
2532
+ //不需要加载数据,完整的loading动画
2533
+ start(target) {
2534
+ target = target ? target : this.selector;
2535
+ // b(target + "[data-ae-load]").addClass("ae-load");
2536
+ // b(target + "[data-ae-load]").removeClass("ae-tt-complete ae-tt-done ae-tt-loading");
2537
+ // setTimeout(function() {
2538
+ // b(target + "[data-ae-load]").addClass("ae-tt-complete");
2539
+ // setTimeout(function() {b(target + "[data-ae-load]").removeClass("ae-load ae-tt-complete");}, 1000);
2540
+ // }, 100);
2541
+ base(target + "[data-ae-load]").addClass("ae-load")
2542
+ .removeClass("ae-tt-complete ae-tt-done ae-tt-loading")
2543
+ .addClass("ae-tt-complete");
2544
+ setTimeout(function() {
2545
+ base(target + "[data-ae-load]").removeClass("ae-load ae-tt-complete");
2546
+ }, this.options.time);
2547
+ }
2548
+
2549
+ //显示loading动画
2550
+ loading(target) {
2551
+ target = target ? target : this.selector;
2552
+
2553
+ base("[data-ae-load]").addClass("ae-load");
2554
+ base(target + "[data-ae-load]").each(function(currentTarget) {
2555
+ let minWidth = base(currentTarget).data("al-mw");
2556
+ let minHeight = base(currentTarget).data("al-mh");
2557
+ if (minWidth) base(currentTarget).css("min-width", minWidth);
2558
+ if (minHeight) base(currentTarget).css("min-height", minHeight);
2559
+
2560
+ // b(currentTarget).removeClass("ae-tt-complete ae-tt-done ae-tt-loading");
2561
+ // setTimeout(function() {
2562
+ // b(currentTarget).addClass("ae-tt-loading");
2563
+ // }, 1);
2564
+ base(currentTarget).removeClass("ae-tt-complete ae-tt-done ae-tt-loading").addClass("ae-tt-loading");
2565
+ })
2566
+ }
2567
+
2568
+ //loading动画完成,显示数据
2569
+ done(target) {
2570
+ target = target ? target : this.selector;
2571
+ // b(target + "[data-ae-load]").removeClass("ae-tt-done");
2572
+ // setTimeout(function() {
2573
+ // b(target + "[data-ae-load]").addClass("ae-tt-done");
2574
+ // setTimeout(function() {b(target + "[data-ae-load]").removeClass("ae-load ae-tt-loading ae-tt-done");}, 1000);
2575
+ // }, 1);
2576
+ base(target + "[data-ae-load]").removeClass("ae-tt-done").addClass("ae-tt-done");
2577
+ setTimeout(function() {
2578
+ base(target + "[data-ae-load]").removeClass("ae-load ae-tt-loading ae-tt-done");
2579
+ }, this.options.time);
2580
+ }
2581
+
2582
+ }
2583
+
2584
+
2585
+ /* ========================================================================
2586
+ * 7. 分页
2587
+ * 2024年6月29日 10:28:55
2588
+ * ========================================================================
2589
+ * <pre>
2590
+ <div class="be-paging-warp">
2591
+ <p></p>
2592
+ <nav>
2593
+ <ul id="ipagination" class="be-paging"></ul>
2594
+ </nav>
2595
+ </div>
2596
+
2597
+ new u.IPagination('#ipagination', {
2598
+ totalItems: 100,
2599
+ itemsPerPage: 10,
2600
+ visiblePages: 5,
2601
+ // prev: '<i class="bi bi-chevron-left"></i>',
2602
+ // next: '<i class="bi bi-chevron-right"></i>',
2603
+ // first: '<i class="bi bi-chevron-double-left"></i>',
2604
+ // last: '<i class="bi bi-chevron-double-right"></i>',
2605
+ onButtonClick: (page) => {
2606
+ console.log('当前页为:', page);
2607
+ }
2608
+ })
2609
+ * </pre>
2610
+ * ======================================================================== */
2611
+ class IPagination {
2612
+ constructor(selector, custom) {
2613
+ this.selector = selector;
2614
+ defaultConstructor(this, selector, custom, (target) => {
2615
+ let t = this;
2616
+ target.elements.forEach( ( element ) => {
2617
+ let myElems = base( element );
2618
+ if (!myElems.data( "be.ipagination" ))
2619
+ myElems.data( "be.ipagination", target );
2620
+
2621
+ t.currentPage = 1;
2622
+ t.totalPages = Math.ceil(t.options.totalItems / t.options.itemsPerPage);
2623
+ target.init( );
2624
+ } )
2625
+ } );
2626
+ }
2627
+ // containerId, totalItems, itemsPerPage, visiblePages = 5
2628
+ options = {
2629
+ targetWarp: '.be-paging-warp',
2630
+ totalItems: 0, //总条数
2631
+ itemsPerPage: 0, //一页几条数据
2632
+ visiblePages: 5, //显示多少可见页
2633
+ prev: '上一页', //or: <i class="bi bi-chevron-left"></i>
2634
+ next: '下一页', //or: <i class="bi bi-chevron-right"></i>
2635
+ first: '首页', //or: <i class="bi bi-chevron-double-left"></i>
2636
+ last: '尾页', //or: <i class="bi bi-chevron-double-right"></i>
2637
+ onButtonClick: function (currentPage) {}
2638
+ }
2639
+
2640
+ init() {
2641
+ let target = this,
2642
+ options = target.options;
2643
+
2644
+ base(this.selector).html('');
2645
+
2646
+ // 添加上一页和首页按钮
2647
+ this.addPageButton(options.first, 1, () => this.goToPage(1));
2648
+ this.addPageButton(options.prev, this.currentPage - 1, () => this.goToPrevPage());
2649
+
2650
+ // 根据当前页码计算要显示的页码范围
2651
+ let startPage = Math.max(1, this.currentPage - Math.floor(options.visiblePages / 2)),
2652
+ endPage = Math.min(this.totalPages, startPage + options.visiblePages - 1);
2653
+
2654
+ // 如果范围小于可见页数,则调整开始页码以显示更多前面的页码
2655
+ if (endPage - startPage < options.visiblePages - 1) {
2656
+ startPage = Math.max(1, endPage - options.visiblePages + 1);
2657
+ }
2658
+ // 显示页码按钮
2659
+ for (let i = startPage; i <= endPage; i++) {
2660
+ this.addPageButton(i, i, () => this.goToPage(i));
2661
+ }
2662
+
2663
+ // 添加下一页和尾页按钮
2664
+ this.addPageButton(options.next, this.currentPage + 1, () => this.goToNextPage());
2665
+ this.addPageButton(options.last, this.totalPages, () => this.goToPage(this.totalPages));
2666
+ const start = options.itemsPerPage * (target.currentPage - 1) + 1,
2667
+ end = (start < options.totalItems - options.itemsPerPage ) ? ( start + options.itemsPerPage - 1 ) : ( start + options.totalItems % options.itemsPerPage - 1 );
2668
+ base('p', options.targetWarp).html('显示 ' + start + ' 至 ' + end + ' 条,共有 ' + options.totalItems + ' 条');
2669
+ }
2670
+
2671
+ addPageButton(text, page, onClick) {
2672
+ const li = document.createElement('li');
2673
+ li.classList.add('page-item');
2674
+ if ( typeof text === 'number' && Number.isFinite(text) || !isNaN(Number(text)) && Number.isFinite(Number(text)) ) {
2675
+ li.classList.add('pi-t2');
2676
+ } else {
2677
+ li.classList.add('pi-t1');
2678
+ }
2679
+ const button = document.createElement('button');
2680
+ li.append(button);
2681
+ button.innerHTML = text;
2682
+ button.onclick = onClick;
2683
+ if (page === this.currentPage || page === 0 || page === this.totalPages + 1) {
2684
+ li.classList.add('active');
2685
+ li.classList.add('disabled');
2686
+ // button.disabled = true;
2687
+ }
2688
+
2689
+ base(this.selector).append(li);
2690
+ }
2691
+ goToPrevPage() {
2692
+ if (this.currentPage > 1) {
2693
+ this.currentPage--;
2694
+ this.init();
2695
+ this.options.onButtonClick(this.currentPage);
2696
+ }
2697
+ }
2698
+ goToNextPage() {
2699
+ if (this.currentPage < this.totalPages) {
2700
+ this.currentPage++;
2701
+ this.init();
2702
+ this.options.onButtonClick(this.currentPage);
2703
+ }
2704
+ }
2705
+ goToPage(page) {
2706
+ if (page >= 1 && page <= this.totalPages) {
2707
+ this.currentPage = page;
2708
+ this.init();
2709
+ this.options.onButtonClick(this.currentPage);
2710
+ }
2711
+ }
2712
+ }
2713
+
2714
+ /* ========================================================================
2715
+ * 8. 列表查询分页封装插件
2716
+ * 列表查询分页封装插件,opacity-* 为css透明度
2717
+ * 2016年7月27日15:02:29
2718
+ * ========================================================================
2719
+ * <pre>
2720
+ // 1. 基础模板
2721
+ <script type="text/template" id="tp-list">
2722
+ <div class="be-list-data"></div>
2723
+ <div class="be-list-loading">
2724
+ <div class="do-preloader-3">
2725
+ <div class="do-p3">
2726
+ <div class="do-p3-inner do-p3-i1"></div>
2727
+ <div class="do-p3-inner do-p3-i2"></div>
2728
+ <div class="do-p3-inner do-p3-i3"></div>
2729
+ </div>
2730
+ </div>
2731
+ </div>
2732
+ <div class="be-list-nofound">查询不到相应数据!</div>
2733
+ <div class="be-list-page">
2734
+ <div class="be-paging-warp">
2735
+ <p></p>
2736
+ <nav>
2737
+ <ul id="ipagination" class="be-paging"></ul>
2738
+ </nav>
2739
+ </div>
2740
+ </div>
2741
+ </script>
2742
+ // 2. 数据列表模型,如新闻
2743
+ <script type="text/template" id="tp-data-news">
2744
+ {{#if isInit true}}
2745
+ <table class="be-table">
2746
+ <thead>
2747
+ <tr>
2748
+ <td class="xs-show be-te-check is-check">
2749
+ <input type="checkbox" class="ilist-check-all" data-flag="1" data-url={{url}} />
2750
+ </td>
2751
+ <td class="xs-hid">时间</td>
2752
+ <td class="xs-show" data-sortname="a.title" data-is-sort="true">标题</td>
2753
+ <td>类型</td>
2754
+ <td>作者</td>
2755
+ <td class="be-list-events">操作</td>
2756
+ </tr>
2757
+ </thead>
2758
+ <tbody class="be-list-data-body">
2759
+ {{/if}}
2760
+ {{#each items}}
2761
+ <tr>
2762
+ <td class="xs-show be-te-check">
2763
+ <input type="checkbox" class="ilist-check" data-flag="1" data-id="{{id}}" data-url={{url}}/>
2764
+ </td>
2765
+ <td class="xs-hid">{{createDate}}</td>
2766
+ <td class="xs-show">{{title}}</td>
2767
+ <td>{{sort}}</td>
2768
+ <td>{{author}}</td>
2769
+ <td class="be-list-events">
2770
+ <a href="link/{{id}}" class="be-detail"><i class="bi bi-search"></i></a>
2771
+ <a href="link/{{id}}" class="be-edit"><i class="bi bi-pencil-square"></i></a>
2772
+ <a data-id={{id}} data-url={{url}} href="#" class="be-delete"><i class="bi bi-trash3"></i></a>
2773
+ </td>
2774
+ </tr>
2775
+ {{/each}}
2776
+ {{#if isInit true}}
2777
+ </tbody>
2778
+ </table>
2779
+ {{/if}}
2780
+ </script>
2781
+ // 3. HTML代码查询参数范例,根据情况修改查询参数及列表.be-list ID
2782
+ <div class="be-list-warp">
2783
+ <div class="be-list-filter">
2784
+ <div class="be-lf-btns">
2785
+ <div class="be-lb-left">
2786
+ <a href="javascript:" class="mn-button me-2"><i class="bi bi-plus-square"></i>新增</a>
2787
+ <a href="javascript:" class="mn-button me-2"><i class="bi bi-trash3"></i>删除</a>
2788
+ </div>
2789
+ <div class="be-lb-right">
2790
+ <a id="be-search" href="javascript:" class="mn-button me-2">
2791
+ <i class="bi bi-search"></i>搜索
2792
+ </a>
2793
+ <button class="mn-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#searchMore"
2794
+ aria-expanded="false" aria-controls="searchMore">
2795
+ <i class="bi bi-chevron-double-down"></i>
2796
+ </button>
2797
+ </div>
2798
+ </div>
2799
+ <!-- 隐藏的查询条件 -->
2800
+ <div class="be-lf-params">
2801
+ <div class="collapse" id="searchMore">
2802
+ <div class="be-lf-ps">
2803
+ <label>
2804
+ <span>类型:</span>
2805
+ <select value="0">
2806
+ <option value="0" selected="selected">所有</option>
2807
+ <option value="1">实事</option>
2808
+ <option value="2">娱乐</option>
2809
+ <option value="3">军事</option>
2810
+ </select>
2811
+ </label>
2812
+ <label>
2813
+ <span>标题:</span>
2814
+ <input id="be-input-2" type="text" placeholder="标题"/>
2815
+ </label>
2816
+ <label>
2817
+ <span>时间:</span>
2818
+ <input type="date" />
2819
+ </label>
2820
+ </div>
2821
+ </div>
2822
+ </div>
2823
+ </div>
2824
+ <div id="test-list" class="be-list"></div>
2825
+ </div>
2826
+
2827
+ // JS操作
2828
+ import '../css/bootstrap-icons.css'
2829
+ import 'istyle/src/css/base/be-table.css'
2830
+ import 'istyle/src/css/base/be-paging.css'
2831
+ import 'istyle/src/css/button/mn-button.css'
2832
+ import 'istyle/src/css/loading/do-preloader-3.css'
2833
+ import Handlebars from 'glib/handlebars'
2834
+ import { Tooltip } from 'glib/bootstrap';
2835
+
2836
+ const ilist = new u.IList('#test-list', {
2837
+ url: "./springmvc/news/findNews.action",
2838
+ param: {},
2839
+ method: "get",
2840
+ sortname: "a.id",
2841
+ rp: 10,
2842
+ visiblePages: 5,
2843
+ handlebars: Handlebars,
2844
+ headerMap: { 'token': 'abc123' },
2845
+ onSuccess: function(data) {
2846
+ b.handlebars(Handlebars);
2847
+ const tplEl = b("#tp-data-news");
2848
+ const html = Handlebars.compile(tplEl.html())({
2849
+ items: data.rows,
2850
+ isInit: data.isInit
2851
+ });
2852
+
2853
+ if (data.isInit)
2854
+ b(".be-list-data", "#test-list").html(html);
2855
+ else
2856
+ b(".be-list-data-body", "#test-list").html(html);
2857
+
2858
+ b.tip(Tooltip);
2859
+ // 测试获取列ID
2860
+ // b(".ip").click(function() {
2861
+ // alert("该列数据id为" + b(this).data("id"));
2862
+ // })
2863
+ },
2864
+ onError: (e) => {
2865
+ console.error(e);
2866
+ }
2867
+ });
2868
+
2869
+ b('#be-search').click(() => {
2870
+ ilist.reload({
2871
+ 'title': b('#be-input-2').val()
2872
+ })
2873
+ });
2874
+
2875
+ * </pre>
2876
+ * ======================================================================== */
2877
+ class IList {
2878
+
2879
+ constructor(selector, custom) {
2880
+ this.selector = selector;
2881
+ defaultConstructor( this, selector, custom, ( target ) => {
2882
+ target.elements.forEach( ( element ) => {
2883
+ let myElems = base( element );
2884
+ if (!myElems.data( "be.ilist" ))
2885
+ myElems.data( "be.ilist", target );
2886
+
2887
+ if (typeof Handlebars !== 'undefined' && custom.handlebars === null) custom.handlebars = Handlebars;
2888
+ target.init( element, custom );
2889
+ } );
2890
+ } );
2891
+ }
2892
+
2893
+ options = {
2894
+ rp: "10",
2895
+ visiblePages: 7,
2896
+ sortname: "id",
2897
+ sortorder: "desc",
2898
+ method: "post",
2899
+ dataType: "json",
2900
+ // async: true,
2901
+ // jsonp: null,
2902
+ // jsonpCallback: null,
2903
+ param: {},
2904
+ handlebars: null,//必须的模板生成工具
2905
+ url: "",
2906
+ loadColor: "#0a0a0a",//必须是16进制,不能缩写
2907
+ lang: "cn",
2908
+ template: "#tp-list",
2909
+ headerMap: { }, //{ 'Content-Type': 'application/json'}
2910
+ cache: 'default',
2911
+ prev: '上一页', //or: <i class="bi bi-chevron-left"></i>
2912
+ next: '下一页', //or: <i class="bi bi-chevron-right"></i>
2913
+ first: '首页', //or: <i class="bi bi-chevron-double-left"></i>
2914
+ last: '尾页', //or: <i class="bi bi-chevron-double-right"></i>
2915
+ onSuccess: false,
2916
+ onError: false
2917
+ }
2918
+
2919
+ init(element, options) {
2920
+ let target = this,
2921
+ myElement = base(element),
2922
+ html = myElement.data("be.ilist.html");
2923
+ if (options === undefined)
2924
+ options = target.options
2925
+ myElement.data("be.ilist.flag", true);
2926
+
2927
+ if (html) {
2928
+ // myElement.html(html);
2929
+ base(".be-list-data-body", element).html("");
2930
+ } else {
2931
+ const tplEl = base(options.template),
2932
+ html = options.handlebars.compile(tplEl.html())({});
2933
+ myElement.html(html);
2934
+ myElement.data("be.ilist.html", html);
2935
+ }
2936
+
2937
+ let param = base.extend(
2938
+ { page: 1, rp: options.rp, sortname: options.sortname, sortorder: options.sortorder },
2939
+ options.param );
2940
+ options.isInit = true;// 是否为初始化列表,表头只在初始化生成
2941
+ base(element).data("be.ilist.event", true);
2942
+ target.getData(element, options, param);
2943
+ };
2944
+
2945
+ // 数据查询
2946
+ getData(element, options, param) {
2947
+ let target = this;
2948
+ base(".be-list-data-body", element).html("");
2949
+ base(".be-list-loading", element).addClass("opacity-100");
2950
+ base(".be-list-nofound", element).removeClass("opacity-100");
2951
+ base(".be-list-page", element).removeClass("opacity-100");
2952
+
2953
+ base.ajax({
2954
+ method: options.method,
2955
+ url: options.url,
2956
+ headerMap: options.headerMap,
2957
+ // beforeSend: function(request) {
2958
+ // for (let key in options.headerMap) {
2959
+ // if (options.headerMap.hasOwnProperty(key)) {
2960
+ // request.setRequestHeader(key, options.headerMap[key]);
2961
+ // }
2962
+ // }
2963
+ // },
2964
+ data: param,
2965
+ cache: options.cache,
2966
+ // jsonp: options.jsonp,
2967
+ // jsonpCallback: options.jsonp,
2968
+ async: options.async,
2969
+ dataType: options.dataType,
2970
+ success: function (data) {
2971
+ // b(".be-list-loading", element).css("display", "none");
2972
+ base(".be-list-loading", element).removeClass("opacity-100").addClass("opacity-0");
2973
+ base(".be-list-data", element).removeClass("opacity-0");
2974
+ base(".be-list-data-body", element).css("display", "table-row-group");
2975
+
2976
+ data.isInit = options.isInit;
2977
+ if (options.onSuccess)
2978
+ options.onSuccess(data);
2979
+
2980
+ if (data.total) {
2981
+ target.page(element, options, param, data.total);//翻页
2982
+ //全选/全清
2983
+ base(".ilist-check-all").checkAll('.ilist-check');
2984
+
2985
+ if (base(element).data("be.ilist.event")) {
2986
+ base(element).data("be.ilist.event", false);
2987
+
2988
+ //选择单列/取消选择单列
2989
+ base( ".ilist-check", element ).change( e => {
2990
+ let isChecked = base( e.currentTarget ).is( ":checked" );
2991
+ if (isChecked)
2992
+ base(e.currentTarget).parents("tr").addClass("active");
2993
+ else
2994
+ base(e.currentTarget).parents("tr").removeClass("active");
2995
+ } );
2996
+
2997
+ //全选列/全清列
2998
+ base( ".ilist-check-all", element ).change( e => {
2999
+ let isChecked = base( e.currentTarget ).is( ":checked" );
3000
+ if (isChecked)
3001
+ base( ".ilist-check" ).addClass( "active" ).trigger("change");
3002
+ else
3003
+ base( ".ilist-check" ).removeClass( "active" ).trigger("change");
3004
+ } );
3005
+
3006
+ //点击列选择单列/点击列取消选择单列
3007
+ base( "table > tbody tr", element ).click( e => {
3008
+ let target = base( e.target );
3009
+ if (!(target.is( "input" ) || target.is( "i" ) || target.is( "a" ))) {
3010
+ base( ".ilist-check", e.currentTarget ).click();
3011
+ }
3012
+ } )
3013
+
3014
+ //排序,<td data-sortname="a.title" data-is-sort="true"
3015
+ base( "table > thead tr td", element ).click( e => {
3016
+ const sortname = base( e.currentTarget ).data( "sortname" );
3017
+ if (sortname) {
3018
+ param.sortname = sortname;
3019
+ if (!base( e.currentTarget ).hasClass( "is-check" ) && param.sortname) {
3020
+ let sortorder = base( e.currentTarget ).attr( "data-sort-order" );
3021
+
3022
+ base( "table > thead tr td", element ).removeAttr( "data-sort-order" );
3023
+
3024
+ if (sortorder) {
3025
+ if (sortorder === "desc") {
3026
+ base( e.currentTarget ).attr( "data-sort-order", "asc" );
3027
+ sortorder = "asc";
3028
+ } else {
3029
+ base( e.currentTarget ).attr( "data-sort-order", "desc" );
3030
+ sortorder = "desc";
3031
+ }
3032
+ param.sortorder = sortorder;
3033
+ } else {
3034
+ base( e.currentTarget ).attr( "data-sort-order", "desc" );
3035
+ param.sortorder = "desc";
3036
+ }
3037
+
3038
+ base( element ).data( "be.ilist.flag", true );
3039
+ param.page = "1";
3040
+ options.isInit = false;
3041
+ target.getData( element, options, param );
3042
+ } else {
3043
+ base( e.currentTarget ).css( "cursor", "auto ! important" );
3044
+ }
3045
+ }
3046
+ } );
3047
+ }
3048
+ base(".be-list-page", element).addClass("opacity-100");//b(".be-list-page", element).css("visibility", "visible");
3049
+ } else {
3050
+ base(".be-list-nofound", element).addClass("opacity-100");//b(".be-list-nofound", element).css("display", "block");
3051
+ base(".be-list-page", element).removeClass("opacity-100");
3052
+ }
3053
+ },
3054
+ error: function (XMLHttpRequest, textStatus, errorThrown) {
3055
+ try {
3056
+ if (options.onError) options.onError(XMLHttpRequest, textStatus, errorThrown);
3057
+ } catch (e) {}
3058
+ }
3059
+ });
3060
+ }
3061
+
3062
+ // 分页查询
3063
+ page(element, options, param, total) {
3064
+ let target = this,
3065
+ myElement = base(element);
3066
+ if (myElement.data("be.ilist.flag")) {
3067
+ new IPagination('#ipagination', {
3068
+ totalItems: total,
3069
+ itemsPerPage: options.rp,
3070
+ visiblePages: options.visiblePages,
3071
+ prev: options.prev,
3072
+ next: options.next,
3073
+ first: options.first,
3074
+ last: options.last,
3075
+ onButtonClick: ( page ) => {
3076
+ document.querySelector('.ilist-check-all').checked = false;
3077
+ param.page = page;
3078
+ options.isInit = false;
3079
+ target.getData( element, options, param );
3080
+ }
3081
+ } )
3082
+ }
3083
+ myElement.data("be.ilist.flag", false);
3084
+ }
3085
+
3086
+ // 设置参数重新搜索
3087
+ reload(param) {
3088
+ let target = base(this),
3089
+ data = target.data("be.ilist"),
3090
+ newParam = base.extend(param,
3091
+ { page: 1, rp: data.options.rp, sortname: data.options.sortname, sortorder: data.options.sortorder });
3092
+ data.options.isInit = false;
3093
+ target.data("be.ilist.flag", true);
3094
+ data["getData"](data['selector'], data.options, newParam);
3095
+ }
3096
+ }
3097
+
3098
+
3099
+ /* ========================================================================
3100
+ * 9. 手风琴导航菜单
3101
+ * 右侧导航菜单
3102
+ * 2024年7月18日 10:17:08
3103
+ * ========================================================================
3104
+ * <pre>
3105
+ <button id="iaccordion-btn" class="ce-accordion-btn"><i class="bi bi-layout-text-sidebar-reverse"></i></button>
3106
+ <ul class="ce-accordion" id="iaccordion">
3107
+ <li class="sub-menu"><a href="javascript:"><i class="bi bi-sunset"></i><span>主页</span></a></li>
3108
+ <li class="sub-menu"><a href="#"><i class="bi bi-twitch"></i><span>数据</span></a>
3109
+ <ul class="sub">
3110
+ <li class="sub-menu"><a href="javascript:"><span>人员管理</span></a></li>
3111
+ <li class="sub-menu"><a href="javascript:"><span>日志</span></a></li>
3112
+ <li class="sub-menu"><a href="javascript:"><span>新闻管理</span></a></li>
3113
+ <li class="sub-menu"><a href="javascript:"><span>签到</span></a></li>
3114
+ </ul>
3115
+ </li>
3116
+ <li class="sub-menu"><a href="#"><i class="bi bi-twitter"></i><span>权限</span></a>
3117
+ <ul class="sub">
3118
+ <li class="sub-menu"><a href="javascript:"><span>新闻平台权限</span></a></li>
3119
+ <li class="sub-menu"><a href="javascript:"><span>商城权限</span></a>
3120
+ <ul class="sub">
3121
+ <li class="sub-menu"><a href="javascript:"><span>商城查询权限</span></a></li>
3122
+ </ul>
3123
+ </li>
3124
+ </ul>
3125
+ </li>
3126
+ </ul>
3127
+
3128
+ import 'istyle/src/css/accordion/ce-accordion.css'
3129
+ new u.IAccordion('#iaccordion', { speed: 300, showCount: true });
3130
+ b("#iaccordion-btn").click((e) => {
3131
+ b('#iaccordion').toggleClass("ce-accordion-small")
3132
+ b(e.currentTarget).toggleClass("ce-ab-small")
3133
+ })
3134
+ * </pre>
3135
+ * ======================================================================== */
3136
+ class IAccordion {
3137
+ constructor(selector, custom) {
3138
+ this.selector = selector;
3139
+ defaultConstructor(this, selector, custom, (target) => {
3140
+ target.elements.forEach( ( element ) => {
3141
+ let myElems = base( element );
3142
+ if (!myElems.data( "be.iaccordion" ))
3143
+ myElems.data( "be.iaccordion", target );
3144
+
3145
+ target.init( element, custom );
3146
+ } );
3147
+ } );
3148
+ }
3149
+
3150
+ options = {
3151
+ classParent: 'ia-parent', // 包含ul的父级菜单
3152
+ classActive : 'active', // 当前激活菜单
3153
+ classArrow: 'ia-icon', // 菜单右侧展开缩小图标: - and +
3154
+ classCount: 'ia-count',
3155
+ autoExpand: false,
3156
+ classExpand : 'ia-current-parent',
3157
+ autoClose: true, // 打开菜单时是否关闭其他承担
3158
+ speed: 300,
3159
+ saveState : true, // 下次打开是否使用当前的菜单
3160
+ disableLink : true, // 需要展开子项的不触发浏览链接
3161
+ showCount: false, // 显示一样多少菜单
3162
+ cookie: 'ia-cookie',
3163
+ smallClass: 'ce-accordion-small'
3164
+ }
3165
+
3166
+ init(element, options) {
3167
+ const target = this,
3168
+ myLinks = base( 'li > a', element ),
3169
+ mySub = base( 'li > ul', element );
3170
+
3171
+ options = base.extend( options, target.options );
3172
+ const classActive = options.classActive;
3173
+
3174
+ this.setUpAccordion(element, myLinks, mySub, options);
3175
+ if (options.saveState === true) {
3176
+ target.checkCookie( options.cookie, element, classActive );
3177
+ }
3178
+ if (options.autoExpand === true) {
3179
+ base( 'li.' + options.classExpand + ' > a' ).addClass( classActive );
3180
+ }
3181
+
3182
+ myLinks.click( function ( e ) {
3183
+ const myTarget = base( e.currentTarget ),
3184
+ myActiveLi = myTarget.parent(),
3185
+ isSmall = target.isSmall( e, element, options.smallClass);
3186
+ // 需要展开子项的不触发浏览链接
3187
+ if (options.disableLink === true) {
3188
+ if (myTarget.siblings( 'ul' ).length > 0) {
3189
+ e.preventDefault();
3190
+ }
3191
+ }
3192
+
3193
+ // 关闭其他展开的菜单
3194
+ if (options.autoClose === true) {
3195
+ target.autoCloseAccordion( element, myTarget, isSmall, options )
3196
+ }
3197
+
3198
+ if (base( '> ul', myActiveLi ).length === 0) {
3199
+ base( '> a', myActiveLi ).addClass( classActive );
3200
+ } else if (base( '> ul', myActiveLi ).css( 'display' ) !== 'none') {
3201
+ // 已经打开的则关闭
3202
+ target.slideUp( base( 'ul', myActiveLi ), isSmall, options )
3203
+ base( 'a', myActiveLi ).removeClass( classActive );
3204
+ } else {
3205
+ if (base( e.currentTarget ).siblings( 'ul' ).css( 'display' ) === 'none') {
3206
+ target.slideDown(base( e.currentTarget ).siblings( 'ul' ).css("overflow", "hidden"), isSmall, options)
3207
+ } else {
3208
+ target.slideUp( base( e.currentTarget ).siblings( 'ul' ), isSmall, options )
3209
+ }
3210
+ base( '> a', myActiveLi ).addClass( classActive );
3211
+ }
3212
+
3213
+ // 设置cookie
3214
+ if (options.saveState === true) {
3215
+ target.createCookie( options.cookie, element, classActive );
3216
+ }
3217
+ });
3218
+ }
3219
+
3220
+ setUpAccordion(target, myLinks, mySub, options) {
3221
+ const classArrowHtml = '<span class="' + options.classArrow + '"></span>',
3222
+ classParentLi = options.classParent + '-li';
3223
+ mySub.show();
3224
+ base( 'li', target ).each(e => {
3225
+ if (base( '> ul', e ).length > 0) {
3226
+ base( e ).addClass( classParentLi );
3227
+ base( '> a', e ).addClass( options.classParent ).append( classArrowHtml );
3228
+ }
3229
+ });
3230
+ mySub.hide();
3231
+ // 显示数量
3232
+ if (options.showCount === true) {
3233
+ base( 'ul', target ).each((ele) => {
3234
+ base( '> a', base(ele).parent() ).append( ' <span class="' + options.classCount + '">(' + ele.children.length + ')</span>' );
3235
+ })
3236
+ }
3237
+ }
3238
+
3239
+ // 关闭其它标签
3240
+ autoCloseAccordion( element, target, isSmall, options ) {
3241
+ const t = this;
3242
+ base( 'ul', element ).each((ele) => {
3243
+ let isParent = false;
3244
+ target.parents("ul").each((parentEle) => {
3245
+ if (parentEle === ele)
3246
+ isParent = true;
3247
+ });
3248
+ if (!isParent && target.siblings( 'ul' ).elements[0] !== ele && ele.style.display !== 'none') {
3249
+ t.slideUp( base(ele), isSmall, options )
3250
+ }
3251
+ })
3252
+ // 重置激活菜单
3253
+ base( 'a', element ).removeClass( options.classActive );
3254
+ target.parents("li").each((ele) => {
3255
+ base( '> a', ele).addClass( options.classActive );
3256
+ })
3257
+ // target.addClass( options.classActive );
3258
+ }
3259
+
3260
+ // 检索cookie值
3261
+ checkCookie(cookieId, target, classActive) {
3262
+ const t = this,
3263
+ cookieVal = base.getCookie(cookieId);
3264
+ if( cookieVal !== null && cookieVal !== "" ) {
3265
+ const activeArray = cookieVal.split(',');
3266
+ t.setActiveMenu( target, activeArray, 0, classActive )
3267
+ }
3268
+ }
3269
+
3270
+ // 通过cookie设置之前的存档
3271
+ setActiveMenu(target, activeArray, index, classActive) {
3272
+ const myCookieLi = base('li:eq(' + activeArray[index] + ')', target),
3273
+ myA = base('> a', myCookieLi ),
3274
+ myUl = myA.siblings('ul');
3275
+ myA.addClass( classActive );
3276
+ myUl.css('display', '');
3277
+
3278
+ if (activeArray.length > index + 1) {
3279
+ this.setActiveMenu(myUl, activeArray, ++index, classActive);
3280
+ }
3281
+ }
3282
+
3283
+ // 创建cookie
3284
+ createCookie(cookieId, target, classActive){
3285
+ let activeIndex = [];
3286
+ // 激活菜单列表
3287
+ base('li a.' + classActive, target).each((e) => {
3288
+ const myArrayItem = base(e).parent('li'),
3289
+ // itemIndex = b('li', target).index(myArrayItem);
3290
+ itemIndex = myArrayItem.index();
3291
+ activeIndex.push(itemIndex);
3292
+ });
3293
+ base.setCookie(cookieId, activeIndex);
3294
+ }
3295
+
3296
+ // 是否为在缩小模式下的下拉按钮
3297
+ isSmall(e, element, smallClass) {
3298
+ if (base(element).hasClass(smallClass) && base(e.currentTarget).siblings('ul').length !== 0) {
3299
+ e.preventDefault();
3300
+ return true;
3301
+ } else {
3302
+ return false;
3303
+ }
3304
+ }
3305
+
3306
+ // 菜单列显示
3307
+ slideDown(myElement, isSmall, options) {
3308
+ if (!isSmall)
3309
+ myElement.slideDown(options.speed)
3310
+ }
3311
+
3312
+ // 菜单列隐藏
3313
+ slideUp(myElement, isSmall, options) {
3314
+ if (!isSmall)
3315
+ myElement.slideUp(options.speed)
3316
+ }
3317
+ }
3318
+
3319
+ /* ========================================================================
3320
+ * 10. 弹框搜索面板
3321
+ * 2016年5月22日19:01:48
3322
+ * ========================================================================
3323
+ * <pre>
3324
+ <script type="text/template" id="tp-popover-items">
3325
+ {{#each items}}
3326
+ <div class="popover-content-item row">
3327
+ {{#if type 'text'}}
3328
+ <div class="col-sm-3 text-right">
3329
+ <label class="label-control">{{desc}}:</label>
3330
+ </div>
3331
+ <div class="col-sm-8 no-padding-left">
3332
+ <input name="{{name}}" class="form-control popover-form-item" placeholder="{{desc}}" value="{{value}}"/>
3333
+ </div>
3334
+ {{/if}}
3335
+ {{#if type 'date'}}
3336
+ <div class="col-sm-3 text-right">
3337
+ <label class="label-control">{{desc}}:</label>
3338
+ </div>
3339
+ <div class="col-sm-8 no-padding-left be-rel">
3340
+ <input id="airDatepicker" name="{{name}}" class="form-control popover-form-item popover-form-date" placeholder="{{desc}}" value="{{value}}"/>
3341
+ </div>
3342
+ {{/if}}
3343
+ {{#if type 'select'}}
3344
+ <div class="col-sm-3 text-right">
3345
+ <label class="label-control">{{desc}}:</label>
3346
+ </div>
3347
+ <div class="col-sm-8 no-padding-left">
3348
+ <select name="{{name}}" class="form-select popover-form-item">
3349
+ {{#each options}}
3350
+ <option value="{{name}}" {{#if selected true}}selected="selected"{{/if}}>{{value}}</option>
3351
+ {{/each}}
3352
+ </select>
3353
+ </div>
3354
+ {{/if}}
3355
+ </div>
3356
+ {{/each}}
3357
+ </script>
3358
+
3359
+ <script type="text/template" id="tp-popover">
3360
+ <div class="popover tooltip ce-popover" role="tooltip">
3361
+ <h3 class="popover-title">详细搜索</h3>
3362
+ <div class="popover-content">
3363
+ <div class="popover-content-items"></div>
3364
+ </div>
3365
+ <div class="popover-footer">
3366
+ <a class="ce-popover-ok"><i class="bi bi-search"></i>搜索</a>
3367
+ <a class="ce-popover-cancel"><i class="bi bi-x-square"></i>关闭</a>
3368
+ <a class="ce-popover-clear"><i class="bi bi-trash3"></i>清除</a>
3369
+ </div>
3370
+ </div>
3371
+ </script>
3372
+
3373
+ <a id="ipopover" tabindex="0" class="btn btn-sm btn-danger">弹出搜索框</a>
3374
+
3375
+ // JS调用
3376
+ <script src="/js/bootstrap.bundle.js"></script>
3377
+ <script src="/js/handlebars.min.js"></script>
3378
+ <script>
3379
+ Handlebars.registerHelper("if", function(v1, v2, options) {
3380
+ return (v1 === v2) ? options.fn(this) : options.inverse(this);
3381
+ });
3382
+ </script>
3383
+ or
3384
+ import "istyle/src/css/base/init.css";
3385
+ import "istyle/src/css/case/ce-popover.css";
3386
+ import Handlebars from 'glib/handlebars'
3387
+ import * as bootstrap from 'glib/bootstrap';
3388
+
3389
+ b.handlebars(Handlebars);
3390
+ import AirDatepicker from 'glib/air-datepicker'
3391
+ import localeZh from 'glib/air-datepicker/locale/zh';
3392
+ import 'glib/air-datepicker/air-datepicker.css'
3393
+ import 'istyle/src/css/form/fm-datepicker.css'
3394
+
3395
+ new u.PopoverSearch('#ipopover', {
3396
+ handlebars: Handlebars,
3397
+ airDatepicker: AirDatepicker,
3398
+ localeZh: localeZh,
3399
+ bootstrap: bootstrap,
3400
+ items: [
3401
+ {name: "name", desc: "姓名", type: "text", value: ""},
3402
+ {name: "time", desc: "开始时间", type: "date", value: ""},
3403
+ {name: "select", desc: "选项", type: "select",
3404
+ options: [
3405
+ {name: "", value: "所有", selected: false},//如果默认查询所有,name设置为""
3406
+ {name: "o1", value: "选项1", selected: false},
3407
+ {name: "o2", value: "选项2", selected: true}
3408
+ ]
3409
+ }
3410
+ ],
3411
+ onSerach: function(e) {
3412
+ // $("#ipopover").click();
3413
+ console.log(e.param);//参数及参数值对象,{name: "arisu", time: "2016-07-16 17:02:59", select: "o2"}
3414
+ }
3415
+ });
3416
+ * </pre>
3417
+ * ======================================================================== */
3418
+ class PopoverSearch {
3419
+ constructor( selector, custom ) {
3420
+ this.selector = selector;
3421
+ defaultConstructor( this, selector, custom, ( target ) => {
3422
+ target.elements.forEach( ( element ) => {
3423
+ let myElems = base( element );
3424
+ if (!myElems.data( "be.popoversearch" ))
3425
+ myElems.data( "be.popoversearch", target );
3426
+
3427
+ if (typeof Handlebars !== 'undefined' && custom.handlebars === null) custom.handlebars = Handlebars;
3428
+ if (typeof bootstrap !== 'undefined' && custom.bootstrap === null) custom.bootstrap = bootstrap;
3429
+ if (typeof AirDatepicker !== 'undefined' && custom.airDatepicker === null) custom.airDatepicker = AirDatepicker;
3430
+ if (typeof localeZh !== 'undefined' && custom.localeZh === null) custom.localeZh = localeZh;
3431
+ target.init( element, custom );
3432
+ } );
3433
+ } );
3434
+ }
3435
+
3436
+ options = {
3437
+ handlebars: null, //模板生成工具
3438
+ bootstrap: null, //bootstrap Popover
3439
+ airDatepicker: null,//日期控件
3440
+ localeZh: null, //日期控件中文支持
3441
+ template: "#tp-popover",
3442
+ templateItems: "#tp-popover-items",
3443
+ html: true,
3444
+ title: "详细搜索",
3445
+ trigger: "click",
3446
+ toggle: "popover",
3447
+ placement: "auto",
3448
+ onSerach: false,
3449
+ items: [], //搜索框json数据
3450
+ // startView: 2,
3451
+ // minView: 2,
3452
+ timepicker: true, //是否显示时分秒
3453
+ format: "yyyy-MM-dd hh:mm:ss"
3454
+ }
3455
+
3456
+ init(element, options) {
3457
+ let target = this;
3458
+ target.itemsValue = []; // 搜索框值
3459
+ // var $element = $(element);
3460
+ // var target = this;
3461
+
3462
+ const template = options.handlebars.compile(base(options.template).html())({});
3463
+
3464
+ const popr = new options.bootstrap.Popover(element, {
3465
+ html: options.html,
3466
+ title: options.title,
3467
+ trigger: options.trigger,
3468
+ toggle: options.toggle,
3469
+ placement: options.placement,
3470
+ template: template,
3471
+ animation: true,
3472
+ param: null
3473
+ });
3474
+
3475
+ element.addEventListener('inserted.bs.popover', () => {
3476
+ target.addItem(options);
3477
+ })
3478
+
3479
+ element.addEventListener('shown.bs.popover', () => {
3480
+ target.search(target, options);
3481
+ target.close(popr);
3482
+ target.clear();
3483
+ })
3484
+
3485
+ element.addEventListener('hide.bs.popover', () => {
3486
+ target.itemsHtml = base(".popover-content-items").html();
3487
+ target.itemsValue = [];
3488
+ base(".popover-form-item").each((e) => {
3489
+ target.itemsValue.push(base(e).val());
3490
+ })
3491
+ })
3492
+ }
3493
+
3494
+ // 添加搜索框
3495
+ addItem(options) {
3496
+ const target = this;
3497
+ if (target.itemsHtml) {
3498
+ base(".ce-popover > .popover-content .popover-content-items").html(target.itemsHtml);
3499
+ } else {
3500
+ const html = options.handlebars.compile(base(options.templateItems).html())({
3501
+ items: options.items
3502
+ });
3503
+ base(".ce-popover > .popover-content .popover-content-items").html(html);
3504
+ }
3505
+
3506
+ base('.popover-form-item').each((e, i) => {
3507
+ const myEle = base(e);
3508
+ myEle.val(target.itemsValue[i])
3509
+ if (myEle.hasClass('popover-form-date')) {
3510
+ try {
3511
+ new options.airDatepicker( ".ce-popover input[name='" + myEle.attr('name') + "']", {
3512
+ classes: 'fm-datepicker',
3513
+ autoClose: true,
3514
+ inline: false,
3515
+ timepicker: options.timepicker,
3516
+ buttons: ['today', 'clear'],
3517
+ locale: options.localeZh,
3518
+ dateFormat( date ) {
3519
+ return date.format( options.format )
3520
+ }
3521
+ } )
3522
+ } catch (e) {
3523
+ base(".ce-popover input[name='" + myEle.attr('name') + "']").attr('type', 'date');
3524
+ }
3525
+ }
3526
+ })
3527
+ }
3528
+
3529
+ // 关闭
3530
+ close(popr) {
3531
+ // b.l(element)
3532
+ // b.l(b(".ce-popover-cancel", element))
3533
+ base(".ce-popover-cancel", '.ce-popover').off("click").on("click", () => {
3534
+ popr.hide();
3535
+ });
3536
+ }
3537
+
3538
+ // 清空条件
3539
+ clear() {
3540
+ base(".ce-popover-clear", ".ce-popover").off("click").on("click", () => {
3541
+ base('.popover-form-item', '.ce-popover').each((e) => {
3542
+ base(e).val("");
3543
+ })
3544
+ });
3545
+ }
3546
+
3547
+ // 获取参数
3548
+ getParam() {
3549
+ const params = {};
3550
+ base.l(base(".popover-form-item"))
3551
+ base(".popover-form-item").each(function(e) {
3552
+ const myEle = base(e),
3553
+ name = myEle.attr("name"),
3554
+ val = myEle.val();
3555
+ if (val) params[name] = val;
3556
+ })
3557
+ return params;
3558
+ };
3559
+
3560
+ // 调用参数中的搜索方法
3561
+ search(target, options) {
3562
+ base(".ce-popover-ok", ".ce-popover").off("click").on("click", () => {
3563
+ if (options.onSerach) options.onSerach({param: target.getParam()});
3564
+ })
3565
+ }
3566
+
3567
+ }
3568
+
3569
+ /* ========================================================================
3570
+ * 11. 文字切换动画特效
3571
+ * 2023年7月5日 12:58:24
3572
+ * ========================================================================
3573
+ * <pre>
3574
+ <div id="ce-flash" class="ce-txt">
3575
+ <span>
3576
+ <b class="is-visible">尖端设计.</b>
3577
+ <b>编码流畅严谨.</b>
3578
+ <b>完美构图.</b>
3579
+ </span>
3580
+ </div>
3581
+
3582
+ import "istyle/src/css/case/ce-txt.css";
3583
+ new u.Flash("#ce-flash", {
3584
+ animationDelay: 3000,
3585
+ lettersDelay: 50
3586
+ })
3587
+ * </pre>
3588
+ * ======================================================================== */
3589
+ class Flash {
3590
+ constructor( selector, custom ) {
3591
+ this.selector = selector;
3592
+ defaultConstructor( this, selector, custom, ( target ) => {
3593
+ target.elements.forEach( ( element ) => {
3594
+ let myElems = base( element );
3595
+ if (!myElems.data( "be.flash" ))
3596
+ myElems.data( "be.flash", target );
3597
+
3598
+ target.init( element, custom );
3599
+ } );
3600
+ } );
3601
+ }
3602
+
3603
+ options = {
3604
+ //动画间隔时间5秒
3605
+ animationDelay: 5000,
3606
+ //letters: 每个字特效的时间间隔
3607
+ lettersDelay: 50,
3608
+ }
3609
+
3610
+ init(element, options) {
3611
+ const target = this;
3612
+ if (options.type === 1) {
3613
+ base(element).addClass("letters");
3614
+ }
3615
+ target.singleLetters(element);
3616
+ //初始化动画
3617
+ target.animateHeadline(element, options);
3618
+ }
3619
+
3620
+ // 文本加入HTML标签方便控制
3621
+ singleLetters(element) {
3622
+ const target = this,
3623
+ myB = base(element).find("b");
3624
+ myB.each(function(e) {
3625
+ const myWord = base(e),
3626
+ letters = myWord.text().split(""),
3627
+ selected = myWord.hasClass("is-visible");
3628
+ for (const i in letters) {
3629
+ if (letters.hasOwnProperty(i)) {
3630
+ if (myWord.parents( target.selector ).length > 0) letters[i] = "<em>" + letters[i] + "</em>";
3631
+ letters[i] = (selected) ? "<i class='in'>" + letters[i] + "</i>" : "<i>" + letters[i] + "</i>";
3632
+ }
3633
+ }
3634
+ const newLetters = letters.join("");
3635
+ myWord.html(newLetters).css("opacity", 1);
3636
+ });
3637
+ }
3638
+
3639
+ // 开始动画
3640
+ animateHeadline(element, options) {
3641
+ const target = this,
3642
+ myElement = base(element);
3643
+ let duration = options.animationDelay;
3644
+ myElement.each(function(ele){
3645
+ const myEle = base(ele);
3646
+ setTimeout(() => { target.hideWord( myEle.find(".is-visible").first() ) }, duration);
3647
+ })
3648
+ }
3649
+
3650
+ // 文字隐藏显示切换,myWord: Base封装的每行文字
3651
+ hideWord(myWord) {
3652
+ const target = this,
3653
+ nextWord = target.takeNext(myWord);
3654
+
3655
+ const bool = myWord.children().length >= nextWord.children().length;
3656
+ target.hideLetter(myWord.find("i").first(), myWord, bool, target.options.lettersDelay);
3657
+ target.showLetter(nextWord.find("i").first(), nextWord, bool, target.options.lettersDelay);
3658
+ }
3659
+
3660
+ // 获取下一行,如果是最后一行跳到第一行
3661
+ takeNext(myWord) {
3662
+ return (myWord.length !== 0 && !myWord.is(":last-child")) ? myWord.next() : myWord.parent().children().first();
3663
+ }
3664
+
3665
+ hideLetter(myLetter, myWord, bool, duration) {
3666
+ const target = this;
3667
+ myLetter.removeClass("in").addClass("out");
3668
+ if(myLetter.length !== 0 && !myLetter.is(":last-child")) {
3669
+ setTimeout(() => { target.hideLetter(myLetter.next(), myWord, bool, duration); }, duration);
3670
+ } else if(bool) {
3671
+ setTimeout(() => { target.hideWord(target.takeNext(myWord)) }, target.options.animationDelay);
3672
+ }
3673
+ }
3674
+
3675
+ showLetter(myLetter, myWord, bool, duration) {
3676
+ const target = this;
3677
+ myLetter.addClass("in").removeClass("out");
3678
+
3679
+ if(myLetter.length !== 0 && !myLetter.is(":last-child")) {
3680
+ setTimeout(() => { target.showLetter(myLetter.next(), myWord, bool, duration); }, duration);
3681
+ } else {
3682
+ // if(myWord.parents(target.options.selector).hasClass("type")) { setTimeout(() => { myWord.parents("span").addClass("waiting"); }, 200);}
3683
+ if(!bool) { setTimeout(() => { target.hideWord(myWord) }, target.options.animationDelay) }
3684
+ }
3685
+ }
3686
+ }
3687
+
3688
+
3689
+ /* ========================================================================
3690
+ * 12. 绘制点线背景动画,依赖tweenlite
3691
+ * 2018年6月2日09:54:29
3692
+ * ========================================================================
3693
+ * <pre>
3694
+ <div id="canvas-warp">
3695
+ <canvas id="iCanvas" style="background-color: rgb(63, 81, 181)" ></canvas>
3696
+ </div>
3697
+
3698
+ import "./plugin/tweenlite/easepack.min"
3699
+ import "./plugin/tweenlite/tweenlite.min"
3700
+ new u.LineEffect("#canvas-warp", {
3701
+ //pointColor: "rgba(0, 0, 0, 1)",
3702
+ //lineColor: "0, 0, 0" ,
3703
+ //height: 302,
3704
+ isWindowWidth: false,
3705
+ width: 500,
3706
+ height: 600,
3707
+ num: 11,
3708
+ canvasId: "iCanvas"
3709
+ });
3710
+ * </pre>
3711
+ * ======================================================================== */
3712
+ class Circle {
3713
+ constructor(options, pos, rad) {
3714
+ this.pos = pos || null;
3715
+ this.radius = rad || null;
3716
+ // this.color = color || null;
3717
+ this.active = true; // 假设默认激活状态
3718
+ this.options = options;
3719
+ }
3720
+ draw(ctx) {
3721
+ if (!this.active) return;
3722
+ ctx.beginPath();
3723
+ ctx.arc(this.pos.x, this.pos.y, this.radius, 0, 2 * Math.PI, false);
3724
+ ctx.fillStyle = "rgba(" + this.options.pointColor + "," + this.active + ")";
3725
+ ctx.fill();
3726
+ }
3727
+ }
3728
+ class LineEffect {
3729
+ constructor( selector, custom ) {
3730
+ this.selector = selector;
3731
+ defaultConstructor( this, selector, custom, ( target ) => {
3732
+ target.elements.forEach( ( element ) => {
3733
+ let myElems = base( element );
3734
+ if (!myElems.data( "be.lineeffect" ))
3735
+ myElems.data( "be.lineeffect", target );
3736
+
3737
+ target.init( element, custom );
3738
+ } );
3739
+ } );
3740
+
3741
+ }
3742
+
3743
+ options = {
3744
+
3745
+ canvasId: "targetCanvas",
3746
+ animateHeader: true,
3747
+
3748
+ width: window.innerWidth,
3749
+ height: window.innerHeight,
3750
+ isWindowWidth: false,
3751
+ isWindowHeight: false,
3752
+ num: 20,
3753
+
3754
+ pointColor: "156,217,249", //点颜色
3755
+ lineColor: "156,217,249" //线颜色
3756
+ }
3757
+
3758
+ init(element, options) {
3759
+ const target = this,
3760
+ xy = { x: options.width/2, y: options.height/2 };
3761
+
3762
+ const canvas = document.getElementById(options.canvasId);
3763
+ canvas.width = options.width;
3764
+ canvas.height = options.height;
3765
+ const ctx = canvas.getContext("2d");
3766
+
3767
+ // 绘制点
3768
+ const points = [];
3769
+ for(let x = 0; x < options.width; x = x + options.width / options.num) {
3770
+ for(let y = 0; y < options.height; y = y + options.height / options.num) {
3771
+ let px = x + Math.random() * options.width / options.num;
3772
+ let py = y + Math.random() * options.height / options.num;
3773
+ let p = {x: px, originX: px, y: py, originY: py };
3774
+ points.push(p);
3775
+ }
3776
+ }
3777
+
3778
+ // 绘制点周围的点
3779
+ for(let i = 0; i < points.length; i++) {
3780
+ const closest = [],
3781
+ p1 = points[i];
3782
+ for(let j = 0; j < points.length; j++) {
3783
+ let p2 = points[j]
3784
+ if(!(p1 === p2)) {
3785
+ let placed = false;
3786
+ for(let k = 0; k < 5; k++) {
3787
+ if(!placed) {
3788
+ if(closest[k] === undefined) {
3789
+ closest[k] = p2;
3790
+ placed = true;
3791
+ }
3792
+ }
3793
+ }
3794
+
3795
+ for(let k = 0; k < 5; k++) {
3796
+ if(!placed) {
3797
+ if(target.getDistance(p1, p2) < target.getDistance(p1, closest[k])) {
3798
+ closest[k] = p2;
3799
+ placed = true;
3800
+ }
3801
+ }
3802
+ }
3803
+ }
3804
+ }
3805
+ p1.closest = closest;
3806
+ }
3807
+
3808
+
3809
+ // 给每个点分配一个圆
3810
+ for(let i in points) {
3811
+ if (points.hasOwnProperty(i)) {
3812
+ points[i].circle = new Circle( options, points[i], 2 + Math.random() * 2 );
3813
+ }
3814
+ }
3815
+ options.points = points;
3816
+ target.initAnimation(options, ctx, xy);
3817
+ target.addListeners(options, xy, canvas);
3818
+ }
3819
+
3820
+ getDistance(p1, p2) {
3821
+ return Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2);
3822
+ }
3823
+
3824
+ //开始绘制动画效果
3825
+ initAnimation(options, ctx, xy) {
3826
+ const target = this;
3827
+ target.animate(options, ctx, xy);
3828
+ for(let i in options.points) {
3829
+ if (options.points.hasOwnProperty(i)) {
3830
+ target.shiftPoint(options.points[i]);
3831
+ }
3832
+ }
3833
+ }
3834
+
3835
+ animate(options, ctx, xy) {
3836
+ const target = this;
3837
+ if(options.animateHeader) {
3838
+ const points = options.points;
3839
+ ctx.clearRect(0, 0, options.width, options.height);
3840
+ for(let i in points) {
3841
+ if (points.hasOwnProperty(i)) {
3842
+ // 检测范围内的点
3843
+ if(Math.abs(target.getDistance(xy, points[i])) < 4000) {
3844
+ points[i].active = 0.3;
3845
+ points[i].circle.active = 0.6;
3846
+ } else if(Math.abs(target.getDistance(xy, points[i])) < 20000) {
3847
+ points[i].active = 0.1;
3848
+ points[i].circle.active = 0.3;
3849
+ } else if(Math.abs(target.getDistance(xy, points[i])) < 40000) {
3850
+ points[i].active = 0.02;
3851
+ points[i].circle.active = 0.1;
3852
+ } else {
3853
+ points[i].active = 0;
3854
+ points[i].circle.active = 0;
3855
+ }
3856
+
3857
+ target.drawLines(options, points[i], ctx);
3858
+ points[i].circle.draw(ctx);
3859
+ }
3860
+ }
3861
+ }
3862
+ requestAnimationFrame(function() {
3863
+ target.animate(options, ctx, xy)
3864
+ });
3865
+ }
3866
+
3867
+ // 开始绘制动画效果 - 点
3868
+ shiftPoint(p) {
3869
+ const target = this;
3870
+ TweenLite.to(p, 1 + Math.random(), {
3871
+ x: p.originX - 50 + Math.random() * 100,
3872
+ y: p.originY - 50 + Math.random() * 100,
3873
+ ease: Circ.easeInOut,
3874
+ onComplete: function() {
3875
+ target.shiftPoint(p);
3876
+ }
3877
+ }
3878
+ )
3879
+ }
3880
+
3881
+ // 开始绘制动画效果 - 线
3882
+ drawLines(options, p, ctx) {
3883
+ if(!p.active) return;
3884
+ for(let i in p.closest) {
3885
+ if (p.closest.hasOwnProperty(i)) {
3886
+ ctx.beginPath();
3887
+ ctx.moveTo( p.x, p.y );
3888
+ ctx.lineTo( p.closest[i].x, p.closest[i].y );
3889
+ ctx.strokeStyle = "rgba(" + options.lineColor + "," + p.active + ")";
3890
+ ctx.stroke();
3891
+ }
3892
+ }
3893
+ }
3894
+
3895
+ // 监听事件,移动鼠标, 滚动, 改变屏幕大小
3896
+ addListeners(options, xy, canvas) {
3897
+ const target = this;
3898
+ if(!('ontouchstart' in window)) {
3899
+ window.addEventListener("mousemove", (e) => {
3900
+ target.mouseMove(e, xy);
3901
+ });
3902
+ }
3903
+ window.addEventListener("scroll", () => {
3904
+ target.scrollCheck(options);
3905
+ });
3906
+ window.addEventListener("resize", () => {
3907
+ target.resize(options, canvas);
3908
+ });
3909
+ }
3910
+
3911
+ mouseMove(e, xy) {
3912
+ const canvas = document.getElementById(this.options.canvasId),
3913
+ rect = canvas.getBoundingClientRect(),
3914
+ scrollTop = window.pageYOffset || document.documentElement.scrollTop,
3915
+ scrollLeft = window.pageXOffset || document.documentElement.scrollLeft,
3916
+ offsetTop = rect.top + scrollTop,
3917
+ offsetLeft = rect.left + scrollLeft;
3918
+
3919
+ let posx = 0,
3920
+ posy = 0;
3921
+ if (e.pageX || e.pageY) {
3922
+ posx = e.pageX;
3923
+ posy = e.pageY;
3924
+ } else if (e.clientX || e.clientY) {
3925
+ posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
3926
+ posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
3927
+ }
3928
+ xy.x = posx - offsetLeft;
3929
+ xy.y = posy - offsetTop;
3930
+ }
3931
+
3932
+ scrollCheck(options) {
3933
+ options.animateHeader = document.body.scrollTop <= options.height
3934
+ }
3935
+
3936
+ resize(options, canvas) {
3937
+ if (options.isWindowWidth) canvas.width = window.innerWidth;
3938
+ if (options.isWindowHeight) canvas.height = window.innerHeight;
3939
+ }
3940
+ }
3941
+
3942
+
3943
+
3944
+ /* ========================================================================
3945
+ * 12. 鼠标上下左右划入监听实现对应动画
3946
+ * 2022年7月28日 10:50:06
3947
+ * ========================================================================
3948
+ * <pre>
3949
+ <div class="p-3">
3950
+ <div class="ce-thumbs row" id="ce-thumbs">
3951
+ <div class="ce-thumb col-4">
3952
+ <a href="#">
3953
+ <img src="//arisu.cn/file/images/res/anime/anime1470402086147.jpg" class="w-100" />
3954
+ <div>
3955
+ <div class="ce-ts-info"> MAPLE </div>
3956
+ </div>
3957
+ </a>
3958
+ </div>
3959
+ <div class="ce-thumb col-4">
3960
+ <a href="#">
3961
+ <img src="//arisu.cn/file/images/res/anime/anime1470402086147.jpg" class="w-100" />
3962
+ <div>
3963
+ <div class="ce-ts-info"> BIRCH </div>
3964
+ </div>
3965
+ </a>
3966
+ </div>
3967
+ <div class="ce-thumb col-4">
3968
+ <a href="#">
3969
+ <img src="//arisu.cn/file/images/res/anime/anime1470402086147.jpg" class="w-100" />
3970
+ <div>
3971
+ <div class="ce-ts-info"> BLACK WALNUT </div>
3972
+ </div>
3973
+ </a>
3974
+ </div>
3975
+ <div class="ce-thumb col-4">
3976
+ <a href="#">
3977
+ <img src="//arisu.cn/file/images/res/anime/anime1470402086147.jpg" class="w-100" />
3978
+ <div>
3979
+ <div class="ce-ts-info"> OLIVE </div>
3980
+ </div>
3981
+ </a>
3982
+ </div>
3983
+ <div class="ce-thumb col-4">
3984
+ <a href="#">
3985
+ <img src="//arisu.cn/file/images/res/anime/anime1470402086147.jpg" class="w-100" />
3986
+ <div class="ce-ts-info">
3987
+ <div class="ce-ts-info"> DOGWOOD </div>
3988
+ </div>
3989
+ </a>
3990
+ </div>
3991
+ <div class="ce-thumb col-4">
3992
+ <a href="#">
3993
+ <img src="//arisu.cn/file/images/res/anime/anime1470402086147.jpg" class="w-100" />
3994
+ <div>
3995
+ <div class="ce-ts-info"> POPLAR </div>
3996
+ </div>
3997
+ </a>
3998
+ </div>
3999
+ </div>
4000
+ </div>
4001
+
4002
+ import "istyle/src/css/case/ce-thumbs.css";
4003
+ new u.HoverDir(".ce-thumb", {
4004
+ reverse: false
4005
+ })
4006
+ * </pre>
4007
+ * ======================================================================== */
4008
+ class HoverDir {
4009
+ constructor( selector, custom ) {
4010
+ this.selector = selector;
4011
+ defaultConstructor( this, selector, custom, ( target ) => {
4012
+ target.elements.forEach( ( element ) => {
4013
+ let myElems = base( element );
4014
+ if (!myElems.data( "be.hoverdir" ))
4015
+ myElems.data( "be.hoverdir", target );
4016
+
4017
+ target.init( element, custom );
4018
+ } );
4019
+ } )
4020
+ }
4021
+
4022
+ options = {
4023
+ reverse: false
4024
+ }
4025
+
4026
+ init(element, options) {
4027
+ const target = this,
4028
+ myElement = base(element);
4029
+ myElement.on("mouseenter", (event) => this.mouseEvent(event, target, options));
4030
+ myElement.on("mouseleave", (event) => this.mouseEvent(event, target, options));
4031
+ }
4032
+
4033
+ mouseEvent(event, target, options) {
4034
+ const myEle = base(event.currentTarget),
4035
+ evType = event.type,
4036
+ myHoverElem = myEle.find("div"),
4037
+ direction = target.getDir(myEle, { x: event.pageX, y: event.pageY }),
4038
+ hoverClasses = target.getClasses(direction, options);
4039
+ myHoverElem.removeClass();
4040
+ if (evType === "mouseenter") {
4041
+ setTimeout(() => {
4042
+ myHoverElem.css('display', 'none').addClass(hoverClasses.from);
4043
+ myHoverElem.show(15, (e) => {
4044
+ base(e).addClass(hoverClasses.to);
4045
+ })
4046
+ }, 15);
4047
+ } else {
4048
+ myHoverElem.addClass(hoverClasses.from);
4049
+ }
4050
+ }
4051
+
4052
+ getDir(myEle, coordinates) {
4053
+ const w = myEle.width(),
4054
+ h = myEle.height(),
4055
+ x = (coordinates.x - myEle.offset().left - (w / 2)) * (w > h ? (h / w) : 1),
4056
+ y = (coordinates.y - myEle.offset().top - (h / 2)) * (h > w ? (w / h) : 1);
4057
+ return Math.round((((Math.atan2(y, x) * (180 / Math.PI)) + 180) / 90) + 3) % 4;
4058
+ }
4059
+
4060
+ getClasses(direction, options) {
4061
+ let fromClass, toClass;
4062
+ switch (direction) {
4063
+ case 0: (!options.reverse) ? fromClass = "ce-slideFromTop" : fromClass = "ce-slideFromBottom"; toClass = "ce-slideTop"; break;
4064
+ case 1: (!options.reverse) ? fromClass = "ce-slideFromRight" : fromClass = "ce-slideFromLeft"; toClass = "ce-slideLeft"; break;
4065
+ case 2: (!options.reverse) ? fromClass = "ce-slideFromBottom" : fromClass = "ce-slideFromTop"; toClass = "ce-slideTop"; break;
4066
+ case 3: (!options.reverse) ? fromClass = "ce-slideFromLeft" : fromClass = "ce-slideFromRight"; toClass = "ce-slideLeft"; break;
4067
+ }
4068
+ return {from: fromClass, to: toClass };
4069
+ }
4070
+ }
4071
+
4072
+
4073
+
4074
+
4075
+ /* harmony default export */ const utils = (base);
4076
+
4077
+ ;// CONCATENATED MODULE: ./src/js/main.js
4078
+
4079
+
4080
+ /* ========================================================================
4081
+ * 实际开发常用方法及模块插件扩展或初始化,需要依赖jQuery的插件建议本地安装jQuery,而不是引入全局
4082
+ * ========================================================================
4083
+ //使用范例
4084
+ import { b, u, m } from 'ilib/main'
4085
+
4086
+ 1. Main类,用户常用登录登出token设置获取等操作
4087
+ 2. handlebars模板判断表达式支持,不依赖其他框架:b.handlebars(Handlebars);
4088
+ 3. bootstrap 文本提示框,依赖bootstrap
4089
+ <a href="#" class="me-1 js-detail"><i class="bi bi-search"></i></a>
4090
+ import { Tooltip } from 'glib/bootstrap';
4091
+ b.tip(Tooltip);
4092
+ 4. 全部隐藏bootstrap 文本提示框,依赖bootstrap
4093
+ 5. jquery滚屏插件owl.carousel默认参数调用,单图可直接使用https://arisu.cn/springmvc/api/5#bootstrap-carousel,依赖jQuery
4094
+ <div id="carousel-image" class="owl-carousel owl-theme">
4095
+ <div class="item thumbnail"><img src="//arisu.cn/file/images/res/anime/anime1470402086147.jpg"></img></div>
4096
+ <div class="item thumbnail">....
4097
+ b.owl($("#carousel-image"), {});
4098
+ 6. 消息弹框,依赖jQuery:b.al("你好,世界", 'success');
4099
+ 7. 确定框,依赖jQuery:
4100
+ b.cf("是否确定删除该记录!", "删除", () => {
4101
+ b.al("删除成功!", "success");
4102
+ }, 2, "ice");
4103
+ 8. meanmenu导出菜单,npm安装版本有BUG,只能用本地的,依赖jQuery
4104
+ 9. textillate文字特效,依赖jQuery
4105
+ 10. jquery.form表单提交工具,依赖jQuery
4106
+ 11. air-datepicker时间控件,不依赖其他框架
4107
+ 12. niceScroll滚动条,依赖jQuery
4108
+ 13. validationEngine表单验证,依赖jQuery
4109
+ 14. validate确认是否验证通过
4110
+
4111
+ * ======================================================================== */
4112
+
4113
+ // 1. Main类,用户常用登录登出token设置获取等操作
4114
+ class Main {
4115
+ // 用户登录
4116
+ login(userParam) {
4117
+ let user = { id: userParam.id, name: userParam.nickname, menus: userParam.menu };
4118
+ localStorage.setItem("user", JSON.stringify(user));
4119
+ localStorage.setItem("token", userParam.token);
4120
+ }
4121
+
4122
+ // 用户注销登录
4123
+ logout() {
4124
+ return new Promise(( ) => {
4125
+ localStorage.removeItem("user");
4126
+ localStorage.removeItem("token");
4127
+ });
4128
+ }
4129
+
4130
+ // 获取当前用户
4131
+ getUser() { return JSON.parse(localStorage.getItem("user")); }
4132
+
4133
+ // 获取当前用户token
4134
+ getToken() { return localStorage.getItem("token"); }
4135
+
4136
+ // 设置当前用户token
4137
+ setToken(token) { localStorage.setItem("token", token); }
4138
+ }
4139
+
4140
+
4141
+ // base类扩展
4142
+
4143
+ // 2. handlebars模板判断表达式支持,不依赖jQuery等框架
4144
+ function handlebars(h) {
4145
+ if (typeof h !== 'undefined') {
4146
+ //等于
4147
+ h.registerHelper("if", function(v1, v2, options) {
4148
+ return (v1 === v2) ? options.fn(this) : options.inverse(this);
4149
+ });
4150
+ //小于
4151
+ h.registerHelper("lt", function(v1, v2, options) {
4152
+ return (v1 < v2) ? options.fn(this) : options.inverse(this);
4153
+ });
4154
+ //大于
4155
+ h.registerHelper("rt", function(v1, v2, options) {
4156
+ return (v1 > v2) ? options.fn(this) : options.inverse(this);
4157
+ });
4158
+ //小于等于
4159
+ h.registerHelper("lte", function(v1, v2, options) {
4160
+ return (v1 <= v2) ? options.fn(this) : options.inverse(this);
4161
+ });
4162
+ //大于等于
4163
+ h.registerHelper("rte", function(v1, v2, options) {
4164
+ return (v1 >= v2) ? options.fn(this) : options.inverse(this);
4165
+ });
4166
+ }
4167
+ }
4168
+ utils['handlebars'] = handlebars;
4169
+
4170
+ // 3. bootstrap 文本提示框,<a href="#" class="me-1 js-detail"><i class="bi bi-search"></i></a> import { Tooltip } from 'glib/bootstrap';
4171
+ // b.tip(Tooltip); //依赖bootstrap
4172
+ function tip(tooltip) {
4173
+ utils(".be-detail").attr('data-bs-title', '详细页').attr('data-bs-toggle', 'tooltip').attr('data-bs-custom-class', 'be-tooltip');
4174
+ utils(".be-edit").attr('data-bs-title', '编辑页').attr('data-bs-toggle', 'tooltip').attr('data-bs-custom-class', 'be-tooltip');
4175
+ utils(".be-delete").attr('data-bs-title', '删除').attr('data-bs-toggle', 'tooltip').attr('data-bs-custom-class', 'be-tooltip');
4176
+ const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]');
4177
+ [...tooltipTriggerList].map(tooltipTriggerEl => new tooltip(tooltipTriggerEl));
4178
+ }
4179
+ utils['tip'] = tip;
4180
+
4181
+ // 4. 全部隐藏bootstrap 文本提示框,依赖bootstrap
4182
+ function tipHide() {
4183
+ utils(".tooltip").removeClass("show");
4184
+ }
4185
+ utils['tipHide'] = tipHide;
4186
+
4187
+ // 5. jquery滚屏插件owl.carousel默认参数调用:npm i owl.carousel@2.3.4,依赖jQuery
4188
+ function owl($target, options) {
4189
+ options = utils.extend(options, {
4190
+ loop: true,
4191
+ // animateOut: "animate__animated animate__slideOutDown",
4192
+ // animateIn: "animate__animated animate__fadeIn",
4193
+ margin: 0,
4194
+ nav: true,
4195
+ smartSpeed: 500,
4196
+ autoHeight: false,
4197
+ autoplay: true,
4198
+ dots: true,
4199
+ items: 4,
4200
+ autoplayTimeout: 7000,
4201
+ navText: [
4202
+ '<div class="mn-carousel-left"><i class="bi bi-chevron-left"></i></div>', '<div class="mn-carousel-right"><i class="bi bi-chevron-right"></i></div>'
4203
+ ],
4204
+ responsive: {
4205
+ 0: { items: 1 }, 600: { items: 1 }, 800: { items: 1 }, 1024: { items: 4 }, 1500: { items: 5 }, 1900: { items: 6 }
4206
+ },
4207
+ onInitialized: () => {
4208
+ // $(".ix-cd-1").textillate({
4209
+ // in: {effect: "animate__animated animate__fadeInLeftBig", sequence: false, sync: false, shuffle: false, reverse: true}
4210
+ // });
4211
+ // $(".ix-cd-2").textillate({in: {effect: "animate__animated animate__fadeInRightBig"}});
4212
+ // $(".ix-cd-3").textillate({in: {effect: "animate__animated animate__wobble"}});
4213
+ // $(".ix-cd-4").textillate({in: {effect: "animate__animated animate__fadeInUp"}});
4214
+ // $(".ix-cd-5").textillate({in: {effect: "animate__animated animate__fadeInDown"}});
4215
+ },
4216
+ onChanged: () => {
4217
+ // //debug($( ".owl-item:eq(" + this.currentItem +")"));
4218
+ // //alert($(".mn-cd-1", ".owl-item:eq(" + this.currentItem +")").html());
4219
+ // //$(".ix-cd-1, .ix-cd-2, .ix-cd-3, .ix-cd-4, .ix-cd-5", ".owl-item:eq(" + this.currentItem +")").textillate("start");
4220
+ // $(".ix-cd-1, .ix-cd-2, .ix-cd-3, .ix-cd-4, .ix-cd-5", ".owl-item:eq(" + e.item.index +")").textillate("start");
4221
+ }
4222
+ } );
4223
+ $target.owlCarousel(options);
4224
+ }
4225
+ utils['owl'] = owl;
4226
+
4227
+
4228
+ // 消息框参数设置
4229
+ function messageInit(type, classes, theme) {
4230
+ // 弹框样式,需要导入对应CSS
4231
+ if (theme === 1) {
4232
+ theme = "flat";
4233
+ } else if (theme === 2) {
4234
+ theme = "future";
4235
+ } else if (theme === 3) {
4236
+ theme = "block";
4237
+ } else if (theme === 4) {
4238
+ theme = "air";
4239
+ } else if (theme === 5) {
4240
+ theme = "ice";
4241
+ } else {
4242
+ theme = "ice";
4243
+ }
4244
+ let options = utils.extend({ type: type, classes: classes, theme: theme }, { type: "info", classes: 3, theme: "ice" });
4245
+
4246
+ // 弹框弹出位置
4247
+ let extraClasses;
4248
+ if (options.classes === 1) {
4249
+ extraClasses = "messenger-fixed messenger-theme-" + options.theme + " messenger-on-top messenger-on-left";
4250
+ } else if (options.classes === 2) {
4251
+ extraClasses = "messenger-fixed messenger-theme-" + options.theme + " messenger-on-top";
4252
+ } else if (options.classes === 3) {
4253
+ extraClasses = "messenger-fixed messenger-theme-" + options.theme + " messenger-on-top messenger-on-right";
4254
+ } else if (options.classes === 4) {
4255
+ extraClasses = "messenger-fixed messenger-theme-" + options.theme + " messenger-on-bottom messenger-on-right";
4256
+ } else if (options.classes === 5) {
4257
+ extraClasses = "messenger-fixed messenger-theme-" + options.theme + " messenger-on-bottom";
4258
+ } else if (options.classes === 6) {
4259
+ extraClasses = "messenger-fixed messenger-theme-" + options.theme + " messenger-on-bottom messenger-on-left";
4260
+ } else {
4261
+ extraClasses = "messenger-fixed messenger-theme-" + options.theme + " messenger-on-top";
4262
+ }
4263
+
4264
+ // 初始化设置
4265
+ Messenger.options = {
4266
+ extraClasses: extraClasses,
4267
+ theme: options.theme
4268
+ }
4269
+ }
4270
+
4271
+ /**
4272
+ * 6. 消息弹框:npm i messenger-hubspot@1.5.0-b2
4273
+ * @param message 消息
4274
+ * @param type info / error / success
4275
+ * @param classes 消息位置(2:顶部 / 6:左下下) ,按顺时针显示
4276
+ * @param theme 样式(2:黑色)
4277
+ <pre>
4278
+ import 'messenger-hubspot/build/css/messenger.css';
4279
+ import 'messenger-hubspot/build/css/messenger-spinner.css';
4280
+ import 'messenger-hubspot/build/css/messenger-theme-flat.css';
4281
+ import 'messenger-hubspot/build/css/messenger-theme-future.css';
4282
+ import 'messenger-hubspot/build/css/messenger-theme-block.css';
4283
+ import 'messenger-hubspot/build/css/messenger-theme-air.css';
4284
+ import 'messenger-hubspot/build/css/messenger-theme-ice.css';
4285
+
4286
+ import 'messenger-hubspot/build/js/messenger.min.js';
4287
+ import 'messenger-hubspot/build/js/messenger-theme-flat.js';
4288
+
4289
+ b.al("你好,世界", 'success', 3, 4);
4290
+ </pre>
4291
+ **/
4292
+ function al(message, type, classes, theme) {
4293
+ messageInit(type, classes, theme);
4294
+ Messenger().post({
4295
+ message: message,
4296
+ type: type,
4297
+ hideAfter: 5,
4298
+ showCloseButton: true
4299
+ });
4300
+ }
4301
+ utils['al'] = al;
4302
+
4303
+ /**
4304
+ * 7. message插件方法封装 - 确定框
4305
+ * @param message 消息
4306
+ * @param label 按钮文字
4307
+ * @param fun 回调方法
4308
+ * @param classes 消息位置(2:顶部 / 6:左下下) ,按顺时针显示
4309
+ * @param theme 样式(2:黑色)
4310
+ <pre>
4311
+ b.cf("是否确定删除该记录!", "删除", () => {
4312
+ b.al("删除成功!", "success");
4313
+ }, 2, "ice");
4314
+ </pre>
4315
+ */
4316
+ function cf(message, label, fun, classes, theme) {
4317
+ Messenger().hideAll();
4318
+
4319
+ messageInit('info', classes, theme);
4320
+ Messenger().post({
4321
+ message: message,
4322
+ actions: {
4323
+ retry: {
4324
+ label: label,
4325
+ phrase: "",
4326
+ auto: false,
4327
+ delay: 10,
4328
+ action: function() {
4329
+ Messenger().hideAll();
4330
+ fun();
4331
+ }
4332
+ },
4333
+ cancel: {
4334
+ label: "取消",
4335
+ action: function() {
4336
+ Messenger().hideAll();
4337
+ return false;
4338
+ }
4339
+ }
4340
+ }
4341
+ });
4342
+ }
4343
+ utils['cf'] = cf;
4344
+
4345
+ /**
4346
+ * 8. meanmenu导出菜单,npm安装版本有BUG,只能用本地的:...\WebTemplate\WebRoot\WEB\js\meanMenu,依赖jQuery
4347
+ * @param $target jQuery选择器
4348
+ * @param options 参数
4349
+ <pre>
4350
+ <div class="collapse navbar-collapse mean-menu">
4351
+ <ul class="navbar-nav m-auto">
4352
+ <li class="nav-item">
4353
+ <a href="index.html" class="nav-link ce-a">首页</a>
4354
+ </li>
4355
+ <li class="nav-item">
4356
+ <a href="#" class="nav-link ce-a">关于我们</a>
4357
+ <ul class="dropdown-menu">
4358
+ <li class="nav-item">
4359
+ <a href="about1info.html" class="nav-link">公司简介</a>
4360
+ </li>
4361
+ <li class="nav-item">
4362
+ <a href="about2system.html" class="nav-link">组织架构</a>
4363
+ </li>
4364
+ <li class="nav-item">
4365
+ <a href="about3team.html" class="nav-link">管理团队</a>
4366
+ </li>
4367
+ </ul>
4368
+ </li>
4369
+ </ul>
4370
+ </div>
4371
+
4372
+ import './plugin/meanMenu/meanmenu.min.css'
4373
+ import './plugin/meanMenu/meanmenu.min'
4374
+
4375
+ b.meanmenu($('.mean-menu'));
4376
+ </pre>
4377
+ */
4378
+ function meanmenu($target, options) {
4379
+ options = utils.extend(options, { meanScreenWidth: "991" })
4380
+ $target.meanmenu(options);
4381
+ }
4382
+ utils['meanmenu'] = meanmenu;
4383
+
4384
+ /**
4385
+ * 9. textillate文字特效,依赖animate.v4.css:npm i textillate@0.4.1,依赖jQuery
4386
+ * @param $target jQuery选择器
4387
+ * @param options 参数
4388
+ <pre>
4389
+ import '../css/animate.v4.css'
4390
+ import 'textillate/assets/jquery.fittext.js'
4391
+ import 'textillate/assets/jquery.lettering.js'
4392
+ import 'textillate/jquery.textillate.js'
4393
+
4394
+ b.textillate(".ix-cd-1",{
4395
+ in: {effect: "animate__animated animate__fadeInLeftBig", sequence: false, sync: false, shuffle: false, reverse: true}
4396
+ });
4397
+ or
4398
+ b.textillate(".ix-cd-1, .ix-cd-2, .ix-cd-3, .ix-cd-4, .ix-cd-5", ".owl-item:eq(" + e.item.index +")", {"start"});
4399
+
4400
+ </pre>
4401
+ */
4402
+ function textillate($target, options) {
4403
+ // options = b.extend(options, { meanScreenWidth: "991" })
4404
+ $target.textillate(options);
4405
+ }
4406
+ utils['textillate'] = textillate;
4407
+
4408
+ /**
4409
+ * 10. jquery.form表单提交工具:npm i jquery-form@4.3.0,可能有点问题还要用 npm i jquery-form@3.50.0,依赖jQuery
4410
+ * @param $target jQuery选择器
4411
+ * @param options 参数
4412
+ <pre>
4413
+ <form id="myForm" action="./springmvc/news/findNews.action">
4414
+ <input name="page" type="text" value="1" />
4415
+ <input name="rp" type="text" value="15" />
4416
+ <input name="sortname" type="text" value="a.id" />
4417
+ <input name="sortorder" type="text" value="desc" />
4418
+ <input name="query" type="text" value="" />
4419
+ <input name="qtype" type="text" value="project" />
4420
+ <button type="submit" value="submit">submit</button>
4421
+ <button type="reset" value="reset">reset</button>
4422
+ </form>
4423
+
4424
+ const $target = $("#myForm");
4425
+ b.formSubmit($target, {
4426
+ //formData:页面表单数据
4427
+ //jqForm: 表单jquery dom信息
4428
+ //options:参数
4429
+ beforeSubmit: function(formData, jqForm, options) {
4430
+ //调用前
4431
+ let result = false;
4432
+ if ($target.is(jqForm)) {
4433
+ // let isSuccessed = $target.validationEngine("validate");
4434
+ // if (isSuccessed) {}
4435
+ formData.push({
4436
+ name: "title",
4437
+ required: false,
4438
+ type: "text",
4439
+ value: "美国"
4440
+ });
4441
+ result = true;
4442
+ }
4443
+ return result;
4444
+ },
4445
+ //responseText:请求需要数据
4446
+ //statusText: 状态码文本
4447
+ //xhr:xhr信息
4448
+ //$form: 表单jquery dom信息
4449
+ success: function(responseText, statusText, xhr, $form) {
4450
+ if (responseText.result === "200") {
4451
+ b.al(responseText.message, "info", 3);
4452
+ // window.location.href = "../manage#/news";
4453
+ } else {
4454
+ b.al(responseText.message, "error", 3);
4455
+ }
4456
+ },
4457
+ error: () => {}
4458
+ })
4459
+ </pre>
4460
+ **/
4461
+ function formSubmit($target, options) {
4462
+ options = utils.extend(options, {
4463
+ clearForm: false, //是否清空表单
4464
+ resetForm: false, //是否重置表单
4465
+ type: "post",
4466
+ dataType: "json",
4467
+ timeout: 30000,
4468
+ });
4469
+ $target.submit(() => {
4470
+ try {
4471
+ $target.ajaxSubmit(options);
4472
+ } catch (e) { console.log(e); }
4473
+ return false;
4474
+ });
4475
+ }
4476
+ utils['formSubmit'] = formSubmit;
4477
+
4478
+ /**
4479
+ * 11. air-datepicker时间控件,不依赖其他框架:npm i air-datepicker@3.5.3
4480
+ * @param AirDatepicker import AirDatepicker的日期组件
4481
+ * @param localeZh import localeZh的中文支持
4482
+ * @param options 参数
4483
+ <pre>
4484
+ <input id="airDatepicker" type="text" placeholder="时间">
4485
+ <button id="airDatepickerBth" class="btn btn-danger">获取时间</button>
4486
+
4487
+ import AirDatepicker from 'glib/air-datepicker'
4488
+ import localeZh from 'glib/air-datepicker/locale/zh';
4489
+ import 'glib/air-datepicker/air-datepicker.css'
4490
+ import 'istyle/src/css/form/fm-datepicker.css'
4491
+
4492
+ const ad = b.datepicker(AirDatepicker, localeZh)
4493
+ b("#airDatepickerBth").click(() => {
4494
+ b.l(ad.selectedDates[0].format("yyyy-MM-dd hh:mm:ss"))
4495
+ })
4496
+ </pre>
4497
+ **/
4498
+ function datepicker(AirDatepicker, localeZh, options) {
4499
+ options = utils.extend(options, {
4500
+ target: '#airDatepicker',
4501
+ classes: 'fm-datepicker',
4502
+ autoClose: true,
4503
+ inline: false,
4504
+ timepicker: true,
4505
+ buttons: ['today', 'clear'],
4506
+ locale: localeZh,
4507
+ dateFormat(date) {
4508
+ return date.format("yyyy年MM月dd日 hh:mm:ss")
4509
+ }
4510
+ });
4511
+ return new AirDatepicker(options.target, options);
4512
+ }
4513
+ utils['datepicker'] = datepicker;
4514
+
4515
+ /**
4516
+ * 12. niceScroll滚动条, npm i jquery.nicescroll,依赖jQuery
4517
+ * @param $target jQuery选择器
4518
+ * @param options 参数
4519
+ <pre>
4520
+ //最好不用在body和html上设置,设置的标签要有高度,且内部元素高度超出它,在线安装可能有问题
4521
+ import './plugin/jquery.nicescroll/jquery.nicescroll.min'
4522
+ b.niceScroll($('.container'));
4523
+ </pre>
4524
+ **/
4525
+ function niceScroll($target, options) {
4526
+ options = utils.extend(options, {
4527
+ styler : "fb",
4528
+ cursorcolor : "#999",
4529
+ cursorwidth : "6",
4530
+ cursorborderradius : "0px",
4531
+ background : "#fff",
4532
+ spacebarenabled : false,
4533
+ cursorborder : "",
4534
+ smoothscroll: true, // ease动画滚动
4535
+ scrollspeed: 100,
4536
+ mousescrollstep: 100, //滚轮滚动速度
4537
+ zindex : "1000"
4538
+ });
4539
+ $target.niceScroll(options);
4540
+
4541
+ window.addEventListener('resize', () => {
4542
+ $target.getNiceScroll().resize();
4543
+ });
4544
+ }
4545
+ utils['niceScroll'] = niceScroll;
4546
+
4547
+
4548
+ /**
4549
+ * 13. validationEngine表单验证,高版本jQuery需要把jquery.validationEngine.js里面的size()方法换成length,依赖jQuery
4550
+ 官网:https://github.com/posabsolute/jQuery-Validation-Engine
4551
+ * @param $target jQuery选择器
4552
+ * @param options 参数
4553
+ <pre>
4554
+ <form id="form-1" method="post" action="javascript:">
4555
+ <ul class="list-unstyled">
4556
+ <li>
4557
+ <div class="login">异步验证: </div>
4558
+ <input class="validate[ajax[validate]]" data-tag="1001" type="text" id="email" value="mikoarisu@gmail.com" />
4559
+ </li>
4560
+ </ul>
4561
+ </form>
4562
+
4563
+ <form id="form-2" method="post" action="#">
4564
+ <ul class="">
4565
+ <li>
4566
+ <div class="login">必须为5 - 20之间的数字: </div>
4567
+ <input type="text" value="123a" class="validate[required,custom[number],min[5],max[20]]"/>
4568
+ </li>
4569
+ <li>
4570
+ <div class="login">[日期必须介于2009-01-01,2009-12-31之间]: </div>
4571
+ <input type="text" id="birthday" value="2029-01-01"
4572
+ class="validate[required,custom[date],future[2009-01-01],past[2009-12-31]]"/>
4573
+ </li>
4574
+ <li>
4575
+ <div class="login">必须选择两项 : </div>
4576
+ <input class="validate[minCheckbox[2]]" type="checkbox" name="group1" id="maxcheck1" value="5"/>a
4577
+ <input class="validate[minCheckbox[2]]" type="checkbox" name="group1" id="maxcheck2" value="3"/>b
4578
+ <input class="validate[minCheckbox[2]]" type="checkbox" name="group1" id="maxcheck3" value="9"/>c
4579
+ </li>
4580
+ <li>
4581
+ <div class="login">输入框长度在5 - 20: </div>
4582
+ <input type="text" class="validate[minSize[5], maxSize[20]]" value="3"/>
4583
+ </li>
4584
+ <li>
4585
+ <div class="login">url验证: </div>
4586
+ <input type="text" class="validate[custom[url]]" value="aa"/>
4587
+ </li>
4588
+ <li>
4589
+ <div class="login">不能为特殊字符: </div>
4590
+ <input type="text" class="validate[custom[unSp]]" value="#"/>
4591
+ </li>
4592
+ <li>
4593
+ <div class="login">密码: </div>
4594
+ <input id="psw" type="text" value="cc"/>
4595
+ </li>
4596
+ <li>
4597
+ <div class="login">密码再输入一次验证:validate[equals[psw]]其中psw为上一个密码ID</div>
4598
+ <input type="password" class="validate[equals[psw]]" value="cc3"/>
4599
+ </li>
4600
+ <li>
4601
+ <div class="login">ipv4验证: </div>
4602
+ <input type="text" class="validate[custom[ipv4]]" value="cc3"/>
4603
+ </li>
4604
+ <li>
4605
+ <div class="login">不能纯数字: </div>
4606
+ <input type="text" class="validate[validate[custom[noOnlyNum]]]" value="111"/>
4607
+ </li>
4608
+ <li class="padding-top-20">
4609
+ <button id="ve-1" type="button" class="btn btn-danger">表单验证</button>
4610
+ </li>
4611
+ </ul>
4612
+ </form>
4613
+
4614
+ // input中常用class
4615
+ validate[required, maxSize[50]] 最大50个字符
4616
+ validate[required, max[150]] 最大值为150
4617
+ validate[required,custom[onlyLetterNumber]]
4618
+ validate[required,ajax[checkWordContent]]
4619
+ validate[required, custom[url]]
4620
+ validate[custom[onlyLetterNumber2]]
4621
+ validate[required,custom[email]]
4622
+ validate[required, custom[number], min[3], max[150]]
4623
+
4624
+ import './plugin/validationEngine/css/validationEngine.jquery.css'
4625
+ import 'istyle/src/css/form/fm-validation.css';
4626
+ import './plugin/validationEngine/js/jquery.validationEngine'
4627
+ import './plugin/validationEngine/js/languages/jquery.validationEngine-zh_CN'
4628
+ b.validationEngine($("#form-1, #form-2"));
4629
+ b("#validate-btn-1").click(() => {
4630
+ const isSuccessed = b.validate($("#form-1"), 'validate');
4631
+ b.l(isSuccessed)
4632
+ })
4633
+ b("#validate-btn-2").click(() => {
4634
+ const isSuccessed = b.validate($("#form-2"), 'validate');
4635
+ b.l(isSuccessed)
4636
+ })
4637
+ </pre>
4638
+ **/
4639
+ function validationEngine($target, options) {
4640
+ options = utils.extend(options, {
4641
+ focusFirstField : false,
4642
+ promptPosition: "topRight"
4643
+ });
4644
+ $target.validationEngine(options);
4645
+ }
4646
+ utils['validationEngine'] = validationEngine;
4647
+
4648
+ /**
4649
+ * 14. validationEngine表单验证,确认是否验证通过
4650
+ * @param $target jQuery选择器
4651
+ * @param command 字符串方法名
4652
+ <pre>
4653
+ const isSuccessed = b.validate($("#form-2"));
4654
+ </pre>
4655
+ **/
4656
+ function validate($target, command) {
4657
+ const options = utils.extend( { command: command }, { command: "validate" });
4658
+ return $target.validationEngine(options.command);
4659
+ }
4660
+ utils['validate'] = validate;
4661
+
4662
+
4663
+
4664
+ /* harmony default export */ const main = (utils);
4665
+ /******/ return __webpack_exports__;
4666
+ /******/ })()
4667
+ ;
4668
+ });