@ray-js/smart-ui 2.2.1 → 2.2.2-beta-2

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.
@@ -283,5 +283,10 @@ export interface SmartCalendarEvents {
283
283
  * 点击日历副标题时触发
284
284
  */
285
285
  onClickSubtitle?: (e: WechatMiniprogram.CustomEvent<WechatMiniprogram.TouchEvent>) => void;
286
+ /**
287
+ * 时区偏差(分钟数)
288
+ * @default -480
289
+ */
290
+ utcOffset?: number;
286
291
  }
287
292
  export type SmartCalendar = SmartComponent<SmartCalendarProps, SmartCalendarEvents>;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import type { SmartCalendar } from './PropTypes';
3
- declare const Calendar: import("react").FC<SmartCalendar>;
4
- export { Calendar };
3
+ declare const SmartCalendar: import("react").FC<SmartCalendar>;
4
+ export declare const Calendar: React.FC<SmartCalendar>;
5
5
  export { SmartCalendar, SmartCalendarEvents, SmartCalendarPoppableProps, SmartCalendarProps, SmartCalendarRangeProps, Day, } from './PropTypes';
@@ -1,3 +1,72 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /* eslint-disable prefer-destructuring */
1
3
  import _Calendar from './Calendar';
2
- const Calendar = _Calendar;
3
- export { Calendar };
4
+ const SmartCalendar = _Calendar;
5
+ const wrapUtc = (dt, targetOffset) => {
6
+ const date = new Date(dt);
7
+ const offset = date.getTimezoneOffset(); // 获取当前时区的偏移
8
+ // 假设我们想要将时间调整为 UTC+8(比如北京时区)
9
+ const timeDifference = offset - targetOffset; // 计算差值
10
+ // 创建一个新的日期对象,将其调整为目标时区
11
+ const adjustedDate = new Date(date.getTime() + timeDifference * 60000); // 时间差转换为毫秒
12
+ return adjustedDate.getTime();
13
+ };
14
+ const unwrapUtc = (dt, targetOffset) => {
15
+ const date = new Date(dt);
16
+ const offset = date.getTimezoneOffset(); // 获取当前时区的偏移
17
+ // 计算反向差值
18
+ const timeDifference = targetOffset - offset; // 目标时区偏移量和当前时区偏移量之间的差异
19
+ // 创建一个新的日期对象,将其调整回 UTC
20
+ const utcDate = new Date(date.getTime() - timeDifference * 60000); // 时间差转换为毫秒
21
+ return utcDate.getTime();
22
+ };
23
+ export const Calendar = props => {
24
+ var _a;
25
+ const utcOffset = (_a = props.utcOffset) !== null && _a !== void 0 ? _a : -480;
26
+ let defaultDate = props.defaultDate;
27
+ let maxDate = props.maxDate;
28
+ let minDate = props.minDate;
29
+ if (utcOffset) {
30
+ if (props.defaultDate) {
31
+ if (Array.isArray(props.defaultDate)) {
32
+ defaultDate = props.defaultDate.map(date => wrapUtc(date, utcOffset));
33
+ }
34
+ else {
35
+ defaultDate = wrapUtc(props.defaultDate, utcOffset);
36
+ }
37
+ }
38
+ if (props.maxDate) {
39
+ maxDate = wrapUtc(props.maxDate, utcOffset);
40
+ }
41
+ if (props.minDate) {
42
+ minDate = wrapUtc(props.minDate, utcOffset);
43
+ }
44
+ }
45
+ return (_jsx(SmartCalendar, Object.assign({}, props, { defaultDate: defaultDate, minDate: minDate, maxDate: maxDate, onConfirm: event => {
46
+ if (props.onConfirm) {
47
+ let detail = event.detail;
48
+ if (utcOffset) {
49
+ if (Array.isArray(event.detail)) {
50
+ detail = event.detail.map(date => new Date(unwrapUtc(date, utcOffset)));
51
+ }
52
+ else {
53
+ detail = new Date(unwrapUtc(event.detail, utcOffset));
54
+ }
55
+ }
56
+ props.onConfirm(Object.assign(Object.assign({}, event), { detail }));
57
+ }
58
+ }, onSelect: event => {
59
+ if (props.onSelect) {
60
+ let detail = event.detail;
61
+ if (utcOffset) {
62
+ if (Array.isArray(event.detail)) {
63
+ detail = event.detail.map(date => new Date(unwrapUtc(date, utcOffset)));
64
+ }
65
+ else {
66
+ detail = new Date(unwrapUtc(event.detail, utcOffset));
67
+ }
68
+ }
69
+ props.onSelect(Object.assign(Object.assign({}, event), { detail }));
70
+ }
71
+ } })));
72
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/smart-ui",
3
- "version": "2.2.1",
3
+ "version": "2.2.2-beta-2",
4
4
  "description": "轻量、可靠的智能小程序 UI 组件库",
5
5
  "scripts": {
6
6
  "syncMiniappData": "node ./build/syncMiniappData.js",