@tuya-miniapp/smart-ui 2.2.1-beta-2 → 2.2.1-beta-3

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.
@@ -4,7 +4,7 @@
4
4
  <header
5
5
  title="{{ title }}"
6
6
  showTitle="{{ showTitle }}"
7
- subtitle="{{ type === 'year' ? '' : type === 'month' ? computed.formatYearTitle(currentDate, visibleIndex, locale.yearFormatter) : computed.formatMonthTitle(months[visibleIndex], subFormatter) }}"
7
+ subtitle="{{ type === 'year' ? '' : type === 'month' ? computed.formatYearTitle(originCurrentDateMonthly, visibleIndex, locale.yearFormatter) : computed.formatMonthTitle(months[visibleIndex], subFormatter) }}"
8
8
  subFormatter="{{locale.subFormatter || 'YYYY-MM'}}"
9
9
  showSubtitle="{{ showSubtitle }}"
10
10
  firstDayOfWeek="{{ firstDayOfWeek }}"
@@ -59,6 +59,8 @@
59
59
  date="{{currentDate}}"
60
60
  color="{{color}}"
61
61
  readonly="{{readonly}}"
62
+ visibleIndex="{{visibleIndex}}"
63
+ bind:changemonthtitle="onChangeMonthTitleDate"
62
64
  />
63
65
  </block>
64
66
 
@@ -17,6 +17,11 @@ SmartComponent({
17
17
  this.initRect();
18
18
  this.scrollIntoView();
19
19
  }
20
+ else {
21
+ this.setData({
22
+ visibleIndex: 0,
23
+ });
24
+ }
20
25
  },
21
26
  },
22
27
  locale: {
@@ -142,6 +147,7 @@ SmartComponent({
142
147
  data: {
143
148
  subtitle: '',
144
149
  currentDate: null,
150
+ originCurrentDateMonthly: null,
145
151
  scrollIntoView: '',
146
152
  visibleIndex: 0,
147
153
  months: [],
@@ -174,12 +180,8 @@ SmartComponent({
174
180
  return;
175
181
  }
176
182
  if (this.data.type === 'month') {
177
- const nextDate = new Date(this.data.currentDate);
178
- nextDate.setFullYear(nextDate.getFullYear() - 1);
179
- this.select(nextDate, true);
180
183
  this.setData({
181
184
  visibleIndex,
182
- currentDate: nextDate,
183
185
  });
184
186
  return;
185
187
  }
@@ -198,12 +200,8 @@ SmartComponent({
198
200
  return;
199
201
  }
200
202
  if (this.data.type === 'month') {
201
- const nextDate = new Date(this.data.currentDate);
202
- nextDate.setFullYear(nextDate.getFullYear() + 1);
203
- this.select(nextDate, true);
204
203
  this.setData({
205
204
  visibleIndex,
206
- currentDate: nextDate,
207
205
  });
208
206
  return;
209
207
  }
@@ -214,7 +212,8 @@ SmartComponent({
214
212
  }
215
213
  },
216
214
  reset() {
217
- this.setData({ currentDate: this.getInitialDate(this.data.defaultDate) });
215
+ const currentDate = this.getInitialDate(this.data.defaultDate);
216
+ this.setData({ currentDate, visibleIndex: 0 });
218
217
  this.scrollIntoView();
219
218
  },
220
219
  initData() {
@@ -227,6 +226,8 @@ SmartComponent({
227
226
  const isMonth = this.data.type === 'month';
228
227
  const data = {
229
228
  currentDate,
229
+ // 初始化时记录一份,用于month列表展示头部
230
+ originCurrentDateMonthly: currentDate,
230
231
  months,
231
232
  visibleIndex: visibleIndex,
232
233
  };
@@ -368,6 +369,16 @@ SmartComponent({
368
369
  }
369
370
  const date = event.detail;
370
371
  this.select(date, true);
372
+ this.setData({
373
+ visibleIndex: 0,
374
+ });
375
+ },
376
+ onChangeMonthTitleDate(event) {
377
+ if (this.data.originCurrentDateMonthly !== event.detail) {
378
+ this.setData({
379
+ originCurrentDateMonthly: event.detail,
380
+ });
381
+ }
371
382
  },
372
383
  unselect(dateArray) {
373
384
  const date = dateArray[0];
@@ -50,7 +50,7 @@ function formatYearTitle(date, offset, formatter = 'YYYY') {
50
50
  return formatter.replace('YYYY', year + '');
51
51
  }
52
52
 
53
- module.exports = {
53
+ module.exports = {
54
54
  getMonths: getMonths,
55
55
  getVisible: getVisible,
56
56
  getButtonDisabled: getButtonDisabled,
@@ -11,11 +11,6 @@ SmartComponent({
11
11
  props: {
12
12
  date: {
13
13
  type: null,
14
- observer(newVal, oldVal) {
15
- if (newVal !== oldVal) {
16
- this.getMonthList();
17
- }
18
- },
19
14
  },
20
15
  color: {
21
16
  type: String,
@@ -37,6 +32,15 @@ SmartComponent({
37
32
  type: null,
38
33
  value: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'],
39
34
  },
35
+ visibleIndex: {
36
+ type: Number,
37
+ value: 0,
38
+ observer(newVal, oldVal) {
39
+ if (newVal !== oldVal) {
40
+ this.getMonthList(newVal);
41
+ }
42
+ },
43
+ },
40
44
  },
41
45
  /**
42
46
  * 组件的初始数据
@@ -46,19 +50,20 @@ SmartComponent({
46
50
  currentMonth: null,
47
51
  },
48
52
  created() {
49
- this.getMonthList();
53
+ this.getMonthList(0);
50
54
  },
51
55
  /**
52
56
  * 组件的方法列表
53
57
  */
54
58
  methods: {
55
- getMonthList() {
59
+ getMonthList(visibleIndex) {
56
60
  const { minDate, maxDate, monthsFormatter = [] } = this.data;
57
- const curDate = new Date(this.data.date);
61
+ const currentDate = new Date(this.data.date);
62
+ const curDate = new Date(currentDate.getFullYear() + visibleIndex, currentDate.getMonth(), currentDate.getDay());
58
63
  const cur = curDate.getFullYear();
59
64
  const curMonthDate = new Date(curDate.getFullYear(), curDate.getMonth(), 1);
60
- const start = new Date(cur, 0, 1).getTime();
61
- const end = new Date(cur, 11, 31).getTime();
65
+ const start = new Date(cur, 0, 1, 0, 0, 0).getTime();
66
+ const end = new Date(cur, 11, 31, 23, 59, 59).getTime();
62
67
  const minDateTime = new Date(minDate).getTime();
63
68
  const maxDateTime = new Date(maxDate).getTime();
64
69
  const months = getMonths(start, end);
@@ -80,6 +85,7 @@ SmartComponent({
80
85
  months: monthlist,
81
86
  currentMonth: curMonthDate.getTime(),
82
87
  });
88
+ this.$emit('changemonthtitle', curDate.getTime());
83
89
  },
84
90
  onClick(event) {
85
91
  if (this.data.readonly)
@@ -4,7 +4,7 @@
4
4
  <view wx:if="{{item.type === 'disabled'}}" class="item item_disabled" data-index="{{index}}">
5
5
  {{item.text}}
6
6
  </view>
7
- <view wx:elif="{{currentMonth === item.value}}" class="item item_active" data-index="{{index}}" bindtap="onClick" style="background: {{ color }};">
7
+ <view wx:elif="{{date === item.value}}" class="item item_active" data-index="{{index}}" bindtap="onClick" style="background: {{ color }};">
8
8
  {{item.text}}
9
9
  </view>
10
10
  <view wx:else class="item" data-index="{{index}}" bindtap="onClick">
@@ -76,15 +76,15 @@ SmartComponent({
76
76
  const offset = visibleIndex * 12;
77
77
  const start = new Date(cur + offset - 5, 0, 1).getTime();
78
78
  const end = new Date(cur + offset + 6, 11, 31).getTime();
79
- const minStart = new Date(minDate).getTime();
80
- const maxStart = new Date(maxDate).getTime();
79
+ const minStart = new Date(minDate).getFullYear();
80
+ const maxStart = new Date(maxDate).getFullYear();
81
81
  const years = getYears(start, end);
82
82
  const yearlist = years.map(date => {
83
83
  const yearVal = new Date(date).getFullYear();
84
- const curTime = new Date(date).getTime();
84
+ const curTime = new Date(date).getFullYear();
85
85
  let isDisabled = false;
86
86
  if (minDate && maxDate) {
87
- isDisabled = curTime <= minStart || curTime >= maxStart;
87
+ isDisabled = curTime < minStart || curTime > maxStart;
88
88
  }
89
89
  return {
90
90
  value: date,
@@ -4,7 +4,7 @@
4
4
  <header
5
5
  title="{{ title }}"
6
6
  showTitle="{{ showTitle }}"
7
- subtitle="{{ type === 'year' ? '' : type === 'month' ? computed.formatYearTitle(currentDate, visibleIndex, locale.yearFormatter) : computed.formatMonthTitle(months[visibleIndex], subFormatter) }}"
7
+ subtitle="{{ type === 'year' ? '' : type === 'month' ? computed.formatYearTitle(originCurrentDateMonthly, visibleIndex, locale.yearFormatter) : computed.formatMonthTitle(months[visibleIndex], subFormatter) }}"
8
8
  subFormatter="{{locale.subFormatter || 'YYYY-MM'}}"
9
9
  showSubtitle="{{ showSubtitle }}"
10
10
  firstDayOfWeek="{{ firstDayOfWeek }}"
@@ -59,6 +59,8 @@
59
59
  date="{{currentDate}}"
60
60
  color="{{color}}"
61
61
  readonly="{{readonly}}"
62
+ visibleIndex="{{visibleIndex}}"
63
+ bind:changemonthtitle="onChangeMonthTitleDate"
62
64
  />
63
65
  </block>
64
66
 
@@ -4,21 +4,15 @@ var component_1 = require("../../common/component");
4
4
  (0, component_1.SmartComponent)({
5
5
  data: {
6
6
  // day
7
- curDayDate: new Date(2024, 0, 15).getTime(),
8
- minDayDate: new Date(2024, 0, 4).getTime(),
9
- maxDayDate: new Date(2024, 1, 20).getTime(),
7
+ curDayDate: new Date(2024, 1, 1, 0, 0, 0).getTime(),
8
+ minDayDate: new Date(2023, 0, 4).getTime(),
9
+ maxDayDate: new Date(2024, 3, 20).getTime(),
10
10
  // weekday
11
- curWeekDayDate: [
12
- new Date(2024, 0, 15).getTime(),
13
- new Date(2024, 0, 21).getTime(),
14
- ],
11
+ curWeekDayDate: [new Date(2024, 0, 15).getTime(), new Date(2024, 0, 21).getTime()],
15
12
  minWeekDayDate: new Date(2024, 0, 4).getTime(),
16
13
  maxWeekDayDate: new Date(2024, 1, 20).getTime(),
17
14
  // range
18
- curRangeDayDate: [
19
- new Date(2024, 0, 10).getTime(),
20
- new Date(2024, 0, 20).getTime(),
21
- ],
15
+ curRangeDayDate: [new Date(2024, 0, 10).getTime(), new Date(2024, 0, 20).getTime()],
22
16
  minRangeDayDate: new Date(2024, 0, 4).getTime(),
23
17
  maxRangeDayDate: new Date(2024, 1, 20).getTime(),
24
18
  // month
@@ -26,8 +20,8 @@ var component_1 = require("../../common/component");
26
20
  minMonthDate: new Date(2024, 2, 1).getTime(),
27
21
  maxMonthDate: new Date(2025, 9, 31).getTime(),
28
22
  // year
29
- curYearDate: new Date(2017, 6, 1).getTime(),
30
- minYearDate: new Date(2012, 0, 1).getTime(),
23
+ curYearDate: new Date(2025, 0, 23).getTime(),
24
+ minYearDate: new Date(2024, 10, 12).getTime(),
31
25
  maxYearDate: new Date(2029, 10, 31).getTime(),
32
26
  // locale
33
27
  confirmText: I18n.t('confirm'),
@@ -59,13 +53,14 @@ var component_1 = require("../../common/component");
59
53
  I18n.t('cal_Sept'),
60
54
  I18n.t('cal_Oct'),
61
55
  I18n.t('cal_Nov'),
62
- I18n.t('cal_Dec')
63
- ]
56
+ I18n.t('cal_Dec'),
57
+ ],
64
58
  },
65
59
  showDayPicker: false,
66
60
  dayClassMap: {
67
- '2024-01-17': "calendar-disabled"
68
- }
61
+ '2024-01-17': 'calendar-disabled',
62
+ },
63
+ type: 'single',
69
64
  },
70
65
  methods: {
71
66
  setCurDay: function (event) {
@@ -104,5 +99,12 @@ var component_1 = require("../../common/component");
104
99
  showDayPicker: !this.data.showDayPicker,
105
100
  });
106
101
  },
102
+ selectDate: function (e) { },
103
+ changeType: function (e) {
104
+ var _a, _b;
105
+ this.setData({
106
+ type: (_b = (_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.dataset) === null || _b === void 0 ? void 0 : _b.type,
107
+ });
108
+ },
107
109
  },
108
110
  });
@@ -31,6 +31,11 @@ var getTime = function (date) { return (date instanceof Date ? date.getTime() :
31
31
  this.initRect();
32
32
  this.scrollIntoView();
33
33
  }
34
+ else {
35
+ this.setData({
36
+ visibleIndex: 0,
37
+ });
38
+ }
34
39
  },
35
40
  },
36
41
  locale: {
@@ -156,6 +161,7 @@ var getTime = function (date) { return (date instanceof Date ? date.getTime() :
156
161
  data: {
157
162
  subtitle: '',
158
163
  currentDate: null,
164
+ originCurrentDateMonthly: null,
159
165
  scrollIntoView: '',
160
166
  visibleIndex: 0,
161
167
  months: [],
@@ -188,12 +194,8 @@ var getTime = function (date) { return (date instanceof Date ? date.getTime() :
188
194
  return;
189
195
  }
190
196
  if (this.data.type === 'month') {
191
- var nextDate = new Date(this.data.currentDate);
192
- nextDate.setFullYear(nextDate.getFullYear() - 1);
193
- this.select(nextDate, true);
194
197
  this.setData({
195
198
  visibleIndex: visibleIndex,
196
- currentDate: nextDate,
197
199
  });
198
200
  return;
199
201
  }
@@ -212,12 +214,8 @@ var getTime = function (date) { return (date instanceof Date ? date.getTime() :
212
214
  return;
213
215
  }
214
216
  if (this.data.type === 'month') {
215
- var nextDate = new Date(this.data.currentDate);
216
- nextDate.setFullYear(nextDate.getFullYear() + 1);
217
- this.select(nextDate, true);
218
217
  this.setData({
219
218
  visibleIndex: visibleIndex,
220
- currentDate: nextDate,
221
219
  });
222
220
  return;
223
221
  }
@@ -228,7 +226,8 @@ var getTime = function (date) { return (date instanceof Date ? date.getTime() :
228
226
  }
229
227
  },
230
228
  reset: function () {
231
- this.setData({ currentDate: this.getInitialDate(this.data.defaultDate) });
229
+ var currentDate = this.getInitialDate(this.data.defaultDate);
230
+ this.setData({ currentDate: currentDate, visibleIndex: 0 });
232
231
  this.scrollIntoView();
233
232
  },
234
233
  initData: function () {
@@ -241,6 +240,8 @@ var getTime = function (date) { return (date instanceof Date ? date.getTime() :
241
240
  var isMonth = this.data.type === 'month';
242
241
  var data = {
243
242
  currentDate: currentDate,
243
+ // 初始化时记录一份,用于month列表展示头部
244
+ originCurrentDateMonthly: currentDate,
244
245
  months: months,
245
246
  visibleIndex: visibleIndex,
246
247
  };
@@ -386,6 +387,16 @@ var getTime = function (date) { return (date instanceof Date ? date.getTime() :
386
387
  }
387
388
  var date = event.detail;
388
389
  this.select(date, true);
390
+ this.setData({
391
+ visibleIndex: 0,
392
+ });
393
+ },
394
+ onChangeMonthTitleDate: function (event) {
395
+ if (this.data.originCurrentDateMonthly !== event.detail) {
396
+ this.setData({
397
+ originCurrentDateMonthly: event.detail,
398
+ });
399
+ }
389
400
  },
390
401
  unselect: function (dateArray) {
391
402
  var date = dateArray[0];
@@ -50,7 +50,7 @@ function formatYearTitle(date, offset, formatter = 'YYYY') {
50
50
  return formatter.replace('YYYY', year + '');
51
51
  }
52
52
 
53
- module.exports = {
53
+ module.exports = {
54
54
  getMonths: getMonths,
55
55
  getVisible: getVisible,
56
56
  getButtonDisabled: getButtonDisabled,
@@ -13,11 +13,6 @@ var maxMonthDate = new Date(currentYear + 10, 12, 31).getTime();
13
13
  props: {
14
14
  date: {
15
15
  type: null,
16
- observer: function (newVal, oldVal) {
17
- if (newVal !== oldVal) {
18
- this.getMonthList();
19
- }
20
- },
21
16
  },
22
17
  color: {
23
18
  type: String,
@@ -39,6 +34,15 @@ var maxMonthDate = new Date(currentYear + 10, 12, 31).getTime();
39
34
  type: null,
40
35
  value: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'],
41
36
  },
37
+ visibleIndex: {
38
+ type: Number,
39
+ value: 0,
40
+ observer: function (newVal, oldVal) {
41
+ if (newVal !== oldVal) {
42
+ this.getMonthList(newVal);
43
+ }
44
+ },
45
+ },
42
46
  },
43
47
  /**
44
48
  * 组件的初始数据
@@ -48,19 +52,20 @@ var maxMonthDate = new Date(currentYear + 10, 12, 31).getTime();
48
52
  currentMonth: null,
49
53
  },
50
54
  created: function () {
51
- this.getMonthList();
55
+ this.getMonthList(0);
52
56
  },
53
57
  /**
54
58
  * 组件的方法列表
55
59
  */
56
60
  methods: {
57
- getMonthList: function () {
61
+ getMonthList: function (visibleIndex) {
58
62
  var _a = this.data, minDate = _a.minDate, maxDate = _a.maxDate, _b = _a.monthsFormatter, monthsFormatter = _b === void 0 ? [] : _b;
59
- var curDate = new Date(this.data.date);
63
+ var currentDate = new Date(this.data.date);
64
+ var curDate = new Date(currentDate.getFullYear() + visibleIndex, currentDate.getMonth(), currentDate.getDay());
60
65
  var cur = curDate.getFullYear();
61
66
  var curMonthDate = new Date(curDate.getFullYear(), curDate.getMonth(), 1);
62
- var start = new Date(cur, 0, 1).getTime();
63
- var end = new Date(cur, 11, 31).getTime();
67
+ var start = new Date(cur, 0, 1, 0, 0, 0).getTime();
68
+ var end = new Date(cur, 11, 31, 23, 59, 59).getTime();
64
69
  var minDateTime = new Date(minDate).getTime();
65
70
  var maxDateTime = new Date(maxDate).getTime();
66
71
  var months = (0, utils_1.getMonths)(start, end);
@@ -82,6 +87,7 @@ var maxMonthDate = new Date(currentYear + 10, 12, 31).getTime();
82
87
  months: monthlist,
83
88
  currentMonth: curMonthDate.getTime(),
84
89
  });
90
+ this.$emit('changemonthtitle', curDate.getTime());
85
91
  },
86
92
  onClick: function (event) {
87
93
  if (this.data.readonly)
@@ -4,7 +4,7 @@
4
4
  <view wx:if="{{item.type === 'disabled'}}" class="item item_disabled" data-index="{{index}}">
5
5
  {{item.text}}
6
6
  </view>
7
- <view wx:elif="{{currentMonth === item.value}}" class="item item_active" data-index="{{index}}" bindtap="onClick" style="background: {{ color }};">
7
+ <view wx:elif="{{date === item.value}}" class="item item_active" data-index="{{index}}" bindtap="onClick" style="background: {{ color }};">
8
8
  {{item.text}}
9
9
  </view>
10
10
  <view wx:else class="item" data-index="{{index}}" bindtap="onClick">
@@ -78,15 +78,15 @@ var component_1 = require("../common/component");
78
78
  var offset = visibleIndex * 12;
79
79
  var start = new Date(cur + offset - 5, 0, 1).getTime();
80
80
  var end = new Date(cur + offset + 6, 11, 31).getTime();
81
- var minStart = new Date(minDate).getTime();
82
- var maxStart = new Date(maxDate).getTime();
81
+ var minStart = new Date(minDate).getFullYear();
82
+ var maxStart = new Date(maxDate).getFullYear();
83
83
  var years = (0, utils_1.getYears)(start, end);
84
84
  var yearlist = years.map(function (date) {
85
85
  var yearVal = new Date(date).getFullYear();
86
- var curTime = new Date(date).getTime();
86
+ var curTime = new Date(date).getFullYear();
87
87
  var isDisabled = false;
88
88
  if (minDate && maxDate) {
89
- isDisabled = curTime <= minStart || curTime >= maxStart;
89
+ isDisabled = curTime < minStart || curTime > maxStart;
90
90
  }
91
91
  return {
92
92
  value: date,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-miniapp/smart-ui",
3
- "version": "2.2.1-beta-2",
3
+ "version": "2.2.1-beta-3",
4
4
  "author": "MiniApp Team",
5
5
  "license": "MIT",
6
6
  "miniprogram": "lib",