@tuya-miniapp/smart-ui 2.1.10 → 2.1.11-beta-2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. package/dist/action-sheet/index.css +1 -1
  2. package/dist/action-sheet/index.js +0 -8
  3. package/dist/action-sheet/index.wxml +1 -1
  4. package/dist/action-sheet/index.wxss +1 -1
  5. package/dist/cell/index.js +10 -4
  6. package/dist/common/utils.d.ts +1 -0
  7. package/dist/common/utils.js +6 -0
  8. package/dist/datetime-picker/demo/index.js +20 -0
  9. package/dist/datetime-picker/index.js +92 -14
  10. package/dist/datetime-picker/index.wxml +1 -0
  11. package/dist/field/index.js +1 -1
  12. package/dist/icon/index.wxs +3 -1
  13. package/dist/notice-bar/index.js +1 -1
  14. package/dist/picker/demo/index.js +1 -0
  15. package/dist/picker/index.wxml +2 -1
  16. package/dist/picker/shared.d.ts +4 -0
  17. package/dist/picker/shared.js +4 -0
  18. package/dist/picker-column/index.css +1 -1
  19. package/dist/picker-column/index.js +154 -44
  20. package/dist/picker-column/index.wxml +22 -11
  21. package/dist/picker-column/index.wxs +22 -5
  22. package/dist/picker-column/index.wxss +1 -1
  23. package/dist/stepper/index.js +2 -0
  24. package/dist/tag/index.js +1 -1
  25. package/lib/action-sheet/index.css +1 -1
  26. package/lib/action-sheet/index.js +0 -8
  27. package/lib/action-sheet/index.wxml +1 -1
  28. package/lib/action-sheet/index.wxss +1 -1
  29. package/lib/cell/index.js +15 -9
  30. package/lib/common/utils.d.ts +1 -0
  31. package/lib/common/utils.js +8 -1
  32. package/lib/datetime-picker/demo/index.js +20 -0
  33. package/lib/datetime-picker/index.js +97 -18
  34. package/lib/datetime-picker/index.wxml +1 -0
  35. package/lib/field/index.js +2 -2
  36. package/lib/icon/index.wxs +3 -1
  37. package/lib/notice-bar/index.js +2 -2
  38. package/lib/picker/demo/index.js +1 -0
  39. package/lib/picker/index.wxml +2 -1
  40. package/lib/picker/shared.d.ts +4 -0
  41. package/lib/picker/shared.js +4 -0
  42. package/lib/picker-column/index.css +1 -1
  43. package/lib/picker-column/index.js +192 -44
  44. package/lib/picker-column/index.wxml +22 -11
  45. package/lib/picker-column/index.wxs +22 -5
  46. package/lib/picker-column/index.wxss +1 -1
  47. package/lib/stepper/index.js +2 -0
  48. package/lib/tag/index.js +2 -2
  49. package/package.json +3 -3
@@ -23,13 +23,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
23
23
  var component_1 = require("../common/component");
24
24
  var validator_1 = require("../common/validator");
25
25
  var shared_1 = require("../picker/shared");
26
+ var utils_1 = require("../common/utils");
26
27
  var currentYear = new Date().getFullYear();
27
28
  function isValidDate(date) {
28
29
  return (0, validator_1.isDef)(date) && !isNaN(new Date(date).getTime());
29
30
  }
30
- function range(num, min, max) {
31
- return Math.min(Math.max(num, min), max);
32
- }
33
31
  function padZero(val) {
34
32
  return "00".concat(val).slice(-2);
35
33
  }
@@ -73,6 +71,18 @@ var defaultFormatter = function (type, value) {
73
71
  }, formatter: {
74
72
  type: null,
75
73
  value: defaultFormatter,
74
+ }, AMText: {
75
+ type: String,
76
+ value: 'AM',
77
+ }, PMText: {
78
+ type: String,
79
+ value: 'PM',
80
+ }, columnsOrder: {
81
+ type: Array,
82
+ value: [],
83
+ }, is12HoursTime: {
84
+ type: Boolean,
85
+ value: false,
76
86
  }, minDate: {
77
87
  type: Number,
78
88
  value: new Date(currentYear - 10, 0, 1).getTime(),
@@ -97,8 +107,12 @@ var defaultFormatter = function (type, value) {
97
107
  type: Number,
98
108
  value: 59,
99
109
  observer: 'updateValue',
110
+ }, formatterMap: {
111
+ type: Object,
112
+ value: undefined,
100
113
  } }),
101
114
  data: {
115
+ part: 0,
102
116
  innerValue: Date.now(),
103
117
  columns: [],
104
118
  },
@@ -129,18 +143,34 @@ var defaultFormatter = function (type, value) {
129
143
  }
130
144
  return this.picker;
131
145
  },
146
+ formatterFunc: function (type, value) {
147
+ var _a;
148
+ var _b;
149
+ var _c = this.data, formatterMap = _c.formatterMap, _d = _c.formatter, formatter = _d === void 0 ? defaultFormatter : _d;
150
+ var mapDetail = formatterMap === null || formatterMap === void 0 ? void 0 : formatterMap[type];
151
+ if (typeof mapDetail === 'string') {
152
+ return (0, utils_1.replacePlaceholders)(mapDetail, (_a = {}, _a[type] = value, _a));
153
+ }
154
+ if (typeof mapDetail === 'object') {
155
+ return (_b = mapDetail[value]) !== null && _b !== void 0 ? _b : formatter(type, value);
156
+ }
157
+ return formatter(type, value);
158
+ },
132
159
  updateColumns: function () {
133
- var _a = this.data, _b = _a.formatter, formatter = _b === void 0 ? defaultFormatter : _b, locale = _a.locale;
160
+ var _this = this;
161
+ var locale = this.data.locale;
134
162
  var results = this.getOriginColumns().map(function (column) { return ({
135
- values: column.values.map(function (value) { return formatter(column.type, value); }),
163
+ values: column.values.map(function (value) { return _this.formatterFunc(column.type, value); }),
164
+ order: column.order,
136
165
  unit: locale === null || locale === void 0 ? void 0 : locale[column.type],
137
166
  }); });
138
167
  return this.set({ columns: results });
139
168
  },
140
169
  getOriginColumns: function () {
141
- var filter = this.data.filter;
142
- var results = this.getRanges().map(function (_a) {
170
+ var _a = this.data, filter = _a.filter, is12HoursTime = _a.is12HoursTime, type = _a.type, AMText = _a.AMText, PMText = _a.PMText, columnsOrder = _a.columnsOrder;
171
+ var results = this.getRanges().map(function (_a, index) {
143
172
  var type = _a.type, range = _a.range;
173
+ var order = columnsOrder[index];
144
174
  var values = times(range[1] - range[0] + 1, function (index) {
145
175
  var value = range[0] + index;
146
176
  return type === 'year' ? "".concat(value) : padZero(value);
@@ -148,12 +178,37 @@ var defaultFormatter = function (type, value) {
148
178
  if (filter) {
149
179
  values = filter(type, values);
150
180
  }
151
- return { type: type, values: values };
181
+ return { type: type, values: values, order: order };
152
182
  });
183
+ if (is12HoursTime && type === 'time') {
184
+ return __spreadArray([
185
+ {
186
+ type: '12hours',
187
+ values: [AMText, PMText],
188
+ order: columnsOrder[0],
189
+ }
190
+ ], results.map(function (item, index) { return (__assign(__assign({}, item), { order: columnsOrder[index + 1] })); }), true).filter(Boolean);
191
+ }
153
192
  return results;
154
193
  },
155
194
  getRanges: function () {
156
195
  var data = this.data;
196
+ if (data.type === 'time' && data.is12HoursTime) {
197
+ var part = data.part;
198
+ return [
199
+ {
200
+ type: 'hour',
201
+ range: [
202
+ Math.max(part ? 13 : 1, data.minHour) - (part ? 12 : 0),
203
+ Math.min(part ? 24 : 12, data.maxHour) - (part ? 12 : 0),
204
+ ],
205
+ },
206
+ {
207
+ type: 'minute',
208
+ range: [data.minMinute, data.maxMinute],
209
+ },
210
+ ];
211
+ }
157
212
  if (data.type === 'time') {
158
213
  return [
159
214
  {
@@ -210,8 +265,8 @@ var defaultFormatter = function (type, value) {
210
265
  // time type
211
266
  if (!isDateType) {
212
267
  var _a = value.split(':'), hour = _a[0], minute = _a[1];
213
- hour = padZero(range(hour, data.minHour, data.maxHour));
214
- minute = padZero(range(minute, data.minMinute, data.maxMinute));
268
+ hour = padZero((0, utils_1.range)(hour, data.minHour, data.maxHour));
269
+ minute = padZero((0, utils_1.range)(minute, data.minMinute, data.maxMinute));
215
270
  return "".concat(hour, ":").concat(minute);
216
271
  }
217
272
  // date type
@@ -265,14 +320,26 @@ var defaultFormatter = function (type, value) {
265
320
  var data = this.data;
266
321
  var value;
267
322
  var picker = this.getPicker();
268
- var originColumns = this.getOriginColumns();
269
- if (data.type === 'time') {
270
- var indexes = picker.getIndexes();
323
+ var indexes = picker.getIndexes();
324
+ if (data.type === 'time' && data.is12HoursTime) {
325
+ var part = indexes[0], hour = indexes[1], minute = indexes[2];
326
+ this.setData({
327
+ part: part,
328
+ });
329
+ var originColumns = this.getOriginColumns();
330
+ value = "".concat((part ? 12 : 0) +
331
+ Number(originColumns[1].values[hour > originColumns[1].values.length - 1 ? originColumns[1].values.length - 1 : hour]), ":").concat(Number(originColumns[2].values[minute > originColumns[2].values.length - 1
332
+ ? originColumns[2].values.length - 1
333
+ : minute]));
334
+ }
335
+ else if (data.type === 'time') {
336
+ var originColumns = this.getOriginColumns();
271
337
  value = "".concat(+originColumns[0].values[indexes[0]], ":").concat(+originColumns[1].values[indexes[1]]);
272
338
  }
273
339
  else {
274
- var indexes = picker.getIndexes();
275
- var values = indexes.map(function (value, index) { return originColumns[index].values[value]; });
340
+ var originColumns_1 = this.getOriginColumns();
341
+ var indexes_1 = picker.getIndexes();
342
+ var values = indexes_1.map(function (value, index) { return originColumns_1[index].values[value]; });
276
343
  var year = getTrueValue(values[0]);
277
344
  var month = getTrueValue(values[1]);
278
345
  var maxDate = getMonthEndDay(year, month);
@@ -298,10 +365,22 @@ var defaultFormatter = function (type, value) {
298
365
  updateColumnValue: function (value) {
299
366
  var _this = this;
300
367
  var values = [];
301
- var type = this.data.type;
302
- var formatter = this.data.formatter || defaultFormatter;
368
+ var _a = this.data, type = _a.type, is12HoursTime = _a.is12HoursTime;
369
+ var formatter = this.formatterFunc;
303
370
  var picker = this.getPicker();
304
- if (type === 'time') {
371
+ if (type === 'time' && is12HoursTime) {
372
+ var _b = value.split(':'), hour = _b[0], minute = _b[1];
373
+ var part = Number(hour) > 0 && Number(hour) < 13 ? 0 : 1;
374
+ this.setData({
375
+ part: part,
376
+ });
377
+ values = [
378
+ part,
379
+ formatter('hour', part ? (!hour ? 12 : hour - 12) : hour),
380
+ formatter('minute', minute),
381
+ ];
382
+ }
383
+ else if (type === 'time') {
305
384
  var pair = value.split(':');
306
385
  values = [formatter('hour', pair[0]), formatter('minute', pair[1])];
307
386
  }
@@ -10,6 +10,7 @@
10
10
  visible-item-count="{{ visibleItemCount }}"
11
11
  confirm-button-text="{{ confirmButtonText }}"
12
12
  cancel-button-text="{{ cancelButtonText }}"
13
+ change-animation="{{ changeAnimation }}"
13
14
  bind:change="onChange"
14
15
  bind:confirm="onConfirm"
15
16
  bind:cancel="onCancel"
@@ -17,7 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  var utils_1 = require("../common/utils");
18
18
  var component_1 = require("../common/component");
19
19
  var props_1 = require("./props");
20
- var Xmark_1 = __importDefault(require("@tuya-miniapp/icons/dist/svg/Xmark"));
20
+ var Xmark_js_1 = __importDefault(require("@tuya-miniapp/icons/dist/svg/Xmark.js"));
21
21
  (0, component_1.SmartComponent)({
22
22
  field: true,
23
23
  classes: ['input-class', 'right-icon-class', 'label-class'],
@@ -40,7 +40,7 @@ var Xmark_1 = __importDefault(require("@tuya-miniapp/icons/dist/svg/Xmark"));
40
40
  value: '6.2em',
41
41
  }, clearIcon: {
42
42
  type: String,
43
- value: Xmark_1.default,
43
+ value: Xmark_js_1.default,
44
44
  }, extraEventParams: {
45
45
  type: Boolean,
46
46
  value: false,
@@ -14,7 +14,7 @@ function rootClass(data) {
14
14
  var classes = ['custom-class'];
15
15
 
16
16
  if (data.classPrefix !== 'smart-icon') {
17
- classes.push('smart-icon--custom')
17
+ classes.push('smart-icon--custom');
18
18
  }
19
19
 
20
20
  if (data.classPrefix != null) {
@@ -54,6 +54,8 @@ function svgStyle(data) {
54
54
  {
55
55
  '-webkit-mask-image': imageBase64Src,
56
56
  '-webkit-mask-size': 'contain',
57
+ '-webkit-mask-repeat': 'no-repeat',
58
+ '-webkit-mask-position': 'center',
57
59
  'mask-image': imageBase64Src,
58
60
  'mask-size': 'contain',
59
61
  width: data.size,
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  var component_1 = require("../common/component");
7
7
  var utils_1 = require("../common/utils");
8
- var Xmark_1 = __importDefault(require("@tuya-miniapp/icons/dist/svg/Xmark"));
8
+ var Xmark_js_1 = __importDefault(require("@tuya-miniapp/icons/dist/svg/Xmark.js"));
9
9
  var Right_1 = __importDefault(require("@tuya-miniapp/icons/dist/svg/Right"));
10
10
  (0, component_1.SmartComponent)({
11
11
  props: {
@@ -83,7 +83,7 @@ var Right_1 = __importDefault(require("@tuya-miniapp/icons/dist/svg/Right"));
83
83
  wrapable: Boolean,
84
84
  },
85
85
  data: {
86
- Xmark: Xmark_1.default,
86
+ Xmark: Xmark_js_1.default,
87
87
  Right: Right_1.default,
88
88
  show: true,
89
89
  },
@@ -51,6 +51,7 @@ var toast_1 = __importDefault(require("../../toast/toast"));
51
51
  methods: {
52
52
  onChange1: function (event) {
53
53
  var _a = event.detail, value = _a.value, index = _a.index;
54
+ console.log("Value: ".concat(value, ", Index\uFF1A").concat(index));
54
55
  (0, toast_1.default)({
55
56
  context: this,
56
57
  message: "Value: ".concat(value, ", Index\uFF1A").concat(index),
@@ -19,10 +19,11 @@
19
19
  data-index="{{ index }}"
20
20
  custom-class="column-class"
21
21
  value-key="{{ valueKey }}"
22
- style="{{ item.style }}"
22
+ style="order: {{ item.order }}; {{ item.style }}"
23
23
  active-style="{{ activeStyle }}"
24
24
  options="{{ item.values }}"
25
25
  unit="{{ item.unit || unit }}"
26
+ changeAnimation="{{ changeAnimation }}"
26
27
  default-index="{{ item.defaultIndex || defaultIndex }}"
27
28
  active-index="{{ item.activeIndex || activeIndex }}"
28
29
  item-height="{{ itemHeight }}"
@@ -18,4 +18,8 @@ export declare const pickerProps: {
18
18
  type: NumberConstructor;
19
19
  value: number;
20
20
  };
21
+ changeAnimation: {
22
+ type: BooleanConstructor;
23
+ value: boolean;
24
+ };
21
25
  };
@@ -21,4 +21,8 @@ exports.pickerProps = {
21
21
  type: Number,
22
22
  value: 44,
23
23
  },
24
+ changeAnimation: {
25
+ type: Boolean,
26
+ value: true,
27
+ },
24
28
  };
@@ -1 +1 @@
1
- @import '../common/index.css';.smart-picker-column{color:var(--picker-option-selected-text-color,var(--app-B6-N1,#000));font-size:var(--picker-option-font-size,16px);font-weight:var(--font-weight-bold,500);position:relative;text-align:center}.smart-picker-column__item{padding:0 5px}.smart-picker-column__item--selected{color:var(--picker-option-selected-text-color,var(--app-B6-N1,#000));font-weight:var(--font-weight-bold,500)}.smart-picker-column__item--disabled{opacity:var(--picker-option-disabled-opacity,.3)}.smart-picker-column__unit{align-items:center;display:flex;justify-content:center;position:absolute;top:50%;transform:translateY(-50%);width:100%}.smart-picker-column__unit_text{color:var(--picker-option-unit-text-color,var(--app-B6-N4,rgba(0,0,0,.4)));font-size:var(--picker-option-unit-font-size,12px)}.smart-picker-column__unit_hidden{opacity:0}.smart-picker-column__max-text{font-weight:var(--font-weight-bold,500);opacity:0}
1
+ @import '../common/index.css';.smart-picker-column{color:var(--picker-option-selected-text-color,var(--app-B6-N1,#000));font-size:var(--picker-option-font-size,16px);font-weight:var(--font-weight-bold,500);text-align:center}.smart-picker-column,.smart-picker-column__offset{position:relative;width:100%}.smart-picker-column__visual{position:absolute;top:0;width:100%}.smart-picker-column__item{pointer-events:none}.smart-picker-column__item--selected{color:var(--picker-option-selected-text-color,var(--app-B6-N1,#000));font-weight:var(--font-weight-bold,500)}.smart-picker-column__item--disabled{opacity:var(--picker-option-disabled-opacity,.3)}.smart-picker-column__mask{background:transparent;display:flex;flex-direction:column;height:100%;position:absolute;top:0;width:100%;z-index:10}.smart-picker-column__mask__item{flex:1}.smart-picker-column__unit{align-items:center;display:flex;justify-content:center;position:absolute;top:50%;transform:translateY(-50%);width:100%}.smart-picker-column__unit_text{color:var(--picker-option-unit-text-color,var(--app-B6-N4,rgba(0,0,0,.4)));font-size:var(--picker-option-unit-font-size,12px)}.smart-picker-column__unit_hidden{opacity:0}.smart-picker-column__max-text{font-weight:var(--font-weight-bold,500);opacity:0}
@@ -1,9 +1,54 @@
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
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
+ if (ar || !(i in from)) {
41
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
+ ar[i] = from[i];
43
+ }
44
+ }
45
+ return to.concat(ar || Array.prototype.slice.call(from));
46
+ };
2
47
  Object.defineProperty(exports, "__esModule", { value: true });
3
48
  var component_1 = require("../common/component");
4
49
  var utils_1 = require("../common/utils");
5
50
  var validator_1 = require("../common/validator");
6
- var DEFAULT_DURATION = 200;
51
+ var DEFAULT_DURATION = 400;
7
52
  (0, component_1.SmartComponent)({
8
53
  classes: ['active-class'],
9
54
  props: {
@@ -27,11 +72,15 @@ var DEFAULT_DURATION = 200;
27
72
  type: Number,
28
73
  value: 0,
29
74
  },
75
+ changeAnimation: {
76
+ type: Boolean,
77
+ value: true,
78
+ },
30
79
  activeIndex: {
31
80
  type: Number,
32
81
  value: -1,
33
82
  observer: function (index) {
34
- this.setIndex(index, false, true);
83
+ this.setIndex(index, false, this.data.changeAnimation);
35
84
  },
36
85
  },
37
86
  unit: {
@@ -50,57 +99,158 @@ var DEFAULT_DURATION = 200;
50
99
  renderStart: 0,
51
100
  animate: false,
52
101
  maxText: '',
102
+ timer: null,
103
+ // animationIndex: -1,
104
+ preOffsetList: [],
53
105
  },
54
106
  created: function () {
55
107
  var _a = this.data, defaultIndex = _a.defaultIndex, activeIndex = _a.activeIndex, options = _a.options;
56
108
  this.updateUint(options);
57
- this.setIndex(activeIndex !== -1 ? activeIndex : defaultIndex, false, true);
109
+ this.setIndex(activeIndex !== -1 ? activeIndex : defaultIndex, false, this.data.changeAnimation);
58
110
  },
59
111
  methods: {
60
112
  getCount: function () {
61
113
  return this.data.options.length;
62
114
  },
63
115
  onTouchStart: function (event) {
116
+ if (this.data.timer) {
117
+ clearTimeout(this.data.timer);
118
+ this.setData({
119
+ timer: null,
120
+ });
121
+ }
64
122
  this.setData({
65
123
  startY: event.touches[0].clientY,
66
124
  startOffset: this.data.offset,
67
- duration: 0,
125
+ duration: 100,
126
+ timer: null,
127
+ preOffsetList: [this.data.offset],
68
128
  });
69
129
  },
70
130
  onTouchMove: function (event) {
71
131
  var data = this.data;
132
+ var preOffsetList = data.preOffsetList;
72
133
  var deltaY = event.touches[0].clientY - data.startY;
134
+ var offset = (0, utils_1.range)(data.startOffset + deltaY, -(this.getCount() * data.itemHeight), data.itemHeight);
135
+ var direction = this.checkIsDown(offset);
136
+ // 上一次滚动的索引
137
+ var preIndex = (0, utils_1.range)(Math.round(-preOffsetList[preOffsetList.length - 1] / data.itemHeight), 0, this.getCount() - 1);
138
+ // 最终定位索引
139
+ var index = (0, utils_1.range)(Math.round(-offset / data.itemHeight), 0, this.getCount() - 1);
140
+ if ((direction === 'up' && index < data.renderStart + 8) ||
141
+ (direction === 'down' && index > data.renderStart + data.renderNum - 8)) {
142
+ this.updateVisibleOptions(index);
143
+ }
144
+ // 索引变化时 粗发震动反馈
145
+ if (index !== preIndex) {
146
+ // @ts-ignore
147
+ this.vibrateShort();
148
+ }
149
+ // const animationIndex = Math.abs(-offset / data.itemHeight);
73
150
  this.setData({
74
- offset: (0, utils_1.range)(data.startOffset + deltaY, -(this.getCount() * data.itemHeight), data.itemHeight),
151
+ offset: offset,
152
+ // animationIndex: animationIndex,
153
+ preOffsetList: __spreadArray(__spreadArray([], data.preOffsetList, true), [offset], false),
154
+ animate: false,
75
155
  });
76
156
  },
77
157
  onTouchEnd: function () {
158
+ return __awaiter(this, void 0, void 0, function () {
159
+ var data, preOffsetList, preOffset, isSameTouch, direction, offset, countHeight, animationOffset, finOffset, index, offsetData, countVibrate;
160
+ var _this = this;
161
+ return __generator(this, function (_a) {
162
+ switch (_a.label) {
163
+ case 0:
164
+ data = this.data;
165
+ preOffsetList = data.preOffsetList;
166
+ 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]));
167
+ if (isNaN(preOffset))
168
+ preOffset = 0;
169
+ preOffset = Math.min(preOffset, 40);
170
+ isSameTouch = (preOffsetList[preOffsetList.length - 1] === preOffsetList[preOffsetList.length - 2] &&
171
+ preOffsetList[preOffsetList.length - 2] === preOffsetList[preOffsetList.length - 3]) ||
172
+ preOffsetList[preOffsetList.length - 1] === -(this.getCount() * data.itemHeight) ||
173
+ preOffsetList[preOffsetList.length - 1] === data.itemHeight;
174
+ direction = this.checkIsDown();
175
+ offset = Math.abs(preOffset) < 3 || isSameTouch || !direction
176
+ ? data.offset
177
+ : data.offset + (direction === 'down' ? -preOffset : preOffset) * 10;
178
+ countHeight = (this.getCount() - 1) * data.itemHeight;
179
+ animationOffset = (0, utils_1.range)(offset, -(this.getCount() * data.itemHeight), data.itemHeight);
180
+ finOffset = animationOffset < -countHeight ? -countHeight : animationOffset > 0 ? 0 : animationOffset;
181
+ index = (0, utils_1.range)(Math.round(-finOffset / data.itemHeight), 0, this.getCount() - 1);
182
+ offsetData = -index * data.itemHeight;
183
+ // 增加惯性音效
184
+ if (Math.abs(offsetData - data.offset) > data.itemHeight && !isSameTouch) {
185
+ countVibrate = Math.abs(offsetData - data.offset) / data.itemHeight;
186
+ // @ts-ignore
187
+ this.vibrateShort(Math.floor(countVibrate), 800);
188
+ }
189
+ // 最终定位索引
190
+ this.setData({
191
+ duration: isSameTouch ? 150 : 800,
192
+ // animationIndex: index,
193
+ offset: offsetData,
194
+ animate: true,
195
+ });
196
+ if (!((direction === 'up' && index < data.renderStart + 8) ||
197
+ (direction === 'down' && index > data.renderStart + data.renderNum - 8))) return [3 /*break*/, 2];
198
+ return [4 /*yield*/, this.updateVisibleOptions(index)];
199
+ case 1:
200
+ _a.sent();
201
+ _a.label = 2;
202
+ case 2:
203
+ // 更新索引
204
+ if (index !== data.currentIndex) {
205
+ this.setData({
206
+ timer: setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
207
+ return __generator(this, function (_a) {
208
+ this.setIndex(index, true, false);
209
+ return [2 /*return*/];
210
+ });
211
+ }); }, isSameTouch ? 150 : 800),
212
+ });
213
+ }
214
+ return [2 /*return*/];
215
+ }
216
+ });
217
+ });
218
+ },
219
+ checkIsDown: function (curr) {
78
220
  var data = this.data;
79
- if (data.offset !== data.startOffset) {
80
- var index = (0, utils_1.range)(Math.round(-data.offset / data.itemHeight), 0, this.getCount() - 1);
81
- this.setIndex(index, true, true);
82
- }
221
+ var preOffsetList = data.preOffsetList;
222
+ var currOffset = curr === undefined ? preOffsetList[preOffsetList.length - 1] : curr;
223
+ var preOffset = curr === undefined
224
+ ? preOffsetList[preOffsetList.length - 2]
225
+ : preOffsetList[preOffsetList.length - 1];
226
+ if (currOffset === undefined || preOffset === undefined || currOffset === preOffset)
227
+ return;
228
+ return currOffset < preOffset ? 'down' : 'up';
83
229
  },
84
- onTransitionEnd: function () {
85
- var _a = this.data, options = _a.options, visibleItemCount = _a.visibleItemCount, currentIndex = _a.currentIndex;
86
- var renderNum = 0;
87
- var renderStart = 0;
88
- if (visibleItemCount < 20 && options.length > visibleItemCount) {
89
- // 选项多于20个时,进行列表优化
90
- renderNum = Math.max(visibleItemCount * 2, 20);
91
- renderStart = Math.max(0, currentIndex - renderNum / 2);
92
- var optionsV = options.slice(renderStart, renderStart + renderNum);
93
- this.setData({ optionsV: optionsV, renderStart: renderStart, renderNum: renderNum, animate: false });
94
- }
95
- else {
96
- this.setData({ animate: false });
97
- }
98
- if (this.fireChange) {
99
- this.$emit('change', currentIndex);
230
+ vibrateShort: function (count, time) {
231
+ var _this = this;
232
+ if (time === void 0) { time = 1000; }
233
+ if (!count) {
234
+ // @ts-ignore
235
+ ty.vibrateShort({ type: 'light' });
236
+ return;
100
237
  }
238
+ var has = 0;
239
+ var timer = setInterval(function () {
240
+ if (has >= count) {
241
+ clearInterval(timer);
242
+ return;
243
+ }
244
+ has++;
245
+ _this.vibrateShort();
246
+ }, time / count - 20);
101
247
  },
102
248
  onClickItem: function (event) {
103
249
  var index = event.currentTarget.dataset.index;
250
+ if (index === this.data.currentIndex || index < 0 || index > this.data.options.length - 1) {
251
+ return;
252
+ }
253
+ this.vibrateShort(Math.abs(index - this.data.currentIndex), DEFAULT_DURATION);
104
254
  this.setIndex(index, true, true);
105
255
  },
106
256
  updateUint: function (options) {
@@ -122,7 +272,7 @@ var DEFAULT_DURATION = 200;
122
272
  if (visibleItemCount < 20 && options.length > visibleItemCount) {
123
273
  var renderNum = 0;
124
274
  var renderStart = 0;
125
- // 选项多于20个时,进行列表优化
275
+ // 选项多于 20 个时,进行列表优化
126
276
  renderNum = Math.max(visibleItemCount * 2, 20);
127
277
  renderStart = Math.max(0, targetIndex - renderNum / 2);
128
278
  var renderEnd = Math.min(options.length, renderStart + renderNum);
@@ -161,36 +311,34 @@ var DEFAULT_DURATION = 200;
161
311
  var data = this.data;
162
312
  return (0, validator_1.isObj)(option) && data.valueKey in option ? option[data.valueKey] : option;
163
313
  },
164
- setIndex: function (index, userAction, animate) {
314
+ setIndex: function (index, userAction, animate, time) {
165
315
  var _this = this;
316
+ if (time === void 0) { time = DEFAULT_DURATION; }
166
317
  var data = this.data;
167
318
  index = this.adjustIndex(index) || 0;
168
319
  var offset = -index * data.itemHeight;
169
- this.fireChange = false;
170
320
  if (index !== data.currentIndex) {
171
321
  // 需要动画的情况下,保持最大的截取
322
+ this.updateVisibleOptions(index);
172
323
  if (animate) {
173
- return this.updateVisibleOptions(index).then(function () {
174
- _this.set({
175
- currentIndex: index,
176
- offset: offset,
177
- animate: true,
178
- duration: DEFAULT_DURATION,
179
- }).then(function () {
180
- if (!userAction)
181
- return;
182
- if ([0, data.optionsV.length - 1].includes(index)) {
183
- _this.$emit('change', index);
184
- return;
185
- }
186
- _this.fireChange = true;
187
- });
324
+ return this.set({
325
+ currentIndex: index,
326
+ // animationIndex: index,
327
+ offset: offset,
328
+ animate: true,
329
+ duration: time,
330
+ }).then(function () {
331
+ if (!userAction)
332
+ return;
333
+ console.log('change', index);
334
+ _this.$emit('change', index);
188
335
  });
189
336
  }
190
337
  return this.set({
191
338
  optionsV: data.options,
192
339
  offset: offset,
193
340
  currentIndex: index,
341
+ // animationIndex: index,
194
342
  renderStart: 0,
195
343
  animate: !!animate,
196
344
  }).then(function () {
@@ -203,7 +351,7 @@ var DEFAULT_DURATION = 200;
203
351
  var options = this.data.options;
204
352
  for (var i = 0; i < options.length; i++) {
205
353
  if (this.getOptionText(options[i]) === value) {
206
- return this.setIndex(i, false, true);
354
+ return this.setIndex(i, false, this.data.changeAnimation);
207
355
  }
208
356
  }
209
357
  return Promise.resolve();