sard-uniapp 1.19.5 → 1.20.0
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.
- package/CHANGELOG.md +22 -0
- package/README.md +1 -1
- package/components/calendar/README.md +20 -20
- package/components/calendar/calendar.vue +1 -1
- package/components/calendar-input/README.md +10 -10
- package/components/calendar-input/calendar-input.vue +2 -2
- package/components/calendar-month/calendar-month.vue +17 -21
- package/components/calendar-popout/calendar-popout.vue +1 -1
- package/components/card/README.md +16 -8
- package/components/card/card.vue +7 -1
- package/components/card/common.d.ts +2 -0
- package/components/card/index.scss +30 -2
- package/components/card/variables.scss +16 -1
- package/components/checkbox/common.d.ts +1 -0
- package/components/checkbox/common.js +1 -0
- package/components/checkbox-input/checkbox-input.vue +9 -0
- package/components/checkbox-popout/README.md +27 -6
- package/components/checkbox-popout/checkbox-popout.vue +113 -47
- package/components/checkbox-popout/common.d.ts +3 -0
- package/components/checkbox-popout/index.scss +16 -0
- package/components/config/index.d.ts +6 -0
- package/components/config/index.js +6 -0
- package/components/datetime-picker/README.md +1 -71
- package/components/datetime-picker/common.d.ts +1 -0
- package/components/datetime-picker/common.js +21 -8
- package/components/datetime-picker/datetime-picker.vue +3 -3
- package/components/datetime-picker-input/README.md +10 -10
- package/components/datetime-picker-input/datetime-picker-input.vue +2 -2
- package/components/datetime-picker-popout/datetime-picker-popout.vue +1 -1
- package/components/datetime-range-picker/datetime-range-picker.vue +12 -10
- package/components/datetime-range-picker-input/README.md +10 -10
- package/components/datetime-range-picker-input/datetime-range-picker-input.vue +2 -2
- package/components/datetime-range-picker-popout/README.md +0 -6
- package/components/datetime-range-picker-popout/datetime-range-picker-popout.vue +11 -8
- package/components/floating-bubble/floating-bubble.vue +3 -3
- package/components/form/README.md +19 -19
- package/components/form/form.vue +1 -1
- package/components/icon/icon.d.ts +1 -1
- package/components/indexes/README.md +4 -0
- package/components/indexes-nav/indexes-nav.vue +2 -2
- package/components/keyboard/common.d.ts +1 -2
- package/components/keyboard/common.js +2 -11
- package/components/keyboard/keyboard.d.ts +2 -2
- package/components/list-item/index.scss +4 -0
- package/components/locale/lang/en-US.d.ts +4 -0
- package/components/locale/lang/en-US.js +4 -0
- package/components/locale/lang/zh-CN.d.ts +4 -0
- package/components/locale/lang/zh-CN.js +4 -0
- package/components/marquee/README.md +8 -2
- package/components/marquee/marquee.vue +9 -1
- package/components/notice-bar/README.md +8 -2
- package/components/notice-bar/notice-bar.vue +14 -8
- package/components/notify/notify.d.ts +1 -1
- package/components/notify-agent/notify-agent.d.ts +1 -1
- package/components/pagination/pagination.vue +2 -2
- package/components/popover/utils.js +4 -4
- package/components/pull-down-refresh/common.d.ts +1 -1
- package/components/radio/common.d.ts +1 -0
- package/components/radio/common.js +1 -0
- package/components/radio-input/radio-input.vue +6 -0
- package/components/radio-popout/README.md +20 -6
- package/components/radio-popout/common.d.ts +2 -0
- package/components/radio-popout/index.scss +4 -0
- package/components/radio-popout/radio-popout.vue +91 -45
- package/components/read-more/README.md +82 -0
- package/components/read-more/common.d.ts +24 -0
- package/components/read-more/common.js +2 -0
- package/components/read-more/index.d.ts +1 -0
- package/components/read-more/index.js +1 -0
- package/components/read-more/index.scss +41 -0
- package/components/read-more/read-more.d.ts +20 -0
- package/components/read-more/read-more.vue +168 -0
- package/components/read-more/variables.scss +12 -0
- package/components/resize-sensor/README.md +55 -0
- package/components/resize-sensor/common.d.ts +19 -0
- package/components/resize-sensor/common.js +2 -0
- package/components/resize-sensor/index.d.ts +1 -0
- package/components/resize-sensor/index.js +1 -0
- package/components/resize-sensor/index.scss +33 -0
- package/components/resize-sensor/resize-sensor.d.ts +16 -0
- package/components/resize-sensor/resize-sensor.vue +152 -0
- package/components/scroll-list/README.md +79 -0
- package/components/scroll-list/common.d.ts +23 -0
- package/components/scroll-list/common.js +1 -0
- package/components/scroll-list/index.d.ts +1 -0
- package/components/scroll-list/index.js +1 -0
- package/components/scroll-list/index.scss +35 -0
- package/components/scroll-list/scroll-list.d.ts +20 -0
- package/components/scroll-list/scroll-list.vue +158 -0
- package/components/scroll-list/variables.scss +11 -0
- package/components/sidebar/README.md +8 -8
- package/components/sidebar/sidebar.vue +1 -1
- package/components/slider/slider.vue +4 -4
- package/components/stepper/stepper.vue +2 -2
- package/components/sticky/README.md +92 -0
- package/components/sticky/common.d.ts +15 -0
- package/components/sticky/common.js +1 -0
- package/components/sticky/index.d.ts +1 -0
- package/components/sticky/index.js +1 -0
- package/components/sticky/index.scss +18 -0
- package/components/sticky/sticky.d.ts +10 -0
- package/components/sticky/sticky.vue +190 -0
- package/components/sticky-box/common.d.ts +19 -0
- package/components/sticky-box/common.js +1 -0
- package/components/sticky-box/index.d.ts +1 -0
- package/components/sticky-box/index.js +1 -0
- package/components/sticky-box/index.scss +19 -0
- package/components/sticky-box/sticky-box.d.ts +10 -0
- package/components/sticky-box/sticky-box.vue +82 -0
- package/components/style/mixins/border.scss +101 -38
- package/components/style/variables-dark.scss +4 -0
- package/components/style/variables.scss +8 -0
- package/components/table/table.vue +2 -1
- package/components/table-fixation/table-fixation.vue +2 -1
- package/components/toast/toast.d.ts +1 -1
- package/components/toast-agent/toast-agent.d.ts +1 -1
- package/components/tree/tree.d.ts +1 -1
- package/components/tree-node/tree-node.vue +2 -2
- package/components/upload/README.md +23 -15
- package/components/upload/common.d.ts +6 -4
- package/components/upload/upload.d.ts +2 -0
- package/components/upload/upload.vue +51 -13
- package/components/upload/utils.d.ts +1 -0
- package/components/upload/utils.js +2 -0
- package/components/upload-preview/index.scss +1 -0
- package/components/upload-preview/upload-preview.d.ts +6 -4
- package/components/upload-preview/upload-preview.vue +17 -24
- package/global.d.ts +5 -0
- package/index.d.ts +5 -0
- package/index.js +5 -0
- package/index.scss +2 -0
- package/package.json +4 -2
- package/use/index.d.ts +4 -0
- package/use/index.js +4 -0
- package/use/useIndeterminate.d.ts +10 -0
- package/use/useIndeterminate.js +27 -0
- package/use/useIntersectionObserver.d.ts +16 -0
- package/use/useIntersectionObserver.js +52 -0
- package/use/useSimulatedClick.js +2 -2
- package/use/useSimulatedPress.js +2 -2
- package/use/useSingleTask.d.ts +6 -0
- package/use/useSingleTask.js +40 -0
- package/use/useWindowResize.d.ts +4 -0
- package/use/useWindowResize.js +15 -0
- package/utils/array.d.ts +28 -0
- package/utils/array.js +90 -0
- package/utils/common.d.ts +3 -0
- package/utils/common.js +1 -0
- package/utils/date.d.ts +84 -11
- package/utils/date.js +120 -63
- package/utils/dom.js +2 -0
- package/utils/geometry.d.ts +56 -38
- package/utils/geometry.js +56 -30
- package/utils/index.d.ts +8 -1
- package/utils/index.js +8 -1
- package/utils/is.d.ts +12 -0
- package/utils/is.js +16 -0
- package/utils/number.d.ts +24 -0
- package/utils/number.js +37 -0
- package/utils/object.d.ts +29 -0
- package/utils/object.js +139 -0
- package/utils/persist.d.ts +15 -0
- package/utils/persist.js +89 -0
- package/utils/physics.d.ts +34 -0
- package/utils/physics.js +66 -0
- package/utils/request.d.ts +227 -0
- package/utils/request.js +249 -0
- package/utils/router.d.ts +47 -0
- package/utils/router.js +115 -0
- package/utils/string.d.ts +46 -0
- package/utils/string.js +134 -0
- package/utils/url-query.d.ts +19 -0
- package/utils/url-query.js +95 -0
- package/utils/utils.d.ts +0 -166
- package/utils/utils.js +0 -441
- package/utils/case.d.ts +0 -4
- package/utils/case.js +0 -26
package/utils/date.d.ts
CHANGED
|
@@ -1,15 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 判断是否为闰年。
|
|
3
|
+
*/
|
|
1
4
|
export declare function isLeapYear(year: number): boolean;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare function
|
|
5
|
+
/**
|
|
6
|
+
* 获取某月的天数,月份从0开始。
|
|
7
|
+
*/
|
|
8
|
+
export declare function getDaysInMonth(year: number, month: number): number;
|
|
9
|
+
/**
|
|
10
|
+
* 获取当前日期是一年中的第几天。
|
|
11
|
+
*/
|
|
12
|
+
export declare function getDayOfYear(date: Date): number;
|
|
13
|
+
/**
|
|
14
|
+
* 获取指定月份第一天是星期几,月份从0开始。
|
|
15
|
+
*/
|
|
16
|
+
export declare function getFirstDayWeekday(year: number, month: number): number;
|
|
17
|
+
/**
|
|
18
|
+
* 获取从基准日期(如1970-01-01)到指定日期的总天数。
|
|
19
|
+
*/
|
|
20
|
+
export declare function getDaysSinceUnixEpoch(date: Date): number;
|
|
21
|
+
/**
|
|
22
|
+
* 把日期转换为年月日数值,例如:2025年7月1号 -> 20250601。
|
|
23
|
+
*/
|
|
6
24
|
export declare function toDateNumber(date: Date): number;
|
|
25
|
+
/**
|
|
26
|
+
* 把日期转换为年月日字符串,,例如:2025年7月1号 -> 2025-7-1。
|
|
27
|
+
*/
|
|
7
28
|
export declare function toDateString(date: Date): string;
|
|
29
|
+
/**
|
|
30
|
+
* 把日期转换为年月数值,例如:2025年7月1号 -> 20250600。
|
|
31
|
+
*/
|
|
8
32
|
export declare function toMonthNumber(date: Date): number;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
33
|
+
/**
|
|
34
|
+
* 计算当前月份1号前面需要显示的上个月末尾的天数。
|
|
35
|
+
*/
|
|
36
|
+
export declare function getDaysBeforeFirstDay(year: number, month: number, weekStartsOn?: number): number;
|
|
37
|
+
/**
|
|
38
|
+
* 获取当前月份最后一天之后需要显示的下个月开始的天数。
|
|
39
|
+
*/
|
|
40
|
+
export declare function getDaysAfterLastDay(year: number, month: number, weekStartsOn?: number): number;
|
|
41
|
+
/**
|
|
42
|
+
* 获取当前月份1号之前需要显示的上个月末尾的日期。
|
|
43
|
+
*/
|
|
44
|
+
export declare function getPrevMonthTailDays(year: number, month: number, weekStartsOn?: number): Date[];
|
|
45
|
+
/**
|
|
46
|
+
* 获取当前月份最后一天之后需要显示的下个月开始的日期。
|
|
47
|
+
*/
|
|
48
|
+
export declare function getNextMonthHeadDays(year: number, month: number, weekStartsOn?: number): Date[];
|
|
49
|
+
/**
|
|
50
|
+
* 根据传入的占位符返回格式化后的日期。
|
|
51
|
+
*/
|
|
12
52
|
export declare function formatDate(date: Date, format?: string): string;
|
|
53
|
+
/**
|
|
54
|
+
* 解析日期的字符串表示形式,并返回 Date 实例对象。
|
|
55
|
+
*/
|
|
13
56
|
export declare function parseDate(value: string, format?: string): Date;
|
|
14
57
|
export declare function toDate(date: Date | string, valueFormat?: string): Date;
|
|
15
58
|
export declare function minmaxDate(date: Date, minDate: Date, maxDate: Date): Date;
|
|
@@ -21,26 +64,56 @@ export declare function getNextMonthDate(date: Date): Date;
|
|
|
21
64
|
export declare const lunarInfo: number[];
|
|
22
65
|
export declare const springFestivals: number[][];
|
|
23
66
|
export declare const baseLunarYear = 1900;
|
|
67
|
+
/**
|
|
68
|
+
* 获取农历某年闰月的月份,月份从1开始(0表示无闰月)。
|
|
69
|
+
*/
|
|
24
70
|
export declare function getLunarLeapMonth(year: number): number;
|
|
25
|
-
|
|
71
|
+
/**
|
|
72
|
+
* 获取农历某年闰月的天数。
|
|
73
|
+
*/
|
|
74
|
+
export declare function getLunarLeapMonthDays(year: number): number;
|
|
75
|
+
/**
|
|
76
|
+
* 获取农历某年的总天数。
|
|
77
|
+
*/
|
|
26
78
|
export declare function getLunarYearDays(year: number): number;
|
|
27
|
-
|
|
28
|
-
|
|
79
|
+
/**
|
|
80
|
+
* 获取农历某年某月的天数,月份从1开始。
|
|
81
|
+
*/
|
|
82
|
+
export declare function getLunarMonthDays(year: number, month: number): number;
|
|
83
|
+
/**
|
|
84
|
+
* 公历转农历,月份从1开始(返回的闰月为负数)。
|
|
85
|
+
*/
|
|
86
|
+
export declare function solarToLunar(year: number, month: number, day: number): {
|
|
29
87
|
year: number;
|
|
30
88
|
month: number;
|
|
31
89
|
day: number;
|
|
32
90
|
};
|
|
33
|
-
|
|
91
|
+
/**
|
|
92
|
+
* 农历转公历(闰月需传递负数)。
|
|
93
|
+
*/
|
|
94
|
+
export declare function lunarToSolar(year: number, month: number, day: number): {
|
|
34
95
|
year: number;
|
|
35
96
|
month: number;
|
|
36
97
|
day: number;
|
|
37
98
|
};
|
|
38
99
|
export declare const lunarYearNames: string[];
|
|
100
|
+
/**
|
|
101
|
+
* 将阿拉伯数字的年份转为汉字数字年份
|
|
102
|
+
*/
|
|
39
103
|
export declare function getLunarYearName(year: number): string;
|
|
40
104
|
export declare const lunarMonthNames: string[];
|
|
105
|
+
/**
|
|
106
|
+
* 获取农历月份名称,月份从1开始,例如:正月,十月,腊月。
|
|
107
|
+
*/
|
|
41
108
|
export declare function getLunarMonthName(month: number, isLeapMonth?: boolean): string;
|
|
42
109
|
export declare const lunarDayNames: string[];
|
|
110
|
+
/**
|
|
111
|
+
* 获取农历日期名称,例如:初一,十二,廿一。
|
|
112
|
+
*/
|
|
43
113
|
export declare function getLunarDayName(day: number): string;
|
|
44
114
|
export declare const heavenlyStems: string[];
|
|
45
115
|
export declare const earthlyBranches: string[];
|
|
116
|
+
/**
|
|
117
|
+
* 获取农历时辰名称,例如:子初、子正、午初,午正。
|
|
118
|
+
*/
|
|
46
119
|
export declare function getLunarHourName(hour: number): string;
|
package/utils/date.js
CHANGED
|
@@ -1,70 +1,102 @@
|
|
|
1
|
+
import { clamp } from './number';
|
|
1
2
|
import { escapeRegExp } from './regexp';
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* 判断是否为闰年。
|
|
5
|
+
*/
|
|
4
6
|
export function isLeapYear(year) {
|
|
5
7
|
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
|
6
8
|
}
|
|
7
9
|
const monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* 获取某月的天数,月份从0开始。
|
|
12
|
+
*/
|
|
13
|
+
export function getDaysInMonth(year, month) {
|
|
14
|
+
if (month === 1) {
|
|
11
15
|
return isLeapYear(year) ? 29 : 28;
|
|
12
16
|
}
|
|
13
17
|
else {
|
|
14
|
-
return monthDays[month
|
|
18
|
+
return monthDays[month];
|
|
15
19
|
}
|
|
16
20
|
}
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
/**
|
|
22
|
+
* 获取当前日期是一年中的第几天。
|
|
23
|
+
*/
|
|
24
|
+
export function getDayOfYear(date) {
|
|
19
25
|
const year = date.getFullYear();
|
|
20
26
|
const month = date.getMonth();
|
|
21
27
|
const d = date.getDate();
|
|
22
28
|
let days = 0;
|
|
23
29
|
for (let m = 0; m < month; m++) {
|
|
24
|
-
days +=
|
|
30
|
+
days += getDaysInMonth(year, m);
|
|
25
31
|
}
|
|
26
32
|
return days + d;
|
|
27
33
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
/**
|
|
35
|
+
* 获取指定月份第一天是星期几,月份从0开始。
|
|
36
|
+
*/
|
|
37
|
+
export function getFirstDayWeekday(year, month) {
|
|
38
|
+
return new Date(year, month, 1).getDay();
|
|
31
39
|
}
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
/**
|
|
41
|
+
* 获取从基准日期(如1970-01-01)到指定日期的总天数。
|
|
42
|
+
*/
|
|
43
|
+
export function getDaysSinceUnixEpoch(date) {
|
|
34
44
|
return Math.floor(date.getTime() / 1000 / 60 / 60 / 24);
|
|
35
45
|
}
|
|
36
|
-
|
|
46
|
+
/**
|
|
47
|
+
* 把日期转换为年月日数值,例如:2025年7月1号 -> 20250601。
|
|
48
|
+
*/
|
|
37
49
|
export function toDateNumber(date) {
|
|
38
50
|
return date.getFullYear() * 10000 + date.getMonth() * 100 + date.getDate();
|
|
39
51
|
}
|
|
40
|
-
|
|
52
|
+
/**
|
|
53
|
+
* 把日期转换为年月日字符串,,例如:2025年7月1号 -> 2025-7-1。
|
|
54
|
+
*/
|
|
41
55
|
export function toDateString(date) {
|
|
42
56
|
return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
|
|
43
57
|
}
|
|
44
|
-
|
|
58
|
+
/**
|
|
59
|
+
* 把日期转换为年月数值,例如:2025年7月1号 -> 20250600。
|
|
60
|
+
*/
|
|
45
61
|
export function toMonthNumber(date) {
|
|
46
62
|
return date.getFullYear() * 10000 + date.getMonth() * 100;
|
|
47
63
|
}
|
|
48
|
-
|
|
49
|
-
|
|
64
|
+
/**
|
|
65
|
+
* 计算当前月份1号前面需要显示的上个月末尾的天数。
|
|
66
|
+
*/
|
|
67
|
+
export function getDaysBeforeFirstDay(year, month, weekStartsOn = 0) {
|
|
68
|
+
const week = getFirstDayWeekday(year, month);
|
|
69
|
+
return (week - weekStartsOn + 7) % 7;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 获取当前月份最后一天之后需要显示的下个月开始的天数。
|
|
73
|
+
*/
|
|
74
|
+
export function getDaysAfterLastDay(year, month, weekStartsOn = 0) {
|
|
75
|
+
const daysBefore = getDaysBeforeFirstDay(year, month, weekStartsOn);
|
|
76
|
+
return 42 - daysBefore - getDaysInMonth(year, month);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 获取当前月份1号之前需要显示的上个月末尾的日期。
|
|
80
|
+
*/
|
|
81
|
+
export function getPrevMonthTailDays(year, month, weekStartsOn = 0) {
|
|
82
|
+
const daysBefore = getDaysBeforeFirstDay(year, month, weekStartsOn);
|
|
50
83
|
const dates = [];
|
|
51
|
-
for (let i =
|
|
52
|
-
dates.push(new Date(year, month
|
|
84
|
+
for (let i = daysBefore - 1; i >= 0; i--) {
|
|
85
|
+
dates.push(new Date(year, month, -i));
|
|
53
86
|
}
|
|
54
87
|
return dates;
|
|
55
88
|
}
|
|
56
|
-
|
|
57
|
-
|
|
89
|
+
/**
|
|
90
|
+
* 获取当前月份最后一天之后需要显示的下个月开始的日期。
|
|
91
|
+
*/
|
|
92
|
+
export function getNextMonthHeadDays(year, month, weekStartsOn = 0) {
|
|
93
|
+
const daysAfter = getDaysAfterLastDay(year, month, weekStartsOn);
|
|
58
94
|
const dates = [];
|
|
59
|
-
for (let i = 1; i <=
|
|
60
|
-
dates.push(new Date(year, month + 1
|
|
95
|
+
for (let i = 1; i <= daysAfter; i++) {
|
|
96
|
+
dates.push(new Date(year, month + 1, i));
|
|
61
97
|
}
|
|
62
98
|
return dates;
|
|
63
99
|
}
|
|
64
|
-
// 获取一号偏移的天数
|
|
65
|
-
export function getOffsetDaysFromMonthStart(weekOnMonthStart, weekStartsOn) {
|
|
66
|
-
return (weekOnMonthStart - weekStartsOn + 7) % 7;
|
|
67
|
-
}
|
|
68
100
|
const dateTokensReg = /(YYYY|YY|MM|M|DD|D|HH|H|hh|h|mm|m|ss|s|SSS)/g;
|
|
69
101
|
const dateGetters = {
|
|
70
102
|
YYYY: (date) => String(date.getFullYear()).padStart(4, '0'),
|
|
@@ -83,7 +115,9 @@ const dateGetters = {
|
|
|
83
115
|
s: (date) => String(date.getSeconds()),
|
|
84
116
|
SSS: (date) => String(date.getMilliseconds()).padStart(3, '0'),
|
|
85
117
|
};
|
|
86
|
-
|
|
118
|
+
/**
|
|
119
|
+
* 根据传入的占位符返回格式化后的日期。
|
|
120
|
+
*/
|
|
87
121
|
export function formatDate(date, format = 'YYYY-MM-DD HH:mm:ss') {
|
|
88
122
|
return format.replace(dateTokensReg, (match) => {
|
|
89
123
|
return dateGetters[match](date);
|
|
@@ -116,7 +150,9 @@ function parseDateWithoutFormat(value) {
|
|
|
116
150
|
});
|
|
117
151
|
return date;
|
|
118
152
|
}
|
|
119
|
-
|
|
153
|
+
/**
|
|
154
|
+
* 解析日期的字符串表示形式,并返回 Date 实例对象。
|
|
155
|
+
*/
|
|
120
156
|
export function parseDate(value, format) {
|
|
121
157
|
if (!format) {
|
|
122
158
|
return parseDateWithoutFormat(value);
|
|
@@ -139,22 +175,22 @@ export function parseDate(value, format) {
|
|
|
139
175
|
});
|
|
140
176
|
return date;
|
|
141
177
|
}
|
|
142
|
-
// 确保返回一个Date对象,如果传递字符串,则使用 parseDate
|
|
178
|
+
// 确保返回一个Date对象,如果传递字符串,则使用 parseDate 解析。
|
|
143
179
|
export function toDate(date, valueFormat) {
|
|
144
180
|
if (date instanceof Date) {
|
|
145
181
|
return date;
|
|
146
182
|
}
|
|
147
183
|
return parseDate(date, valueFormat);
|
|
148
184
|
}
|
|
149
|
-
//
|
|
185
|
+
// 限定日期范围,会返回一个新的日期。
|
|
150
186
|
export function minmaxDate(date, minDate, maxDate) {
|
|
151
|
-
return new Date(
|
|
187
|
+
return new Date(clamp(date.getTime(), minDate.getTime(), maxDate.getTime()));
|
|
152
188
|
}
|
|
153
|
-
//
|
|
189
|
+
// 获取上一个月的日期对象。
|
|
154
190
|
export function getPrevMonthDate(date) {
|
|
155
191
|
return new Date(date.getFullYear(), date.getMonth() - 1, 1);
|
|
156
192
|
}
|
|
157
|
-
//
|
|
193
|
+
// 获取下一个月的日期对象。
|
|
158
194
|
export function getNextMonthDate(date) {
|
|
159
195
|
return new Date(date.getFullYear(), date.getMonth() + 1, 1);
|
|
160
196
|
}
|
|
@@ -211,18 +247,24 @@ export const springFestivals = [
|
|
|
211
247
|
[2, 9], // 2100
|
|
212
248
|
];
|
|
213
249
|
export const baseLunarYear = 1900;
|
|
214
|
-
|
|
250
|
+
/**
|
|
251
|
+
* 获取农历某年闰月的月份,月份从1开始(0表示无闰月)。
|
|
252
|
+
*/
|
|
215
253
|
export function getLunarLeapMonth(year) {
|
|
216
254
|
return lunarInfo[year - baseLunarYear] & 0xf;
|
|
217
255
|
}
|
|
218
|
-
|
|
256
|
+
/**
|
|
257
|
+
* 获取农历某年闰月的天数。
|
|
258
|
+
*/
|
|
219
259
|
export function getLunarLeapMonthDays(year) {
|
|
220
260
|
if (getLunarLeapMonth(year)) {
|
|
221
261
|
return lunarInfo[year - baseLunarYear] & 0x10000 ? 30 : 29;
|
|
222
262
|
}
|
|
223
263
|
return 0;
|
|
224
264
|
}
|
|
225
|
-
|
|
265
|
+
/**
|
|
266
|
+
* 获取农历某年的总天数。
|
|
267
|
+
*/
|
|
226
268
|
export function getLunarYearDays(year) {
|
|
227
269
|
let sum = 348; // 29天*12个月
|
|
228
270
|
const info = lunarInfo[year - baseLunarYear];
|
|
@@ -233,14 +275,18 @@ export function getLunarYearDays(year) {
|
|
|
233
275
|
// 加上闰月的天数
|
|
234
276
|
return sum + getLunarLeapMonthDays(year);
|
|
235
277
|
}
|
|
236
|
-
|
|
278
|
+
/**
|
|
279
|
+
* 获取农历某年某月的天数,月份从1开始。
|
|
280
|
+
*/
|
|
237
281
|
export function getLunarMonthDays(year, month) {
|
|
238
282
|
return lunarInfo[year - baseLunarYear] & (0x10000 >> month) ? 30 : 29;
|
|
239
283
|
}
|
|
240
|
-
|
|
241
|
-
|
|
284
|
+
/**
|
|
285
|
+
* 公历转农历,月份从1开始(返回的闰月为负数)。
|
|
286
|
+
*/
|
|
287
|
+
export function solarToLunar(year, month, day) {
|
|
242
288
|
// 计算输入日期与基准日期的天数差
|
|
243
|
-
const offsetDays = Math.floor((Date.UTC(year,
|
|
289
|
+
const offsetDays = Math.floor((Date.UTC(year, month - 1, day) - Date.UTC(baseLunarYear, 0, 31)) /
|
|
244
290
|
(24 * 60 * 60 * 1000));
|
|
245
291
|
// 农历年、月、日初始化
|
|
246
292
|
let lunarYear = baseLunarYear;
|
|
@@ -260,25 +306,25 @@ export function solarToLunar(year, _month, date) {
|
|
|
260
306
|
// 计算农历月和日
|
|
261
307
|
const leapMonth = getLunarLeapMonth(lunarYear);
|
|
262
308
|
let monthDays = 0;
|
|
263
|
-
let
|
|
264
|
-
for (;
|
|
309
|
+
let _month = 1;
|
|
310
|
+
for (; _month <= 12; _month++) {
|
|
265
311
|
// 处理闰月
|
|
266
|
-
if (leapMonth > 0 &&
|
|
312
|
+
if (leapMonth > 0 && _month === leapMonth + 1) {
|
|
267
313
|
monthDays = getLunarLeapMonthDays(lunarYear);
|
|
268
314
|
if (daysRemaining < monthDays) {
|
|
269
315
|
isLeapMonth = true;
|
|
270
|
-
|
|
316
|
+
_month--;
|
|
271
317
|
break;
|
|
272
318
|
}
|
|
273
319
|
daysRemaining -= monthDays;
|
|
274
320
|
}
|
|
275
|
-
monthDays = getLunarMonthDays(lunarYear,
|
|
321
|
+
monthDays = getLunarMonthDays(lunarYear, _month);
|
|
276
322
|
if (daysRemaining < monthDays) {
|
|
277
323
|
break;
|
|
278
324
|
}
|
|
279
325
|
daysRemaining -= monthDays;
|
|
280
326
|
}
|
|
281
|
-
lunarMonth =
|
|
327
|
+
lunarMonth = _month;
|
|
282
328
|
lunarDay = daysRemaining + 1;
|
|
283
329
|
return {
|
|
284
330
|
year: lunarYear,
|
|
@@ -286,24 +332,26 @@ export function solarToLunar(year, _month, date) {
|
|
|
286
332
|
day: lunarDay,
|
|
287
333
|
};
|
|
288
334
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
const
|
|
335
|
+
/**
|
|
336
|
+
* 农历转公历(闰月需传递负数)。
|
|
337
|
+
*/
|
|
338
|
+
export function lunarToSolar(year, month, day) {
|
|
339
|
+
const springFestival = springFestivals[year - baseLunarYear];
|
|
340
|
+
const solarDate = new Date(year, springFestival[0] - 1, springFestival[1]);
|
|
341
|
+
const info = lunarInfo[year - baseLunarYear];
|
|
294
342
|
const leapMonth = info & 0xf;
|
|
295
343
|
let totalDays = 0;
|
|
296
|
-
const absMonth = Math.abs(
|
|
344
|
+
const absMonth = Math.abs(month);
|
|
297
345
|
for (let m = 1; m < absMonth; m++) {
|
|
298
346
|
if (m === leapMonth) {
|
|
299
|
-
totalDays += getLunarLeapMonthDays(
|
|
347
|
+
totalDays += getLunarLeapMonthDays(year);
|
|
300
348
|
}
|
|
301
|
-
totalDays += getLunarMonthDays(
|
|
349
|
+
totalDays += getLunarMonthDays(year, m);
|
|
302
350
|
}
|
|
303
|
-
if (
|
|
304
|
-
totalDays += getLunarMonthDays(
|
|
351
|
+
if (month < 0) {
|
|
352
|
+
totalDays += getLunarMonthDays(year, absMonth);
|
|
305
353
|
}
|
|
306
|
-
totalDays +=
|
|
354
|
+
totalDays += day - 1;
|
|
307
355
|
solarDate.setDate(solarDate.getDate() + totalDays);
|
|
308
356
|
return {
|
|
309
357
|
year: solarDate.getFullYear(),
|
|
@@ -314,6 +362,9 @@ export function lunarToSolar(lunarYear, lunarMonth, lunarDay) {
|
|
|
314
362
|
// 农历年份的名称
|
|
315
363
|
// prettier-ignore
|
|
316
364
|
export const lunarYearNames = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十'];
|
|
365
|
+
/**
|
|
366
|
+
* 将阿拉伯数字的年份转为汉字数字年份
|
|
367
|
+
*/
|
|
317
368
|
export function getLunarYearName(year) {
|
|
318
369
|
return (String(year)
|
|
319
370
|
.split('')
|
|
@@ -323,14 +374,18 @@ export function getLunarYearName(year) {
|
|
|
323
374
|
// 农历月份的名称
|
|
324
375
|
// prettier-ignore
|
|
325
376
|
export const lunarMonthNames = ['正', '二', '三', '四', '五', '六', '七', '八', '九', '十', '冬', '腊'];
|
|
326
|
-
|
|
377
|
+
/**
|
|
378
|
+
* 获取农历月份名称,月份从1开始,例如:正月,十月,腊月。
|
|
379
|
+
*/
|
|
327
380
|
export function getLunarMonthName(month, isLeapMonth) {
|
|
328
381
|
return (isLeapMonth ? '闰' : '') + lunarMonthNames[month - 1] + '月';
|
|
329
382
|
}
|
|
330
383
|
// 农历日期的名称
|
|
331
384
|
// prettier-ignore
|
|
332
385
|
export const lunarDayNames = ['初一', '初二', '初三', '初四', '初五', '初六', '初七', '初八', '初九', '初十', '十一', '十二', '十三', '十四', '十五', '十六', '十七', '十八', '十九', '二十', '廿一', '廿二', '廿三', '廿四', '廿五', '廿六', '廿七', '廿八', '廿九', '三十'];
|
|
333
|
-
|
|
386
|
+
/**
|
|
387
|
+
* 获取农历日期名称,例如:初一,十二,廿一。
|
|
388
|
+
*/
|
|
334
389
|
export function getLunarDayName(day) {
|
|
335
390
|
return lunarDayNames[day - 1];
|
|
336
391
|
}
|
|
@@ -340,7 +395,9 @@ export const heavenlyStems = ['甲', '乙', '丙', '丁', '戊', '己', '庚', '
|
|
|
340
395
|
// 十二地支
|
|
341
396
|
// prettier-ignore
|
|
342
397
|
export const earthlyBranches = ['子', '丑', '寅', '卯', '辰', '巳', '午', '未', '申', '酉', '戌', '亥'];
|
|
343
|
-
|
|
398
|
+
/**
|
|
399
|
+
* 获取农历时辰名称,例如:子初、子正、午初,午正。
|
|
400
|
+
*/
|
|
344
401
|
export function getLunarHourName(hour) {
|
|
345
402
|
const index = Math.floor(((hour === 23 ? 0 : hour) + 1) / 2) % 12;
|
|
346
403
|
return earthlyBranches[index] + (hour % 2 === 1 ? '初' : '正');
|
package/utils/dom.js
CHANGED
package/utils/geometry.d.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
export type ScrollIntoViewPosition = 'start' | 'center' | 'end' | 'nearest';
|
|
2
|
-
export interface ScrollIntoViewValueOptions {
|
|
3
|
-
position?: ScrollIntoViewPosition;
|
|
4
|
-
startOffset?: number;
|
|
5
|
-
endOffset?: number;
|
|
6
|
-
}
|
|
7
2
|
export interface ScrollIntoViewOptions {
|
|
8
3
|
position?: ScrollIntoViewPosition;
|
|
9
4
|
startOffset?: number;
|
|
@@ -11,36 +6,32 @@ export interface ScrollIntoViewOptions {
|
|
|
11
6
|
duration?: number;
|
|
12
7
|
}
|
|
13
8
|
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
- viewportScrollTop: viewport 新的垂直滚动值
|
|
41
|
-
|
|
42
|
-
*/
|
|
43
|
-
export declare function getScrollIntoViewValue(viewportHeight: number, viewportScrollTop: number, elementHeight: number, elementOffsetTop: number, options?: ScrollIntoViewValueOptions): number;
|
|
9
|
+
* 根据最后位置计算 page 滚动到顶部的值。
|
|
10
|
+
*
|
|
11
|
+
* 也可计算水平方向的滚动值。
|
|
12
|
+
*
|
|
13
|
+
* page
|
|
14
|
+
* ╱
|
|
15
|
+
* ╭───────────────╮ viewport
|
|
16
|
+
* ╭─│─ ─ ─ ─ ─ ─ ─ ─│─╮ ╱
|
|
17
|
+
* │ │ ╭───────────╮ │ │
|
|
18
|
+
* │ │ │ element │ │ │
|
|
19
|
+
* │ │ ╰───────────╯ │ │
|
|
20
|
+
* ╰─│─ ─ ─ ─ ─ ─ ─ ─│─╯
|
|
21
|
+
* │ │
|
|
22
|
+
* │ │
|
|
23
|
+
* ╰───────────────╯
|
|
24
|
+
*
|
|
25
|
+
* @param {number} viewportHeight viewport 高度
|
|
26
|
+
* @param {number} viewportScrollTop viewport 垂直滚动值
|
|
27
|
+
* @param {number} elementHeight element 高度
|
|
28
|
+
* @param {number} elementOffsetTop element 距离页面顶部距离
|
|
29
|
+
* @param {string} options.position element 在 viewport 中的位置,可选:'start' | 'center' | 'end' | 'nearest'
|
|
30
|
+
* @param {number} options.startOffset element 距离视窗顶部的偏移量
|
|
31
|
+
* @param {number} options.endOffset element 距离视窗底部的偏移量
|
|
32
|
+
* @return {number} viewport 新的垂直滚动值
|
|
33
|
+
*/
|
|
34
|
+
export declare function getScrollIntoViewValue(viewportHeight: number, viewportScrollTop: number, elementHeight: number, elementOffsetTop: number, options?: ScrollIntoViewOptions): number;
|
|
44
35
|
export interface NodeRect {
|
|
45
36
|
top: number;
|
|
46
37
|
right: number;
|
|
@@ -49,19 +40,46 @@ export interface NodeRect {
|
|
|
49
40
|
height: number;
|
|
50
41
|
width: number;
|
|
51
42
|
}
|
|
52
|
-
interface MatchScrollVisibleOptions {
|
|
43
|
+
export interface MatchScrollVisibleOptions {
|
|
53
44
|
offset?: number;
|
|
54
45
|
errorValue?: number;
|
|
55
46
|
}
|
|
56
47
|
/**
|
|
57
|
-
*
|
|
48
|
+
* 匹配元素列表中第一个位于滚动盒子可视区域的元素
|
|
49
|
+
*
|
|
50
|
+
* @param {array} rects NodeRect 类型数组
|
|
51
|
+
* @param {function} callback 匹配成功时调用,会接收匹配的元素的下标
|
|
52
|
+
* @param {number} options.offset 偏移量
|
|
53
|
+
* @param {number} options.errorValue 容错值
|
|
58
54
|
*/
|
|
59
55
|
export declare function matchScrollVisible(rects: NodeRect[], callback: (index: number) => unknown, options?: MatchScrollVisibleOptions): Promise<unknown>;
|
|
56
|
+
/**
|
|
57
|
+
* 保持纵横比缩放图片,只保证图片的短边能完全显示出来。也就是说,图片通常只在水平或垂直方向是完整的,另一个方向将会发生截取。
|
|
58
|
+
*/
|
|
60
59
|
export declare function getAspectFillSize(origWidth: number, origHeight: number, containerWidth: number, containerHeight: number): [number, number];
|
|
60
|
+
/**
|
|
61
|
+
* 保持纵横比缩放图片,使图片的长边能完全显示出来。也就是说,可以完整地将图片显示出来。
|
|
62
|
+
*/
|
|
61
63
|
export declare function getAspectFitSize(origWidth: number, origHeight: number, containerWidth: number, containerHeight: number): [number, number];
|
|
62
|
-
interface Point {
|
|
64
|
+
export interface Point {
|
|
63
65
|
x: number;
|
|
64
66
|
y: number;
|
|
65
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* 获取两点间的距离
|
|
70
|
+
*/
|
|
66
71
|
export declare function getTwoPointsDistance(p1: Point, p2: Point): number;
|
|
72
|
+
interface Rect {
|
|
73
|
+
x: number;
|
|
74
|
+
y: number;
|
|
75
|
+
width: number;
|
|
76
|
+
height: number;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* @description: 根据原始坐标尺寸和缩放后的坐标尺寸算出转换的原点
|
|
80
|
+
* @param {Rect} rect
|
|
81
|
+
* @param {Rect} scaleRect
|
|
82
|
+
* @return {[number, number]}
|
|
83
|
+
*/
|
|
84
|
+
export declare function getTransformOrigin(rect: Rect, scaleRect: Rect): [number, number];
|
|
67
85
|
export {};
|