ss
重庆迈尖科技有限公司
2020-06-16 b67f2c4fce992a818f287783ae7029a0b03509d3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/     // The module cache
/******/     var installedModules = {};
/******/
/******/     // The require function
/******/     function __webpack_require__(moduleId) {
/******/
/******/         // Check if module is in cache
/******/         if(installedModules[moduleId]) {
/******/             return installedModules[moduleId].exports;
/******/         }
/******/         // Create a new module (and put it into the cache)
/******/         var module = installedModules[moduleId] = {
/******/             i: moduleId,
/******/             l: false,
/******/             exports: {}
/******/         };
/******/
/******/         // Execute the module function
/******/         modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/         // Flag the module as loaded
/******/         module.l = true;
/******/
/******/         // Return the exports of the module
/******/         return module.exports;
/******/     }
/******/
/******/
/******/     // expose the modules object (__webpack_modules__)
/******/     __webpack_require__.m = modules;
/******/
/******/     // expose the module cache
/******/     __webpack_require__.c = installedModules;
/******/
/******/     // identity function for calling harmony imports with the correct context
/******/     __webpack_require__.i = function(value) { return value; };
/******/
/******/     // define getter function for harmony exports
/******/     __webpack_require__.d = function(exports, name, getter) {
/******/         if(!__webpack_require__.o(exports, name)) {
/******/             Object.defineProperty(exports, name, {
/******/                 configurable: false,
/******/                 enumerable: true,
/******/                 get: getter
/******/             });
/******/         }
/******/     };
/******/
/******/     // getDefaultExport function for compatibility with non-harmony modules
/******/     __webpack_require__.n = function(module) {
/******/         var getter = module && module.__esModule ?
/******/             function getDefault() { return module['default']; } :
/******/             function getModuleExports() { return module; };
/******/         __webpack_require__.d(getter, 'a', getter);
/******/         return getter;
/******/     };
/******/
/******/     // Object.prototype.hasOwnProperty.call
/******/     __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/     // __webpack_public_path__
/******/     __webpack_require__.p = "/";
/******/
/******/     // Load entry module and return exports
/******/     return __webpack_require__(__webpack_require__.s = 6);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {
 
// this module is a runtime utility for cleaner component module output and will
// be included in the final webpack user bundle
 
module.exports = function normalizeComponent (
  rawScriptExports,
  compiledTemplate,
  scopeId,
  cssModules
) {
  var esModule
  var scriptExports = rawScriptExports = rawScriptExports || {}
 
  // ES6 modules interop
  var type = typeof rawScriptExports.default
  if (type === 'object' || type === 'function') {
    esModule = rawScriptExports
    scriptExports = rawScriptExports.default
  }
 
  // Vue.extend constructor export interop
  var options = typeof scriptExports === 'function'
    ? scriptExports.options
    : scriptExports
 
  // render functions
  if (compiledTemplate) {
    options.render = compiledTemplate.render
    options.staticRenderFns = compiledTemplate.staticRenderFns
  }
 
  // scopedId
  if (scopeId) {
    options._scopeId = scopeId
  }
 
  // inject cssModules
  if (cssModules) {
    var computed = Object.create(options.computed || null)
    Object.keys(cssModules).forEach(function (key) {
      var module = cssModules[key]
      computed[key] = function () { return module }
    })
    options.computed = computed
  }
 
  return {
    esModule: esModule,
    exports: scriptExports,
    options: options
  }
}
 
 
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
 
 
/* styles */
__webpack_require__(8)
 
var Component = __webpack_require__(0)(
  /* script */
  __webpack_require__(4),
  /* template */
  __webpack_require__(10),
  /* scopeId */
  null,
  /* cssModules */
  null
)
 
module.exports = Component.exports
 
 
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
 
 
/* styles */
__webpack_require__(7)
 
var Component = __webpack_require__(0)(
  /* script */
  __webpack_require__(5),
  /* template */
  __webpack_require__(9),
  /* scopeId */
  null,
  /* cssModules */
  null
)
 
module.exports = Component.exports
 
 
/***/ }),
/* 3 */
/***/ (function(module, exports) {
 
module.exports = require("vue");
 
/***/ }),
/* 4 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
 
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
 
/* harmony default export */ __webpack_exports__["default"] = ({
    name: 'wcSlide',
    methods: {
        clickHandler: function clickHandler() {
            this.$emit('click');
        }
    }
});
 
/***/ }),
/* 5 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
 
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
 
function toArray(arraylike) {
    return Array.prototype.slice.call(arraylike);
}
/* harmony default export */ __webpack_exports__["default"] = ({
    name: 'wcSwiper',
    props: {
        /*一次滑动的默认时间*/
        duration: {
            default: 500
        },
        /*两次滑动的间隔时间*/
        interval: {
            default: 2500
        },
        /*是否自动播放*/
        autoplay: {
            default: true
        },
        /*用户滑动多少距离, 翻页*/
        therehold: {
            default: 110
        },
        defaultSlide: {
            default: 0
        },
        pagination: {
            default: true
        },
        /* 有时候全屏滚动, 的确想要禁用垂直方向的滚动的时候 */
        vLock: {
            default: false
        }
    },
    data: function data() {
        return {
            swiper: null,
            swiperWidth: 0,
            slides: null,
            slidesNumber: 0,
            reallySlidesNumber: 0,
            currentSlide: 0,
            timer: null,
            userDuration: 200,
            pos: {
                startX: 0,
                moveX: 0,
                endX: 0,
                local: 0,
                distance: 0
            },
            moving: false,
            unlock: false,
            activeId: '',
            mousedown: false,
            box: '',
            isOnly: false
        };
    },
    mounted: function mounted() {
        var _this = this;
 
        this.box = 'wc-swiper-box-' + Math.random().toFixed(2) * 1000;
        setTimeout(function () {
            /*初始化的时候, 拿到所有的 DOM 元素以及相关属性*/
            _this.initElement();
 
            if (_this.isOnly) {
                return;
            }
            /*克隆两个节点, 用来实现 loop 效果*/
            _this.cloneSlide();
            /*克隆结束之后, 需要设置默认显示的slide*/
            _this.setDefaultSlide();
            /*
       ## start
       设置默认slide之后, 就需要开始设置定时器, 自动轮播
   */
            if (_this.autoplay) {
                _this.play();
            }
        }, 100);
    },
 
    methods: {
        /*阻止容器的上下滚动, 并且只有在水平方向上面滚动超过 10px 才可以阻止 */
        fn: function fn(e) {
            if (this.vLock || Math.abs(this.pos.startX - this.pos.moveX) > 10) {
                e.preventDefault();
            }
        },
 
        /*滑动到指定的页面*/
        slideTo: function slideTo(index) {
            if (!this.moving) {
                var currentSlide = Math.round(Math.abs(this.left()) / this.swiperWidth);
                /* 如果索引值不合法 或者和目前的值相等 */
                if (index > this.slidesNumber - 2 - 1 || index < 0 || currentSlide == index + 1) {
                    return;
                }
                this.moving = true;
                clearTimeout(this.timer);
                /*
        说明要往右边滑动
        注意这里不管需要滑动多少个, duration 都是 300, 这个如果需要, 可以
        自己根据起点/终点计算出一个合适的值. 
    */
                this.transitionDuration(300);
 
                this.translateX(-this.swiperWidth * (index + 1));
            }
        },
        next: function next() {
            if (!this.moving) {
                clearTimeout(this.timer);
                this.moving = true;
                this.transitionDuration(this.userDuration);
                this.translateX(this.left() - this.swiperWidth);
            }
        },
        previous: function previous() {
            if (!this.moving) {
                clearTimeout(this.timer);
                this.moving = true;
                this.transitionDuration(this.userDuration);
                this.translateX(this.left() + this.swiperWidth);
            }
        },
        initElement: function initElement() {
            /* 因为传递过来的是个字符串, 所以要手动加点 */
            this.swiper = document.querySelector('.' + this.box);
            this.swiperWidth = this.swiper.clientWidth;
            this.slides = toArray(this.swiper.children);
            this.slidesNumber = this.slides.length;
            /*实际的 slide 个数, 因为 slidesNumber 会在后面重新赋值*/
            this.reallySlidesNumber = this.slides.length;
 
            /* 如果就仅仅只有一个 slide, 那么不克隆, 不绑定, 就纯展示就可以了 */
 
            if (this.reallySlidesNumber === 1) {
                this.isOnly = true;
            }
        },
        cloneSlide: function cloneSlide() {
            var head = this.slides[0].cloneNode(this.slides[0], true);
            var tail = this.slides[this.slidesNumber - 1].cloneNode(this.slides[this.slidesNumber - 1], true);
            this.swiper.appendChild(head);
            this.swiper.insertBefore(tail, this.slides[0]);
            /*克隆节点之后, 需要重置一些属性*/
            this.slides = toArray(this.swiper.children);
            this.slidesNumber = this.slides.length;
        },
 
        /* 根据用户给定的 defaultSlide 设置 init slide 的值 */
        setDefaultSlide: function setDefaultSlide() {
 
            /* 
           一切用户给定的值, 都是从 0 - x 开始, 比如用户数据里面有 6个数据
       那么给定的就是 0 - 5
       但是我们内部运算的时候, 实际上我们的索引能到 0 - 7
       0 是实际的 5 的拷贝, 7 实际上是实际的0的拷贝
       
       所以当用户给定的 defaultSlide =0, 我们实际上是要让展示内部索引为 1 的元素
       */
 
            /* 如果用户设置了一个非法值, 直接抛出异常*/
            if (this.defaultSlide < 0 || this.defaultSlide > this.slidesNumber - 2 - 1) {
                throw new Error('[wc-swiper:Error]: You have set a wrong defaultSlide value with defaultSlide = ' + this.defaultSlide);
            }
            this.translateX(-this.swiperWidth * (this.defaultSlide + 1));
            //
            // this.currentSlide = this.defaultSlide;
        },
 
        /*
      ## start
  */
        play: function play() {
            var _this2 = this;
 
            this.timer = setTimeout(function () {
                clearTimeout(_this2.timer);
                _this2.moving = true;
                _this2.unlock = false;
                _this2.transitionDuration(_this2.duration);
                _this2.translateX(-(_this2.swiperWidth + Math.abs(_this2.left())));
            }, this.interval);
        },
        transitionend: function transitionend() {
            this.transitionDuration(0);
 
            /*
       一次滑动结束之后, 通过计算, 实际上我们可以拿到当前处于内部索引的第几个 slide
       拿到这个 currentSlide 我们就知道当前是不是滚动到最后一个了
   */
            var currentSlide = Math.round(Math.abs(this.left()) / this.swiperWidth);
 
            this.currentSlide = currentSlide - 1;
            /* 如果滚动到最后一个, 那么就要瞬间跳转一下, 到外部看起来的第一个, 内部的*/
            if (currentSlide == this.slidesNumber - 1) {
 
                this.translateX(-this.swiperWidth);
                this.currentSlide = 0;
            }
            if (currentSlide == 0) {
                this.translateX(-this.swiperWidth * (this.slidesNumber - 2));
                this.currentSlide = this.slidesNumber - 3;
            }
 
            this.$emit('transitionend', this.currentSlide);
            /*
       防止极限操作, 用户在滑动结束之后事件还没发送出去又滑动导致计算
       结果错误, 所以等事件发出去之后再解开 
   */
            this.moving = false;
            /*
       ##start
   */
            if (this.autoplay) {
                this.play();
            }
        },
 
        /*toushstart handler*/
        s: function s(e) {
            if (this.isOnly) {
                return;
            }
 
            if (e.type === 'mousedown' && !this.moving) {
                this.mousedown = true;
                this.pos.startX = e.pageX;
                this.pos.local = this.left();
                clearTimeout(this.timer);
                this.transitionDuration(0);
            } else {
                this.activeId = toArray(e.changedTouches)[0].identifier;
                if (!this.moving) {
                    var active = e.touches.length - 1;
                    clearTimeout(this.timer);
                    this.transitionDuration(0);
                    this.unlock = true;
                    this.pos.startX = e.touches[active].clientX;
                    /* 一次 touch 的 起始local 点, 是固定的 */
                    this.pos.local = this.left();
                }
            }
        },
 
        /*toushmove handler*/
        m: function m(e) {
 
            if (this.isOnly) {
                return;
            }
 
            if (e.type === 'mousemove' && this.mousedown && !this.moving) {
                this.pos.moveX = e.pageX;
                this.pos.distance = this.pos.moveX - this.pos.startX;
                this.translateX(this.pos.local + this.pos.distance);
            } else {
                if (!this.moving && this.unlock) {
                    var active = e.touches.length - 1;
                    this.pos.moveX = e.touches[active].clientX;
                    this.pos.distance = this.pos.moveX - this.pos.startX;
                    this.translateX(this.pos.local + this.pos.distance);
                }
            }
        },
 
        /*toushend handler*/
        e: function e(_e) {
 
            if (this.isOnly) {
                return;
            }
 
            if (_e.type === 'mouseup' && this.mousedown && !this.moving) {
                this.mousedown = false;
                this.pos.endX = _e.pageX;
                this.pos.distance = this.pos.endX - this.pos.startX;
                this.recover();
            } else {
                var curId = toArray(_e.changedTouches)[0].identifier;
                if (!this.moving && this.unlock && curId == this.activeId) {
                    this.unlock = false;
                    this.pos.endX = _e.changedTouches[0].clientX;
                    this.pos.distance = this.pos.endX - this.pos.startX;
                    this.recover();
                }
            }
        },
 
        /*响应用户滚动行为*/
        recover: function recover() {
            this.transitionDuration(this.userDuration);
            var distance = Math.abs(this.left()) % this.swiperWidth;
            var point = [];
            var direction = '';
            /*
       主要是为了拿到当前状态下面, swiper 距离正常状态的, 左右移动的距离分别是多少. 
   */
            if (this.left() > 0) {
                point = [distance, this.swiperWidth - distance];
            } else {
                point = [this.swiperWidth - distance, distance];
            }
            if (this.pos.distance > 0) {
                direction = 'to-right';
            } else if (this.pos.distance < 0) {
                direction = 'to-left';
            } else {
                direction = 'none';
            }
            if (direction == 'none') {
                if (this.autoplay) {
                    this.play();
                }
            }
            if (direction === 'to-right') {
                this.moving = true;
                /*说明需要向右边移动*/
                if (point[0] > this.therehold) {
                    this.translateX(this.left() + point[1]);
                    var next = (this.left() + point[1]) / this.swiperWidth;
                    if (Math.abs(next) === 0) {
                        this.unlock = false;
                    }
                } else {
                    this.translateX(this.left() - point[0]);
                }
            }
            if (direction === 'to-left') {
                this.moving = true;
                if (point[1] > this.therehold) {
                    this.translateX(this.left() - point[0]);
                    var _next = (this.left() - point[0]) / this.swiperWidth;
                    if (Math.abs(_next) === this.slidesNumber - 1) {
                        this.unlock = false;
                    }
                } else {
                    this.translateX(this.left() + point[1]);
                }
            }
        },
        translateX: function translateX(value) {
            this.swiper.style.transform = 'translate3d(' + value + 'px, 0, 0)';
        },
        transitionDuration: function transitionDuration(ms) {
            this.swiper.style.transitionDuration = ms + 'ms';
        },
        left: function left() {
            return this.swiper.getBoundingClientRect().left;
        }
    }
});
 
/***/ }),
/* 6 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
 
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_vue__ = __webpack_require__(3);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_vue__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__wcSwiper__ = __webpack_require__(2);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__wcSwiper___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1__wcSwiper__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__wcSlide__ = __webpack_require__(1);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__wcSlide___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2__wcSlide__);
 
 
 
 
/* harmony default export */ __webpack_exports__["default"] = ({
    install: function install(Vue) {
        Vue.component('wcSwiper', Vue.extend(__WEBPACK_IMPORTED_MODULE_1__wcSwiper___default.a));
        Vue.component('wcSlide', Vue.extend(__WEBPACK_IMPORTED_MODULE_2__wcSlide___default.a));
    }
});
 
/***/ }),
/* 7 */
/***/ (function(module, exports) {
 
// removed by extract-text-webpack-plugin
 
/***/ }),
/* 8 */
/***/ (function(module, exports) {
 
// removed by extract-text-webpack-plugin
 
/***/ }),
/* 9 */
/***/ (function(module, exports) {
 
module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;
  return _c('div', {
    staticClass: "wc-swiper-container",
    on: {
      "touchmove": _vm.fn
    }
  }, [_c('div', {
    staticClass: "wc-default-swiper-box",
    class: _vm.box,
    on: {
      "transitionend": _vm.transitionend,
      "touchstart": _vm.s,
      "touchmove": _vm.m,
      "touchend": _vm.e,
      "mousedown": _vm.s,
      "mousemove": _vm.m,
      "mouseup": _vm.e
    }
  }, [_vm._t("default")], 2), _vm._v(" "), _vm._t("pagination", [(_vm.pagination) ? _c('div', {
    staticClass: "wc-pagination"
  }, _vm._l((_vm.reallySlidesNumber), function(value, key) {
    return _c('div', {
      key: key,
      staticClass: "wc-dot",
      class: {
        'wc-dot-active': _vm.currentSlide == key
      }
    })
  })) : _vm._e()]), _vm._v(" "), _vm._t("arrowLeft"), _vm._v(" "), _vm._t("arrowRight"), _vm._v(" "), _vm._t("g")], 2)
},staticRenderFns: []}
 
/***/ }),
/* 10 */
/***/ (function(module, exports) {
 
module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;
  return _c('div', {
    staticClass: "wc-slide",
    on: {
      "click": _vm.clickHandler
    }
  }, [_vm._t("default")], 2)
},staticRenderFns: []}
 
/***/ })
/******/ ]);