@tuya-miniapp/smart-ui 2.6.4-beta-6 → 2.6.4-beta-8
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/common/utils.d.ts +1 -0
- package/dist/common/utils.js +7 -0
- package/dist/picker-column/index.css +1 -1
- package/dist/picker-column/index.js +85 -264
- package/dist/picker-column/index.wxml +63 -25
- package/dist/picker-column/index.wxs +453 -26
- package/dist/picker-column/index.wxss +1 -1
- package/dist/wxs/strToStyleObject.wxs +10 -0
- package/lib/common/utils.d.ts +1 -0
- package/lib/common/utils.js +9 -1
- package/lib/picker-column/index.css +1 -1
- package/lib/picker-column/index.js +80 -297
- package/lib/picker-column/index.wxml +63 -25
- package/lib/picker-column/index.wxs +453 -26
- package/lib/picker-column/index.wxss +1 -1
- package/lib/wxs/strToStyleObject.wxs +10 -0
- package/package.json +1 -1
|
@@ -1,40 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
3
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
4
|
if (ar || !(i in from)) {
|
|
@@ -52,7 +16,12 @@ var component_1 = require("../common/component");
|
|
|
52
16
|
var utils_1 = require("../common/utils");
|
|
53
17
|
var validator_1 = require("../common/validator");
|
|
54
18
|
var ty_1 = __importDefault(require("../common/ty"));
|
|
55
|
-
var
|
|
19
|
+
var compIdList = [];
|
|
20
|
+
var getId = function () {
|
|
21
|
+
var id = 'smart-picker-column-' + compIdList.length;
|
|
22
|
+
compIdList.push(id);
|
|
23
|
+
return id;
|
|
24
|
+
};
|
|
56
25
|
(0, component_1.SmartComponent)({
|
|
57
26
|
classes: ['active-class'],
|
|
58
27
|
props: {
|
|
@@ -71,8 +40,8 @@ var DEFAULT_DURATION = 400;
|
|
|
71
40
|
observer: function (value) {
|
|
72
41
|
if (!this.data.isInit)
|
|
73
42
|
return;
|
|
43
|
+
this.updateViewOptions();
|
|
74
44
|
this.updateUint(value);
|
|
75
|
-
this.updateVisibleOptions(this.data.currentIndex);
|
|
76
45
|
},
|
|
77
46
|
},
|
|
78
47
|
defaultIndex: {
|
|
@@ -90,10 +59,10 @@ var DEFAULT_DURATION = 400;
|
|
|
90
59
|
activeIndex: {
|
|
91
60
|
type: Number,
|
|
92
61
|
value: -1,
|
|
93
|
-
observer: function (
|
|
62
|
+
observer: function () {
|
|
94
63
|
if (!this.data.isInit)
|
|
95
64
|
return;
|
|
96
|
-
this.
|
|
65
|
+
this.updateViewOptions();
|
|
97
66
|
},
|
|
98
67
|
},
|
|
99
68
|
unit: {
|
|
@@ -104,6 +73,10 @@ var DEFAULT_DURATION = 400;
|
|
|
104
73
|
type: Number,
|
|
105
74
|
value: 300,
|
|
106
75
|
},
|
|
76
|
+
loop: {
|
|
77
|
+
type: Boolean,
|
|
78
|
+
value: false,
|
|
79
|
+
},
|
|
107
80
|
},
|
|
108
81
|
data: {
|
|
109
82
|
startY: 0,
|
|
@@ -118,165 +91,71 @@ var DEFAULT_DURATION = 400;
|
|
|
118
91
|
playing: false,
|
|
119
92
|
isInit: false,
|
|
120
93
|
maxText: '',
|
|
94
|
+
instanceId: '',
|
|
121
95
|
timer: null,
|
|
122
96
|
preOffsetList: [],
|
|
97
|
+
viewOptions: [],
|
|
123
98
|
},
|
|
124
99
|
created: function () {
|
|
125
|
-
|
|
100
|
+
this.setData({
|
|
101
|
+
instanceId: getId(),
|
|
102
|
+
});
|
|
103
|
+
this.checkIndex();
|
|
104
|
+
this.updateViewOptions();
|
|
105
|
+
var options = this.data.options;
|
|
126
106
|
this.updateUint(options);
|
|
127
|
-
this.setIndex(activeIndex !== -1 ? activeIndex : defaultIndex, false, this.data.changeAnimation, this.data.animationTime);
|
|
128
107
|
this.setData({
|
|
129
108
|
isInit: true,
|
|
130
109
|
});
|
|
131
110
|
},
|
|
132
111
|
methods: {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (this.data.disabled) {
|
|
112
|
+
checkIndex: function () {
|
|
113
|
+
var activeIndex = this.data.activeIndex;
|
|
114
|
+
var index = this.adjustIndex(activeIndex);
|
|
115
|
+
if (activeIndex === index)
|
|
138
116
|
return;
|
|
139
|
-
}
|
|
140
|
-
if (this.data.timer) {
|
|
141
|
-
clearTimeout(this.data.timer);
|
|
142
|
-
this.setData({
|
|
143
|
-
timer: null,
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
if (!this.data.playing) {
|
|
147
|
-
this.$emit('animation-start');
|
|
148
|
-
}
|
|
149
117
|
this.setData({
|
|
150
|
-
|
|
151
|
-
startOffset: this.data.offset,
|
|
152
|
-
duration: 100,
|
|
153
|
-
playing: true,
|
|
154
|
-
timer: null,
|
|
155
|
-
preOffsetList: [this.data.offset],
|
|
118
|
+
activeIndex: index,
|
|
156
119
|
});
|
|
157
120
|
},
|
|
158
|
-
|
|
159
|
-
if (this.data.disabled) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
121
|
+
adjustIndex: function (index) {
|
|
162
122
|
var data = this.data;
|
|
163
|
-
var
|
|
164
|
-
|
|
165
|
-
var
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
var preIndex = (0, utils_1.range)(Math.round(-preOffsetList[preOffsetList.length - 1] / data.itemHeight), 0, this.getCount() - 1);
|
|
169
|
-
// 最终定位索引
|
|
170
|
-
var index = (0, utils_1.range)(Math.round(-offset / data.itemHeight), 0, this.getCount() - 1);
|
|
171
|
-
if ((direction === 'up' && index < data.renderStart + 8) ||
|
|
172
|
-
(direction === 'down' && index > data.renderStart + data.renderNum - 8)) {
|
|
173
|
-
this.updateVisibleOptions(index);
|
|
123
|
+
var count = this.data.options.length;
|
|
124
|
+
index = (0, utils_1.range)(index, 0, count);
|
|
125
|
+
for (var i = index; i < count; i++) {
|
|
126
|
+
if (!this.isDisabled(data.options[i]))
|
|
127
|
+
return i;
|
|
174
128
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
this.vibrateShort();
|
|
129
|
+
for (var i = index - 1; i >= 0; i--) {
|
|
130
|
+
if (!this.isDisabled(data.options[i]))
|
|
131
|
+
return i;
|
|
179
132
|
}
|
|
180
|
-
var animationIndex = Math.abs(-offset / data.itemHeight);
|
|
181
|
-
this.setData({
|
|
182
|
-
offset: offset,
|
|
183
|
-
animationIndex: animationIndex,
|
|
184
|
-
preOffsetList: __spreadArray(__spreadArray([], data.preOffsetList, true), [offset], false),
|
|
185
|
-
animate: false,
|
|
186
|
-
});
|
|
187
133
|
},
|
|
188
|
-
|
|
189
|
-
return
|
|
190
|
-
var data, preOffsetList, preOffset, isSameTouch, direction, offset, countHeight, animationOffset, finOffset, index, offsetData, countVibrate, time;
|
|
191
|
-
var _this = this;
|
|
192
|
-
return __generator(this, function (_a) {
|
|
193
|
-
switch (_a.label) {
|
|
194
|
-
case 0:
|
|
195
|
-
data = this.data;
|
|
196
|
-
if (data.disabled) {
|
|
197
|
-
return [2 /*return*/];
|
|
198
|
-
}
|
|
199
|
-
preOffsetList = data.preOffsetList;
|
|
200
|
-
preOffset = Math.max(Math.abs(preOffsetList[preOffsetList.length - 3] - preOffsetList[preOffsetList.length - 4]), Math.abs(preOffsetList[preOffsetList.length - 2] - preOffsetList[preOffsetList.length - 3]), Math.abs(preOffsetList[preOffsetList.length - 1] - preOffsetList[preOffsetList.length - 2]));
|
|
201
|
-
if (isNaN(preOffset))
|
|
202
|
-
preOffset = 0;
|
|
203
|
-
preOffset = Math.min(preOffset, 40);
|
|
204
|
-
isSameTouch = (preOffsetList[preOffsetList.length - 1] === preOffsetList[preOffsetList.length - 2] &&
|
|
205
|
-
preOffsetList[preOffsetList.length - 2] === preOffsetList[preOffsetList.length - 3]) ||
|
|
206
|
-
preOffsetList[preOffsetList.length - 1] === -(this.getCount() * data.itemHeight) ||
|
|
207
|
-
preOffsetList[preOffsetList.length - 1] === data.itemHeight;
|
|
208
|
-
direction = this.checkIsDown();
|
|
209
|
-
offset = Math.abs(preOffset) < 3 || isSameTouch || !direction
|
|
210
|
-
? data.offset
|
|
211
|
-
: data.offset + (direction === 'down' ? -preOffset : preOffset) * 10;
|
|
212
|
-
countHeight = (this.getCount() - 1) * data.itemHeight;
|
|
213
|
-
animationOffset = (0, utils_1.range)(offset, -(this.getCount() * data.itemHeight), data.itemHeight);
|
|
214
|
-
finOffset = animationOffset < -countHeight ? -countHeight : animationOffset > 0 ? 0 : animationOffset;
|
|
215
|
-
index = (0, utils_1.range)(Math.round(-finOffset / data.itemHeight), 0, this.getCount() - 1);
|
|
216
|
-
offsetData = -index * data.itemHeight;
|
|
217
|
-
// 增加惯性音效
|
|
218
|
-
if (Math.abs(offsetData - data.offset) > data.itemHeight && !isSameTouch) {
|
|
219
|
-
countVibrate = Math.abs(offsetData - data.offset) / data.itemHeight;
|
|
220
|
-
// @ts-ignore
|
|
221
|
-
this.vibrateShort(Math.floor(countVibrate), data.animationTime);
|
|
222
|
-
}
|
|
223
|
-
// 最终定位索引
|
|
224
|
-
this.setData({
|
|
225
|
-
duration: isSameTouch ? 150 : data.animationTime,
|
|
226
|
-
animationIndex: index,
|
|
227
|
-
offset: offsetData,
|
|
228
|
-
animate: true,
|
|
229
|
-
});
|
|
230
|
-
if (!((direction === 'up' && index < data.renderStart + 8) ||
|
|
231
|
-
(direction === 'down' && index > data.renderStart + data.renderNum - 8))) return [3 /*break*/, 2];
|
|
232
|
-
return [4 /*yield*/, this.updateVisibleOptions(index)];
|
|
233
|
-
case 1:
|
|
234
|
-
_a.sent();
|
|
235
|
-
_a.label = 2;
|
|
236
|
-
case 2:
|
|
237
|
-
// 更新索引
|
|
238
|
-
if (index !== data.currentIndex) {
|
|
239
|
-
time = isSameTouch ? 150 : data.animationTime;
|
|
240
|
-
// if (!isSameTouch) {
|
|
241
|
-
// this.timer = setInterval(() => {
|
|
242
|
-
// if (Math.abs(this.data.animationIndex - index) < 0.5) return clearInterval(this.timer);
|
|
243
|
-
// this.setData({
|
|
244
|
-
// animationIndex: this.data.animationIndex + (index - data.currentIndex > 0 ? 1 : -1),
|
|
245
|
-
// });
|
|
246
|
-
// }, data.animationTime / Math.abs(index - data.currentIndex));
|
|
247
|
-
// }
|
|
248
|
-
return [2 /*return*/, this.setData({
|
|
249
|
-
timer: setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
250
|
-
return __generator(this, function (_a) {
|
|
251
|
-
this.setIndex(index, true, false, this.data.animationTime);
|
|
252
|
-
return [2 /*return*/];
|
|
253
|
-
});
|
|
254
|
-
}); }, time),
|
|
255
|
-
})];
|
|
256
|
-
}
|
|
257
|
-
this.setData({
|
|
258
|
-
playing: false,
|
|
259
|
-
});
|
|
260
|
-
this.$emit('animation-end');
|
|
261
|
-
return [2 /*return*/];
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
});
|
|
134
|
+
isDisabled: function (option) {
|
|
135
|
+
return (0, validator_1.isObj)(option) && option.disabled;
|
|
265
136
|
},
|
|
266
|
-
|
|
267
|
-
var
|
|
268
|
-
var
|
|
269
|
-
var
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
137
|
+
updateViewOptions: function () {
|
|
138
|
+
var currActiveIndex = this.data.activeIndex < 0 ? 0 : this.data.activeIndex;
|
|
139
|
+
var partNum = Math.floor(currActiveIndex / 10);
|
|
140
|
+
var lastNum = this.data.activeIndex - partNum * 10;
|
|
141
|
+
if (lastNum < 5 && partNum > 0) {
|
|
142
|
+
partNum -= 1;
|
|
143
|
+
}
|
|
144
|
+
var part2Times = Math.floor(partNum / 2);
|
|
145
|
+
var part2Percent = partNum % 2;
|
|
146
|
+
var onePartOffset = part2Percent + part2Times;
|
|
147
|
+
var twoPartOffset = part2Times;
|
|
148
|
+
var isReverse = onePartOffset > twoPartOffset;
|
|
149
|
+
var startPart = twoPartOffset + onePartOffset;
|
|
150
|
+
var viewIndexList = !isReverse
|
|
151
|
+
? (0, utils_1.generateRangeArray)(startPart * 10, startPart * 10 + 20)
|
|
152
|
+
: __spreadArray(__spreadArray([], (0, utils_1.generateRangeArray)(startPart * 10 + 10, startPart * 10 + 20), true), (0, utils_1.generateRangeArray)(startPart * 10, startPart * 10 + 10), true);
|
|
153
|
+
this.setData({
|
|
154
|
+
viewOptions: viewIndexList,
|
|
155
|
+
});
|
|
276
156
|
},
|
|
277
157
|
vibrateShort: function (count, time) {
|
|
278
158
|
var _this = this;
|
|
279
|
-
if (time === void 0) { time = DEFAULT_DURATION; }
|
|
280
159
|
if (!count) {
|
|
281
160
|
ty_1.default.vibrateShort({ type: 'light' });
|
|
282
161
|
return;
|
|
@@ -289,17 +168,7 @@ var DEFAULT_DURATION = 400;
|
|
|
289
168
|
}
|
|
290
169
|
has++;
|
|
291
170
|
_this.vibrateShort();
|
|
292
|
-
}, time / count - 20);
|
|
293
|
-
},
|
|
294
|
-
onClickItem: function (event) {
|
|
295
|
-
if (this.data.disabled)
|
|
296
|
-
return;
|
|
297
|
-
var index = event.currentTarget.dataset.index;
|
|
298
|
-
if (index === this.data.currentIndex || index < 0 || index > this.data.options.length - 1) {
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
this.vibrateShort(Math.abs(index - this.data.currentIndex), DEFAULT_DURATION);
|
|
302
|
-
this.setIndex(index, true, true, this.data.animationTime);
|
|
171
|
+
}, (time || this.data.animationTime) / count - 20);
|
|
303
172
|
},
|
|
304
173
|
updateUint: function (options) {
|
|
305
174
|
var _a = this.data, unit = _a.unit, valueKey = _a.valueKey;
|
|
@@ -315,129 +184,43 @@ var DEFAULT_DURATION = 400;
|
|
|
315
184
|
this.setData({ maxText: maxText_1 });
|
|
316
185
|
}
|
|
317
186
|
},
|
|
318
|
-
updateVisibleOptions: function (targetIndex) {
|
|
319
|
-
var _a = this.data, options = _a.options, visibleItemCount = _a.visibleItemCount, currentIndex = _a.currentIndex;
|
|
320
|
-
if (visibleItemCount < 20 && options.length > visibleItemCount) {
|
|
321
|
-
var renderNum = 0;
|
|
322
|
-
var renderStart = 0;
|
|
323
|
-
// 选项多于 20 个时,进行列表优化
|
|
324
|
-
renderNum = Math.max(visibleItemCount * 2, 20);
|
|
325
|
-
renderStart = Math.max(0, targetIndex - renderNum / 2);
|
|
326
|
-
var renderEnd = Math.min(options.length, renderStart + renderNum);
|
|
327
|
-
if (currentIndex >= 0) {
|
|
328
|
-
if (currentIndex < targetIndex) {
|
|
329
|
-
renderStart = Math.max(0, currentIndex - renderNum / 2);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
renderNum = renderEnd - renderStart;
|
|
333
|
-
var optionsV = options.slice(renderStart, renderEnd);
|
|
334
|
-
return this.set({ optionsV: optionsV, renderStart: renderStart, renderNum: renderNum });
|
|
335
|
-
}
|
|
336
|
-
return this.set({
|
|
337
|
-
optionsV: options,
|
|
338
|
-
renderStart: 0,
|
|
339
|
-
renderNum: options.length,
|
|
340
|
-
});
|
|
341
|
-
},
|
|
342
|
-
adjustIndex: function (index) {
|
|
343
|
-
var data = this.data;
|
|
344
|
-
var count = this.getCount();
|
|
345
|
-
index = (0, utils_1.range)(index, 0, count);
|
|
346
|
-
for (var i = index; i < count; i++) {
|
|
347
|
-
if (!this.isDisabled(data.options[i]))
|
|
348
|
-
return i;
|
|
349
|
-
}
|
|
350
|
-
for (var i = index - 1; i >= 0; i--) {
|
|
351
|
-
if (!this.isDisabled(data.options[i]))
|
|
352
|
-
return i;
|
|
353
|
-
}
|
|
354
|
-
},
|
|
355
|
-
isDisabled: function (option) {
|
|
356
|
-
return (0, validator_1.isObj)(option) && option.disabled;
|
|
357
|
-
},
|
|
358
187
|
getOptionText: function (option) {
|
|
359
188
|
var data = this.data;
|
|
360
189
|
return (0, validator_1.isObj)(option) && data.valueKey in option ? option[data.valueKey] : option;
|
|
361
190
|
},
|
|
362
|
-
setIndex: function (index, userAction, animate, time) {
|
|
363
|
-
var _this = this;
|
|
364
|
-
if (time === void 0) { time = DEFAULT_DURATION; }
|
|
365
|
-
var data = this.data;
|
|
366
|
-
index = this.adjustIndex(index) || 0;
|
|
367
|
-
var offset = -index * data.itemHeight;
|
|
368
|
-
if (this.timer) {
|
|
369
|
-
clearTimeout(this.timer);
|
|
370
|
-
this.timer = null;
|
|
371
|
-
}
|
|
372
|
-
if (!data.playing) {
|
|
373
|
-
this.$emit('animation-start');
|
|
374
|
-
this.setData({
|
|
375
|
-
playing: true,
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
if (index !== data.currentIndex) {
|
|
379
|
-
// 需要动画的情况下,保持最大的截取
|
|
380
|
-
this.updateVisibleOptions(index);
|
|
381
|
-
if (animate) {
|
|
382
|
-
return this.set({
|
|
383
|
-
currentIndex: index,
|
|
384
|
-
animationIndex: index,
|
|
385
|
-
offset: offset,
|
|
386
|
-
animate: true,
|
|
387
|
-
duration: time,
|
|
388
|
-
}).then(function () {
|
|
389
|
-
if (!userAction) {
|
|
390
|
-
_this.setData({
|
|
391
|
-
playing: false,
|
|
392
|
-
});
|
|
393
|
-
_this.$emit('animation-end');
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
_this.$emit('change', index);
|
|
397
|
-
_this.setData({
|
|
398
|
-
playing: false,
|
|
399
|
-
});
|
|
400
|
-
_this.$emit('animation-end');
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
return this.set({
|
|
404
|
-
offset: offset,
|
|
405
|
-
currentIndex: index,
|
|
406
|
-
animationIndex: index,
|
|
407
|
-
animate: !!animate,
|
|
408
|
-
}).then(function () {
|
|
409
|
-
if (!userAction) {
|
|
410
|
-
_this.setData({
|
|
411
|
-
playing: false,
|
|
412
|
-
});
|
|
413
|
-
_this.$emit('animation-end');
|
|
414
|
-
return;
|
|
415
|
-
}
|
|
416
|
-
_this.$emit('change', index);
|
|
417
|
-
_this.setData({
|
|
418
|
-
playing: false,
|
|
419
|
-
});
|
|
420
|
-
_this.$emit('animation-end');
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
this.setData({
|
|
424
|
-
playing: false,
|
|
425
|
-
});
|
|
426
|
-
this.$emit('animation-end');
|
|
427
|
-
return this.set({ offset: offset });
|
|
428
|
-
},
|
|
429
191
|
setValue: function (value) {
|
|
430
192
|
var options = this.data.options;
|
|
431
193
|
for (var i = 0; i < options.length; i++) {
|
|
432
194
|
if (this.getOptionText(options[i]) === value) {
|
|
433
|
-
return this.setIndex(i
|
|
195
|
+
return this.setIndex(i);
|
|
434
196
|
}
|
|
435
197
|
}
|
|
436
198
|
return Promise.resolve();
|
|
437
199
|
},
|
|
200
|
+
setIndex: function (index) {
|
|
201
|
+
this.setData({
|
|
202
|
+
activeIndex: index,
|
|
203
|
+
});
|
|
204
|
+
},
|
|
438
205
|
getValue: function () {
|
|
439
206
|
var data = this.data;
|
|
440
|
-
return data.options[data.
|
|
207
|
+
return data.options[data.activeIndex < 0 ? 0 : data.activeIndex];
|
|
208
|
+
},
|
|
209
|
+
viewOptionsChange: function (list) {
|
|
210
|
+
this.setData({
|
|
211
|
+
viewOptions: list,
|
|
212
|
+
});
|
|
213
|
+
},
|
|
214
|
+
activeIndexChange: function (index) {
|
|
215
|
+
this.setData({
|
|
216
|
+
activeIndex: index,
|
|
217
|
+
});
|
|
218
|
+
this.$emit('change', index);
|
|
219
|
+
},
|
|
220
|
+
animationIndexChange: function (index) {
|
|
221
|
+
this.setData({
|
|
222
|
+
animationIndex: index,
|
|
223
|
+
});
|
|
441
224
|
},
|
|
442
225
|
},
|
|
443
226
|
});
|
|
@@ -4,33 +4,71 @@
|
|
|
4
4
|
<view
|
|
5
5
|
class="{{ utils.bem('picker-column', { disabled }) }} custom-class"
|
|
6
6
|
style="{{ computed.rootStyle({ itemHeight, visibleItemCount }) }}"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
instanceId="{{instanceId}}"
|
|
8
|
+
id="{{instanceId}}"
|
|
9
|
+
data-options="{{options}}"
|
|
10
|
+
data-valuekey="{{valueKey}}"
|
|
11
|
+
data-itemheight="{{itemHeight}}"
|
|
12
|
+
data-visibleitemcount="{{visibleItemCount}}"
|
|
13
|
+
data-activeindex="{{activeIndex}}"
|
|
14
|
+
data-loop="{{loop}}"
|
|
15
|
+
data-animationtime="{{animationTime}}"
|
|
16
|
+
options="{{options}}"
|
|
17
|
+
activeindex="{{activeIndex}}"
|
|
18
|
+
loop="{{loop}}"
|
|
19
|
+
valuekey="{{valueKey}}"
|
|
20
|
+
itemheight="{{itemHeight}}"
|
|
21
|
+
visibleitemcount="{{visibleItemCount}}"
|
|
22
|
+
animationtime="{{animationTime}}"
|
|
23
|
+
change:options="{{computed.updateValue(instanceId, 'options')}}"
|
|
24
|
+
change:valuekey="{{computed.updateValue(instanceId,'valueKey')}}"
|
|
25
|
+
change:itemheight="{{computed.updateValue(instanceId,'itemHeight')}}"
|
|
26
|
+
change:visibleitemcount="{{computed.updateValue(instanceId, 'visibleItemCount')}}"
|
|
27
|
+
change:activeindex="{{computed.updateValue(instanceId,'activeIndex')}}"
|
|
28
|
+
change:loop="{{computed.updateValue(instanceId,'loop')}}"
|
|
29
|
+
change:animationtime="{{computed.updateValue(instanceId,'animationTime')}}"
|
|
30
|
+
change:instanceid="{{computed.updateValue(instanceId,'instanceId')}}"
|
|
31
|
+
bind:touchstart="{{computed.touchStart(instanceId)}}"
|
|
32
|
+
catch:touchmove="{{computed.touchMove(instanceId)}}"
|
|
33
|
+
bind:touchend="{{computed.touchEnd(instanceId)}}"
|
|
34
|
+
bind:touchcancel="{{computed.touchEnd(instanceId)}}"
|
|
11
35
|
>
|
|
12
|
-
<view
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
36
|
+
<view
|
|
37
|
+
id="options"
|
|
38
|
+
class="smart-picker-column__offset"
|
|
39
|
+
style="height: {{ itemHeight * options.length }}px;{{ computed.wrapperStyle({ offset, itemHeight, visibleItemCount, animate, duration, renderStart, unit, loop }) }}"
|
|
40
|
+
>
|
|
41
|
+
<view class="smart-picker-column__visual">
|
|
42
|
+
<view class="smart-picker-column__visual__item_1">
|
|
43
|
+
<view
|
|
44
|
+
wx:for="{{ computed.sliceArray(viewOptions, 0, 10) }}"
|
|
45
|
+
wx:key="index"
|
|
46
|
+
data-index="{{item}}"
|
|
47
|
+
style="{{computed.wrapperItemStyle({ itemHeight, animationIndex, index: item, visibleItemCount })}}"
|
|
48
|
+
class="smart-picker-column__item_{{index}} {{ computed.wrapperItemClass({ index: item, animationIndex, options })}}"
|
|
49
|
+
bind:tap="{{computed.tapItem(instanceId)}}"
|
|
50
|
+
>
|
|
51
|
+
<view
|
|
52
|
+
class="smart-picker-column__item__text"
|
|
53
|
+
style="{{computed.wrapperItemTextStyle({ fontStyle, activeStyle, index: item, animationIndex })}}"
|
|
54
|
+
></view>
|
|
55
|
+
</view>
|
|
56
|
+
</view>
|
|
57
|
+
<view class="smart-picker-column__visual__item_2">
|
|
58
|
+
<view
|
|
59
|
+
wx:for="{{ computed.sliceArray(viewOptions, 10) }}"
|
|
60
|
+
wx:key="index"
|
|
61
|
+
data-index="{{item}}"
|
|
62
|
+
style="{{computed.wrapperItemStyle({ itemHeight, fontStyle, activeStyle: item === currentIndex ? activeStyle : '', animationIndex, index: item, visibleItemCount })}}"
|
|
63
|
+
class="smart-picker-column__item_{{index + 10}} {{ computed.wrapperItemClass({ index: item, animationIndex, options })}}"
|
|
64
|
+
bind:tap="{{computed.tapItem(instanceId)}}"
|
|
65
|
+
>
|
|
66
|
+
<view
|
|
67
|
+
class="smart-picker-column__item__text"
|
|
68
|
+
style="{{computed.wrapperItemTextStyle({ fontStyle, activeStyle, index: item, animationIndex })}}"
|
|
69
|
+
></view>
|
|
70
|
+
</view>
|
|
23
71
|
</view>
|
|
24
|
-
</view>
|
|
25
|
-
</view>
|
|
26
|
-
<view class="smart-picker-column__mask">
|
|
27
|
-
<view
|
|
28
|
-
wx:for="{{ visibleItemCount }}"
|
|
29
|
-
wx:key="index"
|
|
30
|
-
class="smart-picker-column__mask__item"
|
|
31
|
-
data-index="{{ currentIndex + index - 2 }}"
|
|
32
|
-
bind:tap="onClickItem"
|
|
33
|
-
>
|
|
34
72
|
</view>
|
|
35
73
|
</view>
|
|
36
74
|
<view wx:if="{{unit}}" class="smart-picker-column__unit" style="height: {{ itemHeight }}px">
|