@tuya-miniapp/smart-ui 2.10.0 → 2.10.1-beta-1

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
  },
@@ -25,6 +25,12 @@ SmartComponent({
25
25
  type: Boolean,
26
26
  value: true,
27
27
  },
28
+ sidebarFontSize: {
29
+ type: String,
30
+ },
31
+ sidebarLineHeight: {
32
+ type: String,
33
+ },
28
34
  zIndex: {
29
35
  type: Number,
30
36
  value: 1,
@@ -52,6 +58,8 @@ SmartComponent({
52
58
  activeAnchorIndex: null,
53
59
  showSidebar: false,
54
60
  },
61
+ // @ts-ignore
62
+ pendingAnchor: null,
55
63
  watch: {
56
64
  activeAnchorIndex(newVal) {
57
65
  if (newVal !== null && newVal !== -1) {
@@ -79,7 +87,7 @@ SmartComponent({
79
87
  });
80
88
  },
81
89
  setRect() {
82
- return Promise.all([this.setAnchorsRect(), this.setListRect(), this.setSiderbarRect()]);
90
+ return Promise.all([this.setAnchorsRect(), this.setListRect(), this.setSidebarRect()]);
83
91
  },
84
92
  setAnchorsRect() {
85
93
  return Promise.all(this.children.map(anchor => getRect(anchor, '.smart-index-anchor-wrapper').then(rect => {
@@ -100,7 +108,7 @@ SmartComponent({
100
108
  });
101
109
  });
102
110
  },
103
- setSiderbarRect() {
111
+ setSidebarRect() {
104
112
  return getRect(this, '.smart-index-bar__sidebar').then(res => {
105
113
  if (!isDef(res)) {
106
114
  return;
@@ -227,6 +235,10 @@ SmartComponent({
227
235
  const touch = event.touches[0];
228
236
  const itemHeight = this.sidebar.height / sidebarLength;
229
237
  let index = Math.floor((touch.clientY - this.sidebar.top) / itemHeight);
238
+ // 有时候会莫名间断出现 -90多的情况
239
+ if (index < -20) {
240
+ return;
241
+ }
230
242
  if (index < 0) {
231
243
  index = 0;
232
244
  }
@@ -246,10 +258,39 @@ SmartComponent({
246
258
  }
247
259
  this.scrollToAnchorIndex = index;
248
260
  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);
261
+ if (!anchor)
262
+ return;
263
+ // 如果当前有正在进行的滚动,将新的滚动任务加入队列
264
+ if (!this.pendingAnchor) {
265
+ this.pendingAnchor = [];
252
266
  }
267
+ if (this.pendingAnchor.length > 0) {
268
+ this.pendingAnchor = [anchor];
269
+ return;
270
+ }
271
+ this.pendingAnchor = [anchor];
272
+ anchor
273
+ .scrollIntoView(this.scrollTop)
274
+ .then(() => {
275
+ if (this.pendingAnchor.length > 0 && this.pendingAnchor[0] !== anchor) {
276
+ const index = this.data.indexList.indexOf(this.pendingAnchor[0].data.index);
277
+ this.scrollToAnchor(index);
278
+ this.pendingAnchor = [];
279
+ return;
280
+ }
281
+ this.pendingAnchor = [];
282
+ })
283
+ .catch(err => {
284
+ console.error(err);
285
+ if (this.pendingAnchor.length > 0 && this.pendingAnchor[0] !== anchor) {
286
+ const index = this.data.indexList.indexOf(this.pendingAnchor[0].data.index);
287
+ this.scrollToAnchor(index);
288
+ this.pendingAnchor = [];
289
+ return;
290
+ }
291
+ this.pendingAnchor = [];
292
+ });
293
+ this.$emit('select', anchor.data.index);
253
294
  },
254
295
  },
255
296
  });
@@ -13,7 +13,7 @@
13
13
  wx:for="{{ indexList }}"
14
14
  wx:key="index"
15
15
  class="smart-index-bar__index"
16
- style="z-index: {{ zIndex + 1 }}; color: {{ activeAnchorIndex === index ? highlightColor : '' }}"
16
+ style="z-index: {{ zIndex + 1 }};color: {{ activeAnchorIndex === index ? highlightColor : '' }};font-size: {{ sidebarFontSize }};line-height: {{ sidebarLineHeight }};"
17
17
  data-index="{{ index }}"
18
18
  >
19
19
  {{ item }}
@@ -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
  },
@@ -30,6 +30,12 @@ var indexList = function () {
30
30
  type: Boolean,
31
31
  value: true,
32
32
  },
33
+ sidebarFontSize: {
34
+ type: String,
35
+ },
36
+ sidebarLineHeight: {
37
+ type: String,
38
+ },
33
39
  zIndex: {
34
40
  type: Number,
35
41
  value: 1,
@@ -57,6 +63,8 @@ var indexList = function () {
57
63
  activeAnchorIndex: null,
58
64
  showSidebar: false,
59
65
  },
66
+ // @ts-ignore
67
+ pendingAnchor: null,
60
68
  watch: {
61
69
  activeAnchorIndex: function (newVal) {
62
70
  if (newVal !== null && newVal !== -1) {
@@ -85,7 +93,7 @@ var indexList = function () {
85
93
  });
86
94
  },
87
95
  setRect: function () {
88
- return Promise.all([this.setAnchorsRect(), this.setListRect(), this.setSiderbarRect()]);
96
+ return Promise.all([this.setAnchorsRect(), this.setListRect(), this.setSidebarRect()]);
89
97
  },
90
98
  setAnchorsRect: function () {
91
99
  var _this = this;
@@ -110,7 +118,7 @@ var indexList = function () {
110
118
  });
111
119
  });
112
120
  },
113
- setSiderbarRect: function () {
121
+ setSidebarRect: function () {
114
122
  var _this = this;
115
123
  return (0, utils_1.getRect)(this, '.smart-index-bar__sidebar').then(function (res) {
116
124
  if (!(0, utils_1.isDef)(res)) {
@@ -226,6 +234,10 @@ var indexList = function () {
226
234
  var touch = event.touches[0];
227
235
  var itemHeight = this.sidebar.height / sidebarLength;
228
236
  var index = Math.floor((touch.clientY - this.sidebar.top) / itemHeight);
237
+ // 有时候会莫名间断出现 -90多的情况
238
+ if (index < -20) {
239
+ return;
240
+ }
229
241
  if (index < 0) {
230
242
  index = 0;
231
243
  }
@@ -246,10 +258,39 @@ var indexList = function () {
246
258
  }
247
259
  this.scrollToAnchorIndex = index;
248
260
  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);
261
+ if (!anchor)
262
+ return;
263
+ // 如果当前有正在进行的滚动,将新的滚动任务加入队列
264
+ if (!this.pendingAnchor) {
265
+ this.pendingAnchor = [];
252
266
  }
267
+ if (this.pendingAnchor.length > 0) {
268
+ this.pendingAnchor = [anchor];
269
+ return;
270
+ }
271
+ this.pendingAnchor = [anchor];
272
+ anchor
273
+ .scrollIntoView(this.scrollTop)
274
+ .then(function () {
275
+ if (_this.pendingAnchor.length > 0 && _this.pendingAnchor[0] !== anchor) {
276
+ var index_1 = _this.data.indexList.indexOf(_this.pendingAnchor[0].data.index);
277
+ _this.scrollToAnchor(index_1);
278
+ _this.pendingAnchor = [];
279
+ return;
280
+ }
281
+ _this.pendingAnchor = [];
282
+ })
283
+ .catch(function (err) {
284
+ console.error(err);
285
+ if (_this.pendingAnchor.length > 0 && _this.pendingAnchor[0] !== anchor) {
286
+ var index_2 = _this.data.indexList.indexOf(_this.pendingAnchor[0].data.index);
287
+ _this.scrollToAnchor(index_2);
288
+ _this.pendingAnchor = [];
289
+ return;
290
+ }
291
+ _this.pendingAnchor = [];
292
+ });
293
+ this.$emit('select', anchor.data.index);
253
294
  },
254
295
  },
255
296
  });
@@ -13,7 +13,7 @@
13
13
  wx:for="{{ indexList }}"
14
14
  wx:key="index"
15
15
  class="smart-index-bar__index"
16
- style="z-index: {{ zIndex + 1 }}; color: {{ activeAnchorIndex === index ? highlightColor : '' }}"
16
+ style="z-index: {{ zIndex + 1 }};color: {{ activeAnchorIndex === index ? highlightColor : '' }};font-size: {{ sidebarFontSize }};line-height: {{ sidebarLineHeight }};"
17
17
  data-index="{{ index }}"
18
18
  >
19
19
  {{ item }}
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-1",
4
4
  "author": "MiniApp Team",
5
5
  "license": "MIT",
6
6
  "miniprogram": "lib",