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/README.md +374 -0
- package/dist/arisu.js +4668 -0
- package/dist/arisu.min.js +1 -0
- package/package.json +24 -0
- package/src/js/base.js +1884 -0
- package/src/js/main.js +587 -0
- package/src/js/utils.js +2111 -0
- package/webpack.config.js +100 -0
package/src/js/utils.js
ADDED
|
@@ -0,0 +1,2111 @@
|
|
|
1
|
+
import b from './base'
|
|
2
|
+
|
|
3
|
+
/* ========================================================================
|
|
4
|
+
* 常用JS插件组件
|
|
5
|
+
* 2024年6月7日 15:50:36
|
|
6
|
+
* ========================================================================
|
|
7
|
+
//使用范例
|
|
8
|
+
import b, * as u from 'ilib/utils'
|
|
9
|
+
let sf = new u.SubmitFlag(".e2")
|
|
10
|
+
or
|
|
11
|
+
import b, { SubmitFlag } from 'ilib/utils'
|
|
12
|
+
let sf = new SubmitFlag(".e2")
|
|
13
|
+
|
|
14
|
+
1. SubmitFlag防用户多次点击:new u.SubmitFlag(".e2")
|
|
15
|
+
2. 底部按钮快速移动到顶部:new u.GoTop({
|
|
16
|
+
3. 数字增加减少,购物数量控制:new u.ItemCount({
|
|
17
|
+
4. niceSelect自定义下拉框:new u.NiceSelect('#ns2')
|
|
18
|
+
5. 按钮动画:new u.BtnEf(".bn-btn-5")
|
|
19
|
+
6. 局部loading动画:new u.AeLoader()...
|
|
20
|
+
7. 分页:new u.IPagination({ target: '#ipagination'...
|
|
21
|
+
8. 列表查询分页封装插件:const ilist = new u.IList({ target: '#test-list' ..
|
|
22
|
+
9. 手风琴导航菜单:new u.IAccordion({ speed: 300, showCount: true });
|
|
23
|
+
10. 弹框搜索面板:new u.PopoverSearch('#ipopover', {
|
|
24
|
+
11. 文字切换动画特效:new u.Flash("#ce-flash", {
|
|
25
|
+
12. 绘制点线背景动画:new u.LineEffect("#canvas-warp", {
|
|
26
|
+
|
|
27
|
+
* ======================================================================== */
|
|
28
|
+
/**
|
|
29
|
+
* 自定义组件初始化参数
|
|
30
|
+
* @param iclass 自定义组件
|
|
31
|
+
* @param selector 选择器
|
|
32
|
+
* @param custom 自定义参数
|
|
33
|
+
* @param callback 回调方法
|
|
34
|
+
*/
|
|
35
|
+
const defaultConstructor = (iclass, selector, custom, callback) => {
|
|
36
|
+
// if (typeof custom === 'string') {
|
|
37
|
+
// iclass.elements = document.querySelectorAll( custom );
|
|
38
|
+
// iclass.options = b.extend( { target: custom }, iclass.options )
|
|
39
|
+
// iclass.selector = custom;
|
|
40
|
+
// } else {
|
|
41
|
+
// if (typeof custom.target === 'string') {
|
|
42
|
+
// iclass.elements = document.querySelectorAll( custom.target );
|
|
43
|
+
// } else
|
|
44
|
+
// if (custom.target instanceof NodeList || custom.target instanceof HTMLElement) {
|
|
45
|
+
// iclass.elements = [ custom.target ];
|
|
46
|
+
// } else {
|
|
47
|
+
// iclass.elements = document.querySelectorAll( iclass.options.target );
|
|
48
|
+
// }
|
|
49
|
+
// }
|
|
50
|
+
if (typeof selector === 'string') {
|
|
51
|
+
iclass.elements = document.querySelectorAll( selector );
|
|
52
|
+
} else if (selector instanceof NodeList || selector instanceof HTMLElement) {
|
|
53
|
+
iclass.elements = [ selector ];
|
|
54
|
+
} else {
|
|
55
|
+
iclass.elements = document.querySelectorAll( selector );
|
|
56
|
+
}
|
|
57
|
+
iclass.options = b.extend( custom, iclass.options )
|
|
58
|
+
callback(iclass);
|
|
59
|
+
|
|
60
|
+
// if (iclass.elements.length !== 1) {
|
|
61
|
+
// throw new Error('未正确设置生效标签,请确保传入"#id"或唯一的".class"');
|
|
62
|
+
// }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
//普通方法
|
|
67
|
+
// function test(p1, p2) {
|
|
68
|
+
// console.log(this, p1, p2)
|
|
69
|
+
// }
|
|
70
|
+
// b['test'] = test;
|
|
71
|
+
// // 插件
|
|
72
|
+
// +function(b) {
|
|
73
|
+
// function myPlugin(options) {
|
|
74
|
+
// b.l(options);
|
|
75
|
+
// this.each((index, element) => {
|
|
76
|
+
// b.l(index);
|
|
77
|
+
// b.l(element);
|
|
78
|
+
// });
|
|
79
|
+
// return this;
|
|
80
|
+
// }
|
|
81
|
+
// b.plugin('myPlugin', myPlugin);
|
|
82
|
+
// 废弃直接使用:
|
|
83
|
+
// b['plugin'] = plugin;
|
|
84
|
+
// }(Base);
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
// 自定义组件
|
|
90
|
+
|
|
91
|
+
/* ========================================================================
|
|
92
|
+
* 1. 提交后台过程中让按钮不可用,防止用户多次点击
|
|
93
|
+
* 2016年6月26日10:08:11
|
|
94
|
+
* ========================================================================
|
|
95
|
+
* <pre>
|
|
96
|
+
<button href="#" class="e2 btn btn-danger">发送请求a</button>
|
|
97
|
+
<button href="#" class="e2 btn btn-danger">发送请求b</button>
|
|
98
|
+
<button id="stopSF" href="#" class="btn btn-danger">停止发送请求</button>
|
|
99
|
+
|
|
100
|
+
// let sf = new u.SubmitFlag(".e2")
|
|
101
|
+
// 或者
|
|
102
|
+
let sf = new u.SubmitFlag(".e2", {
|
|
103
|
+
text: "数据请求中..",
|
|
104
|
+
useText: true
|
|
105
|
+
})
|
|
106
|
+
b("#stopSF").click(() => {
|
|
107
|
+
sf.complete();
|
|
108
|
+
})
|
|
109
|
+
* </pre>
|
|
110
|
+
* ======================================================================== */
|
|
111
|
+
export class SubmitFlag {
|
|
112
|
+
constructor(selector, custom) {
|
|
113
|
+
this.selector = selector;
|
|
114
|
+
defaultConstructor(this, selector, custom, (target) => {
|
|
115
|
+
target.elements.forEach((element) => {
|
|
116
|
+
let myElems = b(element);
|
|
117
|
+
if (!myElems.data("be.submitflag"))
|
|
118
|
+
myElems.data("be.submitflag", target);
|
|
119
|
+
|
|
120
|
+
target.init(element);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
options = {
|
|
126
|
+
text: "处理中..",
|
|
127
|
+
useText: true
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
init(element) {
|
|
131
|
+
let myElems = b(element),
|
|
132
|
+
data = myElems.data("be.submitflag");
|
|
133
|
+
myElems.data("text", myElems.text()).click((e) => {
|
|
134
|
+
data.request(e.currentTarget);
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
request(element) {
|
|
139
|
+
let myElems = b(element);
|
|
140
|
+
myElems.addClass("submit-flag-request").data("text", myElems.text()).attr("disabled", "disabled");
|
|
141
|
+
myElems.text(this.options.text);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
complete(element) {
|
|
145
|
+
let myElems = (element) ? b(element) : b(this.selector);
|
|
146
|
+
myElems.removeClass("submit-flag-request").removeAttr("disabled");
|
|
147
|
+
if (myElems.data("text") && this.options.useText)
|
|
148
|
+
myElems.text(myElems.data("text"));
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
destroy() {
|
|
152
|
+
b(this.selector).removeData("be.submitflag");
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/* ========================================================================
|
|
157
|
+
* 2. 底部按钮快速移动到顶部,按钮出现/消失需要用到animate.css v4,缓动需要样式html { scroll-behavior: smooth; }
|
|
158
|
+
* 2018年7月3日11:55:06
|
|
159
|
+
* ========================================================================
|
|
160
|
+
* <pre>
|
|
161
|
+
<a class="ce-gotop" href="javascript:">
|
|
162
|
+
<i class="bi bi-chevron-up"></i>
|
|
163
|
+
</a>
|
|
164
|
+
|
|
165
|
+
import 'istyle/src/css/case/ce-gotop.css';
|
|
166
|
+
new u.GoTop(".ce-gotop", {
|
|
167
|
+
position: {
|
|
168
|
+
bottom: "15px",
|
|
169
|
+
right: "15px"
|
|
170
|
+
},
|
|
171
|
+
showEffect: " animate__zoomIn ",
|
|
172
|
+
hideEffect: " animate__zoomOut ",
|
|
173
|
+
type: "fixed",
|
|
174
|
+
offsetTop: "400"
|
|
175
|
+
});
|
|
176
|
+
* </pre>
|
|
177
|
+
* ======================================================================== */
|
|
178
|
+
export class GoTop {
|
|
179
|
+
constructor(selector, custom) {
|
|
180
|
+
this.selector = selector;
|
|
181
|
+
defaultConstructor(this, selector, custom, (target) => {
|
|
182
|
+
target.elements.forEach((element) => {
|
|
183
|
+
let myElems = b(element);
|
|
184
|
+
if (!myElems.data("be.gotop"))
|
|
185
|
+
myElems.data("be.gotop", target);
|
|
186
|
+
|
|
187
|
+
target.init(element);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
options = {
|
|
193
|
+
position: {
|
|
194
|
+
bottom: "15px",
|
|
195
|
+
right: "15px"
|
|
196
|
+
},
|
|
197
|
+
showEffect: " animate__zoomIn ",
|
|
198
|
+
hideEffect: " animate__zoomOut ",
|
|
199
|
+
type: "fixed",
|
|
200
|
+
offsetTop: "400"
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
init(element) {
|
|
204
|
+
let t = this,
|
|
205
|
+
myElem = b(element),
|
|
206
|
+
type = t.options.type,
|
|
207
|
+
showEffect = t.options.showEffect,
|
|
208
|
+
position = t.options.position,
|
|
209
|
+
offsetTop = t.options.offsetTop,
|
|
210
|
+
hideEffect = t.options.hideEffect;
|
|
211
|
+
|
|
212
|
+
myElem.addClass("animate__animated").css({
|
|
213
|
+
"display": "inline-block",
|
|
214
|
+
"position": type,
|
|
215
|
+
"opacity": 0
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
if (type === "fixed" || type === "absolute") {
|
|
219
|
+
myElem.css(position);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
myElem.on("click", (e) => {
|
|
223
|
+
e.preventDefault();
|
|
224
|
+
scrollTo(0, 0);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
if (!offsetTop && !myElem.hasClass("animated-running")) {
|
|
228
|
+
if (myElem.offset().top <= b(window).height()) {
|
|
229
|
+
myElem.addClass("animated-running " + showEffect).css({
|
|
230
|
+
"opacity": ""
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
b(window).on("scroll", function () {
|
|
236
|
+
if (offsetTop) {
|
|
237
|
+
if (b(window).scrollTop() >= offsetTop && !myElem.hasClass("animated-running")) {
|
|
238
|
+
myElem.addClass("animated-running " + showEffect).css({
|
|
239
|
+
"opacity": ""
|
|
240
|
+
});
|
|
241
|
+
myElem.removeClass(hideEffect);
|
|
242
|
+
} else if (b(window).scrollTop() <= offsetTop && myElem.hasClass("animated-running")) {
|
|
243
|
+
myElem.removeClass("animated-running " + showEffect).css({
|
|
244
|
+
"opacity": 0
|
|
245
|
+
});
|
|
246
|
+
myElem.addClass(hideEffect);
|
|
247
|
+
}
|
|
248
|
+
} else {
|
|
249
|
+
let thisOffsetTop = myElem.offset().top;
|
|
250
|
+
|
|
251
|
+
if (!myElem.hasClass("animated-running")) {
|
|
252
|
+
if (b(window).scrollTop() >= thisOffsetTop - b(window).height()) {
|
|
253
|
+
myElem.addClass("animated-running " + showEffect).css({
|
|
254
|
+
"opacity": ""
|
|
255
|
+
});
|
|
256
|
+
myElem.removeClass(hideEffect);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
b(window).trigger("scroll");
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/* ========================================================================
|
|
267
|
+
* 3. 数字增加减少,购物数量控制
|
|
268
|
+
* 2018年1月20日22:14:46
|
|
269
|
+
* ========================================================================
|
|
270
|
+
* <pre>
|
|
271
|
+
<div class="fm-count fmc1">
|
|
272
|
+
<input class="form-control fm-result" type="text" value="1" readonly="">
|
|
273
|
+
<div class="fm-btns">
|
|
274
|
+
<i class="fm-plus bi bi-chevron-up"></i>
|
|
275
|
+
<i class="fm-minus bi bi-chevron-down"></i>
|
|
276
|
+
</div>
|
|
277
|
+
</div>
|
|
278
|
+
|
|
279
|
+
import 'istyle/src/css/form/fm-count.css';
|
|
280
|
+
new u.ItemCount(".fmc1", {
|
|
281
|
+
num: 1
|
|
282
|
+
})
|
|
283
|
+
* </pre>
|
|
284
|
+
* ======================================================================== */
|
|
285
|
+
export class ItemCount {
|
|
286
|
+
constructor(selector, custom) {
|
|
287
|
+
this.selector = selector;
|
|
288
|
+
defaultConstructor(this, selector, custom, (target) => {
|
|
289
|
+
this.value = 0;
|
|
290
|
+
target.elements.forEach((element) => {
|
|
291
|
+
let myElems = b(element);
|
|
292
|
+
if (!myElems.data("be.itemcount"))
|
|
293
|
+
myElems.data("be.itemcount", target);
|
|
294
|
+
|
|
295
|
+
target.init(element);
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
options = {
|
|
301
|
+
num: 1
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
init(element) {
|
|
305
|
+
let t = this,
|
|
306
|
+
myElem = b(element),
|
|
307
|
+
options = this.options,
|
|
308
|
+
myPlus = myElem.find(".fm-plus"),
|
|
309
|
+
myMinus = myElem.find(".fm-minus"),
|
|
310
|
+
myResult = myElem.find(".fm-result"),
|
|
311
|
+
resultVal = parseInt(myResult.val());
|
|
312
|
+
|
|
313
|
+
myPlus.on("click", function (e) {
|
|
314
|
+
e.preventDefault();
|
|
315
|
+
resultVal += options.num;
|
|
316
|
+
myResult.val(resultVal);
|
|
317
|
+
t.value = resultVal;
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
myMinus.on("click", function (e) {
|
|
321
|
+
e.preventDefault();
|
|
322
|
+
if (resultVal - options.num >= 0) {
|
|
323
|
+
resultVal -= options.num;
|
|
324
|
+
myResult.val(resultVal);
|
|
325
|
+
t.value = resultVal;
|
|
326
|
+
} else {
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
getValue() {
|
|
333
|
+
return this.value;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/* ========================================================================
|
|
338
|
+
* 4. niceSelect下拉框
|
|
339
|
+
* 2022年8月14日 21:41:21
|
|
340
|
+
* ========================================================================
|
|
341
|
+
* <pre>
|
|
342
|
+
<div style="height: 5rem;">
|
|
343
|
+
<select id="ns2" class="ns-select mx-auto">
|
|
344
|
+
<option value="1">All Category</option>
|
|
345
|
+
<option value="2">HTML Template</option>
|
|
346
|
+
<option value="3">WP Theme</option>
|
|
347
|
+
<option value="4">Graphic Design</option>
|
|
348
|
+
</select>
|
|
349
|
+
</div>
|
|
350
|
+
<button id="nsBtn" href="#" class="btn btn-danger">获取下拉框值</button>
|
|
351
|
+
|
|
352
|
+
import 'istyle/src/css/case/ce-nice-select.css';
|
|
353
|
+
let ns = new u.NiceSelect('#ns2');
|
|
354
|
+
b("#nsBtn").click(() => {
|
|
355
|
+
b.l(ns.getValue())//选中下拉框value的值
|
|
356
|
+
b.l(ns.getText()) //选中下拉框文本
|
|
357
|
+
})
|
|
358
|
+
* </pre>
|
|
359
|
+
* ======================================================================== */
|
|
360
|
+
export class NiceSelect {
|
|
361
|
+
constructor(selector, custom) {
|
|
362
|
+
this.selector = selector;
|
|
363
|
+
defaultConstructor(this, selector, custom, (target) => {
|
|
364
|
+
this.selector = target.selector;
|
|
365
|
+
target.elements.forEach((element) => {
|
|
366
|
+
let myElems = b(element);
|
|
367
|
+
if (!myElems.data("be.niceselect"))
|
|
368
|
+
myElems.data("be.niceselect", target);
|
|
369
|
+
|
|
370
|
+
target.init(element);
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
options = {}
|
|
376
|
+
|
|
377
|
+
create(element) {
|
|
378
|
+
let t = this,
|
|
379
|
+
mySelect = b(element),
|
|
380
|
+
myDropdown = mySelect.after('<div></div>').next()
|
|
381
|
+
.addClass('ce-nice-select')
|
|
382
|
+
.addClass(mySelect.attr('class') || '')
|
|
383
|
+
.addClass(mySelect.attr('disabled') ? 'disabled' : '')
|
|
384
|
+
.attr('tabindex', mySelect.attr('disabled') ? null : '0')
|
|
385
|
+
.html('<span class="current"></span><ul class="list"></ul>');
|
|
386
|
+
|
|
387
|
+
let myOptions = mySelect.find('option');
|
|
388
|
+
let mySelected = b(element.options[element.selectedIndex]);
|
|
389
|
+
|
|
390
|
+
t.text = mySelected.data('display') || mySelected.text();
|
|
391
|
+
myDropdown.find('.current').html(t.text);
|
|
392
|
+
|
|
393
|
+
myOptions.each(function(element) {
|
|
394
|
+
let myOption = b(element),
|
|
395
|
+
display = myOption.data('display'),
|
|
396
|
+
isDisplay = (display !== null && display !== undefined ? display : ""),
|
|
397
|
+
isSelect = mySelected.text() === myOption.text() ? 'selected' : '';
|
|
398
|
+
myDropdown.find('ul').append("<li data-value=\"" + myOption.val() + "\" data-display=\"" + isDisplay +
|
|
399
|
+
"\" class=\"option " + isSelect + "\">" + myOption.text() + "</li>");
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
init(element) {
|
|
404
|
+
let t = this,
|
|
405
|
+
mySelector = b(t.selector),
|
|
406
|
+
myElement = b(element);
|
|
407
|
+
myElement.hide();
|
|
408
|
+
t.create(element);
|
|
409
|
+
let myNS = mySelector.next();
|
|
410
|
+
myNS.on('click', function() {
|
|
411
|
+
let myDropdown = myElement.next();
|
|
412
|
+
myDropdown.toggleClass('open');
|
|
413
|
+
if (myDropdown.hasClass('open')) {
|
|
414
|
+
myDropdown.find('.option');
|
|
415
|
+
myDropdown.find('.focus').removeClass('focus');
|
|
416
|
+
myDropdown.find('.selected').addClass('focus');
|
|
417
|
+
} else {
|
|
418
|
+
myDropdown.focus();
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
b('.option', myNS).on('click', function(e) {
|
|
423
|
+
let myOption = b(e.currentTarget);
|
|
424
|
+
let myDropdown = myNS;
|
|
425
|
+
myDropdown.find('.selected').removeClass('selected');
|
|
426
|
+
myOption.addClass('selected');
|
|
427
|
+
|
|
428
|
+
t.text = myOption.data('display') || myOption.text();
|
|
429
|
+
myDropdown.find('.current').text(t.text);
|
|
430
|
+
t.value = myOption.data('value');
|
|
431
|
+
myDropdown.prev('select').val(t.value).trigger('change');
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
return this;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
getText() {
|
|
438
|
+
return this.text;
|
|
439
|
+
}
|
|
440
|
+
getValue() {
|
|
441
|
+
return this.value;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
/* ========================================================================
|
|
447
|
+
* 5. 按钮动画
|
|
448
|
+
* 2023年8月30日 10:41:03
|
|
449
|
+
* ========================================================================
|
|
450
|
+
* <pre>
|
|
451
|
+
<a href="#" class="bn-btn-5">
|
|
452
|
+
<span>了解更多</span>
|
|
453
|
+
</a>
|
|
454
|
+
|
|
455
|
+
import 'istyle/src/css/button/bn-btn-5.css';
|
|
456
|
+
new u.BtnEf(".bn-btn-5");
|
|
457
|
+
* </pre>
|
|
458
|
+
* ======================================================================== */
|
|
459
|
+
export class BtnEf {
|
|
460
|
+
constructor(selector, custom) {
|
|
461
|
+
this.selector = selector;
|
|
462
|
+
defaultConstructor(this, selector, custom, (target) => {
|
|
463
|
+
this.value = 0;
|
|
464
|
+
target.elements.forEach((element) => {
|
|
465
|
+
let myElems = b(element);
|
|
466
|
+
if (!myElems.data("be.btnef"))
|
|
467
|
+
myElems.data("be.btnef", target);
|
|
468
|
+
|
|
469
|
+
target.init(element);
|
|
470
|
+
});
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
options = {};
|
|
475
|
+
|
|
476
|
+
init(element) {
|
|
477
|
+
b(element).append('<b></b>');
|
|
478
|
+
b(element).on('mouseenter', function (e) {
|
|
479
|
+
let parentOffset = b(this).offset(),
|
|
480
|
+
relX = e.pageX - parentOffset.left,
|
|
481
|
+
relY = e.pageY - parentOffset.top;
|
|
482
|
+
b(this).find('b').css({
|
|
483
|
+
'top': relY + 'px',
|
|
484
|
+
'left': relX + 'px'
|
|
485
|
+
});
|
|
486
|
+
}).on('mouseout', function (e) {
|
|
487
|
+
let parentOffset = b(this).offset(),
|
|
488
|
+
relX = e.pageX - parentOffset.left,
|
|
489
|
+
relY = e.pageY - parentOffset.top;
|
|
490
|
+
b(this).find('b').css({
|
|
491
|
+
'top': relY + 'px',
|
|
492
|
+
'left': relX + 'px'
|
|
493
|
+
});
|
|
494
|
+
});
|
|
495
|
+
// b("." + b(element).attr('class') + "[href='#']").click(function (e) {
|
|
496
|
+
// e.preventDefault()
|
|
497
|
+
// });
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
/* ========================================================================
|
|
503
|
+
* 6. 局部loading动画
|
|
504
|
+
* 2023年8月5日 10:55:51
|
|
505
|
+
* ========================================================================
|
|
506
|
+
* <pre>
|
|
507
|
+
<div class="do-load-warp mx-auto" style="text-align: left; width: 620px;">
|
|
508
|
+
<p class="mb-3 ae-test-target" data-ae-load>
|
|
509
|
+
在线客服正在为您服务
|
|
510
|
+
</p>
|
|
511
|
+
<h2 class="mb-3 ae-test-target" data-ae-load>
|
|
512
|
+
欢迎!我们能为您提供什么帮助?
|
|
513
|
+
</h2>
|
|
514
|
+
<div class="mb-5 " data-ae-load>
|
|
515
|
+
<img src="//arisu.cn/file/images/res/anime/anime1470402086147.jpg" class="img-fluid mx-auto d-block"/>
|
|
516
|
+
</div>
|
|
517
|
+
</div>
|
|
518
|
+
|
|
519
|
+
<a id="ae-load-loading" class="btn btn-primary" href="#">显示loading动画</a>
|
|
520
|
+
<a id="ae-load-done" class="btn btn-primary" href="#">loading动画完成,显示数据</a>
|
|
521
|
+
<a id="ae-load-start" class="btn btn-primary" href="#">不需要加载数据,完整的loading动画</a>// let al = new u.AeLoader();//建议使用这个,在根据情况指定触发
|
|
522
|
+
|
|
523
|
+
import 'istyle/src/css/loading/ae-load.css';
|
|
524
|
+
// let al = new u.AeLoader();//建议使用这个,在根据情况指定触发
|
|
525
|
+
let al = new u.AeLoader('.ae-test-target', {
|
|
526
|
+
time: 1000 //默认1秒,修改需要同时也需要修改CSS动画
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
// 不需要加载数据,完整的loading动画
|
|
530
|
+
b("#ae-load-start").click(function(e) {
|
|
531
|
+
e.preventDefault();
|
|
532
|
+
//全部触发
|
|
533
|
+
al.start();
|
|
534
|
+
// 指定触发,如果初始化有指定则不需要
|
|
535
|
+
// al.start(".ae-test-target");
|
|
536
|
+
});
|
|
537
|
+
// 显示loading动画
|
|
538
|
+
b("#ae-load-loading").click(function(e) {
|
|
539
|
+
e.preventDefault();
|
|
540
|
+
//全部触发
|
|
541
|
+
al.loading();
|
|
542
|
+
// 指定触发,如果初始化有指定则不需要
|
|
543
|
+
// al.loading(".ae-test-target");
|
|
544
|
+
});
|
|
545
|
+
// loading动画完成,显示数据
|
|
546
|
+
b("#ae-load-done").click(function(e) {
|
|
547
|
+
e.preventDefault();
|
|
548
|
+
//全部触发
|
|
549
|
+
al.done();
|
|
550
|
+
// 指定触发,如果初始化有指定则不需要
|
|
551
|
+
// al.done(".ae-test-target");
|
|
552
|
+
});
|
|
553
|
+
* </pre>
|
|
554
|
+
* ======================================================================== */
|
|
555
|
+
export class AeLoader {
|
|
556
|
+
constructor(selector, custom) {
|
|
557
|
+
this.selector = selector;
|
|
558
|
+
this.options = b.extend( custom, this.options )
|
|
559
|
+
b("[data-ae-load]").addClass("ae-load");
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
options = {
|
|
563
|
+
target: '',
|
|
564
|
+
//默认1秒,修改需要同时也需要修改CSS动画
|
|
565
|
+
time: 1000
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
//不需要加载数据,完整的loading动画
|
|
569
|
+
start(target) {
|
|
570
|
+
target = target ? target : this.selector;
|
|
571
|
+
// b(target + "[data-ae-load]").addClass("ae-load");
|
|
572
|
+
// b(target + "[data-ae-load]").removeClass("ae-tt-complete ae-tt-done ae-tt-loading");
|
|
573
|
+
// setTimeout(function() {
|
|
574
|
+
// b(target + "[data-ae-load]").addClass("ae-tt-complete");
|
|
575
|
+
// setTimeout(function() {b(target + "[data-ae-load]").removeClass("ae-load ae-tt-complete");}, 1000);
|
|
576
|
+
// }, 100);
|
|
577
|
+
b(target + "[data-ae-load]").addClass("ae-load")
|
|
578
|
+
.removeClass("ae-tt-complete ae-tt-done ae-tt-loading")
|
|
579
|
+
.addClass("ae-tt-complete");
|
|
580
|
+
setTimeout(function() {
|
|
581
|
+
b(target + "[data-ae-load]").removeClass("ae-load ae-tt-complete");
|
|
582
|
+
}, this.options.time);
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
//显示loading动画
|
|
586
|
+
loading(target) {
|
|
587
|
+
target = target ? target : this.selector;
|
|
588
|
+
|
|
589
|
+
b("[data-ae-load]").addClass("ae-load");
|
|
590
|
+
b(target + "[data-ae-load]").each(function(currentTarget) {
|
|
591
|
+
let minWidth = b(currentTarget).data("al-mw");
|
|
592
|
+
let minHeight = b(currentTarget).data("al-mh");
|
|
593
|
+
if (minWidth) b(currentTarget).css("min-width", minWidth);
|
|
594
|
+
if (minHeight) b(currentTarget).css("min-height", minHeight);
|
|
595
|
+
|
|
596
|
+
// b(currentTarget).removeClass("ae-tt-complete ae-tt-done ae-tt-loading");
|
|
597
|
+
// setTimeout(function() {
|
|
598
|
+
// b(currentTarget).addClass("ae-tt-loading");
|
|
599
|
+
// }, 1);
|
|
600
|
+
b(currentTarget).removeClass("ae-tt-complete ae-tt-done ae-tt-loading").addClass("ae-tt-loading");
|
|
601
|
+
})
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
//loading动画完成,显示数据
|
|
605
|
+
done(target) {
|
|
606
|
+
target = target ? target : this.selector;
|
|
607
|
+
// b(target + "[data-ae-load]").removeClass("ae-tt-done");
|
|
608
|
+
// setTimeout(function() {
|
|
609
|
+
// b(target + "[data-ae-load]").addClass("ae-tt-done");
|
|
610
|
+
// setTimeout(function() {b(target + "[data-ae-load]").removeClass("ae-load ae-tt-loading ae-tt-done");}, 1000);
|
|
611
|
+
// }, 1);
|
|
612
|
+
b(target + "[data-ae-load]").removeClass("ae-tt-done").addClass("ae-tt-done");
|
|
613
|
+
setTimeout(function() {
|
|
614
|
+
b(target + "[data-ae-load]").removeClass("ae-load ae-tt-loading ae-tt-done");
|
|
615
|
+
}, this.options.time);
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
/* ========================================================================
|
|
622
|
+
* 7. 分页
|
|
623
|
+
* 2024年6月29日 10:28:55
|
|
624
|
+
* ========================================================================
|
|
625
|
+
* <pre>
|
|
626
|
+
<div class="be-paging-warp">
|
|
627
|
+
<p></p>
|
|
628
|
+
<nav>
|
|
629
|
+
<ul id="ipagination" class="be-paging"></ul>
|
|
630
|
+
</nav>
|
|
631
|
+
</div>
|
|
632
|
+
|
|
633
|
+
new u.IPagination('#ipagination', {
|
|
634
|
+
totalItems: 100,
|
|
635
|
+
itemsPerPage: 10,
|
|
636
|
+
visiblePages: 5,
|
|
637
|
+
// prev: '<i class="bi bi-chevron-left"></i>',
|
|
638
|
+
// next: '<i class="bi bi-chevron-right"></i>',
|
|
639
|
+
// first: '<i class="bi bi-chevron-double-left"></i>',
|
|
640
|
+
// last: '<i class="bi bi-chevron-double-right"></i>',
|
|
641
|
+
onButtonClick: (page) => {
|
|
642
|
+
console.log('当前页为:', page);
|
|
643
|
+
}
|
|
644
|
+
})
|
|
645
|
+
* </pre>
|
|
646
|
+
* ======================================================================== */
|
|
647
|
+
export class IPagination {
|
|
648
|
+
constructor(selector, custom) {
|
|
649
|
+
this.selector = selector;
|
|
650
|
+
defaultConstructor(this, selector, custom, (target) => {
|
|
651
|
+
let t = this;
|
|
652
|
+
target.elements.forEach( ( element ) => {
|
|
653
|
+
let myElems = b( element );
|
|
654
|
+
if (!myElems.data( "be.ipagination" ))
|
|
655
|
+
myElems.data( "be.ipagination", target );
|
|
656
|
+
|
|
657
|
+
t.currentPage = 1;
|
|
658
|
+
t.totalPages = Math.ceil(t.options.totalItems / t.options.itemsPerPage);
|
|
659
|
+
target.init( );
|
|
660
|
+
} )
|
|
661
|
+
} );
|
|
662
|
+
}
|
|
663
|
+
// containerId, totalItems, itemsPerPage, visiblePages = 5
|
|
664
|
+
options = {
|
|
665
|
+
targetWarp: '.be-paging-warp',
|
|
666
|
+
totalItems: 0, //总条数
|
|
667
|
+
itemsPerPage: 0, //一页几条数据
|
|
668
|
+
visiblePages: 5, //显示多少可见页
|
|
669
|
+
prev: '上一页', //or: <i class="bi bi-chevron-left"></i>
|
|
670
|
+
next: '下一页', //or: <i class="bi bi-chevron-right"></i>
|
|
671
|
+
first: '首页', //or: <i class="bi bi-chevron-double-left"></i>
|
|
672
|
+
last: '尾页', //or: <i class="bi bi-chevron-double-right"></i>
|
|
673
|
+
onButtonClick: function (currentPage) {}
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
init() {
|
|
677
|
+
let target = this,
|
|
678
|
+
options = target.options;
|
|
679
|
+
|
|
680
|
+
b(this.selector).html('');
|
|
681
|
+
|
|
682
|
+
// 添加上一页和首页按钮
|
|
683
|
+
this.addPageButton(options.first, 1, () => this.goToPage(1));
|
|
684
|
+
this.addPageButton(options.prev, this.currentPage - 1, () => this.goToPrevPage());
|
|
685
|
+
|
|
686
|
+
// 根据当前页码计算要显示的页码范围
|
|
687
|
+
let startPage = Math.max(1, this.currentPage - Math.floor(options.visiblePages / 2)),
|
|
688
|
+
endPage = Math.min(this.totalPages, startPage + options.visiblePages - 1);
|
|
689
|
+
|
|
690
|
+
// 如果范围小于可见页数,则调整开始页码以显示更多前面的页码
|
|
691
|
+
if (endPage - startPage < options.visiblePages - 1) {
|
|
692
|
+
startPage = Math.max(1, endPage - options.visiblePages + 1);
|
|
693
|
+
}
|
|
694
|
+
// 显示页码按钮
|
|
695
|
+
for (let i = startPage; i <= endPage; i++) {
|
|
696
|
+
this.addPageButton(i, i, () => this.goToPage(i));
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
// 添加下一页和尾页按钮
|
|
700
|
+
this.addPageButton(options.next, this.currentPage + 1, () => this.goToNextPage());
|
|
701
|
+
this.addPageButton(options.last, this.totalPages, () => this.goToPage(this.totalPages));
|
|
702
|
+
const start = options.itemsPerPage * (target.currentPage - 1) + 1,
|
|
703
|
+
end = (start < options.totalItems - options.itemsPerPage ) ? ( start + options.itemsPerPage - 1 ) : ( start + options.totalItems % options.itemsPerPage - 1 );
|
|
704
|
+
b('p', options.targetWarp).html('显示 ' + start + ' 至 ' + end + ' 条,共有 ' + options.totalItems + ' 条');
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
addPageButton(text, page, onClick) {
|
|
708
|
+
const li = document.createElement('li');
|
|
709
|
+
li.classList.add('page-item');
|
|
710
|
+
if ( typeof text === 'number' && Number.isFinite(text) || !isNaN(Number(text)) && Number.isFinite(Number(text)) ) {
|
|
711
|
+
li.classList.add('pi-t2');
|
|
712
|
+
} else {
|
|
713
|
+
li.classList.add('pi-t1');
|
|
714
|
+
}
|
|
715
|
+
const button = document.createElement('button');
|
|
716
|
+
li.append(button);
|
|
717
|
+
button.innerHTML = text;
|
|
718
|
+
button.onclick = onClick;
|
|
719
|
+
if (page === this.currentPage || page === 0 || page === this.totalPages + 1) {
|
|
720
|
+
li.classList.add('active');
|
|
721
|
+
li.classList.add('disabled');
|
|
722
|
+
// button.disabled = true;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
b(this.selector).append(li);
|
|
726
|
+
}
|
|
727
|
+
goToPrevPage() {
|
|
728
|
+
if (this.currentPage > 1) {
|
|
729
|
+
this.currentPage--;
|
|
730
|
+
this.init();
|
|
731
|
+
this.options.onButtonClick(this.currentPage);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
goToNextPage() {
|
|
735
|
+
if (this.currentPage < this.totalPages) {
|
|
736
|
+
this.currentPage++;
|
|
737
|
+
this.init();
|
|
738
|
+
this.options.onButtonClick(this.currentPage);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
goToPage(page) {
|
|
742
|
+
if (page >= 1 && page <= this.totalPages) {
|
|
743
|
+
this.currentPage = page;
|
|
744
|
+
this.init();
|
|
745
|
+
this.options.onButtonClick(this.currentPage);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/* ========================================================================
|
|
751
|
+
* 8. 列表查询分页封装插件
|
|
752
|
+
* 列表查询分页封装插件,opacity-* 为css透明度
|
|
753
|
+
* 2016年7月27日15:02:29
|
|
754
|
+
* ========================================================================
|
|
755
|
+
* <pre>
|
|
756
|
+
// 1. 基础模板
|
|
757
|
+
<script type="text/template" id="tp-list">
|
|
758
|
+
<div class="be-list-data"></div>
|
|
759
|
+
<div class="be-list-loading">
|
|
760
|
+
<div class="do-preloader-3">
|
|
761
|
+
<div class="do-p3">
|
|
762
|
+
<div class="do-p3-inner do-p3-i1"></div>
|
|
763
|
+
<div class="do-p3-inner do-p3-i2"></div>
|
|
764
|
+
<div class="do-p3-inner do-p3-i3"></div>
|
|
765
|
+
</div>
|
|
766
|
+
</div>
|
|
767
|
+
</div>
|
|
768
|
+
<div class="be-list-nofound">查询不到相应数据!</div>
|
|
769
|
+
<div class="be-list-page">
|
|
770
|
+
<div class="be-paging-warp">
|
|
771
|
+
<p></p>
|
|
772
|
+
<nav>
|
|
773
|
+
<ul id="ipagination" class="be-paging"></ul>
|
|
774
|
+
</nav>
|
|
775
|
+
</div>
|
|
776
|
+
</div>
|
|
777
|
+
</script>
|
|
778
|
+
// 2. 数据列表模型,如新闻
|
|
779
|
+
<script type="text/template" id="tp-data-news">
|
|
780
|
+
{{#if isInit true}}
|
|
781
|
+
<table class="be-table">
|
|
782
|
+
<thead>
|
|
783
|
+
<tr>
|
|
784
|
+
<td class="xs-show be-te-check is-check">
|
|
785
|
+
<input type="checkbox" class="ilist-check-all" data-flag="1" data-url={{url}} />
|
|
786
|
+
</td>
|
|
787
|
+
<td class="xs-hid">时间</td>
|
|
788
|
+
<td class="xs-show" data-sortname="a.title" data-is-sort="true">标题</td>
|
|
789
|
+
<td>类型</td>
|
|
790
|
+
<td>作者</td>
|
|
791
|
+
<td class="be-list-events">操作</td>
|
|
792
|
+
</tr>
|
|
793
|
+
</thead>
|
|
794
|
+
<tbody class="be-list-data-body">
|
|
795
|
+
{{/if}}
|
|
796
|
+
{{#each items}}
|
|
797
|
+
<tr>
|
|
798
|
+
<td class="xs-show be-te-check">
|
|
799
|
+
<input type="checkbox" class="ilist-check" data-flag="1" data-id="{{id}}" data-url={{url}}/>
|
|
800
|
+
</td>
|
|
801
|
+
<td class="xs-hid">{{createDate}}</td>
|
|
802
|
+
<td class="xs-show">{{title}}</td>
|
|
803
|
+
<td>{{sort}}</td>
|
|
804
|
+
<td>{{author}}</td>
|
|
805
|
+
<td class="be-list-events">
|
|
806
|
+
<a href="link/{{id}}" class="be-detail"><i class="bi bi-search"></i></a>
|
|
807
|
+
<a href="link/{{id}}" class="be-edit"><i class="bi bi-pencil-square"></i></a>
|
|
808
|
+
<a data-id={{id}} data-url={{url}} href="#" class="be-delete"><i class="bi bi-trash3"></i></a>
|
|
809
|
+
</td>
|
|
810
|
+
</tr>
|
|
811
|
+
{{/each}}
|
|
812
|
+
{{#if isInit true}}
|
|
813
|
+
</tbody>
|
|
814
|
+
</table>
|
|
815
|
+
{{/if}}
|
|
816
|
+
</script>
|
|
817
|
+
// 3. HTML代码查询参数范例,根据情况修改查询参数及列表.be-list ID
|
|
818
|
+
<div class="be-list-warp">
|
|
819
|
+
<div class="be-list-filter">
|
|
820
|
+
<div class="be-lf-btns">
|
|
821
|
+
<div class="be-lb-left">
|
|
822
|
+
<a href="javascript:" class="mn-button me-2"><i class="bi bi-plus-square"></i>新增</a>
|
|
823
|
+
<a href="javascript:" class="mn-button me-2"><i class="bi bi-trash3"></i>删除</a>
|
|
824
|
+
</div>
|
|
825
|
+
<div class="be-lb-right">
|
|
826
|
+
<a id="be-search" href="javascript:" class="mn-button me-2">
|
|
827
|
+
<i class="bi bi-search"></i>搜索
|
|
828
|
+
</a>
|
|
829
|
+
<button class="mn-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#searchMore"
|
|
830
|
+
aria-expanded="false" aria-controls="searchMore">
|
|
831
|
+
<i class="bi bi-chevron-double-down"></i>
|
|
832
|
+
</button>
|
|
833
|
+
</div>
|
|
834
|
+
</div>
|
|
835
|
+
<!-- 隐藏的查询条件 -->
|
|
836
|
+
<div class="be-lf-params">
|
|
837
|
+
<div class="collapse" id="searchMore">
|
|
838
|
+
<div class="be-lf-ps">
|
|
839
|
+
<label>
|
|
840
|
+
<span>类型:</span>
|
|
841
|
+
<select value="0">
|
|
842
|
+
<option value="0" selected="selected">所有</option>
|
|
843
|
+
<option value="1">实事</option>
|
|
844
|
+
<option value="2">娱乐</option>
|
|
845
|
+
<option value="3">军事</option>
|
|
846
|
+
</select>
|
|
847
|
+
</label>
|
|
848
|
+
<label>
|
|
849
|
+
<span>标题:</span>
|
|
850
|
+
<input id="be-input-2" type="text" placeholder="标题"/>
|
|
851
|
+
</label>
|
|
852
|
+
<label>
|
|
853
|
+
<span>时间:</span>
|
|
854
|
+
<input type="date" />
|
|
855
|
+
</label>
|
|
856
|
+
</div>
|
|
857
|
+
</div>
|
|
858
|
+
</div>
|
|
859
|
+
</div>
|
|
860
|
+
<div id="test-list" class="be-list"></div>
|
|
861
|
+
</div>
|
|
862
|
+
|
|
863
|
+
// JS操作
|
|
864
|
+
import '../css/bootstrap-icons.css'
|
|
865
|
+
import 'istyle/src/css/base/be-table.css'
|
|
866
|
+
import 'istyle/src/css/base/be-paging.css'
|
|
867
|
+
import 'istyle/src/css/button/mn-button.css'
|
|
868
|
+
import 'istyle/src/css/loading/do-preloader-3.css'
|
|
869
|
+
import Handlebars from 'glib/handlebars'
|
|
870
|
+
import { Tooltip } from 'glib/bootstrap';
|
|
871
|
+
|
|
872
|
+
const ilist = new u.IList('#test-list', {
|
|
873
|
+
url: "./springmvc/news/findNews.action",
|
|
874
|
+
param: {},
|
|
875
|
+
method: "get",
|
|
876
|
+
sortname: "a.id",
|
|
877
|
+
rp: 10,
|
|
878
|
+
visiblePages: 5,
|
|
879
|
+
handlebars: Handlebars,
|
|
880
|
+
headerMap: { 'token': 'abc123' },
|
|
881
|
+
onSuccess: function(data) {
|
|
882
|
+
b.handlebars(Handlebars);
|
|
883
|
+
const tplEl = b("#tp-data-news");
|
|
884
|
+
const html = Handlebars.compile(tplEl.html())({
|
|
885
|
+
items: data.rows,
|
|
886
|
+
isInit: data.isInit
|
|
887
|
+
});
|
|
888
|
+
|
|
889
|
+
if (data.isInit)
|
|
890
|
+
b(".be-list-data", "#test-list").html(html);
|
|
891
|
+
else
|
|
892
|
+
b(".be-list-data-body", "#test-list").html(html);
|
|
893
|
+
|
|
894
|
+
b.tip(Tooltip);
|
|
895
|
+
// 测试获取列ID
|
|
896
|
+
// b(".ip").click(function() {
|
|
897
|
+
// alert("该列数据id为" + b(this).data("id"));
|
|
898
|
+
// })
|
|
899
|
+
},
|
|
900
|
+
onError: (e) => {
|
|
901
|
+
console.error(e);
|
|
902
|
+
}
|
|
903
|
+
});
|
|
904
|
+
|
|
905
|
+
b('#be-search').click(() => {
|
|
906
|
+
ilist.reload({
|
|
907
|
+
'title': b('#be-input-2').val()
|
|
908
|
+
})
|
|
909
|
+
});
|
|
910
|
+
|
|
911
|
+
* </pre>
|
|
912
|
+
* ======================================================================== */
|
|
913
|
+
export class IList {
|
|
914
|
+
|
|
915
|
+
constructor(selector, custom) {
|
|
916
|
+
this.selector = selector;
|
|
917
|
+
defaultConstructor( this, selector, custom, ( target ) => {
|
|
918
|
+
target.elements.forEach( ( element ) => {
|
|
919
|
+
let myElems = b( element );
|
|
920
|
+
if (!myElems.data( "be.ilist" ))
|
|
921
|
+
myElems.data( "be.ilist", target );
|
|
922
|
+
|
|
923
|
+
if (typeof Handlebars !== 'undefined' && custom.handlebars === null) custom.handlebars = Handlebars;
|
|
924
|
+
target.init( element, custom );
|
|
925
|
+
} );
|
|
926
|
+
} );
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
options = {
|
|
930
|
+
rp: "10",
|
|
931
|
+
visiblePages: 7,
|
|
932
|
+
sortname: "id",
|
|
933
|
+
sortorder: "desc",
|
|
934
|
+
method: "post",
|
|
935
|
+
dataType: "json",
|
|
936
|
+
// async: true,
|
|
937
|
+
// jsonp: null,
|
|
938
|
+
// jsonpCallback: null,
|
|
939
|
+
param: {},
|
|
940
|
+
handlebars: null,//必须的模板生成工具
|
|
941
|
+
url: "",
|
|
942
|
+
loadColor: "#0a0a0a",//必须是16进制,不能缩写
|
|
943
|
+
lang: "cn",
|
|
944
|
+
template: "#tp-list",
|
|
945
|
+
headerMap: { }, //{ 'Content-Type': 'application/json'}
|
|
946
|
+
cache: 'default',
|
|
947
|
+
prev: '上一页', //or: <i class="bi bi-chevron-left"></i>
|
|
948
|
+
next: '下一页', //or: <i class="bi bi-chevron-right"></i>
|
|
949
|
+
first: '首页', //or: <i class="bi bi-chevron-double-left"></i>
|
|
950
|
+
last: '尾页', //or: <i class="bi bi-chevron-double-right"></i>
|
|
951
|
+
onSuccess: false,
|
|
952
|
+
onError: false
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
init(element, options) {
|
|
956
|
+
let target = this,
|
|
957
|
+
myElement = b(element),
|
|
958
|
+
html = myElement.data("be.ilist.html");
|
|
959
|
+
if (options === undefined)
|
|
960
|
+
options = target.options
|
|
961
|
+
myElement.data("be.ilist.flag", true);
|
|
962
|
+
|
|
963
|
+
if (html) {
|
|
964
|
+
// myElement.html(html);
|
|
965
|
+
b(".be-list-data-body", element).html("");
|
|
966
|
+
} else {
|
|
967
|
+
const tplEl = b(options.template),
|
|
968
|
+
html = options.handlebars.compile(tplEl.html())({});
|
|
969
|
+
myElement.html(html);
|
|
970
|
+
myElement.data("be.ilist.html", html);
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
let param = b.extend(
|
|
974
|
+
{ page: 1, rp: options.rp, sortname: options.sortname, sortorder: options.sortorder },
|
|
975
|
+
options.param );
|
|
976
|
+
options.isInit = true;// 是否为初始化列表,表头只在初始化生成
|
|
977
|
+
b(element).data("be.ilist.event", true);
|
|
978
|
+
target.getData(element, options, param);
|
|
979
|
+
};
|
|
980
|
+
|
|
981
|
+
// 数据查询
|
|
982
|
+
getData(element, options, param) {
|
|
983
|
+
let target = this;
|
|
984
|
+
b(".be-list-data-body", element).html("");
|
|
985
|
+
b(".be-list-loading", element).addClass("opacity-100");
|
|
986
|
+
b(".be-list-nofound", element).removeClass("opacity-100");
|
|
987
|
+
b(".be-list-page", element).removeClass("opacity-100");
|
|
988
|
+
|
|
989
|
+
b.ajax({
|
|
990
|
+
method: options.method,
|
|
991
|
+
url: options.url,
|
|
992
|
+
headerMap: options.headerMap,
|
|
993
|
+
// beforeSend: function(request) {
|
|
994
|
+
// for (let key in options.headerMap) {
|
|
995
|
+
// if (options.headerMap.hasOwnProperty(key)) {
|
|
996
|
+
// request.setRequestHeader(key, options.headerMap[key]);
|
|
997
|
+
// }
|
|
998
|
+
// }
|
|
999
|
+
// },
|
|
1000
|
+
data: param,
|
|
1001
|
+
cache: options.cache,
|
|
1002
|
+
// jsonp: options.jsonp,
|
|
1003
|
+
// jsonpCallback: options.jsonp,
|
|
1004
|
+
async: options.async,
|
|
1005
|
+
dataType: options.dataType,
|
|
1006
|
+
success: function (data) {
|
|
1007
|
+
// b(".be-list-loading", element).css("display", "none");
|
|
1008
|
+
b(".be-list-loading", element).removeClass("opacity-100").addClass("opacity-0");
|
|
1009
|
+
b(".be-list-data", element).removeClass("opacity-0");
|
|
1010
|
+
b(".be-list-data-body", element).css("display", "table-row-group");
|
|
1011
|
+
|
|
1012
|
+
data.isInit = options.isInit;
|
|
1013
|
+
if (options.onSuccess)
|
|
1014
|
+
options.onSuccess(data);
|
|
1015
|
+
|
|
1016
|
+
if (data.total) {
|
|
1017
|
+
target.page(element, options, param, data.total);//翻页
|
|
1018
|
+
//全选/全清
|
|
1019
|
+
b(".ilist-check-all").checkAll('.ilist-check');
|
|
1020
|
+
|
|
1021
|
+
if (b(element).data("be.ilist.event")) {
|
|
1022
|
+
b(element).data("be.ilist.event", false);
|
|
1023
|
+
|
|
1024
|
+
//选择单列/取消选择单列
|
|
1025
|
+
b( ".ilist-check", element ).change( e => {
|
|
1026
|
+
let isChecked = b( e.currentTarget ).is( ":checked" );
|
|
1027
|
+
if (isChecked)
|
|
1028
|
+
b(e.currentTarget).parents("tr").addClass("active");
|
|
1029
|
+
else
|
|
1030
|
+
b(e.currentTarget).parents("tr").removeClass("active");
|
|
1031
|
+
} );
|
|
1032
|
+
|
|
1033
|
+
//全选列/全清列
|
|
1034
|
+
b( ".ilist-check-all", element ).change( e => {
|
|
1035
|
+
let isChecked = b( e.currentTarget ).is( ":checked" );
|
|
1036
|
+
if (isChecked)
|
|
1037
|
+
b( ".ilist-check" ).addClass( "active" ).trigger("change");
|
|
1038
|
+
else
|
|
1039
|
+
b( ".ilist-check" ).removeClass( "active" ).trigger("change");
|
|
1040
|
+
} );
|
|
1041
|
+
|
|
1042
|
+
//点击列选择单列/点击列取消选择单列
|
|
1043
|
+
b( "table > tbody tr", element ).click( e => {
|
|
1044
|
+
let target = b( e.target );
|
|
1045
|
+
if (!(target.is( "input" ) || target.is( "i" ) || target.is( "a" ))) {
|
|
1046
|
+
b( ".ilist-check", e.currentTarget ).click();
|
|
1047
|
+
}
|
|
1048
|
+
} )
|
|
1049
|
+
|
|
1050
|
+
//排序,<td data-sortname="a.title" data-is-sort="true"
|
|
1051
|
+
b( "table > thead tr td", element ).click( e => {
|
|
1052
|
+
const sortname = b( e.currentTarget ).data( "sortname" );
|
|
1053
|
+
if (sortname) {
|
|
1054
|
+
param.sortname = sortname;
|
|
1055
|
+
if (!b( e.currentTarget ).hasClass( "is-check" ) && param.sortname) {
|
|
1056
|
+
let sortorder = b( e.currentTarget ).attr( "data-sort-order" );
|
|
1057
|
+
|
|
1058
|
+
b( "table > thead tr td", element ).removeAttr( "data-sort-order" );
|
|
1059
|
+
|
|
1060
|
+
if (sortorder) {
|
|
1061
|
+
if (sortorder === "desc") {
|
|
1062
|
+
b( e.currentTarget ).attr( "data-sort-order", "asc" );
|
|
1063
|
+
sortorder = "asc";
|
|
1064
|
+
} else {
|
|
1065
|
+
b( e.currentTarget ).attr( "data-sort-order", "desc" );
|
|
1066
|
+
sortorder = "desc";
|
|
1067
|
+
}
|
|
1068
|
+
param.sortorder = sortorder;
|
|
1069
|
+
} else {
|
|
1070
|
+
b( e.currentTarget ).attr( "data-sort-order", "desc" );
|
|
1071
|
+
param.sortorder = "desc";
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
b( element ).data( "be.ilist.flag", true );
|
|
1075
|
+
param.page = "1";
|
|
1076
|
+
options.isInit = false;
|
|
1077
|
+
target.getData( element, options, param );
|
|
1078
|
+
} else {
|
|
1079
|
+
b( e.currentTarget ).css( "cursor", "auto ! important" );
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
} );
|
|
1083
|
+
}
|
|
1084
|
+
b(".be-list-page", element).addClass("opacity-100");//b(".be-list-page", element).css("visibility", "visible");
|
|
1085
|
+
} else {
|
|
1086
|
+
b(".be-list-nofound", element).addClass("opacity-100");//b(".be-list-nofound", element).css("display", "block");
|
|
1087
|
+
b(".be-list-page", element).removeClass("opacity-100");
|
|
1088
|
+
}
|
|
1089
|
+
},
|
|
1090
|
+
error: function (XMLHttpRequest, textStatus, errorThrown) {
|
|
1091
|
+
try {
|
|
1092
|
+
if (options.onError) options.onError(XMLHttpRequest, textStatus, errorThrown);
|
|
1093
|
+
} catch (e) {}
|
|
1094
|
+
}
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
// 分页查询
|
|
1099
|
+
page(element, options, param, total) {
|
|
1100
|
+
let target = this,
|
|
1101
|
+
myElement = b(element);
|
|
1102
|
+
if (myElement.data("be.ilist.flag")) {
|
|
1103
|
+
new IPagination('#ipagination', {
|
|
1104
|
+
totalItems: total,
|
|
1105
|
+
itemsPerPage: options.rp,
|
|
1106
|
+
visiblePages: options.visiblePages,
|
|
1107
|
+
prev: options.prev,
|
|
1108
|
+
next: options.next,
|
|
1109
|
+
first: options.first,
|
|
1110
|
+
last: options.last,
|
|
1111
|
+
onButtonClick: ( page ) => {
|
|
1112
|
+
document.querySelector('.ilist-check-all').checked = false;
|
|
1113
|
+
param.page = page;
|
|
1114
|
+
options.isInit = false;
|
|
1115
|
+
target.getData( element, options, param );
|
|
1116
|
+
}
|
|
1117
|
+
} )
|
|
1118
|
+
}
|
|
1119
|
+
myElement.data("be.ilist.flag", false);
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
// 设置参数重新搜索
|
|
1123
|
+
reload(param) {
|
|
1124
|
+
let target = b(this),
|
|
1125
|
+
data = target.data("be.ilist"),
|
|
1126
|
+
newParam = b.extend(param,
|
|
1127
|
+
{ page: 1, rp: data.options.rp, sortname: data.options.sortname, sortorder: data.options.sortorder });
|
|
1128
|
+
data.options.isInit = false;
|
|
1129
|
+
target.data("be.ilist.flag", true);
|
|
1130
|
+
data["getData"](data['selector'], data.options, newParam);
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
|
|
1135
|
+
/* ========================================================================
|
|
1136
|
+
* 9. 手风琴导航菜单
|
|
1137
|
+
* 右侧导航菜单
|
|
1138
|
+
* 2024年7月18日 10:17:08
|
|
1139
|
+
* ========================================================================
|
|
1140
|
+
* <pre>
|
|
1141
|
+
<button id="iaccordion-btn" class="ce-accordion-btn"><i class="bi bi-layout-text-sidebar-reverse"></i></button>
|
|
1142
|
+
<ul class="ce-accordion" id="iaccordion">
|
|
1143
|
+
<li class="sub-menu"><a href="javascript:"><i class="bi bi-sunset"></i><span>主页</span></a></li>
|
|
1144
|
+
<li class="sub-menu"><a href="#"><i class="bi bi-twitch"></i><span>数据</span></a>
|
|
1145
|
+
<ul class="sub">
|
|
1146
|
+
<li class="sub-menu"><a href="javascript:"><span>人员管理</span></a></li>
|
|
1147
|
+
<li class="sub-menu"><a href="javascript:"><span>日志</span></a></li>
|
|
1148
|
+
<li class="sub-menu"><a href="javascript:"><span>新闻管理</span></a></li>
|
|
1149
|
+
<li class="sub-menu"><a href="javascript:"><span>签到</span></a></li>
|
|
1150
|
+
</ul>
|
|
1151
|
+
</li>
|
|
1152
|
+
<li class="sub-menu"><a href="#"><i class="bi bi-twitter"></i><span>权限</span></a>
|
|
1153
|
+
<ul class="sub">
|
|
1154
|
+
<li class="sub-menu"><a href="javascript:"><span>新闻平台权限</span></a></li>
|
|
1155
|
+
<li class="sub-menu"><a href="javascript:"><span>商城权限</span></a>
|
|
1156
|
+
<ul class="sub">
|
|
1157
|
+
<li class="sub-menu"><a href="javascript:"><span>商城查询权限</span></a></li>
|
|
1158
|
+
</ul>
|
|
1159
|
+
</li>
|
|
1160
|
+
</ul>
|
|
1161
|
+
</li>
|
|
1162
|
+
</ul>
|
|
1163
|
+
|
|
1164
|
+
import 'istyle/src/css/accordion/ce-accordion.css'
|
|
1165
|
+
new u.IAccordion('#iaccordion', { speed: 300, showCount: true });
|
|
1166
|
+
b("#iaccordion-btn").click((e) => {
|
|
1167
|
+
b('#iaccordion').toggleClass("ce-accordion-small")
|
|
1168
|
+
b(e.currentTarget).toggleClass("ce-ab-small")
|
|
1169
|
+
})
|
|
1170
|
+
* </pre>
|
|
1171
|
+
* ======================================================================== */
|
|
1172
|
+
export class IAccordion {
|
|
1173
|
+
constructor(selector, custom) {
|
|
1174
|
+
this.selector = selector;
|
|
1175
|
+
defaultConstructor(this, selector, custom, (target) => {
|
|
1176
|
+
target.elements.forEach( ( element ) => {
|
|
1177
|
+
let myElems = b( element );
|
|
1178
|
+
if (!myElems.data( "be.iaccordion" ))
|
|
1179
|
+
myElems.data( "be.iaccordion", target );
|
|
1180
|
+
|
|
1181
|
+
target.init( element, custom );
|
|
1182
|
+
} );
|
|
1183
|
+
} );
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
options = {
|
|
1187
|
+
classParent: 'ia-parent', // 包含ul的父级菜单
|
|
1188
|
+
classActive : 'active', // 当前激活菜单
|
|
1189
|
+
classArrow: 'ia-icon', // 菜单右侧展开缩小图标: - and +
|
|
1190
|
+
classCount: 'ia-count',
|
|
1191
|
+
autoExpand: false,
|
|
1192
|
+
classExpand : 'ia-current-parent',
|
|
1193
|
+
autoClose: true, // 打开菜单时是否关闭其他承担
|
|
1194
|
+
speed: 300,
|
|
1195
|
+
saveState : true, // 下次打开是否使用当前的菜单
|
|
1196
|
+
disableLink : true, // 需要展开子项的不触发浏览链接
|
|
1197
|
+
showCount: false, // 显示一样多少菜单
|
|
1198
|
+
cookie: 'ia-cookie',
|
|
1199
|
+
smallClass: 'ce-accordion-small'
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
init(element, options) {
|
|
1203
|
+
const target = this,
|
|
1204
|
+
myLinks = b( 'li > a', element ),
|
|
1205
|
+
mySub = b( 'li > ul', element );
|
|
1206
|
+
|
|
1207
|
+
options = b.extend( options, target.options );
|
|
1208
|
+
const classActive = options.classActive;
|
|
1209
|
+
|
|
1210
|
+
this.setUpAccordion(element, myLinks, mySub, options);
|
|
1211
|
+
if (options.saveState === true) {
|
|
1212
|
+
target.checkCookie( options.cookie, element, classActive );
|
|
1213
|
+
}
|
|
1214
|
+
if (options.autoExpand === true) {
|
|
1215
|
+
b( 'li.' + options.classExpand + ' > a' ).addClass( classActive );
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
myLinks.click( function ( e ) {
|
|
1219
|
+
const myTarget = b( e.currentTarget ),
|
|
1220
|
+
myActiveLi = myTarget.parent(),
|
|
1221
|
+
isSmall = target.isSmall( e, element, options.smallClass);
|
|
1222
|
+
// 需要展开子项的不触发浏览链接
|
|
1223
|
+
if (options.disableLink === true) {
|
|
1224
|
+
if (myTarget.siblings( 'ul' ).length > 0) {
|
|
1225
|
+
e.preventDefault();
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
// 关闭其他展开的菜单
|
|
1230
|
+
if (options.autoClose === true) {
|
|
1231
|
+
target.autoCloseAccordion( element, myTarget, isSmall, options )
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
if (b( '> ul', myActiveLi ).length === 0) {
|
|
1235
|
+
b( '> a', myActiveLi ).addClass( classActive );
|
|
1236
|
+
} else if (b( '> ul', myActiveLi ).css( 'display' ) !== 'none') {
|
|
1237
|
+
// 已经打开的则关闭
|
|
1238
|
+
target.slideUp( b( 'ul', myActiveLi ), isSmall, options )
|
|
1239
|
+
b( 'a', myActiveLi ).removeClass( classActive );
|
|
1240
|
+
} else {
|
|
1241
|
+
if (b( e.currentTarget ).siblings( 'ul' ).css( 'display' ) === 'none') {
|
|
1242
|
+
target.slideDown(b( e.currentTarget ).siblings( 'ul' ).css("overflow", "hidden"), isSmall, options)
|
|
1243
|
+
} else {
|
|
1244
|
+
target.slideUp( b( e.currentTarget ).siblings( 'ul' ), isSmall, options )
|
|
1245
|
+
}
|
|
1246
|
+
b( '> a', myActiveLi ).addClass( classActive );
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
// 设置cookie
|
|
1250
|
+
if (options.saveState === true) {
|
|
1251
|
+
target.createCookie( options.cookie, element, classActive );
|
|
1252
|
+
}
|
|
1253
|
+
});
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
setUpAccordion(target, myLinks, mySub, options) {
|
|
1257
|
+
const classArrowHtml = '<span class="' + options.classArrow + '"></span>',
|
|
1258
|
+
classParentLi = options.classParent + '-li';
|
|
1259
|
+
mySub.show();
|
|
1260
|
+
b( 'li', target ).each(e => {
|
|
1261
|
+
if (b( '> ul', e ).length > 0) {
|
|
1262
|
+
b( e ).addClass( classParentLi );
|
|
1263
|
+
b( '> a', e ).addClass( options.classParent ).append( classArrowHtml );
|
|
1264
|
+
}
|
|
1265
|
+
});
|
|
1266
|
+
mySub.hide();
|
|
1267
|
+
// 显示数量
|
|
1268
|
+
if (options.showCount === true) {
|
|
1269
|
+
b( 'ul', target ).each((ele) => {
|
|
1270
|
+
b( '> a', b(ele).parent() ).append( ' <span class="' + options.classCount + '">(' + ele.children.length + ')</span>' );
|
|
1271
|
+
})
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
// 关闭其它标签
|
|
1276
|
+
autoCloseAccordion( element, target, isSmall, options ) {
|
|
1277
|
+
const t = this;
|
|
1278
|
+
b( 'ul', element ).each((ele) => {
|
|
1279
|
+
let isParent = false;
|
|
1280
|
+
target.parents("ul").each((parentEle) => {
|
|
1281
|
+
if (parentEle === ele)
|
|
1282
|
+
isParent = true;
|
|
1283
|
+
});
|
|
1284
|
+
if (!isParent && target.siblings( 'ul' ).elements[0] !== ele && ele.style.display !== 'none') {
|
|
1285
|
+
t.slideUp( b(ele), isSmall, options )
|
|
1286
|
+
}
|
|
1287
|
+
})
|
|
1288
|
+
// 重置激活菜单
|
|
1289
|
+
b( 'a', element ).removeClass( options.classActive );
|
|
1290
|
+
target.parents("li").each((ele) => {
|
|
1291
|
+
b( '> a', ele).addClass( options.classActive );
|
|
1292
|
+
})
|
|
1293
|
+
// target.addClass( options.classActive );
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
// 检索cookie值
|
|
1297
|
+
checkCookie(cookieId, target, classActive) {
|
|
1298
|
+
const t = this,
|
|
1299
|
+
cookieVal = b.getCookie(cookieId);
|
|
1300
|
+
if( cookieVal !== null && cookieVal !== "" ) {
|
|
1301
|
+
const activeArray = cookieVal.split(',');
|
|
1302
|
+
t.setActiveMenu( target, activeArray, 0, classActive )
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
// 通过cookie设置之前的存档
|
|
1307
|
+
setActiveMenu(target, activeArray, index, classActive) {
|
|
1308
|
+
const myCookieLi = b('li:eq(' + activeArray[index] + ')', target),
|
|
1309
|
+
myA = b('> a', myCookieLi ),
|
|
1310
|
+
myUl = myA.siblings('ul');
|
|
1311
|
+
myA.addClass( classActive );
|
|
1312
|
+
myUl.css('display', '');
|
|
1313
|
+
|
|
1314
|
+
if (activeArray.length > index + 1) {
|
|
1315
|
+
this.setActiveMenu(myUl, activeArray, ++index, classActive);
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
// 创建cookie
|
|
1320
|
+
createCookie(cookieId, target, classActive){
|
|
1321
|
+
let activeIndex = [];
|
|
1322
|
+
// 激活菜单列表
|
|
1323
|
+
b('li a.' + classActive, target).each((e) => {
|
|
1324
|
+
const myArrayItem = b(e).parent('li'),
|
|
1325
|
+
// itemIndex = b('li', target).index(myArrayItem);
|
|
1326
|
+
itemIndex = myArrayItem.index();
|
|
1327
|
+
activeIndex.push(itemIndex);
|
|
1328
|
+
});
|
|
1329
|
+
b.setCookie(cookieId, activeIndex);
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
// 是否为在缩小模式下的下拉按钮
|
|
1333
|
+
isSmall(e, element, smallClass) {
|
|
1334
|
+
if (b(element).hasClass(smallClass) && b(e.currentTarget).siblings('ul').length !== 0) {
|
|
1335
|
+
e.preventDefault();
|
|
1336
|
+
return true;
|
|
1337
|
+
} else {
|
|
1338
|
+
return false;
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
// 菜单列显示
|
|
1343
|
+
slideDown(myElement, isSmall, options) {
|
|
1344
|
+
if (!isSmall)
|
|
1345
|
+
myElement.slideDown(options.speed)
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
// 菜单列隐藏
|
|
1349
|
+
slideUp(myElement, isSmall, options) {
|
|
1350
|
+
if (!isSmall)
|
|
1351
|
+
myElement.slideUp(options.speed)
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
/* ========================================================================
|
|
1356
|
+
* 10. 弹框搜索面板
|
|
1357
|
+
* 2016年5月22日19:01:48
|
|
1358
|
+
* ========================================================================
|
|
1359
|
+
* <pre>
|
|
1360
|
+
<script type="text/template" id="tp-popover-items">
|
|
1361
|
+
{{#each items}}
|
|
1362
|
+
<div class="popover-content-item row">
|
|
1363
|
+
{{#if type 'text'}}
|
|
1364
|
+
<div class="col-sm-3 text-right">
|
|
1365
|
+
<label class="label-control">{{desc}}:</label>
|
|
1366
|
+
</div>
|
|
1367
|
+
<div class="col-sm-8 no-padding-left">
|
|
1368
|
+
<input name="{{name}}" class="form-control popover-form-item" placeholder="{{desc}}" value="{{value}}"/>
|
|
1369
|
+
</div>
|
|
1370
|
+
{{/if}}
|
|
1371
|
+
{{#if type 'date'}}
|
|
1372
|
+
<div class="col-sm-3 text-right">
|
|
1373
|
+
<label class="label-control">{{desc}}:</label>
|
|
1374
|
+
</div>
|
|
1375
|
+
<div class="col-sm-8 no-padding-left be-rel">
|
|
1376
|
+
<input id="airDatepicker" name="{{name}}" class="form-control popover-form-item popover-form-date" placeholder="{{desc}}" value="{{value}}"/>
|
|
1377
|
+
</div>
|
|
1378
|
+
{{/if}}
|
|
1379
|
+
{{#if type 'select'}}
|
|
1380
|
+
<div class="col-sm-3 text-right">
|
|
1381
|
+
<label class="label-control">{{desc}}:</label>
|
|
1382
|
+
</div>
|
|
1383
|
+
<div class="col-sm-8 no-padding-left">
|
|
1384
|
+
<select name="{{name}}" class="form-select popover-form-item">
|
|
1385
|
+
{{#each options}}
|
|
1386
|
+
<option value="{{name}}" {{#if selected true}}selected="selected"{{/if}}>{{value}}</option>
|
|
1387
|
+
{{/each}}
|
|
1388
|
+
</select>
|
|
1389
|
+
</div>
|
|
1390
|
+
{{/if}}
|
|
1391
|
+
</div>
|
|
1392
|
+
{{/each}}
|
|
1393
|
+
</script>
|
|
1394
|
+
|
|
1395
|
+
<script type="text/template" id="tp-popover">
|
|
1396
|
+
<div class="popover tooltip ce-popover" role="tooltip">
|
|
1397
|
+
<h3 class="popover-title">详细搜索</h3>
|
|
1398
|
+
<div class="popover-content">
|
|
1399
|
+
<div class="popover-content-items"></div>
|
|
1400
|
+
</div>
|
|
1401
|
+
<div class="popover-footer">
|
|
1402
|
+
<a class="ce-popover-ok"><i class="bi bi-search"></i>搜索</a>
|
|
1403
|
+
<a class="ce-popover-cancel"><i class="bi bi-x-square"></i>关闭</a>
|
|
1404
|
+
<a class="ce-popover-clear"><i class="bi bi-trash3"></i>清除</a>
|
|
1405
|
+
</div>
|
|
1406
|
+
</div>
|
|
1407
|
+
</script>
|
|
1408
|
+
|
|
1409
|
+
<a id="ipopover" tabindex="0" class="btn btn-sm btn-danger">弹出搜索框</a>
|
|
1410
|
+
|
|
1411
|
+
// JS调用
|
|
1412
|
+
<script src="/js/bootstrap.bundle.js"></script>
|
|
1413
|
+
<script src="/js/handlebars.min.js"></script>
|
|
1414
|
+
<script>
|
|
1415
|
+
Handlebars.registerHelper("if", function(v1, v2, options) {
|
|
1416
|
+
return (v1 === v2) ? options.fn(this) : options.inverse(this);
|
|
1417
|
+
});
|
|
1418
|
+
</script>
|
|
1419
|
+
or
|
|
1420
|
+
import "istyle/src/css/base/init.css";
|
|
1421
|
+
import "istyle/src/css/case/ce-popover.css";
|
|
1422
|
+
import Handlebars from 'glib/handlebars'
|
|
1423
|
+
import * as bootstrap from 'glib/bootstrap';
|
|
1424
|
+
|
|
1425
|
+
b.handlebars(Handlebars);
|
|
1426
|
+
import AirDatepicker from 'glib/air-datepicker'
|
|
1427
|
+
import localeZh from 'glib/air-datepicker/locale/zh';
|
|
1428
|
+
import 'glib/air-datepicker/air-datepicker.css'
|
|
1429
|
+
import 'istyle/src/css/form/fm-datepicker.css'
|
|
1430
|
+
|
|
1431
|
+
new u.PopoverSearch('#ipopover', {
|
|
1432
|
+
handlebars: Handlebars,
|
|
1433
|
+
airDatepicker: AirDatepicker,
|
|
1434
|
+
localeZh: localeZh,
|
|
1435
|
+
bootstrap: bootstrap,
|
|
1436
|
+
items: [
|
|
1437
|
+
{name: "name", desc: "姓名", type: "text", value: ""},
|
|
1438
|
+
{name: "time", desc: "开始时间", type: "date", value: ""},
|
|
1439
|
+
{name: "select", desc: "选项", type: "select",
|
|
1440
|
+
options: [
|
|
1441
|
+
{name: "", value: "所有", selected: false},//如果默认查询所有,name设置为""
|
|
1442
|
+
{name: "o1", value: "选项1", selected: false},
|
|
1443
|
+
{name: "o2", value: "选项2", selected: true}
|
|
1444
|
+
]
|
|
1445
|
+
}
|
|
1446
|
+
],
|
|
1447
|
+
onSerach: function(e) {
|
|
1448
|
+
// $("#ipopover").click();
|
|
1449
|
+
console.log(e.param);//参数及参数值对象,{name: "arisu", time: "2016-07-16 17:02:59", select: "o2"}
|
|
1450
|
+
}
|
|
1451
|
+
});
|
|
1452
|
+
* </pre>
|
|
1453
|
+
* ======================================================================== */
|
|
1454
|
+
export class PopoverSearch {
|
|
1455
|
+
constructor( selector, custom ) {
|
|
1456
|
+
this.selector = selector;
|
|
1457
|
+
defaultConstructor( this, selector, custom, ( target ) => {
|
|
1458
|
+
target.elements.forEach( ( element ) => {
|
|
1459
|
+
let myElems = b( element );
|
|
1460
|
+
if (!myElems.data( "be.popoversearch" ))
|
|
1461
|
+
myElems.data( "be.popoversearch", target );
|
|
1462
|
+
|
|
1463
|
+
if (typeof Handlebars !== 'undefined' && custom.handlebars === null) custom.handlebars = Handlebars;
|
|
1464
|
+
if (typeof bootstrap !== 'undefined' && custom.bootstrap === null) custom.bootstrap = bootstrap;
|
|
1465
|
+
if (typeof AirDatepicker !== 'undefined' && custom.airDatepicker === null) custom.airDatepicker = AirDatepicker;
|
|
1466
|
+
if (typeof localeZh !== 'undefined' && custom.localeZh === null) custom.localeZh = localeZh;
|
|
1467
|
+
target.init( element, custom );
|
|
1468
|
+
} );
|
|
1469
|
+
} );
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
options = {
|
|
1473
|
+
handlebars: null, //模板生成工具
|
|
1474
|
+
bootstrap: null, //bootstrap Popover
|
|
1475
|
+
airDatepicker: null,//日期控件
|
|
1476
|
+
localeZh: null, //日期控件中文支持
|
|
1477
|
+
template: "#tp-popover",
|
|
1478
|
+
templateItems: "#tp-popover-items",
|
|
1479
|
+
html: true,
|
|
1480
|
+
title: "详细搜索",
|
|
1481
|
+
trigger: "click",
|
|
1482
|
+
toggle: "popover",
|
|
1483
|
+
placement: "auto",
|
|
1484
|
+
onSerach: false,
|
|
1485
|
+
items: [], //搜索框json数据
|
|
1486
|
+
// startView: 2,
|
|
1487
|
+
// minView: 2,
|
|
1488
|
+
timepicker: true, //是否显示时分秒
|
|
1489
|
+
format: "yyyy-MM-dd hh:mm:ss"
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
init(element, options) {
|
|
1493
|
+
let target = this;
|
|
1494
|
+
target.itemsValue = []; // 搜索框值
|
|
1495
|
+
// var $element = $(element);
|
|
1496
|
+
// var target = this;
|
|
1497
|
+
|
|
1498
|
+
const template = options.handlebars.compile(b(options.template).html())({});
|
|
1499
|
+
|
|
1500
|
+
const popr = new options.bootstrap.Popover(element, {
|
|
1501
|
+
html: options.html,
|
|
1502
|
+
title: options.title,
|
|
1503
|
+
trigger: options.trigger,
|
|
1504
|
+
toggle: options.toggle,
|
|
1505
|
+
placement: options.placement,
|
|
1506
|
+
template: template,
|
|
1507
|
+
animation: true,
|
|
1508
|
+
param: null
|
|
1509
|
+
});
|
|
1510
|
+
|
|
1511
|
+
element.addEventListener('inserted.bs.popover', () => {
|
|
1512
|
+
target.addItem(options);
|
|
1513
|
+
})
|
|
1514
|
+
|
|
1515
|
+
element.addEventListener('shown.bs.popover', () => {
|
|
1516
|
+
target.search(target, options);
|
|
1517
|
+
target.close(popr);
|
|
1518
|
+
target.clear();
|
|
1519
|
+
})
|
|
1520
|
+
|
|
1521
|
+
element.addEventListener('hide.bs.popover', () => {
|
|
1522
|
+
target.itemsHtml = b(".popover-content-items").html();
|
|
1523
|
+
target.itemsValue = [];
|
|
1524
|
+
b(".popover-form-item").each((e) => {
|
|
1525
|
+
target.itemsValue.push(b(e).val());
|
|
1526
|
+
})
|
|
1527
|
+
})
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
// 添加搜索框
|
|
1531
|
+
addItem(options) {
|
|
1532
|
+
const target = this;
|
|
1533
|
+
if (target.itemsHtml) {
|
|
1534
|
+
b(".ce-popover > .popover-content .popover-content-items").html(target.itemsHtml);
|
|
1535
|
+
} else {
|
|
1536
|
+
const html = options.handlebars.compile(b(options.templateItems).html())({
|
|
1537
|
+
items: options.items
|
|
1538
|
+
});
|
|
1539
|
+
b(".ce-popover > .popover-content .popover-content-items").html(html);
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
b('.popover-form-item').each((e, i) => {
|
|
1543
|
+
const myEle = b(e);
|
|
1544
|
+
myEle.val(target.itemsValue[i])
|
|
1545
|
+
if (myEle.hasClass('popover-form-date')) {
|
|
1546
|
+
try {
|
|
1547
|
+
new options.airDatepicker( ".ce-popover input[name='" + myEle.attr('name') + "']", {
|
|
1548
|
+
classes: 'fm-datepicker',
|
|
1549
|
+
autoClose: true,
|
|
1550
|
+
inline: false,
|
|
1551
|
+
timepicker: options.timepicker,
|
|
1552
|
+
buttons: ['today', 'clear'],
|
|
1553
|
+
locale: options.localeZh,
|
|
1554
|
+
dateFormat( date ) {
|
|
1555
|
+
return date.format( options.format )
|
|
1556
|
+
}
|
|
1557
|
+
} )
|
|
1558
|
+
} catch (e) {
|
|
1559
|
+
b(".ce-popover input[name='" + myEle.attr('name') + "']").attr('type', 'date');
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
})
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
// 关闭
|
|
1566
|
+
close(popr) {
|
|
1567
|
+
// b.l(element)
|
|
1568
|
+
// b.l(b(".ce-popover-cancel", element))
|
|
1569
|
+
b(".ce-popover-cancel", '.ce-popover').off("click").on("click", () => {
|
|
1570
|
+
popr.hide();
|
|
1571
|
+
});
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
// 清空条件
|
|
1575
|
+
clear() {
|
|
1576
|
+
b(".ce-popover-clear", ".ce-popover").off("click").on("click", () => {
|
|
1577
|
+
b('.popover-form-item', '.ce-popover').each((e) => {
|
|
1578
|
+
b(e).val("");
|
|
1579
|
+
})
|
|
1580
|
+
});
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
// 获取参数
|
|
1584
|
+
getParam() {
|
|
1585
|
+
const params = {};
|
|
1586
|
+
b.l(b(".popover-form-item"))
|
|
1587
|
+
b(".popover-form-item").each(function(e) {
|
|
1588
|
+
const myEle = b(e),
|
|
1589
|
+
name = myEle.attr("name"),
|
|
1590
|
+
val = myEle.val();
|
|
1591
|
+
if (val) params[name] = val;
|
|
1592
|
+
})
|
|
1593
|
+
return params;
|
|
1594
|
+
};
|
|
1595
|
+
|
|
1596
|
+
// 调用参数中的搜索方法
|
|
1597
|
+
search(target, options) {
|
|
1598
|
+
b(".ce-popover-ok", ".ce-popover").off("click").on("click", () => {
|
|
1599
|
+
if (options.onSerach) options.onSerach({param: target.getParam()});
|
|
1600
|
+
})
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
/* ========================================================================
|
|
1606
|
+
* 11. 文字切换动画特效
|
|
1607
|
+
* 2023年7月5日 12:58:24
|
|
1608
|
+
* ========================================================================
|
|
1609
|
+
* <pre>
|
|
1610
|
+
<div id="ce-flash" class="ce-txt">
|
|
1611
|
+
<span>
|
|
1612
|
+
<b class="is-visible">尖端设计.</b>
|
|
1613
|
+
<b>编码流畅严谨.</b>
|
|
1614
|
+
<b>完美构图.</b>
|
|
1615
|
+
</span>
|
|
1616
|
+
</div>
|
|
1617
|
+
|
|
1618
|
+
import "istyle/src/css/case/ce-txt.css";
|
|
1619
|
+
new u.Flash("#ce-flash", {
|
|
1620
|
+
animationDelay: 3000,
|
|
1621
|
+
lettersDelay: 50
|
|
1622
|
+
})
|
|
1623
|
+
* </pre>
|
|
1624
|
+
* ======================================================================== */
|
|
1625
|
+
export class Flash {
|
|
1626
|
+
constructor( selector, custom ) {
|
|
1627
|
+
this.selector = selector;
|
|
1628
|
+
defaultConstructor( this, selector, custom, ( target ) => {
|
|
1629
|
+
target.elements.forEach( ( element ) => {
|
|
1630
|
+
let myElems = b( element );
|
|
1631
|
+
if (!myElems.data( "be.flash" ))
|
|
1632
|
+
myElems.data( "be.flash", target );
|
|
1633
|
+
|
|
1634
|
+
target.init( element, custom );
|
|
1635
|
+
} );
|
|
1636
|
+
} );
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
options = {
|
|
1640
|
+
//动画间隔时间5秒
|
|
1641
|
+
animationDelay: 5000,
|
|
1642
|
+
//letters: 每个字特效的时间间隔
|
|
1643
|
+
lettersDelay: 50,
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
init(element, options) {
|
|
1647
|
+
const target = this;
|
|
1648
|
+
if (options.type === 1) {
|
|
1649
|
+
b(element).addClass("letters");
|
|
1650
|
+
}
|
|
1651
|
+
target.singleLetters(element);
|
|
1652
|
+
//初始化动画
|
|
1653
|
+
target.animateHeadline(element, options);
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
// 文本加入HTML标签方便控制
|
|
1657
|
+
singleLetters(element) {
|
|
1658
|
+
const target = this,
|
|
1659
|
+
myB = b(element).find("b");
|
|
1660
|
+
myB.each(function(e) {
|
|
1661
|
+
const myWord = b(e),
|
|
1662
|
+
letters = myWord.text().split(""),
|
|
1663
|
+
selected = myWord.hasClass("is-visible");
|
|
1664
|
+
for (const i in letters) {
|
|
1665
|
+
if (letters.hasOwnProperty(i)) {
|
|
1666
|
+
if (myWord.parents( target.selector ).length > 0) letters[i] = "<em>" + letters[i] + "</em>";
|
|
1667
|
+
letters[i] = (selected) ? "<i class='in'>" + letters[i] + "</i>" : "<i>" + letters[i] + "</i>";
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
const newLetters = letters.join("");
|
|
1671
|
+
myWord.html(newLetters).css("opacity", 1);
|
|
1672
|
+
});
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
// 开始动画
|
|
1676
|
+
animateHeadline(element, options) {
|
|
1677
|
+
const target = this,
|
|
1678
|
+
myElement = b(element);
|
|
1679
|
+
let duration = options.animationDelay;
|
|
1680
|
+
myElement.each(function(ele){
|
|
1681
|
+
const myEle = b(ele);
|
|
1682
|
+
setTimeout(() => { target.hideWord( myEle.find(".is-visible").first() ) }, duration);
|
|
1683
|
+
})
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
// 文字隐藏显示切换,myWord: Base封装的每行文字
|
|
1687
|
+
hideWord(myWord) {
|
|
1688
|
+
const target = this,
|
|
1689
|
+
nextWord = target.takeNext(myWord);
|
|
1690
|
+
|
|
1691
|
+
const bool = myWord.children().length >= nextWord.children().length;
|
|
1692
|
+
target.hideLetter(myWord.find("i").first(), myWord, bool, target.options.lettersDelay);
|
|
1693
|
+
target.showLetter(nextWord.find("i").first(), nextWord, bool, target.options.lettersDelay);
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
// 获取下一行,如果是最后一行跳到第一行
|
|
1697
|
+
takeNext(myWord) {
|
|
1698
|
+
return (myWord.length !== 0 && !myWord.is(":last-child")) ? myWord.next() : myWord.parent().children().first();
|
|
1699
|
+
}
|
|
1700
|
+
|
|
1701
|
+
hideLetter(myLetter, myWord, bool, duration) {
|
|
1702
|
+
const target = this;
|
|
1703
|
+
myLetter.removeClass("in").addClass("out");
|
|
1704
|
+
if(myLetter.length !== 0 && !myLetter.is(":last-child")) {
|
|
1705
|
+
setTimeout(() => { target.hideLetter(myLetter.next(), myWord, bool, duration); }, duration);
|
|
1706
|
+
} else if(bool) {
|
|
1707
|
+
setTimeout(() => { target.hideWord(target.takeNext(myWord)) }, target.options.animationDelay);
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
showLetter(myLetter, myWord, bool, duration) {
|
|
1712
|
+
const target = this;
|
|
1713
|
+
myLetter.addClass("in").removeClass("out");
|
|
1714
|
+
|
|
1715
|
+
if(myLetter.length !== 0 && !myLetter.is(":last-child")) {
|
|
1716
|
+
setTimeout(() => { target.showLetter(myLetter.next(), myWord, bool, duration); }, duration);
|
|
1717
|
+
} else {
|
|
1718
|
+
// if(myWord.parents(target.options.selector).hasClass("type")) { setTimeout(() => { myWord.parents("span").addClass("waiting"); }, 200);}
|
|
1719
|
+
if(!bool) { setTimeout(() => { target.hideWord(myWord) }, target.options.animationDelay) }
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
|
|
1725
|
+
/* ========================================================================
|
|
1726
|
+
* 12. 绘制点线背景动画,依赖tweenlite
|
|
1727
|
+
* 2018年6月2日09:54:29
|
|
1728
|
+
* ========================================================================
|
|
1729
|
+
* <pre>
|
|
1730
|
+
<div id="canvas-warp">
|
|
1731
|
+
<canvas id="iCanvas" style="background-color: rgb(63, 81, 181)" ></canvas>
|
|
1732
|
+
</div>
|
|
1733
|
+
|
|
1734
|
+
import "./plugin/tweenlite/easepack.min"
|
|
1735
|
+
import "./plugin/tweenlite/tweenlite.min"
|
|
1736
|
+
new u.LineEffect("#canvas-warp", {
|
|
1737
|
+
//pointColor: "rgba(0, 0, 0, 1)",
|
|
1738
|
+
//lineColor: "0, 0, 0" ,
|
|
1739
|
+
//height: 302,
|
|
1740
|
+
isWindowWidth: false,
|
|
1741
|
+
width: 500,
|
|
1742
|
+
height: 600,
|
|
1743
|
+
num: 11,
|
|
1744
|
+
canvasId: "iCanvas"
|
|
1745
|
+
});
|
|
1746
|
+
* </pre>
|
|
1747
|
+
* ======================================================================== */
|
|
1748
|
+
class Circle {
|
|
1749
|
+
constructor(options, pos, rad) {
|
|
1750
|
+
this.pos = pos || null;
|
|
1751
|
+
this.radius = rad || null;
|
|
1752
|
+
// this.color = color || null;
|
|
1753
|
+
this.active = true; // 假设默认激活状态
|
|
1754
|
+
this.options = options;
|
|
1755
|
+
}
|
|
1756
|
+
draw(ctx) {
|
|
1757
|
+
if (!this.active) return;
|
|
1758
|
+
ctx.beginPath();
|
|
1759
|
+
ctx.arc(this.pos.x, this.pos.y, this.radius, 0, 2 * Math.PI, false);
|
|
1760
|
+
ctx.fillStyle = "rgba(" + this.options.pointColor + "," + this.active + ")";
|
|
1761
|
+
ctx.fill();
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
export class LineEffect {
|
|
1765
|
+
constructor( selector, custom ) {
|
|
1766
|
+
this.selector = selector;
|
|
1767
|
+
defaultConstructor( this, selector, custom, ( target ) => {
|
|
1768
|
+
target.elements.forEach( ( element ) => {
|
|
1769
|
+
let myElems = b( element );
|
|
1770
|
+
if (!myElems.data( "be.lineeffect" ))
|
|
1771
|
+
myElems.data( "be.lineeffect", target );
|
|
1772
|
+
|
|
1773
|
+
target.init( element, custom );
|
|
1774
|
+
} );
|
|
1775
|
+
} );
|
|
1776
|
+
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1779
|
+
options = {
|
|
1780
|
+
|
|
1781
|
+
canvasId: "targetCanvas",
|
|
1782
|
+
animateHeader: true,
|
|
1783
|
+
|
|
1784
|
+
width: window.innerWidth,
|
|
1785
|
+
height: window.innerHeight,
|
|
1786
|
+
isWindowWidth: false,
|
|
1787
|
+
isWindowHeight: false,
|
|
1788
|
+
num: 20,
|
|
1789
|
+
|
|
1790
|
+
pointColor: "156,217,249", //点颜色
|
|
1791
|
+
lineColor: "156,217,249" //线颜色
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1794
|
+
init(element, options) {
|
|
1795
|
+
const target = this,
|
|
1796
|
+
xy = { x: options.width/2, y: options.height/2 };
|
|
1797
|
+
|
|
1798
|
+
const canvas = document.getElementById(options.canvasId);
|
|
1799
|
+
canvas.width = options.width;
|
|
1800
|
+
canvas.height = options.height;
|
|
1801
|
+
const ctx = canvas.getContext("2d");
|
|
1802
|
+
|
|
1803
|
+
// 绘制点
|
|
1804
|
+
const points = [];
|
|
1805
|
+
for(let x = 0; x < options.width; x = x + options.width / options.num) {
|
|
1806
|
+
for(let y = 0; y < options.height; y = y + options.height / options.num) {
|
|
1807
|
+
let px = x + Math.random() * options.width / options.num;
|
|
1808
|
+
let py = y + Math.random() * options.height / options.num;
|
|
1809
|
+
let p = {x: px, originX: px, y: py, originY: py };
|
|
1810
|
+
points.push(p);
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
|
|
1814
|
+
// 绘制点周围的点
|
|
1815
|
+
for(let i = 0; i < points.length; i++) {
|
|
1816
|
+
const closest = [],
|
|
1817
|
+
p1 = points[i];
|
|
1818
|
+
for(let j = 0; j < points.length; j++) {
|
|
1819
|
+
let p2 = points[j]
|
|
1820
|
+
if(!(p1 === p2)) {
|
|
1821
|
+
let placed = false;
|
|
1822
|
+
for(let k = 0; k < 5; k++) {
|
|
1823
|
+
if(!placed) {
|
|
1824
|
+
if(closest[k] === undefined) {
|
|
1825
|
+
closest[k] = p2;
|
|
1826
|
+
placed = true;
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1831
|
+
for(let k = 0; k < 5; k++) {
|
|
1832
|
+
if(!placed) {
|
|
1833
|
+
if(target.getDistance(p1, p2) < target.getDistance(p1, closest[k])) {
|
|
1834
|
+
closest[k] = p2;
|
|
1835
|
+
placed = true;
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
p1.closest = closest;
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1844
|
+
|
|
1845
|
+
// 给每个点分配一个圆
|
|
1846
|
+
for(let i in points) {
|
|
1847
|
+
if (points.hasOwnProperty(i)) {
|
|
1848
|
+
points[i].circle = new Circle( options, points[i], 2 + Math.random() * 2 );
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
options.points = points;
|
|
1852
|
+
target.initAnimation(options, ctx, xy);
|
|
1853
|
+
target.addListeners(options, xy, canvas);
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1856
|
+
getDistance(p1, p2) {
|
|
1857
|
+
return Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2);
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
//开始绘制动画效果
|
|
1861
|
+
initAnimation(options, ctx, xy) {
|
|
1862
|
+
const target = this;
|
|
1863
|
+
target.animate(options, ctx, xy);
|
|
1864
|
+
for(let i in options.points) {
|
|
1865
|
+
if (options.points.hasOwnProperty(i)) {
|
|
1866
|
+
target.shiftPoint(options.points[i]);
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
|
|
1871
|
+
animate(options, ctx, xy) {
|
|
1872
|
+
const target = this;
|
|
1873
|
+
if(options.animateHeader) {
|
|
1874
|
+
const points = options.points;
|
|
1875
|
+
ctx.clearRect(0, 0, options.width, options.height);
|
|
1876
|
+
for(let i in points) {
|
|
1877
|
+
if (points.hasOwnProperty(i)) {
|
|
1878
|
+
// 检测范围内的点
|
|
1879
|
+
if(Math.abs(target.getDistance(xy, points[i])) < 4000) {
|
|
1880
|
+
points[i].active = 0.3;
|
|
1881
|
+
points[i].circle.active = 0.6;
|
|
1882
|
+
} else if(Math.abs(target.getDistance(xy, points[i])) < 20000) {
|
|
1883
|
+
points[i].active = 0.1;
|
|
1884
|
+
points[i].circle.active = 0.3;
|
|
1885
|
+
} else if(Math.abs(target.getDistance(xy, points[i])) < 40000) {
|
|
1886
|
+
points[i].active = 0.02;
|
|
1887
|
+
points[i].circle.active = 0.1;
|
|
1888
|
+
} else {
|
|
1889
|
+
points[i].active = 0;
|
|
1890
|
+
points[i].circle.active = 0;
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
target.drawLines(options, points[i], ctx);
|
|
1894
|
+
points[i].circle.draw(ctx);
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
requestAnimationFrame(function() {
|
|
1899
|
+
target.animate(options, ctx, xy)
|
|
1900
|
+
});
|
|
1901
|
+
}
|
|
1902
|
+
|
|
1903
|
+
// 开始绘制动画效果 - 点
|
|
1904
|
+
shiftPoint(p) {
|
|
1905
|
+
const target = this;
|
|
1906
|
+
TweenLite.to(p, 1 + Math.random(), {
|
|
1907
|
+
x: p.originX - 50 + Math.random() * 100,
|
|
1908
|
+
y: p.originY - 50 + Math.random() * 100,
|
|
1909
|
+
ease: Circ.easeInOut,
|
|
1910
|
+
onComplete: function() {
|
|
1911
|
+
target.shiftPoint(p);
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
)
|
|
1915
|
+
}
|
|
1916
|
+
|
|
1917
|
+
// 开始绘制动画效果 - 线
|
|
1918
|
+
drawLines(options, p, ctx) {
|
|
1919
|
+
if(!p.active) return;
|
|
1920
|
+
for(let i in p.closest) {
|
|
1921
|
+
if (p.closest.hasOwnProperty(i)) {
|
|
1922
|
+
ctx.beginPath();
|
|
1923
|
+
ctx.moveTo( p.x, p.y );
|
|
1924
|
+
ctx.lineTo( p.closest[i].x, p.closest[i].y );
|
|
1925
|
+
ctx.strokeStyle = "rgba(" + options.lineColor + "," + p.active + ")";
|
|
1926
|
+
ctx.stroke();
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
// 监听事件,移动鼠标, 滚动, 改变屏幕大小
|
|
1932
|
+
addListeners(options, xy, canvas) {
|
|
1933
|
+
const target = this;
|
|
1934
|
+
if(!('ontouchstart' in window)) {
|
|
1935
|
+
window.addEventListener("mousemove", (e) => {
|
|
1936
|
+
target.mouseMove(e, xy);
|
|
1937
|
+
});
|
|
1938
|
+
}
|
|
1939
|
+
window.addEventListener("scroll", () => {
|
|
1940
|
+
target.scrollCheck(options);
|
|
1941
|
+
});
|
|
1942
|
+
window.addEventListener("resize", () => {
|
|
1943
|
+
target.resize(options, canvas);
|
|
1944
|
+
});
|
|
1945
|
+
}
|
|
1946
|
+
|
|
1947
|
+
mouseMove(e, xy) {
|
|
1948
|
+
const canvas = document.getElementById(this.options.canvasId),
|
|
1949
|
+
rect = canvas.getBoundingClientRect(),
|
|
1950
|
+
scrollTop = window.pageYOffset || document.documentElement.scrollTop,
|
|
1951
|
+
scrollLeft = window.pageXOffset || document.documentElement.scrollLeft,
|
|
1952
|
+
offsetTop = rect.top + scrollTop,
|
|
1953
|
+
offsetLeft = rect.left + scrollLeft;
|
|
1954
|
+
|
|
1955
|
+
let posx = 0,
|
|
1956
|
+
posy = 0;
|
|
1957
|
+
if (e.pageX || e.pageY) {
|
|
1958
|
+
posx = e.pageX;
|
|
1959
|
+
posy = e.pageY;
|
|
1960
|
+
} else if (e.clientX || e.clientY) {
|
|
1961
|
+
posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
|
|
1962
|
+
posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
|
|
1963
|
+
}
|
|
1964
|
+
xy.x = posx - offsetLeft;
|
|
1965
|
+
xy.y = posy - offsetTop;
|
|
1966
|
+
}
|
|
1967
|
+
|
|
1968
|
+
scrollCheck(options) {
|
|
1969
|
+
options.animateHeader = document.body.scrollTop <= options.height
|
|
1970
|
+
}
|
|
1971
|
+
|
|
1972
|
+
resize(options, canvas) {
|
|
1973
|
+
if (options.isWindowWidth) canvas.width = window.innerWidth;
|
|
1974
|
+
if (options.isWindowHeight) canvas.height = window.innerHeight;
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
|
|
1979
|
+
|
|
1980
|
+
/* ========================================================================
|
|
1981
|
+
* 12. 鼠标上下左右划入监听实现对应动画
|
|
1982
|
+
* 2022年7月28日 10:50:06
|
|
1983
|
+
* ========================================================================
|
|
1984
|
+
* <pre>
|
|
1985
|
+
<div class="p-3">
|
|
1986
|
+
<div class="ce-thumbs row" id="ce-thumbs">
|
|
1987
|
+
<div class="ce-thumb col-4">
|
|
1988
|
+
<a href="#">
|
|
1989
|
+
<img src="//arisu.cn/file/images/res/anime/anime1470402086147.jpg" class="w-100" />
|
|
1990
|
+
<div>
|
|
1991
|
+
<div class="ce-ts-info"> MAPLE </div>
|
|
1992
|
+
</div>
|
|
1993
|
+
</a>
|
|
1994
|
+
</div>
|
|
1995
|
+
<div class="ce-thumb col-4">
|
|
1996
|
+
<a href="#">
|
|
1997
|
+
<img src="//arisu.cn/file/images/res/anime/anime1470402086147.jpg" class="w-100" />
|
|
1998
|
+
<div>
|
|
1999
|
+
<div class="ce-ts-info"> BIRCH </div>
|
|
2000
|
+
</div>
|
|
2001
|
+
</a>
|
|
2002
|
+
</div>
|
|
2003
|
+
<div class="ce-thumb col-4">
|
|
2004
|
+
<a href="#">
|
|
2005
|
+
<img src="//arisu.cn/file/images/res/anime/anime1470402086147.jpg" class="w-100" />
|
|
2006
|
+
<div>
|
|
2007
|
+
<div class="ce-ts-info"> BLACK WALNUT </div>
|
|
2008
|
+
</div>
|
|
2009
|
+
</a>
|
|
2010
|
+
</div>
|
|
2011
|
+
<div class="ce-thumb col-4">
|
|
2012
|
+
<a href="#">
|
|
2013
|
+
<img src="//arisu.cn/file/images/res/anime/anime1470402086147.jpg" class="w-100" />
|
|
2014
|
+
<div>
|
|
2015
|
+
<div class="ce-ts-info"> OLIVE </div>
|
|
2016
|
+
</div>
|
|
2017
|
+
</a>
|
|
2018
|
+
</div>
|
|
2019
|
+
<div class="ce-thumb col-4">
|
|
2020
|
+
<a href="#">
|
|
2021
|
+
<img src="//arisu.cn/file/images/res/anime/anime1470402086147.jpg" class="w-100" />
|
|
2022
|
+
<div class="ce-ts-info">
|
|
2023
|
+
<div class="ce-ts-info"> DOGWOOD </div>
|
|
2024
|
+
</div>
|
|
2025
|
+
</a>
|
|
2026
|
+
</div>
|
|
2027
|
+
<div class="ce-thumb col-4">
|
|
2028
|
+
<a href="#">
|
|
2029
|
+
<img src="//arisu.cn/file/images/res/anime/anime1470402086147.jpg" class="w-100" />
|
|
2030
|
+
<div>
|
|
2031
|
+
<div class="ce-ts-info"> POPLAR </div>
|
|
2032
|
+
</div>
|
|
2033
|
+
</a>
|
|
2034
|
+
</div>
|
|
2035
|
+
</div>
|
|
2036
|
+
</div>
|
|
2037
|
+
|
|
2038
|
+
import "istyle/src/css/case/ce-thumbs.css";
|
|
2039
|
+
new u.HoverDir(".ce-thumb", {
|
|
2040
|
+
reverse: false
|
|
2041
|
+
})
|
|
2042
|
+
* </pre>
|
|
2043
|
+
* ======================================================================== */
|
|
2044
|
+
export class HoverDir {
|
|
2045
|
+
constructor( selector, custom ) {
|
|
2046
|
+
this.selector = selector;
|
|
2047
|
+
defaultConstructor( this, selector, custom, ( target ) => {
|
|
2048
|
+
target.elements.forEach( ( element ) => {
|
|
2049
|
+
let myElems = b( element );
|
|
2050
|
+
if (!myElems.data( "be.hoverdir" ))
|
|
2051
|
+
myElems.data( "be.hoverdir", target );
|
|
2052
|
+
|
|
2053
|
+
target.init( element, custom );
|
|
2054
|
+
} );
|
|
2055
|
+
} )
|
|
2056
|
+
}
|
|
2057
|
+
|
|
2058
|
+
options = {
|
|
2059
|
+
reverse: false
|
|
2060
|
+
}
|
|
2061
|
+
|
|
2062
|
+
init(element, options) {
|
|
2063
|
+
const target = this,
|
|
2064
|
+
myElement = b(element);
|
|
2065
|
+
myElement.on("mouseenter", (event) => this.mouseEvent(event, target, options));
|
|
2066
|
+
myElement.on("mouseleave", (event) => this.mouseEvent(event, target, options));
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
mouseEvent(event, target, options) {
|
|
2070
|
+
const myEle = b(event.currentTarget),
|
|
2071
|
+
evType = event.type,
|
|
2072
|
+
myHoverElem = myEle.find("div"),
|
|
2073
|
+
direction = target.getDir(myEle, { x: event.pageX, y: event.pageY }),
|
|
2074
|
+
hoverClasses = target.getClasses(direction, options);
|
|
2075
|
+
myHoverElem.removeClass();
|
|
2076
|
+
if (evType === "mouseenter") {
|
|
2077
|
+
setTimeout(() => {
|
|
2078
|
+
myHoverElem.css('display', 'none').addClass(hoverClasses.from);
|
|
2079
|
+
myHoverElem.show(15, (e) => {
|
|
2080
|
+
b(e).addClass(hoverClasses.to);
|
|
2081
|
+
})
|
|
2082
|
+
}, 15);
|
|
2083
|
+
} else {
|
|
2084
|
+
myHoverElem.addClass(hoverClasses.from);
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
getDir(myEle, coordinates) {
|
|
2089
|
+
const w = myEle.width(),
|
|
2090
|
+
h = myEle.height(),
|
|
2091
|
+
x = (coordinates.x - myEle.offset().left - (w / 2)) * (w > h ? (h / w) : 1),
|
|
2092
|
+
y = (coordinates.y - myEle.offset().top - (h / 2)) * (h > w ? (w / h) : 1);
|
|
2093
|
+
return Math.round((((Math.atan2(y, x) * (180 / Math.PI)) + 180) / 90) + 3) % 4;
|
|
2094
|
+
}
|
|
2095
|
+
|
|
2096
|
+
getClasses(direction, options) {
|
|
2097
|
+
let fromClass, toClass;
|
|
2098
|
+
switch (direction) {
|
|
2099
|
+
case 0: (!options.reverse) ? fromClass = "ce-slideFromTop" : fromClass = "ce-slideFromBottom"; toClass = "ce-slideTop"; break;
|
|
2100
|
+
case 1: (!options.reverse) ? fromClass = "ce-slideFromRight" : fromClass = "ce-slideFromLeft"; toClass = "ce-slideLeft"; break;
|
|
2101
|
+
case 2: (!options.reverse) ? fromClass = "ce-slideFromBottom" : fromClass = "ce-slideFromTop"; toClass = "ce-slideTop"; break;
|
|
2102
|
+
case 3: (!options.reverse) ? fromClass = "ce-slideFromLeft" : fromClass = "ce-slideFromRight"; toClass = "ce-slideLeft"; break;
|
|
2103
|
+
}
|
|
2104
|
+
return {from: fromClass, to: toClass };
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
|
|
2108
|
+
|
|
2109
|
+
|
|
2110
|
+
export { b };
|
|
2111
|
+
export default b;
|