@tuya-miniapp/smart-ui 1.3.0-beta-1 → 1.3.0-beta-2

Sign up to get free protection for your applications and to get access to all the features.
@@ -54,10 +54,14 @@ SmartComponent({
54
54
  },
55
55
  mounted() {
56
56
  var _a;
57
+ const ty = wx;
57
58
  // @ts-ignore
58
- const themeInfo = (_a = ty === null || ty === void 0 ? void 0 : ty.getThemeInfo()) !== null && _a !== void 0 ? _a : {};
59
- const checkMarkIconColor = this.data.activeColor || themeInfo['--app-M1'] || '#3678E3';
60
- this.setData({ checkMarkIconColor });
59
+ if (ty && typeof ty.getThemeInfo === 'function') {
60
+ // @ts-ignore
61
+ const themeInfo = (_a = ty === null || ty === void 0 ? void 0 : ty.getThemeInfo()) !== null && _a !== void 0 ? _a : {};
62
+ const checkMarkIconColor = this.data.activeColor || themeInfo['--app-M1'] || '#3678E3';
63
+ this.setData({ checkMarkIconColor });
64
+ }
61
65
  },
62
66
  methods: {
63
67
  onSelect(event) {
@@ -64,9 +64,11 @@ SmartComponent({
64
64
  },
65
65
  getBgColor() {
66
66
  const WX = wx;
67
- const bgColor = WX.getThemeInfo();
68
- if (bgColor && bgColor['--app-B1-N3']) {
69
- return bgColor['--app-B1-N3'];
67
+ if (WX && typeof WX.getThemeInfo === 'function') {
68
+ const bgColor = WX === null || WX === void 0 ? void 0 : WX.getThemeInfo();
69
+ if (bgColor && bgColor['--app-B1-N3']) {
70
+ return bgColor['--app-B1-N3'];
71
+ }
70
72
  }
71
73
  const d = wx.getSystemInfoSync();
72
74
  if (d && d.theme === 'light') {
@@ -42,6 +42,7 @@
42
42
  allowSameDay="{{ allowSameDay }}"
43
43
  showMonthTitle="{{ index !== 0 || !showSubtitle }}"
44
44
  firstDayOfWeek="{{ firstDayOfWeek }}"
45
+ dayClassMap="{{ dayClassMap }}"
45
46
  bind:click="onClickDay"
46
47
  />
47
48
  </scroll-view>
@@ -3,4 +3,5 @@ export interface Day {
3
3
  type: string;
4
4
  text: number;
5
5
  bottomInfo?: string;
6
+ className?: string;
6
7
  }
@@ -1,5 +1,5 @@
1
1
  import { SmartComponent } from '../../../common/component';
2
- import { getMonthEndDay, compareDay, getPrevDay, getNextDay, } from '../../utils';
2
+ import { getMonthEndDay, compareDay, getPrevDay, getNextDay, formatDate, } from '../../utils';
3
3
  SmartComponent({
4
4
  props: {
5
5
  date: {
@@ -35,7 +35,11 @@ SmartComponent({
35
35
  },
36
36
  visible: {
37
37
  type: Boolean,
38
- value: true
38
+ value: true,
39
+ },
40
+ dayClassMap: {
41
+ type: null,
42
+ observer: 'setDays',
39
43
  },
40
44
  subFormatter: String,
41
45
  rangeStart: String,
@@ -56,6 +60,7 @@ SmartComponent({
56
60
  }
57
61
  },
58
62
  setDays() {
63
+ var _a;
59
64
  const days = [];
60
65
  const startDate = new Date(this.data.date);
61
66
  const year = startDate.getFullYear();
@@ -70,6 +75,7 @@ SmartComponent({
70
75
  text: day,
71
76
  bottomInfo: this.getBottomInfo(type),
72
77
  };
78
+ config.className = (_a = this.data.dayClassMap[formatDate(date)]) !== null && _a !== void 0 ? _a : '';
73
79
  if (this.data.formatter) {
74
80
  config = this.data.formatter(config);
75
81
  }
@@ -152,7 +158,9 @@ SmartComponent({
152
158
  return this.properties.rangeEnd || 'End';
153
159
  }
154
160
  if (type === 'start-end') {
155
- return (this.properties.rangeStart || 'Start') + '/' + (this.properties.rangeEnd || 'End');
161
+ return ((this.properties.rangeStart || 'Start') +
162
+ '/' +
163
+ (this.properties.rangeEnd || 'End'));
156
164
  }
157
165
  }
158
166
  },
@@ -46,7 +46,7 @@ function getDayStyle(type, index, date, rowHeight, color, firstDayOfWeek) {
46
46
  function formatMonthTitle(date, formatter = "YYYY-MM") {
47
47
  date = getDate(date);
48
48
  const year = date.getFullYear();
49
- const month = date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 1 + "";
49
+ const month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1 + "";
50
50
  return formatter.replace('YYYY', year + '').replace('MM', month);
51
51
  }
52
52
 
@@ -33,6 +33,10 @@ SmartComponent({
33
33
  rangeEnd: 'End',
34
34
  },
35
35
  },
36
+ dayClassMap: {
37
+ type: Object,
38
+ value: {},
39
+ },
36
40
  formatter: null,
37
41
  confirmText: {
38
42
  type: String,
@@ -131,7 +135,7 @@ SmartComponent({
131
135
  subtitle: '',
132
136
  currentDate: null,
133
137
  scrollIntoView: '',
134
- visibleIndex: 0
138
+ visibleIndex: 0,
135
139
  },
136
140
  watch: {
137
141
  minDate() {
@@ -173,7 +177,10 @@ SmartComponent({
173
177
  contentObserver.observe('.month', (res) => {
174
178
  if (res.boundingClientRect.top <= res.relativeRect.top) {
175
179
  // @ts-ignore
176
- this.setData({ subtitle: formatMonthTitle(res.dataset.date, this.properties.locale.subFormatter), visibleIndex: res.dataset.index });
180
+ this.setData({
181
+ subtitle: formatMonthTitle(res.dataset.date, this.properties.locale.subFormatter),
182
+ visibleIndex: res.dataset.index,
183
+ });
177
184
  }
178
185
  });
179
186
  },
@@ -231,7 +238,10 @@ SmartComponent({
231
238
  const months = getMonths(minDate, maxDate);
232
239
  months.some((month, index) => {
233
240
  if (compareMonth(month, targetDate) === 0) {
234
- this.setData({ scrollIntoView: `month${index}`, visibleIndex: index });
241
+ this.setData({
242
+ scrollIntoView: `month${index}`,
243
+ visibleIndex: index,
244
+ });
235
245
  return true;
236
246
  }
237
247
  return false;
@@ -37,6 +37,6 @@ function getVisible(visibleIndex, curIndex) {
37
37
 
38
38
  module.exports = {
39
39
  getMonths: getMonths,
40
- getVisible,
40
+ getVisible: getVisible,
41
41
  getButtonDisabled: getButtonDisabled
42
42
  };
@@ -10,3 +10,4 @@ export declare function calcDateNum(date: [Date, Date]): number;
10
10
  export declare function copyDates(dates: Date | Date[]): Date | Date[];
11
11
  export declare function getMonthEndDay(year: number, month: number): number;
12
12
  export declare function getMonths(minDate: number, maxDate: number): number[];
13
+ export declare function formatDate(date: any): string;
@@ -4,7 +4,9 @@ export function formatMonthTitle(date, formatter = 'YYYY-MM') {
4
4
  date = new Date(date);
5
5
  }
6
6
  const year = date.getFullYear();
7
- const month = date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 1 + "";
7
+ const month = date.getMonth() + 1 < 10
8
+ ? `0${date.getMonth() + 1}`
9
+ : date.getMonth() + 1 + '';
8
10
  return formatter.replace('YYYY', year + '').replace('MM', month);
9
11
  }
10
12
  export function compareMonth(date1, date2) {
@@ -83,3 +85,11 @@ export function getMonths(minDate, maxDate) {
83
85
  } while (compareMonth(cursor, maxDate) !== 1);
84
86
  return months;
85
87
  }
88
+ export function formatDate(date) {
89
+ if (!date)
90
+ return '';
91
+ const year = date.getFullYear();
92
+ const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始
93
+ const day = String(date.getDate()).padStart(2, '0');
94
+ return `${year}-${month}-${day}`;
95
+ }
@@ -2,7 +2,7 @@
2
2
  * 是否为 App 主题变量
3
3
  */
4
4
  function isAppThemeVar(key) {
5
- return key.startsWith('--app');
5
+ return key.indexOf('--app') === 0;
6
6
  }
7
7
 
8
8
  module.exports = isAppThemeVar;
@@ -59,10 +59,14 @@ var button_1 = require("../mixins/button");
59
59
  },
60
60
  mounted: function () {
61
61
  var _a;
62
+ var ty = wx;
62
63
  // @ts-ignore
63
- var themeInfo = (_a = ty === null || ty === void 0 ? void 0 : ty.getThemeInfo()) !== null && _a !== void 0 ? _a : {};
64
- var checkMarkIconColor = this.data.activeColor || themeInfo['--app-M1'] || '#3678E3';
65
- this.setData({ checkMarkIconColor: checkMarkIconColor });
64
+ if (ty && typeof ty.getThemeInfo === 'function') {
65
+ // @ts-ignore
66
+ var themeInfo = (_a = ty === null || ty === void 0 ? void 0 : ty.getThemeInfo()) !== null && _a !== void 0 ? _a : {};
67
+ var checkMarkIconColor = this.data.activeColor || themeInfo['--app-M1'] || '#3678E3';
68
+ this.setData({ checkMarkIconColor: checkMarkIconColor });
69
+ }
66
70
  },
67
71
  methods: {
68
72
  onSelect: function (event) {
@@ -59,9 +59,11 @@ var wrapBatteryD = 'M6.5,0 C6.77614237,-5.07265313e-17 7,0.223857625 7,0.5 L7,1
59
59
  },
60
60
  getBgColor: function () {
61
61
  var WX = wx;
62
- var bgColor = WX.getThemeInfo();
63
- if (bgColor && bgColor['--app-B1-N3']) {
64
- return bgColor['--app-B1-N3'];
62
+ if (WX && typeof WX.getThemeInfo === 'function') {
63
+ var bgColor = WX === null || WX === void 0 ? void 0 : WX.getThemeInfo();
64
+ if (bgColor && bgColor['--app-B1-N3']) {
65
+ return bgColor['--app-B1-N3'];
66
+ }
65
67
  }
66
68
  var d = wx.getSystemInfoSync();
67
69
  if (d && d.theme === 'light') {
@@ -42,6 +42,7 @@
42
42
  allowSameDay="{{ allowSameDay }}"
43
43
  showMonthTitle="{{ index !== 0 || !showSubtitle }}"
44
44
  firstDayOfWeek="{{ firstDayOfWeek }}"
45
+ dayClassMap="{{ dayClassMap }}"
45
46
  bind:click="onClickDay"
46
47
  />
47
48
  </scroll-view>
@@ -3,4 +3,5 @@ export interface Day {
3
3
  type: string;
4
4
  text: number;
5
5
  bottomInfo?: string;
6
+ className?: string;
6
7
  }
@@ -37,7 +37,11 @@ var utils_1 = require("../../utils");
37
37
  },
38
38
  visible: {
39
39
  type: Boolean,
40
- value: true
40
+ value: true,
41
+ },
42
+ dayClassMap: {
43
+ type: null,
44
+ observer: 'setDays',
41
45
  },
42
46
  subFormatter: String,
43
47
  rangeStart: String,
@@ -58,6 +62,7 @@ var utils_1 = require("../../utils");
58
62
  }
59
63
  },
60
64
  setDays: function () {
65
+ var _a;
61
66
  var days = [];
62
67
  var startDate = new Date(this.data.date);
63
68
  var year = startDate.getFullYear();
@@ -72,6 +77,7 @@ var utils_1 = require("../../utils");
72
77
  text: day,
73
78
  bottomInfo: this.getBottomInfo(type),
74
79
  };
80
+ config.className = (_a = this.data.dayClassMap[(0, utils_1.formatDate)(date)]) !== null && _a !== void 0 ? _a : '';
75
81
  if (this.data.formatter) {
76
82
  config = this.data.formatter(config);
77
83
  }
@@ -156,7 +162,9 @@ var utils_1 = require("../../utils");
156
162
  return this.properties.rangeEnd || 'End';
157
163
  }
158
164
  if (type === 'start-end') {
159
- return (this.properties.rangeStart || 'Start') + '/' + (this.properties.rangeEnd || 'End');
165
+ return ((this.properties.rangeStart || 'Start') +
166
+ '/' +
167
+ (this.properties.rangeEnd || 'End'));
160
168
  }
161
169
  }
162
170
  },
@@ -46,7 +46,7 @@ function getDayStyle(type, index, date, rowHeight, color, firstDayOfWeek) {
46
46
  function formatMonthTitle(date, formatter = "YYYY-MM") {
47
47
  date = getDate(date);
48
48
  const year = date.getFullYear();
49
- const month = date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 1 + "";
49
+ const month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1 + "";
50
50
  return formatter.replace('YYYY', year + '').replace('MM', month);
51
51
  }
52
52
 
@@ -49,6 +49,10 @@ var getTime = function (date) {
49
49
  rangeEnd: 'End',
50
50
  },
51
51
  },
52
+ dayClassMap: {
53
+ type: Object,
54
+ value: {},
55
+ },
52
56
  formatter: null,
53
57
  confirmText: {
54
58
  type: String,
@@ -147,7 +151,7 @@ var getTime = function (date) {
147
151
  subtitle: '',
148
152
  currentDate: null,
149
153
  scrollIntoView: '',
150
- visibleIndex: 0
154
+ visibleIndex: 0,
151
155
  },
152
156
  watch: {
153
157
  minDate: function () {
@@ -190,7 +194,10 @@ var getTime = function (date) {
190
194
  contentObserver.observe('.month', function (res) {
191
195
  if (res.boundingClientRect.top <= res.relativeRect.top) {
192
196
  // @ts-ignore
193
- _this.setData({ subtitle: (0, utils_1.formatMonthTitle)(res.dataset.date, _this.properties.locale.subFormatter), visibleIndex: res.dataset.index });
197
+ _this.setData({
198
+ subtitle: (0, utils_1.formatMonthTitle)(res.dataset.date, _this.properties.locale.subFormatter),
199
+ visibleIndex: res.dataset.index,
200
+ });
194
201
  }
195
202
  });
196
203
  },
@@ -253,7 +260,10 @@ var getTime = function (date) {
253
260
  var months = (0, utils_1.getMonths)(minDate, maxDate);
254
261
  months.some(function (month, index) {
255
262
  if ((0, utils_1.compareMonth)(month, targetDate) === 0) {
256
- _this.setData({ scrollIntoView: "month".concat(index), visibleIndex: index });
263
+ _this.setData({
264
+ scrollIntoView: "month".concat(index),
265
+ visibleIndex: index,
266
+ });
257
267
  return true;
258
268
  }
259
269
  return false;
@@ -37,6 +37,6 @@ function getVisible(visibleIndex, curIndex) {
37
37
 
38
38
  module.exports = {
39
39
  getMonths: getMonths,
40
- getVisible,
40
+ getVisible: getVisible,
41
41
  getButtonDisabled: getButtonDisabled
42
42
  };
@@ -10,3 +10,4 @@ export declare function calcDateNum(date: [Date, Date]): number;
10
10
  export declare function copyDates(dates: Date | Date[]): Date | Date[];
11
11
  export declare function getMonthEndDay(year: number, month: number): number;
12
12
  export declare function getMonths(minDate: number, maxDate: number): number[];
13
+ export declare function formatDate(date: any): string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getMonths = exports.getMonthEndDay = exports.copyDates = exports.calcDateNum = exports.getToday = exports.getNextDay = exports.getPrevDay = exports.getDayByOffset = exports.compareDay = exports.compareMonth = exports.formatMonthTitle = exports.ROW_HEIGHT = void 0;
3
+ exports.formatDate = exports.getMonths = exports.getMonthEndDay = exports.copyDates = exports.calcDateNum = exports.getToday = exports.getNextDay = exports.getPrevDay = exports.getDayByOffset = exports.compareDay = exports.compareMonth = exports.formatMonthTitle = exports.ROW_HEIGHT = void 0;
4
4
  exports.ROW_HEIGHT = 64;
5
5
  function formatMonthTitle(date, formatter) {
6
6
  if (formatter === void 0) { formatter = 'YYYY-MM'; }
@@ -8,7 +8,9 @@ function formatMonthTitle(date, formatter) {
8
8
  date = new Date(date);
9
9
  }
10
10
  var year = date.getFullYear();
11
- var month = date.getMonth() + 1 < 10 ? "0".concat(date.getMonth() + 1) : date.getMonth() + 1 + "";
11
+ var month = date.getMonth() + 1 < 10
12
+ ? "0".concat(date.getMonth() + 1)
13
+ : date.getMonth() + 1 + '';
12
14
  return formatter.replace('YYYY', year + '').replace('MM', month);
13
15
  }
14
16
  exports.formatMonthTitle = formatMonthTitle;
@@ -98,3 +100,12 @@ function getMonths(minDate, maxDate) {
98
100
  return months;
99
101
  }
100
102
  exports.getMonths = getMonths;
103
+ function formatDate(date) {
104
+ if (!date)
105
+ return '';
106
+ var year = date.getFullYear();
107
+ var month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始
108
+ var day = String(date.getDate()).padStart(2, '0');
109
+ return "".concat(year, "-").concat(month, "-").concat(day);
110
+ }
111
+ exports.formatDate = formatDate;
@@ -2,7 +2,7 @@
2
2
  * 是否为 App 主题变量
3
3
  */
4
4
  function isAppThemeVar(key) {
5
- return key.startsWith('--app');
5
+ return key.indexOf('--app') === 0;
6
6
  }
7
7
 
8
8
  module.exports = isAppThemeVar;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-miniapp/smart-ui",
3
- "version": "1.3.0-beta-1",
3
+ "version": "1.3.0-beta-2",
4
4
  "author": "MiniApp Team",
5
5
  "license": "MIT",
6
6
  "miniprogram": "lib",