@tuya-miniapp/smart-ui 2.6.0-beta-7 → 2.6.0-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.
@@ -1,3 +1,14 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
1
12
  import { SmartComponent } from '../common/component';
2
13
  import { isDef } from '../common/validator';
3
14
  import { pickerProps } from '../picker/shared';
@@ -29,6 +40,18 @@ function getTrueValue(formattedValue) {
29
40
  function getMonthEndDay(year, month) {
30
41
  return 32 - new Date(year, month - 1, 32).getDate();
31
42
  }
43
+ function findIntersection(range1, range2) {
44
+ const [start1, end1] = range1;
45
+ const [start2, end2] = range2;
46
+ // 确定交集的开始和结束
47
+ const intersectionStart = Math.max(start1, start2);
48
+ const intersectionEnd = Math.min(end1, end2);
49
+ // 检查是否有交集
50
+ if (intersectionStart <= intersectionEnd) {
51
+ return [intersectionStart, intersectionEnd];
52
+ }
53
+ return []; // 没有交集
54
+ }
32
55
  const defaultFormatter = (type, value) => value;
33
56
  SmartComponent({
34
57
  classes: ['active-class', 'toolbar-class', 'column-class'],
@@ -94,8 +117,9 @@ SmartComponent({
94
117
  value: undefined,
95
118
  } }),
96
119
  data: {
97
- part: 0,
120
+ part: 'am',
98
121
  innerValue: Date.now(),
122
+ isCreated: false,
99
123
  columns: [],
100
124
  },
101
125
  created() {
@@ -104,12 +128,17 @@ SmartComponent({
104
128
  if (innerValue !== this.data.value) {
105
129
  this.$emit('input', innerValue);
106
130
  }
131
+ this.setData({
132
+ isCreated: true,
133
+ });
107
134
  },
108
135
  methods: {
109
136
  updateValue() {
110
- const { data } = this;
111
- const val = this.correctValue(data.value);
112
- const isEqual = val === data.innerValue;
137
+ const { value, innerValue, isCreated } = this.data;
138
+ if (!isCreated)
139
+ return;
140
+ const val = this.correctValue(value);
141
+ const isEqual = val === innerValue;
113
142
  this.updateColumnValue(val);
114
143
  if (!isEqual) {
115
144
  this.$emit('input', val);
@@ -127,7 +156,7 @@ SmartComponent({
127
156
  formatterFunc(type, value, data) {
128
157
  var _a, _b;
129
158
  if (type === 'part') {
130
- return value === 0 ? data.amText : data.pmText;
159
+ return value === 'am' ? data.amText : data.pmText;
131
160
  }
132
161
  const { formatterMap, formatter = defaultFormatter } = (_a = this === null || this === void 0 ? void 0 : this.data) !== null && _a !== void 0 ? _a : data;
133
162
  const mapDetail = formatterMap === null || formatterMap === void 0 ? void 0 : formatterMap[type];
@@ -157,23 +186,33 @@ SmartComponent({
157
186
  return this.setData({ columns: results });
158
187
  },
159
188
  getOriginColumns() {
160
- const { filter, is12HourClock, type, amText, pmText, columnsOrder } = this.data;
161
- const results = this.getRanges().map(({ type, range }, index) => {
189
+ const { part, filter, is12HourClock, type, amText, pmText, columnsOrder, minHour, maxHour } = this.data;
190
+ const results = this.getRanges().map(({ type: timeType, range }, index) => {
162
191
  const order = columnsOrder[index];
163
192
  let values = times(range[1] - range[0] + 1, index => {
164
193
  const value = range[0] + index;
165
- return type === 'year' ? `${value}` : padZero(value);
194
+ if (is12HourClock && type === 'time' && timeType === 'hour') {
195
+ if (part === 'pm') {
196
+ if (value === 12)
197
+ return '12';
198
+ return padZero(value - 12);
199
+ }
200
+ if (value === 0)
201
+ return '12';
202
+ return padZero(value);
203
+ }
204
+ return timeType === 'year' ? `${value}` : padZero(value);
166
205
  });
167
206
  if (filter) {
168
- values = filter(type, values);
207
+ values = filter(timeType, values);
169
208
  }
170
- return { type, values, order };
209
+ return { type: timeType, values, order };
171
210
  });
172
211
  if (is12HourClock && type === 'time') {
173
212
  return [
174
213
  {
175
214
  type: '12HourClock',
176
- values: [amText, pmText],
215
+ values: minHour > 11 ? [pmText] : maxHour < 12 ? [amText] : [amText, pmText],
177
216
  order: columnsOrder[0],
178
217
  },
179
218
  ...results.map((item, index) => (Object.assign(Object.assign({}, item), { order: columnsOrder[index + 1] }))),
@@ -185,13 +224,11 @@ SmartComponent({
185
224
  const { data } = this;
186
225
  if (data.type === 'time' && data.is12HourClock) {
187
226
  const { part } = data;
227
+ const time12Range = part === 'pm' ? [12, 23] : [0, 11];
188
228
  return [
189
229
  {
190
230
  type: 'hour',
191
- range: [
192
- Math.max(part ? 13 : 1, data.minHour) - (part ? 12 : 0),
193
- Math.min(part ? 24 : 12, data.maxHour) - (part ? 12 : 0),
194
- ],
231
+ range: findIntersection(time12Range, [data.minHour, data.maxHour]),
195
232
  },
196
233
  {
197
234
  type: 'minute',
@@ -241,7 +278,7 @@ SmartComponent({
241
278
  result.splice(2, 3);
242
279
  return result;
243
280
  },
244
- correctValue(value, isOutSide) {
281
+ correctValue(value) {
245
282
  const { data } = this;
246
283
  // validate value
247
284
  const isDateType = data.type !== 'time';
@@ -255,17 +292,11 @@ SmartComponent({
255
292
  // time type
256
293
  if (!isDateType) {
257
294
  let [hour, minute] = value.split(':');
258
- if (Number(hour) === 0 && data.minHour > 0) {
259
- hour = 24;
260
- }
261
- if (Number(hour) === 24 && data.maxHour < 24) {
295
+ if (Number(hour) === 24) {
262
296
  hour = 0;
263
297
  }
264
298
  hour = padZero(range(hour, data.minHour, data.maxHour));
265
299
  minute = padZero(range(minute, data.minMinute, data.maxMinute));
266
- if (isOutSide && Number(hour) === 24) {
267
- hour = 0;
268
- }
269
300
  return `${hour}:${minute}`;
270
301
  }
271
302
  // date type
@@ -319,15 +350,19 @@ SmartComponent({
319
350
  const picker = this.getPicker();
320
351
  const indexes = picker.getIndexes();
321
352
  if (data.type === 'time' && data.is12HourClock) {
322
- const [part, hour, minute] = indexes;
353
+ const originColumns = this.getOriginColumns();
354
+ const [partText, hour, minute] = indexes.map((item, index) => originColumns[index].values[item]);
355
+ const part = partText === this.data.pmText ? 'pm' : 'am';
323
356
  this.setData({
324
357
  part,
325
358
  });
326
- const originColumns = this.getOriginColumns();
327
- value = `${(part ? 12 : 0) +
328
- Number(originColumns[1].values[hour > originColumns[1].values.length - 1 ? originColumns[1].values.length - 1 : hour])}:${Number(originColumns[2].values[minute > originColumns[2].values.length - 1
329
- ? originColumns[2].values.length - 1
330
- : minute])}`;
359
+ value = `${part === 'pm'
360
+ ? hour === '12'
361
+ ? 12
362
+ : Number(hour) + 12
363
+ : hour === '12'
364
+ ? 0
365
+ : Number(hour)}:${Number(minute)}`;
331
366
  }
332
367
  else if (data.type === 'time') {
333
368
  const originColumns = this.getOriginColumns();
@@ -353,26 +388,37 @@ SmartComponent({
353
388
  }
354
389
  value = new Date(year, month - 1, date, hour, minute);
355
390
  }
356
- value = this.correctValue(value, true);
357
- const innerValue = this.correctValue(value);
358
- this.updateColumnValue(innerValue);
391
+ value = this.correctValue(value);
392
+ this.updateColumnValue(value);
359
393
  picker.value = value;
360
394
  this.$emit('input', value);
361
395
  this.$emit('change', picker);
362
396
  },
363
397
  updateColumnValue(value) {
364
398
  let values = [];
399
+ const _a = this.data, { columns, part, value: outerValue } = _a, rest = __rest(_a, ["columns", "part", "value"]);
400
+ rest.innerValue = value;
401
+ const dataStr = JSON.stringify(rest);
402
+ if (dataStr === this.preDataStr)
403
+ return;
404
+ this.preDataStr = dataStr;
365
405
  const { type, is12HourClock } = this.data;
366
406
  const formatter = this.formatterFunc;
367
407
  if (type === 'time' && is12HourClock) {
368
408
  const [hour, minute] = value.split(':');
369
- const part = Number(hour) > 0 && Number(hour) < 13 ? 0 : 1;
409
+ const part = Number(hour) < 12 ? 'am' : 'pm';
370
410
  this.setData({
371
411
  part,
372
412
  });
373
413
  values = [
374
414
  formatter('part', part, this.data),
375
- formatter('hour', part ? (!hour ? '12' : (hour - 12).toString().padStart(2, '0')) : hour, this.data),
415
+ formatter('hour', part === 'am'
416
+ ? hour === '0'
417
+ ? '12'
418
+ : hour
419
+ : hour === '12'
420
+ ? '12'
421
+ : padZero(Number(hour) - 12), this.data),
376
422
  formatter('minute', minute, this.data),
377
423
  ];
378
424
  }
@@ -1,7 +1,7 @@
1
1
  import { SmartComponent } from '../common/component';
2
2
  import { pickerProps } from './shared';
3
3
  SmartComponent({
4
- classes: ['active-class', 'toolbar-class', 'column-class'],
4
+ classes: ['hairline-class', 'active-class', 'toolbar-class', 'column-class'],
5
5
  props: Object.assign(Object.assign({}, pickerProps), { valueKey: {
6
6
  type: String,
7
7
  value: 'text',
@@ -38,7 +38,7 @@
38
38
  />
39
39
 
40
40
  <view
41
- class="smart-picker__frame smart-hairline--top-bottom"
41
+ class="smart-picker__frame smart-hairline--top-bottom hairline-class"
42
42
  style="{{ computed.frameStyle({ itemHeight }) }}"
43
43
  />
44
44
  </view>
@@ -19,6 +19,7 @@ function maskStyle(data) {
19
19
  function frameStyle(data) {
20
20
  return style({
21
21
  height: addUnit(data.itemHeight),
22
+ position: 'absolute'
22
23
  });
23
24
  }
24
25
 
@@ -52,7 +52,7 @@ SmartComponent({
52
52
  observer(index) {
53
53
  if (!this.data.isInit)
54
54
  return;
55
- this.setIndex(index, false, this.data.changeAnimation);
55
+ this.setIndex(index, false, this.data.changeAnimation, this.data.animationTime);
56
56
  },
57
57
  },
58
58
  unit: {
@@ -83,7 +83,7 @@ SmartComponent({
83
83
  created() {
84
84
  const { defaultIndex, activeIndex, options } = this.data;
85
85
  this.updateUint(options);
86
- this.setIndex(activeIndex !== -1 ? activeIndex : defaultIndex, false, this.data.changeAnimation);
86
+ this.setIndex(activeIndex !== -1 ? activeIndex : defaultIndex, false, this.data.changeAnimation, this.data.animationTime);
87
87
  this.setData({
88
88
  isInit: true,
89
89
  });
@@ -196,16 +196,19 @@ SmartComponent({
196
196
  }
197
197
  // 更新索引
198
198
  if (index !== data.currentIndex) {
199
+ const time = isSameTouch ? 150 : data.animationTime;
200
+ // if (!isSameTouch) {
201
+ // this.timer = setInterval(() => {
202
+ // if (Math.abs(this.data.animationIndex - index) < 0.5) return clearInterval(this.timer);
203
+ // this.setData({
204
+ // animationIndex: this.data.animationIndex + (index - data.currentIndex > 0 ? 1 : -1),
205
+ // });
206
+ // }, data.animationTime / Math.abs(index - data.currentIndex));
207
+ // }
199
208
  return this.setData({
200
209
  timer: setTimeout(() => __awaiter(this, void 0, void 0, function* () {
201
- this.setIndex(index, true, false);
202
- // await this.setData({
203
- // timer: null,
204
- // currentIndex: index,
205
- // // animationIndex: index,
206
- // });
207
- // this.$emit('change', index);
208
- }), isSameTouch ? 150 : data.animationTime),
210
+ this.setIndex(index, true, false, this.data.animationTime);
211
+ }), time),
209
212
  });
210
213
  }
211
214
  this.setData({
@@ -225,7 +228,7 @@ SmartComponent({
225
228
  return;
226
229
  return currOffset < preOffset ? 'down' : 'up';
227
230
  },
228
- vibrateShort(count, time = 1000) {
231
+ vibrateShort(count, time = DEFAULT_DURATION) {
229
232
  if (!count) {
230
233
  ty.vibrateShort({ type: 'light' });
231
234
  return;
@@ -248,7 +251,7 @@ SmartComponent({
248
251
  return;
249
252
  }
250
253
  this.vibrateShort(Math.abs(index - this.data.currentIndex), DEFAULT_DURATION);
251
- this.setIndex(index, true, true);
254
+ this.setIndex(index, true, true, this.data.animationTime);
252
255
  },
253
256
  updateUint(options) {
254
257
  const { unit, valueKey } = this.data;
@@ -312,6 +315,10 @@ SmartComponent({
312
315
  const { data } = this;
313
316
  index = this.adjustIndex(index) || 0;
314
317
  const offset = -index * data.itemHeight;
318
+ if (this.timer) {
319
+ clearTimeout(this.timer);
320
+ this.timer = null;
321
+ }
315
322
  if (!data.playing) {
316
323
  this.$emit('animation-start');
317
324
  this.setData({
@@ -373,7 +380,7 @@ SmartComponent({
373
380
  const { options } = this.data;
374
381
  for (let i = 0; i < options.length; i++) {
375
382
  if (this.getOptionText(options[i]) === value) {
376
- return this.setIndex(i, false, this.data.changeAnimation);
383
+ return this.setIndex(i, false, this.data.changeAnimation, this.data.animationTime);
377
384
  }
378
385
  }
379
386
  return Promise.resolve();
@@ -14,10 +14,10 @@
14
14
  <view
15
15
  wx:for="{{ optionsV }}"
16
16
  wx:for-item="option"
17
- wx:key="index"
17
+ wx:key="*this"
18
18
  data-index="{{ renderStart + index }}"
19
- style="{{computed.wrapperItemStyle({ itemHeight, fontStyle, activeStyle: renderStart + index === currentIndex ? activeStyle : '', animationIndex, index: renderStart + index })}}"
20
- class="smart-ellipsis {{ utils.bem('picker-column__item', { disabled: option && option.disabled, selected: renderStart + index === currentIndex }) }} {{ renderStart + index === currentIndex ? 'active-class' : '' }}"
19
+ style="{{computed.wrapperItemStyle({ itemHeight, fontStyle, activeStyle: renderStart + index === currentIndex ? activeStyle : '', animationIndex, index: renderStart + index, visibleItemCount })}}"
20
+ class="{{ computed.wrapperItemClass({ index, renderStart, animationIndex, option })}}"
21
21
  >
22
22
  {{ computed.optionText(option, valueKey) }}
23
23
  </view>
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable */
2
2
  var style = require('../wxs/style.wxs');
3
3
  var addUnit = require('../wxs/add-unit.wxs');
4
+ var wxUtils = require('../wxs/utils.wxs');
4
5
 
5
6
  function isObj(x) {
6
7
  var type = typeof x;
@@ -49,20 +50,30 @@ function wrapperItemStyle(data) {
49
50
  var fontStyleStr = style(data.fontStyle);
50
51
  var activeStyleStr = style(data.activeStyle);
51
52
 
53
+ // var maxSideShow = Math.floor(data.visibleItemCount / 2) + 1;
52
54
  // var offsetIndex = data.animationIndex - data.index;
53
- // var scale = Math.min(Math.abs(offsetIndex * 0.05), 0.05 * 2)
54
- // var rotateX = offsetIndex * 25 > 0 ? Math.min(offsetIndex * 25, 25 * 2) : Math.max(offsetIndex * 25, -25 * 2)
55
+ // var scale = Math.min(Math.abs(offsetIndex * 0.2), 0.2 * maxSideShow)
56
+ // var rotateX = offsetIndex * 25 > 0 ? Math.min(offsetIndex * 25, 25 * maxSideShow) : Math.max(offsetIndex * 25, -25 * maxSideShow)
57
+ // var translateYIndex = offsetIndex > 0 ? Math.min(offsetIndex, maxSideShow) : Math.max(offsetIndex, -maxSideShow)
55
58
  // const transStyle = style({
56
- // transform: `rotateX(${rotateX}deg) scale(${1 - scale})`
59
+ // transform: `rotateX(${rotateX}deg) scale(${1 - scale}) translateY(${translateYIndex * Math.abs(translateYIndex) * Math.abs(translateYIndex) * data.itemHeight * 0.1}px) translateZ(0)`,
57
60
  // });
58
- // return trans + ';' + heightStyleStr + (fontStyleStr ? fontStyleStr + ';' : fontStyleStr) + activeStyleStr
61
+ // return transStyle + ';' + heightStyleStr + (fontStyleStr ? fontStyleStr + ';' : fontStyleStr) + activeStyleStr
59
62
  return heightStyleStr + (fontStyleStr ? fontStyleStr + ';' : fontStyleStr) + activeStyleStr
60
63
  }
61
64
 
65
+ function wrapperItemClass(data) {
66
+ var staticClass = 'smart-ellipsis';
67
+ var activeClass = 'active-class';
68
+ var isActive = Math.abs(data.renderStart + data.index - data.animationIndex) < 0.9;
69
+ return staticClass + ' ' + wxUtils.bem('picker-column__item', { disabled: data.option && data.option.disabled, selected: isActive }) + ' ' + (isActive ? activeClass : '');
70
+ }
71
+
62
72
  module.exports = {
63
73
  optionText: optionText,
64
74
  rootStyle: rootStyle,
65
75
  wrapperStyle: wrapperStyle,
66
76
  wrapperInterStyle: wrapperInterStyle,
67
- wrapperItemStyle: wrapperItemStyle
77
+ wrapperItemStyle: wrapperItemStyle,
78
+ wrapperItemClass: wrapperItemClass
68
79
  };
@@ -10,6 +10,17 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
13
24
  var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
25
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
26
  if (ar || !(i in from)) {
@@ -51,6 +62,18 @@ function getTrueValue(formattedValue) {
51
62
  function getMonthEndDay(year, month) {
52
63
  return 32 - new Date(year, month - 1, 32).getDate();
53
64
  }
65
+ function findIntersection(range1, range2) {
66
+ var start1 = range1[0], end1 = range1[1];
67
+ var start2 = range2[0], end2 = range2[1];
68
+ // 确定交集的开始和结束
69
+ var intersectionStart = Math.max(start1, start2);
70
+ var intersectionEnd = Math.min(end1, end2);
71
+ // 检查是否有交集
72
+ if (intersectionStart <= intersectionEnd) {
73
+ return [intersectionStart, intersectionEnd];
74
+ }
75
+ return []; // 没有交集
76
+ }
54
77
  var defaultFormatter = function (type, value) {
55
78
  return value;
56
79
  };
@@ -118,8 +141,9 @@ var defaultFormatter = function (type, value) {
118
141
  value: undefined,
119
142
  } }),
120
143
  data: {
121
- part: 0,
144
+ part: 'am',
122
145
  innerValue: Date.now(),
146
+ isCreated: false,
123
147
  columns: [],
124
148
  },
125
149
  created: function () {
@@ -128,12 +152,17 @@ var defaultFormatter = function (type, value) {
128
152
  if (innerValue !== this.data.value) {
129
153
  this.$emit('input', innerValue);
130
154
  }
155
+ this.setData({
156
+ isCreated: true,
157
+ });
131
158
  },
132
159
  methods: {
133
160
  updateValue: function () {
134
- var data = this.data;
135
- var val = this.correctValue(data.value);
136
- var isEqual = val === data.innerValue;
161
+ var _a = this.data, value = _a.value, innerValue = _a.innerValue, isCreated = _a.isCreated;
162
+ if (!isCreated)
163
+ return;
164
+ var val = this.correctValue(value);
165
+ var isEqual = val === innerValue;
137
166
  this.updateColumnValue(val);
138
167
  if (!isEqual) {
139
168
  this.$emit('input', val);
@@ -158,7 +187,7 @@ var defaultFormatter = function (type, value) {
158
187
  var _a;
159
188
  var _b, _c;
160
189
  if (type === 'part') {
161
- return value === 0 ? data.amText : data.pmText;
190
+ return value === 'am' ? data.amText : data.pmText;
162
191
  }
163
192
  var _d = (_b = this === null || this === void 0 ? void 0 : this.data) !== null && _b !== void 0 ? _b : data, formatterMap = _d.formatterMap, _e = _d.formatter, formatter = _e === void 0 ? defaultFormatter : _e;
164
193
  var mapDetail = formatterMap === null || formatterMap === void 0 ? void 0 : formatterMap[type];
@@ -189,24 +218,34 @@ var defaultFormatter = function (type, value) {
189
218
  return this.setData({ columns: results });
190
219
  },
191
220
  getOriginColumns: function () {
192
- var _a = this.data, filter = _a.filter, is12HourClock = _a.is12HourClock, type = _a.type, amText = _a.amText, pmText = _a.pmText, columnsOrder = _a.columnsOrder;
221
+ var _a = this.data, part = _a.part, filter = _a.filter, is12HourClock = _a.is12HourClock, type = _a.type, amText = _a.amText, pmText = _a.pmText, columnsOrder = _a.columnsOrder, minHour = _a.minHour, maxHour = _a.maxHour;
193
222
  var results = this.getRanges().map(function (_a, index) {
194
- var type = _a.type, range = _a.range;
223
+ var timeType = _a.type, range = _a.range;
195
224
  var order = columnsOrder[index];
196
225
  var values = times(range[1] - range[0] + 1, function (index) {
197
226
  var value = range[0] + index;
198
- return type === 'year' ? "".concat(value) : padZero(value);
227
+ if (is12HourClock && type === 'time' && timeType === 'hour') {
228
+ if (part === 'pm') {
229
+ if (value === 12)
230
+ return '12';
231
+ return padZero(value - 12);
232
+ }
233
+ if (value === 0)
234
+ return '12';
235
+ return padZero(value);
236
+ }
237
+ return timeType === 'year' ? "".concat(value) : padZero(value);
199
238
  });
200
239
  if (filter) {
201
- values = filter(type, values);
240
+ values = filter(timeType, values);
202
241
  }
203
- return { type: type, values: values, order: order };
242
+ return { type: timeType, values: values, order: order };
204
243
  });
205
244
  if (is12HourClock && type === 'time') {
206
245
  return __spreadArray([
207
246
  {
208
247
  type: '12HourClock',
209
- values: [amText, pmText],
248
+ values: minHour > 11 ? [pmText] : maxHour < 12 ? [amText] : [amText, pmText],
210
249
  order: columnsOrder[0],
211
250
  }
212
251
  ], results.map(function (item, index) { return (__assign(__assign({}, item), { order: columnsOrder[index + 1] })); }), true).filter(Boolean);
@@ -217,13 +256,11 @@ var defaultFormatter = function (type, value) {
217
256
  var data = this.data;
218
257
  if (data.type === 'time' && data.is12HourClock) {
219
258
  var part = data.part;
259
+ var time12Range = part === 'pm' ? [12, 23] : [0, 11];
220
260
  return [
221
261
  {
222
262
  type: 'hour',
223
- range: [
224
- Math.max(part ? 13 : 1, data.minHour) - (part ? 12 : 0),
225
- Math.min(part ? 24 : 12, data.maxHour) - (part ? 12 : 0),
226
- ],
263
+ range: findIntersection(time12Range, [data.minHour, data.maxHour]),
227
264
  },
228
265
  {
229
266
  type: 'minute',
@@ -273,7 +310,7 @@ var defaultFormatter = function (type, value) {
273
310
  result.splice(2, 3);
274
311
  return result;
275
312
  },
276
- correctValue: function (value, isOutSide) {
313
+ correctValue: function (value) {
277
314
  var data = this.data;
278
315
  // validate value
279
316
  var isDateType = data.type !== 'time';
@@ -287,17 +324,11 @@ var defaultFormatter = function (type, value) {
287
324
  // time type
288
325
  if (!isDateType) {
289
326
  var _a = value.split(':'), hour = _a[0], minute = _a[1];
290
- if (Number(hour) === 0 && data.minHour > 0) {
291
- hour = 24;
292
- }
293
- if (Number(hour) === 24 && data.maxHour < 24) {
327
+ if (Number(hour) === 24) {
294
328
  hour = 0;
295
329
  }
296
330
  hour = padZero((0, utils_1.range)(hour, data.minHour, data.maxHour));
297
331
  minute = padZero((0, utils_1.range)(minute, data.minMinute, data.maxMinute));
298
- if (isOutSide && Number(hour) === 24) {
299
- hour = 0;
300
- }
301
332
  return "".concat(hour, ":").concat(minute);
302
333
  }
303
334
  // date type
@@ -352,24 +383,28 @@ var defaultFormatter = function (type, value) {
352
383
  var picker = this.getPicker();
353
384
  var indexes = picker.getIndexes();
354
385
  if (data.type === 'time' && data.is12HourClock) {
355
- var part = indexes[0], hour = indexes[1], minute = indexes[2];
386
+ var originColumns_1 = this.getOriginColumns();
387
+ var _a = indexes.map(function (item, index) { return originColumns_1[index].values[item]; }), partText = _a[0], hour = _a[1], minute = _a[2];
388
+ var part = partText === this.data.pmText ? 'pm' : 'am';
356
389
  this.setData({
357
390
  part: part,
358
391
  });
359
- var originColumns = this.getOriginColumns();
360
- value = "".concat((part ? 12 : 0) +
361
- 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
362
- ? originColumns[2].values.length - 1
363
- : minute]));
392
+ value = "".concat(part === 'pm'
393
+ ? hour === '12'
394
+ ? 12
395
+ : Number(hour) + 12
396
+ : hour === '12'
397
+ ? 0
398
+ : Number(hour), ":").concat(Number(minute));
364
399
  }
365
400
  else if (data.type === 'time') {
366
401
  var originColumns = this.getOriginColumns();
367
402
  value = "".concat(+originColumns[0].values[indexes[0]], ":").concat(+originColumns[1].values[indexes[1]]);
368
403
  }
369
404
  else {
370
- var originColumns_1 = this.getOriginColumns();
405
+ var originColumns_2 = this.getOriginColumns();
371
406
  var indexes_1 = picker.getIndexes();
372
- var values = indexes_1.map(function (value, index) { return originColumns_1[index].values[value]; });
407
+ var values = indexes_1.map(function (value, index) { return originColumns_2[index].values[value]; });
373
408
  var year = getTrueValue(values[0]);
374
409
  var month = getTrueValue(values[1]);
375
410
  var maxDate = getMonthEndDay(year, month);
@@ -386,26 +421,37 @@ var defaultFormatter = function (type, value) {
386
421
  }
387
422
  value = new Date(year, month - 1, date, hour, minute);
388
423
  }
389
- value = this.correctValue(value, true);
390
- var innerValue = this.correctValue(value);
391
- this.updateColumnValue(innerValue);
424
+ value = this.correctValue(value);
425
+ this.updateColumnValue(value);
392
426
  picker.value = value;
393
427
  this.$emit('input', value);
394
428
  this.$emit('change', picker);
395
429
  },
396
430
  updateColumnValue: function (value) {
397
431
  var values = [];
398
- var _a = this.data, type = _a.type, is12HourClock = _a.is12HourClock;
432
+ var _a = this.data, columns = _a.columns, part = _a.part, outerValue = _a.value, rest = __rest(_a, ["columns", "part", "value"]);
433
+ rest.innerValue = value;
434
+ var dataStr = JSON.stringify(rest);
435
+ if (dataStr === this.preDataStr)
436
+ return;
437
+ this.preDataStr = dataStr;
438
+ var _b = this.data, type = _b.type, is12HourClock = _b.is12HourClock;
399
439
  var formatter = this.formatterFunc;
400
440
  if (type === 'time' && is12HourClock) {
401
- var _b = value.split(':'), hour = _b[0], minute = _b[1];
402
- var part = Number(hour) > 0 && Number(hour) < 13 ? 0 : 1;
441
+ var _c = value.split(':'), hour = _c[0], minute = _c[1];
442
+ var part_1 = Number(hour) < 12 ? 'am' : 'pm';
403
443
  this.setData({
404
- part: part,
444
+ part: part_1,
405
445
  });
406
446
  values = [
407
- formatter('part', part, this.data),
408
- formatter('hour', part ? (!hour ? '12' : (hour - 12).toString().padStart(2, '0')) : hour, this.data),
447
+ formatter('part', part_1, this.data),
448
+ formatter('hour', part_1 === 'am'
449
+ ? hour === '0'
450
+ ? '12'
451
+ : hour
452
+ : hour === '12'
453
+ ? '12'
454
+ : padZero(Number(hour) - 12), this.data),
409
455
  formatter('minute', minute, this.data),
410
456
  ];
411
457
  }
@@ -14,7 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
14
14
  var component_1 = require("../common/component");
15
15
  var shared_1 = require("./shared");
16
16
  (0, component_1.SmartComponent)({
17
- classes: ['active-class', 'toolbar-class', 'column-class'],
17
+ classes: ['hairline-class', 'active-class', 'toolbar-class', 'column-class'],
18
18
  props: __assign(__assign({}, shared_1.pickerProps), { valueKey: {
19
19
  type: String,
20
20
  value: 'text',
@@ -38,7 +38,7 @@
38
38
  />
39
39
 
40
40
  <view
41
- class="smart-picker__frame smart-hairline--top-bottom"
41
+ class="smart-picker__frame smart-hairline--top-bottom hairline-class"
42
42
  style="{{ computed.frameStyle({ itemHeight }) }}"
43
43
  />
44
44
  </view>
@@ -19,6 +19,7 @@ function maskStyle(data) {
19
19
  function frameStyle(data) {
20
20
  return style({
21
21
  height: addUnit(data.itemHeight),
22
+ position: 'absolute'
22
23
  });
23
24
  }
24
25
 
@@ -93,7 +93,7 @@ var DEFAULT_DURATION = 400;
93
93
  observer: function (index) {
94
94
  if (!this.data.isInit)
95
95
  return;
96
- this.setIndex(index, false, this.data.changeAnimation);
96
+ this.setIndex(index, false, this.data.changeAnimation, this.data.animationTime);
97
97
  },
98
98
  },
99
99
  unit: {
@@ -124,7 +124,7 @@ var DEFAULT_DURATION = 400;
124
124
  created: function () {
125
125
  var _a = this.data, defaultIndex = _a.defaultIndex, activeIndex = _a.activeIndex, options = _a.options;
126
126
  this.updateUint(options);
127
- this.setIndex(activeIndex !== -1 ? activeIndex : defaultIndex, false, this.data.changeAnimation);
127
+ this.setIndex(activeIndex !== -1 ? activeIndex : defaultIndex, false, this.data.changeAnimation, this.data.animationTime);
128
128
  this.setData({
129
129
  isInit: true,
130
130
  });
@@ -187,7 +187,7 @@ var DEFAULT_DURATION = 400;
187
187
  },
188
188
  onTouchEnd: function () {
189
189
  return __awaiter(this, void 0, void 0, function () {
190
- var data, preOffsetList, preOffset, isSameTouch, direction, offset, countHeight, animationOffset, finOffset, index, offsetData, countVibrate;
190
+ var data, preOffsetList, preOffset, isSameTouch, direction, offset, countHeight, animationOffset, finOffset, index, offsetData, countVibrate, time;
191
191
  var _this = this;
192
192
  return __generator(this, function (_a) {
193
193
  switch (_a.label) {
@@ -236,13 +236,22 @@ var DEFAULT_DURATION = 400;
236
236
  case 2:
237
237
  // 更新索引
238
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
+ // }
239
248
  return [2 /*return*/, this.setData({
240
249
  timer: setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
241
250
  return __generator(this, function (_a) {
242
- this.setIndex(index, true, false);
251
+ this.setIndex(index, true, false, this.data.animationTime);
243
252
  return [2 /*return*/];
244
253
  });
245
- }); }, isSameTouch ? 150 : data.animationTime),
254
+ }); }, time),
246
255
  })];
247
256
  }
248
257
  this.setData({
@@ -267,7 +276,7 @@ var DEFAULT_DURATION = 400;
267
276
  },
268
277
  vibrateShort: function (count, time) {
269
278
  var _this = this;
270
- if (time === void 0) { time = 1000; }
279
+ if (time === void 0) { time = DEFAULT_DURATION; }
271
280
  if (!count) {
272
281
  ty_1.default.vibrateShort({ type: 'light' });
273
282
  return;
@@ -290,7 +299,7 @@ var DEFAULT_DURATION = 400;
290
299
  return;
291
300
  }
292
301
  this.vibrateShort(Math.abs(index - this.data.currentIndex), DEFAULT_DURATION);
293
- this.setIndex(index, true, true);
302
+ this.setIndex(index, true, true, this.data.animationTime);
294
303
  },
295
304
  updateUint: function (options) {
296
305
  var _a = this.data, unit = _a.unit, valueKey = _a.valueKey;
@@ -356,6 +365,10 @@ var DEFAULT_DURATION = 400;
356
365
  var data = this.data;
357
366
  index = this.adjustIndex(index) || 0;
358
367
  var offset = -index * data.itemHeight;
368
+ if (this.timer) {
369
+ clearTimeout(this.timer);
370
+ this.timer = null;
371
+ }
359
372
  if (!data.playing) {
360
373
  this.$emit('animation-start');
361
374
  this.setData({
@@ -417,7 +430,7 @@ var DEFAULT_DURATION = 400;
417
430
  var options = this.data.options;
418
431
  for (var i = 0; i < options.length; i++) {
419
432
  if (this.getOptionText(options[i]) === value) {
420
- return this.setIndex(i, false, this.data.changeAnimation);
433
+ return this.setIndex(i, false, this.data.changeAnimation, this.data.animationTime);
421
434
  }
422
435
  }
423
436
  return Promise.resolve();
@@ -14,10 +14,10 @@
14
14
  <view
15
15
  wx:for="{{ optionsV }}"
16
16
  wx:for-item="option"
17
- wx:key="index"
17
+ wx:key="*this"
18
18
  data-index="{{ renderStart + index }}"
19
- style="{{computed.wrapperItemStyle({ itemHeight, fontStyle, activeStyle: renderStart + index === currentIndex ? activeStyle : '', animationIndex, index: renderStart + index })}}"
20
- class="smart-ellipsis {{ utils.bem('picker-column__item', { disabled: option && option.disabled, selected: renderStart + index === currentIndex }) }} {{ renderStart + index === currentIndex ? 'active-class' : '' }}"
19
+ style="{{computed.wrapperItemStyle({ itemHeight, fontStyle, activeStyle: renderStart + index === currentIndex ? activeStyle : '', animationIndex, index: renderStart + index, visibleItemCount })}}"
20
+ class="{{ computed.wrapperItemClass({ index, renderStart, animationIndex, option })}}"
21
21
  >
22
22
  {{ computed.optionText(option, valueKey) }}
23
23
  </view>
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable */
2
2
  var style = require('../wxs/style.wxs');
3
3
  var addUnit = require('../wxs/add-unit.wxs');
4
+ var wxUtils = require('../wxs/utils.wxs');
4
5
 
5
6
  function isObj(x) {
6
7
  var type = typeof x;
@@ -49,20 +50,30 @@ function wrapperItemStyle(data) {
49
50
  var fontStyleStr = style(data.fontStyle);
50
51
  var activeStyleStr = style(data.activeStyle);
51
52
 
53
+ // var maxSideShow = Math.floor(data.visibleItemCount / 2) + 1;
52
54
  // var offsetIndex = data.animationIndex - data.index;
53
- // var scale = Math.min(Math.abs(offsetIndex * 0.05), 0.05 * 2)
54
- // var rotateX = offsetIndex * 25 > 0 ? Math.min(offsetIndex * 25, 25 * 2) : Math.max(offsetIndex * 25, -25 * 2)
55
+ // var scale = Math.min(Math.abs(offsetIndex * 0.2), 0.2 * maxSideShow)
56
+ // var rotateX = offsetIndex * 25 > 0 ? Math.min(offsetIndex * 25, 25 * maxSideShow) : Math.max(offsetIndex * 25, -25 * maxSideShow)
57
+ // var translateYIndex = offsetIndex > 0 ? Math.min(offsetIndex, maxSideShow) : Math.max(offsetIndex, -maxSideShow)
55
58
  // const transStyle = style({
56
- // transform: `rotateX(${rotateX}deg) scale(${1 - scale})`
59
+ // transform: `rotateX(${rotateX}deg) scale(${1 - scale}) translateY(${translateYIndex * Math.abs(translateYIndex) * Math.abs(translateYIndex) * data.itemHeight * 0.1}px) translateZ(0)`,
57
60
  // });
58
- // return trans + ';' + heightStyleStr + (fontStyleStr ? fontStyleStr + ';' : fontStyleStr) + activeStyleStr
61
+ // return transStyle + ';' + heightStyleStr + (fontStyleStr ? fontStyleStr + ';' : fontStyleStr) + activeStyleStr
59
62
  return heightStyleStr + (fontStyleStr ? fontStyleStr + ';' : fontStyleStr) + activeStyleStr
60
63
  }
61
64
 
65
+ function wrapperItemClass(data) {
66
+ var staticClass = 'smart-ellipsis';
67
+ var activeClass = 'active-class';
68
+ var isActive = Math.abs(data.renderStart + data.index - data.animationIndex) < 0.9;
69
+ return staticClass + ' ' + wxUtils.bem('picker-column__item', { disabled: data.option && data.option.disabled, selected: isActive }) + ' ' + (isActive ? activeClass : '');
70
+ }
71
+
62
72
  module.exports = {
63
73
  optionText: optionText,
64
74
  rootStyle: rootStyle,
65
75
  wrapperStyle: wrapperStyle,
66
76
  wrapperInterStyle: wrapperInterStyle,
67
- wrapperItemStyle: wrapperItemStyle
77
+ wrapperItemStyle: wrapperItemStyle,
78
+ wrapperItemClass: wrapperItemClass
68
79
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-miniapp/smart-ui",
3
- "version": "2.6.0-beta-7",
3
+ "version": "2.6.0-beta-8",
4
4
  "author": "MiniApp Team",
5
5
  "license": "MIT",
6
6
  "miniprogram": "lib",