@tuya-miniapp/smart-ui 2.6.4-beta-10 → 2.6.4-beta-11
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/dist/picker/index.js
CHANGED
|
@@ -100,7 +100,7 @@ SmartComponent({
|
|
|
100
100
|
},
|
|
101
101
|
// get column option index by column index
|
|
102
102
|
getColumnIndex(columnIndex) {
|
|
103
|
-
return (this.getColumn(columnIndex) || {}).data.
|
|
103
|
+
return (this.getColumn(columnIndex) || {}).data.currentIndex;
|
|
104
104
|
},
|
|
105
105
|
// set column option index by column index
|
|
106
106
|
setColumnIndex(columnIndex, optionIndex) {
|
|
@@ -141,7 +141,7 @@ SmartComponent({
|
|
|
141
141
|
},
|
|
142
142
|
// get indexes of all columns
|
|
143
143
|
getIndexes() {
|
|
144
|
-
return this.children.map(child => child.data.
|
|
144
|
+
return this.children.map(child => child.data.currentIndex);
|
|
145
145
|
},
|
|
146
146
|
// set indexes of all columns
|
|
147
147
|
setIndexes(indexes) {
|
|
@@ -28,7 +28,8 @@ SmartComponent({
|
|
|
28
28
|
if (!this.data.isInit)
|
|
29
29
|
return;
|
|
30
30
|
this.updateUint(value);
|
|
31
|
-
this.
|
|
31
|
+
this.updateCurrentIndex(this.data.currentIndex);
|
|
32
|
+
this.updateVisibleOptions();
|
|
32
33
|
},
|
|
33
34
|
},
|
|
34
35
|
defaultIndex: {
|
|
@@ -45,10 +46,11 @@ SmartComponent({
|
|
|
45
46
|
},
|
|
46
47
|
activeIndex: {
|
|
47
48
|
type: null,
|
|
48
|
-
observer() {
|
|
49
|
+
observer(activeIndex) {
|
|
49
50
|
if (!this.data.isInit)
|
|
50
51
|
return;
|
|
51
|
-
this.
|
|
52
|
+
this.updateCurrentIndex(activeIndex);
|
|
53
|
+
this.updateVisibleOptions();
|
|
52
54
|
},
|
|
53
55
|
},
|
|
54
56
|
unit: {
|
|
@@ -68,14 +70,8 @@ SmartComponent({
|
|
|
68
70
|
isInit: false,
|
|
69
71
|
maxText: '',
|
|
70
72
|
optionsVIndexList: [],
|
|
71
|
-
offsetActiveIndex: 0,
|
|
72
|
-
endTimer: null,
|
|
73
|
-
offsetList: [],
|
|
74
|
-
moving: false,
|
|
75
|
-
movingDirection: 'down',
|
|
76
|
-
startY: 0,
|
|
77
|
-
offsetting: 0,
|
|
78
73
|
animationIndex: 0,
|
|
74
|
+
currentIndex: 0,
|
|
79
75
|
isDestroy: false,
|
|
80
76
|
},
|
|
81
77
|
created() {
|
|
@@ -83,7 +79,10 @@ SmartComponent({
|
|
|
83
79
|
instanceId: getId(),
|
|
84
80
|
});
|
|
85
81
|
this.updateUint(this.data.options);
|
|
86
|
-
this.
|
|
82
|
+
const { activeIndex, defaultIndex } = this.data;
|
|
83
|
+
const currIndex = activeIndex !== null ? activeIndex : defaultIndex;
|
|
84
|
+
this.updateCurrentIndex(currIndex);
|
|
85
|
+
this.updateVisibleOptions();
|
|
87
86
|
this.setData({
|
|
88
87
|
isInit: true,
|
|
89
88
|
});
|
|
@@ -94,34 +93,33 @@ SmartComponent({
|
|
|
94
93
|
});
|
|
95
94
|
},
|
|
96
95
|
methods: {
|
|
97
|
-
|
|
98
|
-
const { activeIndex, defaultIndex } = this.data;
|
|
96
|
+
updateCurrentIndex(currIndex) {
|
|
99
97
|
const count = this.data.options.length;
|
|
100
|
-
const currIndex = activeIndex !== null ? activeIndex : defaultIndex;
|
|
101
98
|
let animationIndex = this.getAnimationIndex(currIndex);
|
|
102
99
|
animationIndex = this.adjustIndex(animationIndex);
|
|
103
100
|
let currActiveIndex = this.data.loop ? ((animationIndex + 1) % count) - 1 : animationIndex;
|
|
104
101
|
if (currActiveIndex < 0) {
|
|
105
102
|
currActiveIndex += count;
|
|
106
103
|
}
|
|
107
|
-
const optionsVIndexList = this.getVisibleOptions(animationIndex);
|
|
108
104
|
this.setData({
|
|
109
|
-
|
|
105
|
+
currentIndex: currActiveIndex,
|
|
110
106
|
animationIndex: animationIndex,
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
updateVisibleOptions() {
|
|
110
|
+
const optionsVIndexList = this.getVisibleOptions(this.data.animationIndex);
|
|
111
|
+
this.setData({
|
|
111
112
|
optionsVIndexList: optionsVIndexList,
|
|
112
113
|
});
|
|
113
|
-
// if (currActiveIndex !== activeIndex) {
|
|
114
|
-
// this.$emit('change', currActiveIndex);
|
|
115
|
-
// }
|
|
116
114
|
},
|
|
117
|
-
getAnimationIndex(
|
|
115
|
+
getAnimationIndex(currentIndex) {
|
|
118
116
|
const { animationIndex } = this.data;
|
|
119
117
|
const length = this.data.options.length || 1;
|
|
120
118
|
if (this.data.loop) {
|
|
121
|
-
const newAnimationIndex = this.getNewAnimationIndex(animationIndex,
|
|
119
|
+
const newAnimationIndex = this.getNewAnimationIndex(animationIndex, currentIndex, length, this.data.loop);
|
|
122
120
|
return newAnimationIndex;
|
|
123
121
|
}
|
|
124
|
-
return
|
|
122
|
+
return currentIndex;
|
|
125
123
|
},
|
|
126
124
|
getCount() {
|
|
127
125
|
return this.data.options.length;
|
|
@@ -224,12 +222,12 @@ SmartComponent({
|
|
|
224
222
|
}
|
|
225
223
|
return newArr;
|
|
226
224
|
},
|
|
227
|
-
getNewAnimationIndex(animationIndex,
|
|
228
|
-
const curOptionsNewIndex = Math.floor((animationIndex + 1) / length) * length +
|
|
225
|
+
getNewAnimationIndex(animationIndex, currentIndex, length, loop) {
|
|
226
|
+
const curOptionsNewIndex = Math.floor((animationIndex + 1) / length) * length + currentIndex;
|
|
229
227
|
const preOptionsNewIndex = curOptionsNewIndex - length;
|
|
230
228
|
const afterOptionsNewIndex = curOptionsNewIndex + length;
|
|
231
229
|
const newAnimationIndex = !loop
|
|
232
|
-
?
|
|
230
|
+
? currentIndex
|
|
233
231
|
: Math.abs(preOptionsNewIndex - animationIndex) >
|
|
234
232
|
Math.abs(curOptionsNewIndex - animationIndex)
|
|
235
233
|
? Math.abs(curOptionsNewIndex - animationIndex) >
|
|
@@ -259,12 +257,12 @@ SmartComponent({
|
|
|
259
257
|
}
|
|
260
258
|
return 0;
|
|
261
259
|
}
|
|
262
|
-
const
|
|
263
|
-
for (let i =
|
|
260
|
+
const currentIndex = range(index, 0, count);
|
|
261
|
+
for (let i = currentIndex; i < count; i++) {
|
|
264
262
|
if (!this.isDisabled(data.options[i]) && data.options[i] !== undefined)
|
|
265
263
|
return i;
|
|
266
264
|
}
|
|
267
|
-
for (let i =
|
|
265
|
+
for (let i = currentIndex - 1; i >= 0; i--) {
|
|
268
266
|
if (!this.isDisabled(data.options[i]) && data.options[i] !== undefined)
|
|
269
267
|
return i;
|
|
270
268
|
}
|
|
@@ -287,29 +285,29 @@ SmartComponent({
|
|
|
287
285
|
return Promise.resolve();
|
|
288
286
|
},
|
|
289
287
|
setIndex(index) {
|
|
290
|
-
let
|
|
291
|
-
if (
|
|
292
|
-
|
|
288
|
+
let currentIndex = ((index + 1) % this.data.options.length) - 1;
|
|
289
|
+
if (currentIndex < 0) {
|
|
290
|
+
currentIndex += this.data.options.length;
|
|
293
291
|
}
|
|
294
292
|
this.setData({
|
|
295
|
-
|
|
293
|
+
currentIndex,
|
|
296
294
|
animationIndex: index,
|
|
297
295
|
});
|
|
298
296
|
},
|
|
299
297
|
getValue() {
|
|
300
298
|
const { data } = this;
|
|
301
|
-
return isObj(data.options[data.
|
|
302
|
-
? data.options[data.
|
|
303
|
-
: data.options[data.
|
|
299
|
+
return isObj(data.options[data.currentIndex])
|
|
300
|
+
? data.options[data.currentIndex][data.valueKey]
|
|
301
|
+
: data.options[data.currentIndex];
|
|
304
302
|
},
|
|
305
303
|
activeIndexChange(index) {
|
|
306
|
-
let
|
|
307
|
-
if (
|
|
308
|
-
|
|
304
|
+
let currentIndex = ((index + 1) % this.data.options.length) - 1;
|
|
305
|
+
if (currentIndex < 0) {
|
|
306
|
+
currentIndex += this.data.options.length;
|
|
309
307
|
}
|
|
310
|
-
const isSame =
|
|
308
|
+
const isSame = currentIndex === this.data.activeIndex;
|
|
311
309
|
this.setData({
|
|
312
|
-
|
|
310
|
+
currentIndex,
|
|
313
311
|
animationIndex: index,
|
|
314
312
|
});
|
|
315
313
|
!isSame && this.$emit('change', index);
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
data-valuekey="{{valueKey}}"
|
|
13
13
|
data-itemheight="{{itemHeight}}"
|
|
14
14
|
data-visibleitemcount="{{visibleItemCount}}"
|
|
15
|
-
data-activeindex="{{
|
|
15
|
+
data-activeindex="{{currentIndex}}"
|
|
16
16
|
data-loop="{{loop}}"
|
|
17
17
|
data-animationtime="{{animationTime}}"
|
|
18
18
|
isdestroy="{{isDestroy}}"
|
|
19
19
|
options="{{options}}"
|
|
20
|
-
activeindex="{{
|
|
20
|
+
activeindex="{{currentIndex}}"
|
|
21
21
|
changeanimation="{{changeAnimation}}"
|
|
22
22
|
loop="{{loop}}"
|
|
23
23
|
valuekey="{{valueKey}}"
|
package/lib/picker/index.js
CHANGED
|
@@ -118,7 +118,7 @@ var shared_1 = require("./shared");
|
|
|
118
118
|
},
|
|
119
119
|
// get column option index by column index
|
|
120
120
|
getColumnIndex: function (columnIndex) {
|
|
121
|
-
return (this.getColumn(columnIndex) || {}).data.
|
|
121
|
+
return (this.getColumn(columnIndex) || {}).data.currentIndex;
|
|
122
122
|
},
|
|
123
123
|
// set column option index by column index
|
|
124
124
|
setColumnIndex: function (columnIndex, optionIndex) {
|
|
@@ -161,9 +161,7 @@ var shared_1 = require("./shared");
|
|
|
161
161
|
},
|
|
162
162
|
// get indexes of all columns
|
|
163
163
|
getIndexes: function () {
|
|
164
|
-
return this.children.map(function (child) {
|
|
165
|
-
return child.data.activeIndex === null ? child.data.defaultIndex : child.data.activeIndex;
|
|
166
|
-
});
|
|
164
|
+
return this.children.map(function (child) { return child.data.currentIndex; });
|
|
167
165
|
},
|
|
168
166
|
// set indexes of all columns
|
|
169
167
|
setIndexes: function (indexes) {
|
|
@@ -33,7 +33,8 @@ var getId = function () {
|
|
|
33
33
|
if (!this.data.isInit)
|
|
34
34
|
return;
|
|
35
35
|
this.updateUint(value);
|
|
36
|
-
this.
|
|
36
|
+
this.updateCurrentIndex(this.data.currentIndex);
|
|
37
|
+
this.updateVisibleOptions();
|
|
37
38
|
},
|
|
38
39
|
},
|
|
39
40
|
defaultIndex: {
|
|
@@ -50,10 +51,11 @@ var getId = function () {
|
|
|
50
51
|
},
|
|
51
52
|
activeIndex: {
|
|
52
53
|
type: null,
|
|
53
|
-
observer: function () {
|
|
54
|
+
observer: function (activeIndex) {
|
|
54
55
|
if (!this.data.isInit)
|
|
55
56
|
return;
|
|
56
|
-
this.
|
|
57
|
+
this.updateCurrentIndex(activeIndex);
|
|
58
|
+
this.updateVisibleOptions();
|
|
57
59
|
},
|
|
58
60
|
},
|
|
59
61
|
unit: {
|
|
@@ -73,14 +75,8 @@ var getId = function () {
|
|
|
73
75
|
isInit: false,
|
|
74
76
|
maxText: '',
|
|
75
77
|
optionsVIndexList: [],
|
|
76
|
-
offsetActiveIndex: 0,
|
|
77
|
-
endTimer: null,
|
|
78
|
-
offsetList: [],
|
|
79
|
-
moving: false,
|
|
80
|
-
movingDirection: 'down',
|
|
81
|
-
startY: 0,
|
|
82
|
-
offsetting: 0,
|
|
83
78
|
animationIndex: 0,
|
|
79
|
+
currentIndex: 0,
|
|
84
80
|
isDestroy: false,
|
|
85
81
|
},
|
|
86
82
|
created: function () {
|
|
@@ -88,7 +84,10 @@ var getId = function () {
|
|
|
88
84
|
instanceId: getId(),
|
|
89
85
|
});
|
|
90
86
|
this.updateUint(this.data.options);
|
|
91
|
-
this.
|
|
87
|
+
var _a = this.data, activeIndex = _a.activeIndex, defaultIndex = _a.defaultIndex;
|
|
88
|
+
var currIndex = activeIndex !== null ? activeIndex : defaultIndex;
|
|
89
|
+
this.updateCurrentIndex(currIndex);
|
|
90
|
+
this.updateVisibleOptions();
|
|
92
91
|
this.setData({
|
|
93
92
|
isInit: true,
|
|
94
93
|
});
|
|
@@ -99,34 +98,33 @@ var getId = function () {
|
|
|
99
98
|
});
|
|
100
99
|
},
|
|
101
100
|
methods: {
|
|
102
|
-
|
|
103
|
-
var _a = this.data, activeIndex = _a.activeIndex, defaultIndex = _a.defaultIndex;
|
|
101
|
+
updateCurrentIndex: function (currIndex) {
|
|
104
102
|
var count = this.data.options.length;
|
|
105
|
-
var currIndex = activeIndex !== null ? activeIndex : defaultIndex;
|
|
106
103
|
var animationIndex = this.getAnimationIndex(currIndex);
|
|
107
104
|
animationIndex = this.adjustIndex(animationIndex);
|
|
108
105
|
var currActiveIndex = this.data.loop ? ((animationIndex + 1) % count) - 1 : animationIndex;
|
|
109
106
|
if (currActiveIndex < 0) {
|
|
110
107
|
currActiveIndex += count;
|
|
111
108
|
}
|
|
112
|
-
var optionsVIndexList = this.getVisibleOptions(animationIndex);
|
|
113
109
|
this.setData({
|
|
114
|
-
|
|
110
|
+
currentIndex: currActiveIndex,
|
|
115
111
|
animationIndex: animationIndex,
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
updateVisibleOptions: function () {
|
|
115
|
+
var optionsVIndexList = this.getVisibleOptions(this.data.animationIndex);
|
|
116
|
+
this.setData({
|
|
116
117
|
optionsVIndexList: optionsVIndexList,
|
|
117
118
|
});
|
|
118
|
-
// if (currActiveIndex !== activeIndex) {
|
|
119
|
-
// this.$emit('change', currActiveIndex);
|
|
120
|
-
// }
|
|
121
119
|
},
|
|
122
|
-
getAnimationIndex: function (
|
|
120
|
+
getAnimationIndex: function (currentIndex) {
|
|
123
121
|
var animationIndex = this.data.animationIndex;
|
|
124
122
|
var length = this.data.options.length || 1;
|
|
125
123
|
if (this.data.loop) {
|
|
126
|
-
var newAnimationIndex = this.getNewAnimationIndex(animationIndex,
|
|
124
|
+
var newAnimationIndex = this.getNewAnimationIndex(animationIndex, currentIndex, length, this.data.loop);
|
|
127
125
|
return newAnimationIndex;
|
|
128
126
|
}
|
|
129
|
-
return
|
|
127
|
+
return currentIndex;
|
|
130
128
|
},
|
|
131
129
|
getCount: function () {
|
|
132
130
|
return this.data.options.length;
|
|
@@ -230,12 +228,12 @@ var getId = function () {
|
|
|
230
228
|
}
|
|
231
229
|
return newArr;
|
|
232
230
|
},
|
|
233
|
-
getNewAnimationIndex: function (animationIndex,
|
|
234
|
-
var curOptionsNewIndex = Math.floor((animationIndex + 1) / length) * length +
|
|
231
|
+
getNewAnimationIndex: function (animationIndex, currentIndex, length, loop) {
|
|
232
|
+
var curOptionsNewIndex = Math.floor((animationIndex + 1) / length) * length + currentIndex;
|
|
235
233
|
var preOptionsNewIndex = curOptionsNewIndex - length;
|
|
236
234
|
var afterOptionsNewIndex = curOptionsNewIndex + length;
|
|
237
235
|
var newAnimationIndex = !loop
|
|
238
|
-
?
|
|
236
|
+
? currentIndex
|
|
239
237
|
: Math.abs(preOptionsNewIndex - animationIndex) >
|
|
240
238
|
Math.abs(curOptionsNewIndex - animationIndex)
|
|
241
239
|
? Math.abs(curOptionsNewIndex - animationIndex) >
|
|
@@ -265,12 +263,12 @@ var getId = function () {
|
|
|
265
263
|
}
|
|
266
264
|
return 0;
|
|
267
265
|
}
|
|
268
|
-
var
|
|
269
|
-
for (var i =
|
|
266
|
+
var currentIndex = (0, utils_1.range)(index, 0, count);
|
|
267
|
+
for (var i = currentIndex; i < count; i++) {
|
|
270
268
|
if (!this.isDisabled(data.options[i]) && data.options[i] !== undefined)
|
|
271
269
|
return i;
|
|
272
270
|
}
|
|
273
|
-
for (var i =
|
|
271
|
+
for (var i = currentIndex - 1; i >= 0; i--) {
|
|
274
272
|
if (!this.isDisabled(data.options[i]) && data.options[i] !== undefined)
|
|
275
273
|
return i;
|
|
276
274
|
}
|
|
@@ -293,29 +291,29 @@ var getId = function () {
|
|
|
293
291
|
return Promise.resolve();
|
|
294
292
|
},
|
|
295
293
|
setIndex: function (index) {
|
|
296
|
-
var
|
|
297
|
-
if (
|
|
298
|
-
|
|
294
|
+
var currentIndex = ((index + 1) % this.data.options.length) - 1;
|
|
295
|
+
if (currentIndex < 0) {
|
|
296
|
+
currentIndex += this.data.options.length;
|
|
299
297
|
}
|
|
300
298
|
this.setData({
|
|
301
|
-
|
|
299
|
+
currentIndex: currentIndex,
|
|
302
300
|
animationIndex: index,
|
|
303
301
|
});
|
|
304
302
|
},
|
|
305
303
|
getValue: function () {
|
|
306
304
|
var data = this.data;
|
|
307
|
-
return (0, validator_1.isObj)(data.options[data.
|
|
308
|
-
? data.options[data.
|
|
309
|
-
: data.options[data.
|
|
305
|
+
return (0, validator_1.isObj)(data.options[data.currentIndex])
|
|
306
|
+
? data.options[data.currentIndex][data.valueKey]
|
|
307
|
+
: data.options[data.currentIndex];
|
|
310
308
|
},
|
|
311
309
|
activeIndexChange: function (index) {
|
|
312
|
-
var
|
|
313
|
-
if (
|
|
314
|
-
|
|
310
|
+
var currentIndex = ((index + 1) % this.data.options.length) - 1;
|
|
311
|
+
if (currentIndex < 0) {
|
|
312
|
+
currentIndex += this.data.options.length;
|
|
315
313
|
}
|
|
316
|
-
var isSame =
|
|
314
|
+
var isSame = currentIndex === this.data.activeIndex;
|
|
317
315
|
this.setData({
|
|
318
|
-
|
|
316
|
+
currentIndex: currentIndex,
|
|
319
317
|
animationIndex: index,
|
|
320
318
|
});
|
|
321
319
|
!isSame && this.$emit('change', index);
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
data-valuekey="{{valueKey}}"
|
|
13
13
|
data-itemheight="{{itemHeight}}"
|
|
14
14
|
data-visibleitemcount="{{visibleItemCount}}"
|
|
15
|
-
data-activeindex="{{
|
|
15
|
+
data-activeindex="{{currentIndex}}"
|
|
16
16
|
data-loop="{{loop}}"
|
|
17
17
|
data-animationtime="{{animationTime}}"
|
|
18
18
|
isdestroy="{{isDestroy}}"
|
|
19
19
|
options="{{options}}"
|
|
20
|
-
activeindex="{{
|
|
20
|
+
activeindex="{{currentIndex}}"
|
|
21
21
|
changeanimation="{{changeAnimation}}"
|
|
22
22
|
loop="{{loop}}"
|
|
23
23
|
valuekey="{{valueKey}}"
|