sard-uniapp 1.17.0 → 1.18.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 +25 -0
- package/components/button/button.vue +1 -1
- package/components/calendar-month/calendar-month.vue +8 -8
- package/components/config/index.d.ts +2 -0
- package/components/config/index.js +2 -0
- package/components/datetime-picker/common.d.ts +7 -3
- package/components/datetime-picker/common.js +181 -9
- package/components/datetime-picker/datetime-picker.d.ts +1 -0
- package/components/datetime-picker/datetime-picker.vue +116 -20
- package/components/datetime-picker-input/common.d.ts +1 -0
- package/components/datetime-picker-input/datetime-picker-input.d.ts +1 -0
- package/components/datetime-picker-input/datetime-picker-input.vue +2 -0
- package/components/datetime-picker-popout/common.d.ts +1 -0
- package/components/datetime-picker-popout/datetime-picker-popout.d.ts +1 -0
- package/components/datetime-picker-popout/datetime-picker-popout.vue +2 -0
- package/components/datetime-range-picker/datetime-range-picker.vue +1 -0
- package/components/datetime-range-picker-input/datetime-range-picker-input.vue +1 -0
- package/components/datetime-range-picker-popout/datetime-range-picker-popout.vue +1 -0
- package/components/dropdown/common.d.ts +2 -1
- package/components/dropdown-item/dropdown-item.d.ts +5 -7
- package/components/dropdown-item/dropdown-item.vue +3 -1
- package/components/empty/empty.vue +1 -1
- package/components/fab/fab.vue +1 -1
- package/components/grid-item/grid-item.vue +1 -1
- package/components/icon/icon.vue +9 -4
- package/components/list-item/list-item.vue +1 -1
- package/components/menu-item/menu-item.vue +1 -1
- package/components/navbar-item/navbar-item.vue +1 -1
- package/components/popup/popup.vue +14 -1
- package/components/rate/rate.vue +2 -2
- package/components/result/result.vue +1 -1
- package/components/share-sheet/share-sheet.vue +1 -1
- package/components/step/common.d.ts +22 -0
- package/components/step/common.js +1 -0
- package/components/step/index.d.ts +1 -0
- package/components/step/index.js +1 -0
- package/components/step/index.scss +215 -0
- package/components/step/step.d.ts +10 -0
- package/components/step/step.vue +97 -0
- package/components/steps/common.d.ts +18 -1
- package/components/steps/common.js +1 -0
- package/components/steps/index.d.ts +1 -1
- package/components/steps/index.scss +0 -216
- package/components/steps/steps.d.ts +10 -2
- package/components/steps/steps.vue +34 -56
- package/components/tabbar-item/tabbar-item.vue +1 -5
- package/components/timeline-item/timeline-item.vue +1 -5
- package/global.d.ts +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -1
- package/utils/date.d.ts +33 -3
- package/utils/date.js +209 -11
package/utils/date.js
CHANGED
|
@@ -4,19 +4,30 @@ import { minmax } from './utils';
|
|
|
4
4
|
export function isLeapYear(year) {
|
|
5
5
|
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
8
|
+
// 获取某月的天数
|
|
9
|
+
export function getMonthDays(year, month) {
|
|
10
10
|
if (month === 2) {
|
|
11
11
|
return isLeapYear(year) ? 29 : 28;
|
|
12
12
|
}
|
|
13
13
|
else {
|
|
14
|
-
return [
|
|
14
|
+
return monthDays[month - 1];
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
//
|
|
18
|
-
export function
|
|
19
|
-
|
|
17
|
+
// 获取当前日期是一年中的第几天
|
|
18
|
+
export function getDaysInYear(date) {
|
|
19
|
+
const year = date.getFullYear();
|
|
20
|
+
const month = date.getMonth();
|
|
21
|
+
const d = date.getDate();
|
|
22
|
+
let days = 0;
|
|
23
|
+
for (let m = 0; m < month; m++) {
|
|
24
|
+
days += getMonthDays(year, m + 1);
|
|
25
|
+
}
|
|
26
|
+
return days + d;
|
|
27
|
+
}
|
|
28
|
+
// 获取某月一号对应是星期几
|
|
29
|
+
export function getWeekOfMonthStart(year, month) {
|
|
30
|
+
return new Date(year, month - 1, 1).getDay();
|
|
20
31
|
}
|
|
21
32
|
// 获取 Date 中的总天数
|
|
22
33
|
export function getDaysInDate(date) {
|
|
@@ -38,7 +49,7 @@ export function toMonthNumber(date) {
|
|
|
38
49
|
export function getPadStartDays(year, month, amount) {
|
|
39
50
|
const dates = [];
|
|
40
51
|
for (let i = amount - 1; i >= 0; i--) {
|
|
41
|
-
dates.push(new Date(year, month, -i));
|
|
52
|
+
dates.push(new Date(year, month - 1, -i));
|
|
42
53
|
}
|
|
43
54
|
return dates;
|
|
44
55
|
}
|
|
@@ -46,13 +57,13 @@ export function getPadStartDays(year, month, amount) {
|
|
|
46
57
|
export function getPadEndDays(year, month, amount) {
|
|
47
58
|
const dates = [];
|
|
48
59
|
for (let i = 1; i <= amount; i++) {
|
|
49
|
-
dates.push(new Date(year, month + 1, i));
|
|
60
|
+
dates.push(new Date(year, month + 1 - 1, i));
|
|
50
61
|
}
|
|
51
62
|
return dates;
|
|
52
63
|
}
|
|
53
64
|
// 获取一号偏移的天数
|
|
54
|
-
export function
|
|
55
|
-
return (
|
|
65
|
+
export function getOffsetDaysFromMonthStart(weekOnMonthStart, weekStartsOn) {
|
|
66
|
+
return (weekOnMonthStart - weekStartsOn + 7) % 7;
|
|
56
67
|
}
|
|
57
68
|
const dateTokensReg = /(YYYY|YY|MM|M|DD|D|HH|H|hh|h|mm|m|ss|s|SSS)/g;
|
|
58
69
|
const dateGetters = {
|
|
@@ -147,3 +158,190 @@ export function getPrevMonthDate(date) {
|
|
|
147
158
|
export function getNextMonthDate(date) {
|
|
148
159
|
return new Date(date.getFullYear(), date.getMonth() + 1, 1);
|
|
149
160
|
}
|
|
161
|
+
/****************************************************************
|
|
162
|
+
* 农历
|
|
163
|
+
****************************************************************/
|
|
164
|
+
// prettier-ignore
|
|
165
|
+
export const lunarInfo = [
|
|
166
|
+
0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2, // 1900-1909
|
|
167
|
+
0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977, // 1910-1919
|
|
168
|
+
0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970, // 1920-1929
|
|
169
|
+
0x06566, 0x0d4a0, 0x0ea50, 0x16a95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950, // 1930-1939
|
|
170
|
+
0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557, // 1940-1949
|
|
171
|
+
0x06ca0, 0x0b550, 0x15355, 0x04da0, 0x0a5b0, 0x14573, 0x052b0, 0x0a9a8, 0x0e950, 0x06aa0, // 1950-1959
|
|
172
|
+
0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950, 0x05b57, 0x056a0, // 1960-1969
|
|
173
|
+
0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b6a0, 0x195a6, // 1970-1979
|
|
174
|
+
0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46, 0x0ab60, 0x09570, // 1980-1989
|
|
175
|
+
0x04af5, 0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x05ac0, 0x0ab60, 0x096d5, 0x092e0, // 1990-1999
|
|
176
|
+
0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5, // 2000-2009
|
|
177
|
+
0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930, // 2010-2019
|
|
178
|
+
0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65, 0x0d530, // 2020-2029
|
|
179
|
+
0x05aa0, 0x076a3, 0x096d0, 0x04afb, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, // 2030-2039
|
|
180
|
+
0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0, // 2040-2049
|
|
181
|
+
0x14b63, 0x09370, 0x049f8, 0x04970, 0x064b0, 0x168a6, 0x0ea50, 0x06b20, 0x1a6c4, 0x0aae0, // 2050-2059
|
|
182
|
+
0x092e0, 0x0d2e3, 0x0c960, 0x0d557, 0x0d4a0, 0x0da50, 0x05d55, 0x056a0, 0x0a6d0, 0x055d4, // 2060-2069
|
|
183
|
+
0x052d0, 0x0a9b8, 0x0a950, 0x0b4a0, 0x0b6a6, 0x0ad50, 0x055a0, 0x0aba4, 0x0a5b0, 0x052b0, // 2070-2079
|
|
184
|
+
0x0b273, 0x06930, 0x07337, 0x06aa0, 0x0ad50, 0x14b55, 0x04b60, 0x0a570, 0x054e4, 0x0d160, // 2080-2089
|
|
185
|
+
0x0e968, 0x0d520, 0x0daa0, 0x16aa6, 0x056d0, 0x04ae0, 0x0a9d4, 0x0a2d0, 0x0d150, 0x0f252, // 2090-2099
|
|
186
|
+
0x0d520, // 2100
|
|
187
|
+
];
|
|
188
|
+
// 1900-2100春节对应的公历日期
|
|
189
|
+
// prettier-ignore
|
|
190
|
+
export const springFestivals = [
|
|
191
|
+
[1, 31], [2, 19], [2, 8], [1, 29], [2, 16], [2, 4], [1, 25], [2, 13], [2, 2], [1, 22], // 1900-1909
|
|
192
|
+
[2, 10], [1, 30], [2, 18], [2, 6], [1, 26], [2, 14], [2, 3], [1, 23], [2, 11], [2, 1], // 1910-1919
|
|
193
|
+
[2, 20], [2, 8], [1, 28], [2, 16], [2, 5], [1, 24], [2, 13], [2, 2], [1, 23], [2, 10], // 1920-1929
|
|
194
|
+
[1, 30], [2, 17], [2, 6], [1, 26], [2, 14], [2, 4], [1, 24], [2, 11], [1, 31], [2, 19], // 1930-1939
|
|
195
|
+
[2, 8], [1, 27], [2, 15], [2, 5], [1, 25], [2, 13], [2, 2], [1, 22], [2, 10], [1, 29], // 1940-1949
|
|
196
|
+
[2, 17], [2, 6], [1, 27], [2, 14], [2, 3], [1, 24], [2, 12], [1, 31], [2, 18], [2, 8], // 1950-1959
|
|
197
|
+
[1, 28], [2, 15], [2, 5], [1, 25], [2, 13], [2, 2], [1, 21], [2, 9], [1, 30], [2, 17], // 1960-1969
|
|
198
|
+
[2, 6], [1, 27], [2, 15], [2, 3], [1, 23], [2, 11], [1, 31], [2, 18], [2, 7], [1, 28], // 1970-1979
|
|
199
|
+
[2, 16], [2, 5], [1, 25], [2, 13], [2, 2], [2, 20], [2, 9], [1, 29], [2, 17], [2, 6], // 1980-1989
|
|
200
|
+
[1, 27], [2, 15], [2, 4], [1, 23], [2, 10], [1, 31], [2, 19], [2, 7], [1, 28], [2, 16], // 1990-1999
|
|
201
|
+
[2, 5], [1, 24], [2, 12], [2, 1], [1, 22], [2, 9], [1, 29], [2, 18], [2, 7], [1, 26], // 2000-2009
|
|
202
|
+
[2, 14], [2, 3], [1, 23], [2, 10], [1, 31], [2, 19], [2, 8], [1, 28], [2, 16], [2, 5], // 2010-2019
|
|
203
|
+
[1, 25], [2, 12], [2, 1], [1, 22], [2, 10], [1, 29], [2, 17], [2, 6], [1, 26], [2, 13], // 2020-2029
|
|
204
|
+
[2, 3], [1, 23], [2, 11], [1, 31], [2, 19], [2, 8], [1, 28], [2, 15], [2, 4], [1, 24], // 2030-2039
|
|
205
|
+
[2, 12], [2, 1], [1, 22], [2, 10], [1, 30], [2, 17], [2, 6], [1, 26], [2, 14], [2, 2], // 2040-2049
|
|
206
|
+
[1, 23], [2, 11], [2, 1], [2, 19], [2, 8], [1, 28], [2, 15], [2, 4], [1, 24], [2, 12], // 2050-2059
|
|
207
|
+
[2, 2], [1, 21], [2, 9], [1, 29], [2, 17], [2, 5], [1, 26], [2, 14], [2, 3], [1, 23], // 2060-2069
|
|
208
|
+
[2, 11], [1, 31], [2, 19], [2, 7], [1, 27], [2, 15], [2, 5], [1, 24], [2, 12], [2, 2], // 2070-2079
|
|
209
|
+
[1, 22], [2, 9], [1, 29], [2, 17], [2, 6], [1, 26], [2, 14], [2, 3], [1, 24], [2, 10], // 2080-2089
|
|
210
|
+
[1, 30], [2, 18], [2, 7], [1, 27], [2, 15], [2, 5], [1, 25], [2, 12], [2, 1], [1, 21], // 2090-2099
|
|
211
|
+
[2, 9], // 2100
|
|
212
|
+
];
|
|
213
|
+
export const baseLunarYear = 1900;
|
|
214
|
+
// 获取农历某年闰月的月份(0表示无闰月)
|
|
215
|
+
export function getLunarLeapMonth(year) {
|
|
216
|
+
return lunarInfo[year - baseLunarYear] & 0xf;
|
|
217
|
+
}
|
|
218
|
+
// 获取农历某年闰月的天数
|
|
219
|
+
export function getLunarLeapMonthDays(year) {
|
|
220
|
+
if (getLunarLeapMonth(year)) {
|
|
221
|
+
return lunarInfo[year - baseLunarYear] & 0x10000 ? 30 : 29;
|
|
222
|
+
}
|
|
223
|
+
return 0;
|
|
224
|
+
}
|
|
225
|
+
// 获取农历某年的总天数
|
|
226
|
+
export function getLunarYearDays(year) {
|
|
227
|
+
let sum = 348; // 29天*12个月
|
|
228
|
+
const info = lunarInfo[year - baseLunarYear];
|
|
229
|
+
// 加上大月的天数
|
|
230
|
+
for (let i = 0x8000; i > 0x8; i >>= 1) {
|
|
231
|
+
sum += info & i ? 1 : 0;
|
|
232
|
+
}
|
|
233
|
+
// 加上闰月的天数
|
|
234
|
+
return sum + getLunarLeapMonthDays(year);
|
|
235
|
+
}
|
|
236
|
+
// 获取农历某年某月的天数
|
|
237
|
+
export function getLunarMonthDays(year, month) {
|
|
238
|
+
return lunarInfo[year - baseLunarYear] & (0x10000 >> month) ? 30 : 29;
|
|
239
|
+
}
|
|
240
|
+
// 公历转农历
|
|
241
|
+
export function solarToLunar(year, _month, date) {
|
|
242
|
+
// 计算输入日期与基准日期的天数差
|
|
243
|
+
const offsetDays = Math.floor((Date.UTC(year, _month - 1, date) - Date.UTC(baseLunarYear, 0, 31)) /
|
|
244
|
+
(24 * 60 * 60 * 1000));
|
|
245
|
+
// 农历年、月、日初始化
|
|
246
|
+
let lunarYear = baseLunarYear;
|
|
247
|
+
let lunarMonth = 1;
|
|
248
|
+
let lunarDay = 1;
|
|
249
|
+
let isLeapMonth = false;
|
|
250
|
+
let daysRemaining = offsetDays;
|
|
251
|
+
// 计算农历年
|
|
252
|
+
while (true) {
|
|
253
|
+
const yearDays = getLunarYearDays(lunarYear);
|
|
254
|
+
if (daysRemaining < yearDays) {
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
daysRemaining -= yearDays;
|
|
258
|
+
lunarYear++;
|
|
259
|
+
}
|
|
260
|
+
// 计算农历月和日
|
|
261
|
+
const leapMonth = getLunarLeapMonth(lunarYear);
|
|
262
|
+
let monthDays = 0;
|
|
263
|
+
let month = 1;
|
|
264
|
+
for (; month <= 12; month++) {
|
|
265
|
+
// 处理闰月
|
|
266
|
+
if (leapMonth > 0 && month === leapMonth + 1) {
|
|
267
|
+
monthDays = getLunarLeapMonthDays(lunarYear);
|
|
268
|
+
if (daysRemaining < monthDays) {
|
|
269
|
+
isLeapMonth = true;
|
|
270
|
+
month--;
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
daysRemaining -= monthDays;
|
|
274
|
+
}
|
|
275
|
+
monthDays = getLunarMonthDays(lunarYear, month);
|
|
276
|
+
if (daysRemaining < monthDays) {
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
daysRemaining -= monthDays;
|
|
280
|
+
}
|
|
281
|
+
lunarMonth = month;
|
|
282
|
+
lunarDay = daysRemaining + 1;
|
|
283
|
+
return {
|
|
284
|
+
year: lunarYear,
|
|
285
|
+
month: lunarMonth * (isLeapMonth ? -1 : 1),
|
|
286
|
+
day: lunarDay,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
// 农历转公历(闰月需传递负数)
|
|
290
|
+
export function lunarToSolar(lunarYear, lunarMonth, lunarDay) {
|
|
291
|
+
const springFestival = springFestivals[lunarYear - baseLunarYear];
|
|
292
|
+
const solarDate = new Date(lunarYear, springFestival[0] - 1, springFestival[1]);
|
|
293
|
+
const info = lunarInfo[lunarYear - baseLunarYear];
|
|
294
|
+
const leapMonth = info & 0xf;
|
|
295
|
+
let totalDays = 0;
|
|
296
|
+
const absMonth = Math.abs(lunarMonth);
|
|
297
|
+
for (let m = 1; m < absMonth; m++) {
|
|
298
|
+
if (m === leapMonth) {
|
|
299
|
+
totalDays += getLunarLeapMonthDays(lunarYear);
|
|
300
|
+
}
|
|
301
|
+
totalDays += getLunarMonthDays(lunarYear, m);
|
|
302
|
+
}
|
|
303
|
+
if (lunarMonth < 0) {
|
|
304
|
+
totalDays += getLunarMonthDays(lunarYear, absMonth);
|
|
305
|
+
}
|
|
306
|
+
totalDays += lunarDay - 1;
|
|
307
|
+
solarDate.setDate(solarDate.getDate() + totalDays);
|
|
308
|
+
return {
|
|
309
|
+
year: solarDate.getFullYear(),
|
|
310
|
+
month: solarDate.getMonth() + 1,
|
|
311
|
+
day: solarDate.getDate(),
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
// 农历年份的名称
|
|
315
|
+
// prettier-ignore
|
|
316
|
+
export const lunarYearNames = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十'];
|
|
317
|
+
export function getLunarYearName(year) {
|
|
318
|
+
return (String(year)
|
|
319
|
+
.split('')
|
|
320
|
+
.map((item) => lunarYearNames[+item])
|
|
321
|
+
.join('') + '年');
|
|
322
|
+
}
|
|
323
|
+
// 农历月份的名称
|
|
324
|
+
// prettier-ignore
|
|
325
|
+
export const lunarMonthNames = ['正', '二', '三', '四', '五', '六', '七', '八', '九', '十', '冬', '腊'];
|
|
326
|
+
// 获取农历月份名称
|
|
327
|
+
export function getLunarMonthName(month, isLeapMonth) {
|
|
328
|
+
return (isLeapMonth ? '闰' : '') + lunarMonthNames[month - 1] + '月';
|
|
329
|
+
}
|
|
330
|
+
// 农历日期的名称
|
|
331
|
+
// prettier-ignore
|
|
332
|
+
export const lunarDayNames = ['初一', '初二', '初三', '初四', '初五', '初六', '初七', '初八', '初九', '初十', '十一', '十二', '十三', '十四', '十五', '十六', '十七', '十八', '十九', '二十', '廿一', '廿二', '廿三', '廿四', '廿五', '廿六', '廿七', '廿八', '廿九', '三十'];
|
|
333
|
+
// 获取农历日期名称
|
|
334
|
+
export function getLunarDayName(day) {
|
|
335
|
+
return lunarDayNames[day - 1];
|
|
336
|
+
}
|
|
337
|
+
// 十天干
|
|
338
|
+
// prettier-ignore
|
|
339
|
+
export const heavenlyStems = ['甲', '乙', '丙', '丁', '戊', '己', '庚', '辛', '壬', '癸'];
|
|
340
|
+
// 十二地支
|
|
341
|
+
// prettier-ignore
|
|
342
|
+
export const earthlyBranches = ['子', '丑', '寅', '卯', '辰', '巳', '午', '未', '申', '酉', '戌', '亥'];
|
|
343
|
+
// 获取农历时辰名称
|
|
344
|
+
export function getLunarHourName(hour) {
|
|
345
|
+
const index = Math.floor(((hour === 23 ? 0 : hour) + 1) / 2) % 12;
|
|
346
|
+
return earthlyBranches[index] + (hour % 2 === 1 ? '初' : '正');
|
|
347
|
+
}
|