arisu.js 1.0.0 → 1.0.3

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.
@@ -0,0 +1,467 @@
1
+ /******
2
+ * @描述:可export方法封装,vue可使用
3
+ * @作者:林舒涛
4
+
5
+ <script src="//arisu.cn/file/web/export-method.js" type="module"></script>
6
+ 外部JS调用
7
+ <script type="module">
8
+ 如果报错Uncaught SyntaxError: Cannot use import statement outside a module
9
+ 调用和引入如果的外部JS文件都设置为type="module"
10
+ 如果在html里面写JS也需要把type改成module
11
+
12
+ 只使用默认方法
13
+ import vm from "./WEB/js/i/export-method.js";
14
+ vm();//执行default默认方法
15
+
16
+ 调用默认方法和其中一个方法
17
+ import vm, {vueList as vl, name} from "./WEB/js/i/export-method.js";
18
+ vm("default");//默认方法
19
+ vl("vueList");//vueList重命名后的方法
20
+ console.log(name);//属性name的值
21
+ // console.log(a);//a没有导入报错
22
+ </script>
23
+
24
+ export var a = 1;
25
+ export var name = "arisu";
26
+ export function vueList(str) {
27
+ console.log(str);
28
+ }
29
+ export default function(str) {
30
+ console.log(str);
31
+ }
32
+ * **/
33
+
34
+ export default function() {
35
+ // todo
36
+ }
37
+
38
+
39
+ /* ========================================================================
40
+ * 1. 元素显示切换,由utils.js中ISwitch改造而来,充当改造范例
41
+ * 2020年6月24日11:19:09
42
+ * ========================================================================
43
+
44
+ <div class="ce-switch ce-switch-1 current">11111</div>
45
+ <div class="ce-switch ce-switch-1 current">22222</div>
46
+ <div class="ce-switch ce-switch-1 ce-switch-2 current">3333</div>
47
+ <div class="ce-switch ce-switch-2">44444</div>
48
+
49
+ <button class="iswitch" data-show="ce-switch-1">a</button>
50
+ <button class="iswitch" data-show="ce-switch-2">b</button>
51
+
52
+ let vl = new VueSwitch(".iswitch", {module: ".ce-switch2"});
53
+
54
+ * ======================================================================== */
55
+ export class VueSwitch {
56
+ //构造方法
57
+ constructor(element, options) {
58
+ this.$element = $(element);
59
+ this.options = $.extend({}, this.DEFAULTS, options);
60
+
61
+ this.init(this.options)
62
+ };
63
+
64
+ //默认参数
65
+ DEFAULTS = {
66
+ module: ".ce-switch"
67
+ };
68
+
69
+ //初始化方法
70
+ init = function (options) {
71
+ var $element = this.$element;
72
+
73
+ if ($element.is("select")) {
74
+ $element.change(function() {
75
+ $(options.module).removeClass("current");
76
+
77
+ var className = $element.find("option:selected").data("show");
78
+ $("." + className).addClass("current").removeClass("hide");;
79
+ });
80
+ } else if($element.is("a") || $element.is("button")) {
81
+ $element.click(function() {
82
+ var className = $(this).data("show");
83
+ $(options.module).removeClass("current").addClass("hide");
84
+ $("." + className).addClass("current").removeClass("hide");
85
+ });
86
+ }
87
+
88
+ };
89
+
90
+ vueSwitch = function (option) {
91
+ return this.each(function () {
92
+ var $this = $(this);
93
+ var data = $this.data("be.vueswitch");
94
+
95
+ options = $.extend({}, VueSwitch.DEFAULTS, $this.data(), typeof option == "object" && option);
96
+ if (!data)
97
+ $this.data("be.vueswitch", (data = new VueSwitch(this, options)));
98
+ else
99
+ data["init"]();
100
+ });
101
+ };
102
+ }
103
+
104
+ /* ========================================================================
105
+ * 2. 列表查询分页封装方法 - 使用VUEJS
106
+ * @参数:
107
+ * element: 列表ID
108
+ * vue: vue对象
109
+ * options: 查询参数对象 {..}
110
+ * 2020年6月25日15:20:43
111
+ * ========================================================================
112
+
113
+ import {VueList} from "./WEB/js/i/vue-method.js";
114
+
115
+ $(function() {
116
+ new VueList("#news-list", this, {
117
+ url: "//arisu.cn/springmvc/news/findNews.action",
118
+ param: {type: 0},
119
+ sortname: "a.id",
120
+ rp: 2,
121
+ visiblePages: 5,
122
+ onSuccess: function(data) {
123
+ if (fun)
124
+ fun(data);
125
+ },
126
+ onError: base.error
127
+ });
128
+ })
129
+
130
+ * ======================================================================== */
131
+ export class VueList {
132
+ // 构造函数
133
+ constructor(element, vue, options) {
134
+ this.$element = $(element);
135
+ this.options = $.extend({}, this.DEFAULTS, options);
136
+
137
+ this.init(element, vue, this.options);
138
+ };
139
+
140
+ // 默认值
141
+ DEFAULTS = {
142
+ rp: "10",
143
+ visiblePages: 7,
144
+ sortname: "id",
145
+ sortorder: "desc",
146
+ method: "post",
147
+ param: {},
148
+ url: "",
149
+ onSuccess: false,
150
+ onError: false
151
+ };
152
+
153
+ init = function (element, vue, options) {
154
+ var $element = this.$element;
155
+ var target = this;
156
+ // $element.data("be.vuelist.flag", true); //改造后值出不来
157
+ $element.attr("data-flag", 1); //翻页标识,1需要执行翻页插件生成翻页,null则不需要
158
+
159
+ // vue使用$.ajax({请求过程一段时间页面刷新canvas不显示,直接使用图片省事
160
+ // target.loadEffect();
161
+ // 直接使用图片
162
+ $(".ce-loading-vue", element).removeClass("hidden");
163
+ $(".ce-items", element).addClass("hidden");
164
+
165
+ var param = $.extend({}, {page: 1, rp: options.rp, sortname: options.sortname, sortorder: options.sortorder}, options.param);
166
+ options.isPage = false;
167
+ target.getData(element, vue, options, param);
168
+ };
169
+
170
+
171
+ loadEffect = function() {
172
+ var $element = this.$element;
173
+ var id = $element.attr("id") + "-load";//生成载入动画元素ID
174
+ $(".ce-loading-canvas", $element).attr("id", id);
175
+ // $(".ce-loading-canvas", $element).html("")
176
+ //
177
+ // var temp = document.getElementsByClassName("canvas");
178
+ // while(temp.length - 1 >= 0) {
179
+ // temp[0].remove();
180
+ // }
181
+
182
+ var cl = new CanvasLoader(id);
183
+ cl.setColor("#0a0a0a");
184
+ cl.setShape("roundRect");
185
+ cl.setDensity(11);
186
+ cl.setRange(0.8);
187
+ cl.setSpeed(1);
188
+ cl.setFPS(10);
189
+ cl.show();
190
+ };
191
+
192
+ getData = function (element, vue, options, param) {
193
+ var target = this;
194
+ var $element = this.$element;
195
+ if (!base)
196
+ var base = new Base();
197
+
198
+ $(".ce-items", element).addClass("hidden");
199
+ $(".ce-loading-vue", element).removeClass("hidden");
200
+
201
+
202
+ if ($(".ilist-check-all[data-flag='1']", element).is(":checked"))
203
+ $(".ilist-check-all[data-flag='1']", element).click();
204
+
205
+ $.ajax({
206
+ type: options.method,
207
+ url: options.url,
208
+ data: param,
209
+ cache: false,
210
+ dataType: "json",
211
+ success: function (data) {
212
+ $(".ce-loading-vue", element).addClass("hidden");
213
+ $(".ce-items", element).removeClass("hidden");
214
+
215
+ data.isPage = options.isPage;
216
+ if (options.isPage)
217
+ $(".ce-items-body", element).css("display", "table-row-group");
218
+ else
219
+ $(".ce-items", element).removeClass("hidden");
220
+
221
+ if (options.onSuccess) {
222
+ vue.message = data.message;
223
+ vue.result = data.result;
224
+ vue.rows = data.rows;
225
+ vue.total = data.total;
226
+ options.onSuccess(data);
227
+ }
228
+
229
+ if (data.total) {
230
+ var pageType = $(".ce-list-page").data("type");
231
+ if (pageType == 2)
232
+ target.preNextPage(element, options, param, data.total);//上下两页页翻页
233
+ else
234
+ target.page(element, vue, options, param, data.total);//多页翻页
235
+
236
+ if (param.page == 1)
237
+ $(".ce-list-page .previous").addClass("disabled");
238
+ if (param.page == Math.ceil(data.total / options.rp))
239
+ $(".ce-list-page .next").addClass("disabled");
240
+
241
+
242
+ //全选/全清
243
+ $(".ilist-check-all[data-flag='1']", element).checkAll({targets: ".ilist-check"});
244
+
245
+
246
+ //选择单列/取消选择单列
247
+ base.runInExist((".ilist-check", element), 10, function(e) {
248
+ $("tr", element).removeClass("active");
249
+ if ($(".ilist-check", element).is(":checked")) {
250
+ $(".ilist-check", element).removeAttr("checked");
251
+ }
252
+ $(".ilist-check", element).unbind("change");
253
+ $(".ilist-check", element).change(function() {
254
+ var isChecked = $(this).is(":checked");
255
+ if (isChecked)
256
+ $(this).parents("tr").addClass("active");
257
+ else
258
+ $(this).parents("tr").removeClass("active");
259
+ });
260
+ });
261
+
262
+ //全选列/全清列
263
+ base.runInExist((".ilist-check-all[data-flag='1']", element), 10, function(e) {
264
+ $(".ilist-check-all[data-flag='1']", element).unbind("change");
265
+ $(".ilist-check-all[data-flag='1']", element).change(function() {
266
+ var isChecked = $(this).is(":checked");
267
+ if (isChecked)
268
+ $(".ilist-check").addClass("active").change();
269
+ else
270
+ $(".ilist-check").removeClass("active").change();
271
+ });
272
+ });
273
+
274
+ //点击列选择单列/点击列取消选择单列
275
+ base.runInExist(("table > tbody tr", element), 10, function(e) {
276
+ $("table > tbody tr", element).unbind("click");
277
+ $("table > tbody tr", element).click(function(e) {
278
+ var target = $(e.target);
279
+ if (!(target.is("input") || target.is("i") || target.is("a"))) {
280
+ $(".ilist-check", this).click();
281
+ }
282
+ })
283
+ });
284
+
285
+
286
+ //排序
287
+ base.runInExist(("table > thead tr td", element), 10, function(e) {
288
+ $("table > thead tr td", element).unbind("click");
289
+ $("table > thead tr td", element).click(function(e) {
290
+ param.sortname = $(this).data("sortname");
291
+
292
+ if (!$(this).hasClass("is-check") && param.sortname) {
293
+ var sortorder = $(this).attr("data-sort-order");
294
+
295
+ $("table > thead tr td", element).removeAttr("data-sort-order");
296
+
297
+ if (sortorder) {
298
+ if (sortorder == "asc") {
299
+ $(this).attr("data-sort-order", "desc");
300
+ sortorder = "desc";
301
+ } else {
302
+ $(this).attr("data-sort-order", "asc");
303
+ sortorder = "asc";
304
+ }
305
+ param.sortorder = sortorder;
306
+ } else {
307
+ $(this).attr("data-sort-order", "asc");
308
+ param.sortorder = "asc";
309
+ }
310
+
311
+ $element.attr("data-flag", 1);
312
+ options.isPage = true;
313
+ param.page = "1";
314
+ target.getData(element, vue, options, param);
315
+ } else {
316
+ $(this).css("cursor", "auto ! important");
317
+ }
318
+ });
319
+ });
320
+ } else {
321
+ $(".ce-nofound-vue", element).removeClass("hidden");
322
+ }
323
+
324
+ },
325
+ error: function (XMLHttpRequest, textStatus, errorThrown) {
326
+ try {
327
+ debug(XMLHttpRequest);
328
+ debug(textStatus);
329
+ debug(errorThrowns);
330
+ if (options.onError) options.onError(XMLHttpRequest, textStatus, errorThrown);
331
+ } catch (e) {
332
+ }
333
+ }
334
+ });
335
+ }
336
+
337
+
338
+ /** 分页查询 **/
339
+ page = function (element, vue, options, param, total) {
340
+ var rp = options.rp;
341
+ if (options.rp == 0)
342
+ rp = total;
343
+ var totalPages = Math.ceil(total / rp);
344
+ var target = this;
345
+ var $element = $(element);
346
+
347
+ var end = ((param.page - 1) * rp + rp);
348
+ if (end > total)
349
+ end = total;
350
+
351
+ var html = "显示 " + ((param.page - 1) * rp + 1) + " 至 " + end + " 条,共有 " + total + " 条";
352
+ // if ($element.data("be.vuelist.flag")) { //改造后值出不来
353
+ if ($element.attr("data-flag")) {
354
+ $(".pagination", element).parent().html("<span>" + html + "</span><ul class='pagination pagination-sm'></ul>");
355
+ $(".pagination", element).twbsPagination({
356
+ totalPages: totalPages,
357
+ visiblePages: options.visiblePages,
358
+ first: "首页",
359
+ prev: "上一页",
360
+ next: "下一页",
361
+ last: "尾页",
362
+ onPageClick: function(event, page) {
363
+ param.page = page;
364
+ var end = ((param.page - 1) * rp + rp);
365
+ if (end > total)
366
+ end = total;
367
+ var html = "显示 " + ((param.page - 1) * rp + 1) + " 至 " + end + " 条,共有 " + total + " 条";
368
+ $(".ce-list-page > span", element).html(html);
369
+
370
+ options.isPage = true;
371
+
372
+ target.getData(element, vue, options, param);
373
+ }
374
+ });
375
+ }
376
+ $element.attr("data-flag", null);
377
+ }
378
+
379
+ /** 上下两页分页查询,待改 **/
380
+ preNextPage = function (element, options, param, total) {
381
+ var rp = options.rp;
382
+ if (options.rp == 0)
383
+ rp = total;
384
+ var totalPages = Math.ceil(total / rp);
385
+ var target = this;
386
+ var $element = $(element);
387
+
388
+ var end = ((param.page - 1) * rp + rp);
389
+ if (end > total)
390
+ end = total;
391
+
392
+
393
+ $(document).off("click.clpp").on("click.clpp", ".ce-list-page .previous:not(.disabled)", function(e) {
394
+ param.page = param.page - 1;
395
+ $(".ce-list-page .next").removeClass("disabled");
396
+
397
+ if (param.page == 1) {
398
+ $(this).addClass("disabled");
399
+ }
400
+
401
+ options.isPage = true;
402
+ target.getData(element, options, param);
403
+ });
404
+ $(document).off("click.clpn").on("click.clpn", ".ce-list-page .next:not(.disabled)", function(e) {
405
+ param.page = param.page + 1;
406
+ $(".ce-list-page .previous").removeClass("disabled");
407
+
408
+ if (param.page == totalPages) {
409
+ $(this).addClass("disabled");
410
+ }
411
+ options.isPage = true;
412
+ target.getData(element, options, param);
413
+ });
414
+
415
+ $element.attr("data-flag", null);
416
+ }
417
+
418
+ /** 参数追加搜索 **/
419
+ vueListReload = function (param) {
420
+ var $this = $(this);
421
+ var data = $this.data("be.vuelist");
422
+
423
+ for (var pa in param) {
424
+ if (typeof param[pa] == "string" && param[pa].trim() == "") {
425
+ data.options.param[pa] = undefined;
426
+ param[pa] = undefined;
427
+ }
428
+ }
429
+
430
+ // var p = $.extend({}, data.options.param, param);
431
+ // data.options.param = p;
432
+
433
+ data.options.param = param;
434
+ data["init"](this, data.options);
435
+ // $this.data("be.vuelist", (data = new IList(this, data.options)));
436
+ };
437
+
438
+ vueList = function (option) {
439
+ return this.each(function () {
440
+ var $this = $(this);
441
+ var data = $this.data("be.vuelist");
442
+
443
+ options = $.extend({}, VueList.DEFAULTS, $this.data(), typeof option == "object" && option);
444
+ if (!data)
445
+ $this.data("be.vuelist", (data = new VueList(this, options)));
446
+ else
447
+ data["init"](this, options);
448
+ });
449
+ };
450
+ }
451
+
452
+
453
+
454
+
455
+
456
+
457
+
458
+
459
+
460
+
461
+
462
+
463
+
464
+
465
+
466
+
467
+