@tuya-miniapp/smart-ui 2.10.0 → 2.10.1-beta-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.
@@ -14,10 +14,17 @@ SmartComponent({
14
14
  },
15
15
  methods: {
16
16
  scrollIntoView(scrollTop) {
17
- getRect(this, '.smart-index-anchor-wrapper').then(rect => {
18
- wx.pageScrollTo({
19
- duration: 0,
20
- scrollTop: scrollTop + rect.top - this.parent.data.stickyOffsetTop,
17
+ return new Promise((resolve, reject) => {
18
+ getRect(this, '.smart-index-anchor-wrapper').then(rect => {
19
+ wx.pageScrollTo({
20
+ duration: 0,
21
+ scrollTop: scrollTop + rect.top - this.parent.data.stickyOffsetTop,
22
+ complete: () => {
23
+ setTimeout(() => {
24
+ resolve('success');
25
+ }, 50);
26
+ },
27
+ });
21
28
  });
22
29
  });
23
30
  },
@@ -52,6 +52,8 @@ SmartComponent({
52
52
  activeAnchorIndex: null,
53
53
  showSidebar: false,
54
54
  },
55
+ // @ts-ignore
56
+ pendingAnchor: null,
55
57
  watch: {
56
58
  activeAnchorIndex(newVal) {
57
59
  if (newVal !== null && newVal !== -1) {
@@ -227,6 +229,10 @@ SmartComponent({
227
229
  const touch = event.touches[0];
228
230
  const itemHeight = this.sidebar.height / sidebarLength;
229
231
  let index = Math.floor((touch.clientY - this.sidebar.top) / itemHeight);
232
+ // 有时候会莫名间断出现 -90多的情况
233
+ if (index < -20) {
234
+ return;
235
+ }
230
236
  if (index < 0) {
231
237
  index = 0;
232
238
  }
@@ -246,10 +252,39 @@ SmartComponent({
246
252
  }
247
253
  this.scrollToAnchorIndex = index;
248
254
  const anchor = this.children.find(item => item.data.index === this.data.indexList[index]);
249
- if (anchor) {
250
- anchor.scrollIntoView(this.scrollTop);
251
- this.$emit('select', anchor.data.index);
255
+ if (!anchor)
256
+ return;
257
+ // 如果当前有正在进行的滚动,将新的滚动任务加入队列
258
+ if (!this.pendingAnchor) {
259
+ this.pendingAnchor = [];
260
+ }
261
+ if (this.pendingAnchor.length > 0) {
262
+ this.pendingAnchor = [anchor];
263
+ return;
252
264
  }
265
+ this.pendingAnchor = [anchor];
266
+ anchor
267
+ .scrollIntoView(this.scrollTop)
268
+ .then(() => {
269
+ if (this.pendingAnchor.length > 0 && this.pendingAnchor[0] !== anchor) {
270
+ const index = this.data.indexList.indexOf(this.pendingAnchor[0].data.index);
271
+ this.scrollToAnchor(index);
272
+ this.pendingAnchor = [];
273
+ return;
274
+ }
275
+ this.pendingAnchor = [];
276
+ })
277
+ .catch(err => {
278
+ console.error(err);
279
+ if (this.pendingAnchor.length > 0 && this.pendingAnchor[0] !== anchor) {
280
+ const index = this.data.indexList.indexOf(this.pendingAnchor[0].data.index);
281
+ this.scrollToAnchor(index);
282
+ this.pendingAnchor = [];
283
+ return;
284
+ }
285
+ this.pendingAnchor = [];
286
+ });
287
+ this.$emit('select', anchor.data.index);
253
288
  },
254
289
  },
255
290
  });
@@ -17,10 +17,17 @@ var relation_1 = require("../common/relation");
17
17
  methods: {
18
18
  scrollIntoView: function (scrollTop) {
19
19
  var _this = this;
20
- (0, utils_1.getRect)(this, '.smart-index-anchor-wrapper').then(function (rect) {
21
- wx.pageScrollTo({
22
- duration: 0,
23
- scrollTop: scrollTop + rect.top - _this.parent.data.stickyOffsetTop,
20
+ return new Promise(function (resolve, reject) {
21
+ (0, utils_1.getRect)(_this, '.smart-index-anchor-wrapper').then(function (rect) {
22
+ wx.pageScrollTo({
23
+ duration: 0,
24
+ scrollTop: scrollTop + rect.top - _this.parent.data.stickyOffsetTop,
25
+ complete: function () {
26
+ setTimeout(function () {
27
+ resolve('success');
28
+ }, 50);
29
+ },
30
+ });
24
31
  });
25
32
  });
26
33
  },
@@ -57,6 +57,8 @@ var indexList = function () {
57
57
  activeAnchorIndex: null,
58
58
  showSidebar: false,
59
59
  },
60
+ // @ts-ignore
61
+ pendingAnchor: null,
60
62
  watch: {
61
63
  activeAnchorIndex: function (newVal) {
62
64
  if (newVal !== null && newVal !== -1) {
@@ -226,6 +228,10 @@ var indexList = function () {
226
228
  var touch = event.touches[0];
227
229
  var itemHeight = this.sidebar.height / sidebarLength;
228
230
  var index = Math.floor((touch.clientY - this.sidebar.top) / itemHeight);
231
+ // 有时候会莫名间断出现 -90多的情况
232
+ if (index < -20) {
233
+ return;
234
+ }
229
235
  if (index < 0) {
230
236
  index = 0;
231
237
  }
@@ -246,10 +252,39 @@ var indexList = function () {
246
252
  }
247
253
  this.scrollToAnchorIndex = index;
248
254
  var anchor = this.children.find(function (item) { return item.data.index === _this.data.indexList[index]; });
249
- if (anchor) {
250
- anchor.scrollIntoView(this.scrollTop);
251
- this.$emit('select', anchor.data.index);
255
+ if (!anchor)
256
+ return;
257
+ // 如果当前有正在进行的滚动,将新的滚动任务加入队列
258
+ if (!this.pendingAnchor) {
259
+ this.pendingAnchor = [];
260
+ }
261
+ if (this.pendingAnchor.length > 0) {
262
+ this.pendingAnchor = [anchor];
263
+ return;
252
264
  }
265
+ this.pendingAnchor = [anchor];
266
+ anchor
267
+ .scrollIntoView(this.scrollTop)
268
+ .then(function () {
269
+ if (_this.pendingAnchor.length > 0 && _this.pendingAnchor[0] !== anchor) {
270
+ var index_1 = _this.data.indexList.indexOf(_this.pendingAnchor[0].data.index);
271
+ _this.scrollToAnchor(index_1);
272
+ _this.pendingAnchor = [];
273
+ return;
274
+ }
275
+ _this.pendingAnchor = [];
276
+ })
277
+ .catch(function (err) {
278
+ console.error(err);
279
+ if (_this.pendingAnchor.length > 0 && _this.pendingAnchor[0] !== anchor) {
280
+ var index_2 = _this.data.indexList.indexOf(_this.pendingAnchor[0].data.index);
281
+ _this.scrollToAnchor(index_2);
282
+ _this.pendingAnchor = [];
283
+ return;
284
+ }
285
+ _this.pendingAnchor = [];
286
+ });
287
+ this.$emit('select', anchor.data.index);
253
288
  },
254
289
  },
255
290
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-miniapp/smart-ui",
3
- "version": "2.10.0",
3
+ "version": "2.10.1-beta-0",
4
4
  "author": "MiniApp Team",
5
5
  "license": "MIT",
6
6
  "miniprogram": "lib",