ai.touchui-vue 1.40.0 → 1.40.2

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/lib/slide.js CHANGED
@@ -199,7 +199,7 @@ function normalizeComponent(
199
199
  // ESM COMPAT FLAG
200
200
  __webpack_require__.r(__webpack_exports__);
201
201
 
202
- // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/slide/src/slide.vue?vue&type=template&id=020258e2
202
+ // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/slide/src/slide.vue?vue&type=template&id=0f2000b8
203
203
  var render = function () {
204
204
  var _vm = this
205
205
  var _h = _vm.$createElement
@@ -274,7 +274,7 @@ var staticRenderFns = []
274
274
  render._withStripped = true
275
275
 
276
276
 
277
- // CONCATENATED MODULE: ./packages/slide/src/slide.vue?vue&type=template&id=020258e2
277
+ // CONCATENATED MODULE: ./packages/slide/src/slide.vue?vue&type=template&id=0f2000b8
278
278
 
279
279
  // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/slide/src/slide.vue?vue&type=script&lang=js
280
280
  //
@@ -296,6 +296,31 @@ render._withStripped = true
296
296
  //
297
297
  //
298
298
 
299
+ function db(fn) {
300
+ var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 50;
301
+
302
+ // 通过闭包缓存一个定时器 id
303
+ var timer = null;
304
+ // 将 debounce 处理结果当作函数返回
305
+ // 触发事件回调时执行这个返回函数
306
+ return function () {
307
+ var _this = this;
308
+
309
+ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
310
+ args[_key] = arguments[_key];
311
+ }
312
+
313
+ // 如果已经设定过定时器就清空上一次的定时器
314
+ if (timer) clearTimeout(timer);
315
+ // 开始设定一个新的定时器,定时器结束后执行传入的函数 fn
316
+ timer = setTimeout(function () {
317
+ fn.apply(_this, args);
318
+
319
+ clearTimeout(timer);
320
+ timer = null;
321
+ }, wait);
322
+ };
323
+ }
299
324
  /* harmony default export */ var slidevue_type_script_lang_js = ({
300
325
  name: 'ToSlide',
301
326
  componentName: 'ToSlide',
@@ -334,91 +359,98 @@ render._withStripped = true
334
359
  }
335
360
  },
336
361
  mounted: function mounted() {
337
- var _this = this;
362
+ var _this2 = this;
338
363
 
339
- setTimeout(function () {
340
- _this.width = _this.$el.offsetWidth;
341
- _this.setLength();
342
- _this.$refs.lastFake.innerHTML = _this.$refs.ul.querySelector(':nth-child(2)').innerHTML;
343
- _this.$refs.firstFake.innerHTML = _this.$refs.ul.querySelector(':nth-child(' + (_this.length + 1) + ')').innerHTML;
344
- _this.play();
345
- window.addEventListener('resize', function () {
346
- _this.width = _this.$el.offsetWidth;
347
- });
364
+ this.setLength();
365
+ this.$refs.lastFake.innerHTML = this.$refs.ul.querySelector(':nth-child(2)').innerHTML;
366
+ this.$refs.firstFake.innerHTML = this.$refs.ul.querySelector(':nth-child(' + (this.length + 1) + ')').innerHTML;
367
+ this.play();
348
368
 
349
- // 初始化 MutationObserver
350
- var observer = new MutationObserver(function (mutations) {
351
- _this.setLength(); // 每次子节点变化时更新长度
352
- });
353
- observer.observe(_this.$refs.ul, {
354
- childList: true, // 监听子节点变化
355
- subtree: true // 监听所有后代节点
356
- });
357
- _this.observer = observer;
358
- }, 100);
369
+ window.addEventListener('resize', this.setWidth);
370
+
371
+ // 初始化 MutationObserver
372
+ var observer = new MutationObserver(function (mutations) {
373
+ _this2.setLength(); // 每次子节点变化时更新长度
374
+ });
375
+ observer.observe(this.$refs.ul, {
376
+ childList: true, // 监听子节点变化
377
+ subtree: true // 监听所有后代节点
378
+ });
379
+ this.observer = observer;
380
+
381
+ var mo = new MutationObserver(function (mutations) {
382
+ _this2.width = _this2.$el.offsetWidth;
383
+ });
384
+ mo.observe(document.documentElement, {
385
+ attributes: true,
386
+ attributeFilter: ['style']
387
+ });
359
388
  },
360
389
  beforeDestroy: function beforeDestroy() {
361
- var _this2 = this;
362
-
363
390
  if (this.observer) {
364
391
  this.observer.disconnect(); // 断开监听
365
392
  }
366
393
  clearInterval(this.playTimer); // 清理定时器
367
- window.removeEventListener('resize', function () {
368
- _this2.width = _this2.$el.offsetWidth;
369
- });
394
+ window.removeEventListener('resize', this.setWidth);
370
395
  },
371
396
 
372
397
  methods: {
373
- play: function play() {
398
+ setWidth: function setWidth() {
374
399
  var _this3 = this;
375
400
 
401
+ db(function () {
402
+ _this3.width = _this3.$el.offsetWidth;
403
+ }, 200)();
404
+ },
405
+ play: function play() {
406
+ var _this4 = this;
407
+
376
408
  if (!this.autoplay || this.length < 2) {
377
409
  return;
378
410
  }
379
411
  this.playTimer = setInterval(function () {
380
- _this3.next();
412
+ _this4.next();
381
413
  }, Number(this.speed));
382
414
  },
383
415
  pause: function pause() {
384
416
  clearInterval(this.playTimer);
385
417
  },
386
418
  setLength: function setLength() {
387
- var _this4 = this;
419
+ var _this5 = this;
388
420
 
389
421
  this.$nextTick(function () {
390
- if (_this4.$refs.ul) {
391
- _this4.length = _this4.$refs.ul.children.length - 2;
422
+ if (_this5.$refs.ul) {
423
+ _this5.length = _this5.$refs.ul.children.length - 2;
392
424
  }
393
425
  });
394
426
  },
395
427
  next: function next() {
396
- var _this5 = this;
428
+ var _this6 = this;
397
429
 
398
430
  if (this.animate) {
399
431
  this.current += 1;
400
432
  if (this.current === this.length) {
401
433
  setTimeout(function () {
402
- _this5.animate = false;
403
- _this5.current = 0;
434
+ _this6.animate = false;
435
+ _this6.current = 0;
404
436
  setTimeout(function () {
405
- _this5.animate = true;
437
+ _this6.animate = true;
406
438
  }, 300);
407
439
  }, 300);
408
440
  }
409
441
  }
410
442
  },
411
443
  prev: function prev() {
412
- var _this6 = this;
444
+ var _this7 = this;
413
445
 
414
446
  if (this.animate) {
415
447
  this.current -= 1;
416
448
  if (this.current === -1) {
417
449
  setTimeout(function () {
418
- _this6.animate = false;
419
- _this6.current = _this6.length - 1;
450
+ _this7.animate = false;
451
+ _this7.current = _this7.length - 1;
420
452
  setTimeout(function () {
421
- _this6.animate = true;
453
+ _this7.animate = true;
422
454
  }, 300);
423
455
  }, 300);
424
456
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai.touchui-vue",
3
- "version": "1.40.0",
3
+ "version": "1.40.2",
4
4
  "description": "TouchUI Component Library for Vue.js.",
5
5
  "main": "lib/ai.touchui-vue.common.js",
6
6
  "files": [
@@ -7,16 +7,33 @@
7
7
  <li ref="lastFake"></li>
8
8
  </ul>
9
9
  </div>
10
- <div v-if="length>1" class="fn">
10
+ <div v-if="length > 1" class="fn">
11
11
  <span class="prev" @click="prev()"></span>
12
12
  <span class="next" @click="next()"></span>
13
13
  </div>
14
- <div v-if="length>1" class="page">
15
- <span v-for="index of length" :key="index" :class="{ 'on': index === current + 1 }" @click="jumpTo(index-1)"></span>
14
+ <div v-if="length > 1" class="page">
15
+ <span v-for="index of length" :key="index" :class="{ 'on': index === current + 1 }" @click="jumpTo(index - 1)"></span>
16
16
  </div>
17
17
  </div>
18
18
  </template>
19
19
  <script>
20
+ function db(fn, wait = 50) {
21
+ // 通过闭包缓存一个定时器 id
22
+ let timer = null
23
+ // 将 debounce 处理结果当作函数返回
24
+ // 触发事件回调时执行这个返回函数
25
+ return function(...args) {
26
+ // 如果已经设定过定时器就清空上一次的定时器
27
+ if (timer) clearTimeout(timer)
28
+ // 开始设定一个新的定时器,定时器结束后执行传入的函数 fn
29
+ timer = setTimeout(() => {
30
+ fn.apply(this, args)
31
+
32
+ clearTimeout(timer)
33
+ timer = null
34
+ }, wait)
35
+ }
36
+ }
20
37
  export default {
21
38
  name: 'ToSlide',
22
39
  componentName: 'ToSlide',
@@ -54,38 +71,46 @@ export default {
54
71
  }
55
72
  },
56
73
  mounted() {
57
- setTimeout(() => {
58
- this.width = this.$el.offsetWidth
59
- this.setLength()
60
- this.$refs.lastFake.innerHTML = this.$refs.ul.querySelector(':nth-child(2)').innerHTML
61
- this.$refs.firstFake.innerHTML = this.$refs.ul.querySelector(`:nth-child(${this.length + 1})`).innerHTML
62
- this.play()
63
- window.addEventListener('resize', () => {
64
- this.width = this.$el.offsetWidth
65
- })
66
74
 
67
- // 初始化 MutationObserver
68
- const observer = new MutationObserver((mutations) => {
69
- this.setLength(); // 每次子节点变化时更新长度
70
- });
71
- observer.observe(this.$refs.ul, {
72
- childList: true, // 监听子节点变化
73
- subtree: true // 监听所有后代节点
74
- });
75
- this.observer = observer;
75
+ this.setLength()
76
+ this.$refs.lastFake.innerHTML = this.$refs.ul.querySelector(':nth-child(2)').innerHTML
77
+ this.$refs.firstFake.innerHTML = this.$refs.ul.querySelector(`:nth-child(${this.length + 1})`).innerHTML
78
+ this.play()
79
+
80
+ window.addEventListener('resize', this.setWidth)
81
+
82
+ // 初始化 MutationObserver
83
+ const observer = new MutationObserver((mutations) => {
84
+ this.setLength(); // 每次子节点变化时更新长度
85
+ });
86
+ observer.observe(this.$refs.ul, {
87
+ childList: true, // 监听子节点变化
88
+ subtree: true // 监听所有后代节点
89
+ });
90
+ this.observer = observer;
91
+
92
+ const mo = new MutationObserver((mutations) => {
93
+ this.width = this.$el.offsetWidth
94
+ });
95
+ mo.observe(document.documentElement, {
96
+ attributes: true,
97
+ attributeFilter: ['style']
98
+ });
76
99
 
77
- }, 100)
78
100
  },
79
101
  beforeDestroy() {
80
102
  if (this.observer) {
81
103
  this.observer.disconnect(); // 断开监听
82
104
  }
83
105
  clearInterval(this.playTimer); // 清理定时器
84
- window.removeEventListener('resize', () => {
85
- this.width = this.$el.offsetWidth;
86
- });
106
+ window.removeEventListener('resize', this.setWidth);
87
107
  },
88
108
  methods: {
109
+ setWidth() {
110
+ db(() => {
111
+ this.width = this.$el.offsetWidth
112
+ }, 200)()
113
+ },
89
114
  play() {
90
115
  if (!this.autoplay || this.length < 2) {
91
116
  return
package/src/index.js CHANGED
@@ -455,7 +455,7 @@ if (typeof window !== 'undefined' && window.Vue) {
455
455
  }
456
456
 
457
457
  export default {
458
- version: '1.40.0',
458
+ version: '1.40.2',
459
459
  locale: locale.use,
460
460
  i18n: locale.i18n,
461
461
  install,