tools-min-ns 1.9.2 → 1.9.4
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/README.md +9 -0
- package/esm/date/DateUtil.d.ts +14 -4
- package/esm/date/DateUtil.js +31 -20
- package/esm/url/UrlUtil.d.ts +2 -2
- package/esm/url/UrlUtil.js +48 -10
- package/lib/date/DateUtil.d.ts +14 -4
- package/lib/date/DateUtil.js +31 -20
- package/lib/url/UrlUtil.d.ts +2 -2
- package/lib/url/UrlUtil.js +48 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,6 +5,15 @@ cnpm i tools-min-ns --save
|
|
|
5
5
|
```
|
|
6
6
|
|
|
7
7
|
# updates
|
|
8
|
+
## v1.9.4
|
|
9
|
+
|
|
10
|
+
> UrlUtil 优化setUrlParamsNotRefresh在web,h5中的路由为hash的兼容性
|
|
11
|
+
|
|
12
|
+
## v1.9.3
|
|
13
|
+
|
|
14
|
+
> DateUtil 优化并新增isDateInYearAndMonth方法
|
|
15
|
+
> UrlUtil 优化getUrlRequest在web,h5中的路由为hash的兼容性
|
|
16
|
+
|
|
8
17
|
## v1.9.2
|
|
9
18
|
|
|
10
19
|
> CheckUtil getFormItemRules required默认为false
|
package/esm/date/DateUtil.d.ts
CHANGED
|
@@ -108,15 +108,15 @@ declare namespace DateUtil {
|
|
|
108
108
|
* isLeapYear(2001) = false
|
|
109
109
|
* isLeapYear(2004) = true
|
|
110
110
|
*/
|
|
111
|
-
const isLeapYear: (year: number) => boolean;
|
|
111
|
+
const isLeapYear: (year: string | number) => boolean;
|
|
112
112
|
/**
|
|
113
113
|
* 计算在给定的年份中,给定的月份有多少天(会自动判断是否为闰年)
|
|
114
114
|
* @param {Number} year 年份
|
|
115
|
-
* @param {Number} month 月份 (
|
|
115
|
+
* @param {Number} month 月份 (1-12)
|
|
116
116
|
* @example
|
|
117
117
|
* getDaysInMonth(2012,2) => 31
|
|
118
118
|
*/
|
|
119
|
-
const getDaysInMonth: (year: number, month: number) => number;
|
|
119
|
+
const getDaysInMonth: (year: string | number, month: string | number) => number;
|
|
120
120
|
/**
|
|
121
121
|
* 获取时间的开头
|
|
122
122
|
* @param date 日期
|
|
@@ -250,7 +250,7 @@ declare namespace DateUtil {
|
|
|
250
250
|
* @param {string} day2 '2024'
|
|
251
251
|
* @returns ['2022','2023','2024']
|
|
252
252
|
*/
|
|
253
|
-
const getSectionYearList: (day1: string, day2: string) => string[];
|
|
253
|
+
const getSectionYearList: (day1: string | number, day2: string | number) => (string | number)[];
|
|
254
254
|
/**
|
|
255
255
|
* 后端给的时间修复
|
|
256
256
|
* @param t
|
|
@@ -264,5 +264,15 @@ declare namespace DateUtil {
|
|
|
264
264
|
* @returns ['2024-01-01',...]
|
|
265
265
|
*/
|
|
266
266
|
function getDatesOfMonth(yearMonth: string, format?: string): string[];
|
|
267
|
+
/**
|
|
268
|
+
* 判断日期字符串是否在指定的年月内。
|
|
269
|
+
*
|
|
270
|
+
* @param date 日期
|
|
271
|
+
* @param yearStr 指定的年份,字符串格式
|
|
272
|
+
* @param month 指定的月份,整型(1-12)
|
|
273
|
+
* @param format 目标字符串格式,支持的字符有:y,M,d,q,w,H,h,m,S,默认:yyyy-MM-dd
|
|
274
|
+
* @return 如果在指定的年月内返回true,否则返回false
|
|
275
|
+
*/
|
|
276
|
+
const isDateInYearAndMonth: (date: Date | string | number, yearStr: string, month: number, format?: string) => boolean;
|
|
267
277
|
}
|
|
268
278
|
export default DateUtil;
|
package/esm/date/DateUtil.js
CHANGED
|
@@ -338,17 +338,18 @@ var DateUtil;
|
|
|
338
338
|
* isLeapYear(2004) = true
|
|
339
339
|
*/
|
|
340
340
|
DateUtil.isLeapYear = function (year) {
|
|
341
|
-
|
|
341
|
+
var _year = Number(year);
|
|
342
|
+
return _year % 4 === 0 && _year % 100 !== 0 || _year % 400 === 0;
|
|
342
343
|
};
|
|
343
344
|
/**
|
|
344
345
|
* 计算在给定的年份中,给定的月份有多少天(会自动判断是否为闰年)
|
|
345
346
|
* @param {Number} year 年份
|
|
346
|
-
* @param {Number} month 月份 (
|
|
347
|
+
* @param {Number} month 月份 (1-12)
|
|
347
348
|
* @example
|
|
348
349
|
* getDaysInMonth(2012,2) => 31
|
|
349
350
|
*/
|
|
350
351
|
DateUtil.getDaysInMonth = function (year, month) {
|
|
351
|
-
return [31, DateUtil.isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
|
|
352
|
+
return [31, DateUtil.isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][Number(month) - 1];
|
|
352
353
|
};
|
|
353
354
|
/**
|
|
354
355
|
* 获取时间的开头
|
|
@@ -479,11 +480,11 @@ var DateUtil;
|
|
|
479
480
|
format = 'yyyy-MM-dd';
|
|
480
481
|
}
|
|
481
482
|
try {
|
|
482
|
-
date = DateUtil.parseDate(date);
|
|
483
|
+
date = DateUtil.parseDate(date, format);
|
|
483
484
|
} catch (_a) {
|
|
484
485
|
date = new Date();
|
|
485
486
|
}
|
|
486
|
-
var init = DateUtil.getDateStart(date, 'YEAR');
|
|
487
|
+
var init = DateUtil.getDateStart(date, 'YEAR', format);
|
|
487
488
|
return Math.floor((date.getTime() - init.getTime()) / (24 * 60 * 60 * 1000)) + 1;
|
|
488
489
|
};
|
|
489
490
|
/**
|
|
@@ -500,11 +501,11 @@ var DateUtil;
|
|
|
500
501
|
format = 'yyyy-MM-dd';
|
|
501
502
|
}
|
|
502
503
|
try {
|
|
503
|
-
date = DateUtil.parseDate(date);
|
|
504
|
+
date = DateUtil.parseDate(date, format);
|
|
504
505
|
} catch (_a) {
|
|
505
506
|
date = new Date();
|
|
506
507
|
}
|
|
507
|
-
var init = DateUtil.getDateStart(date, 'YEAR');
|
|
508
|
+
var init = DateUtil.getDateStart(date, 'YEAR', format);
|
|
508
509
|
return Math.floor((date.getTime() - init.getTime()) / (7 * 24 * 60 * 60 * 1000)) + 1;
|
|
509
510
|
};
|
|
510
511
|
/**
|
|
@@ -521,11 +522,11 @@ var DateUtil;
|
|
|
521
522
|
format = 'yyyy-MM-dd';
|
|
522
523
|
}
|
|
523
524
|
try {
|
|
524
|
-
date = DateUtil.parseDate(date);
|
|
525
|
+
date = DateUtil.parseDate(date, format);
|
|
525
526
|
} catch (_a) {
|
|
526
527
|
date = new Date();
|
|
527
528
|
}
|
|
528
|
-
var init = DateUtil.getDateStart(date, 'MONTH');
|
|
529
|
+
var init = DateUtil.getDateStart(date, 'MONTH', format);
|
|
529
530
|
return Math.floor((date.getTime() - init.getTime()) / (7 * 24 * 60 * 60 * 1000)) + 1;
|
|
530
531
|
};
|
|
531
532
|
/**
|
|
@@ -550,22 +551,12 @@ var DateUtil;
|
|
|
550
551
|
} catch (_b) {
|
|
551
552
|
date2 = new Date();
|
|
552
553
|
}
|
|
553
|
-
var
|
|
554
|
-
var timestampDiff = isFirstMore ? date1.getTime() - date2.getTime() : date2.getTime() - date1.getTime();
|
|
554
|
+
var timestampDiff = Math.abs(date1.getTime() - date2.getTime());
|
|
555
555
|
var day = Math.floor(timestampDiff / (24 * 60 * 60 * 1000));
|
|
556
556
|
var hour = Math.floor(timestampDiff % (24 * 60 * 60 * 1000) / (60 * 60 * 1000));
|
|
557
557
|
var minute = Math.floor((timestampDiff - day * 24 * 60 * 60 * 1000 - hour * 60 * 60 * 1000) / (60 * 1000));
|
|
558
558
|
var second = Math.floor((timestampDiff - day * 24 * 60 * 60 * 1000 - hour * 60 * 60 * 1000 - minute * 60 * 1000) / 1000);
|
|
559
559
|
var ms = timestampDiff - day * 24 * 60 * 60 * 1000 - hour * 60 * 60 * 1000 - minute * 60 * 1000 - second * 1000;
|
|
560
|
-
if (isFirstMore) {
|
|
561
|
-
return {
|
|
562
|
-
Day: day === 0 ? 0 : -day,
|
|
563
|
-
Hour: hour === 0 ? 0 : -hour,
|
|
564
|
-
Minute: minute === 0 ? 0 : -minute,
|
|
565
|
-
Second: second === 0 ? 0 : -second,
|
|
566
|
-
Millsecond: ms === 0 ? 0 : -ms
|
|
567
|
-
};
|
|
568
|
-
}
|
|
569
560
|
return {
|
|
570
561
|
Day: day,
|
|
571
562
|
Hour: hour,
|
|
@@ -757,6 +748,26 @@ var DateUtil;
|
|
|
757
748
|
return dates;
|
|
758
749
|
}
|
|
759
750
|
DateUtil.getDatesOfMonth = getDatesOfMonth;
|
|
751
|
+
/**
|
|
752
|
+
* 判断日期字符串是否在指定的年月内。
|
|
753
|
+
*
|
|
754
|
+
* @param date 日期
|
|
755
|
+
* @param yearStr 指定的年份,字符串格式
|
|
756
|
+
* @param month 指定的月份,整型(1-12)
|
|
757
|
+
* @param format 目标字符串格式,支持的字符有:y,M,d,q,w,H,h,m,S,默认:yyyy-MM-dd
|
|
758
|
+
* @return 如果在指定的年月内返回true,否则返回false
|
|
759
|
+
*/
|
|
760
|
+
DateUtil.isDateInYearAndMonth = function (date, yearStr, month, format) {
|
|
761
|
+
if (format === void 0) {
|
|
762
|
+
format = 'yyyy-MM-dd';
|
|
763
|
+
}
|
|
764
|
+
try {
|
|
765
|
+
date = DateUtil.parseDate(date, format);
|
|
766
|
+
} catch (_a) {
|
|
767
|
+
date = new Date();
|
|
768
|
+
}
|
|
769
|
+
return date.getFullYear() == Number(yearStr) && date.getMonth() + 1 == month;
|
|
770
|
+
};
|
|
760
771
|
})(DateUtil || (DateUtil = {}));
|
|
761
772
|
export default DateUtil;
|
|
762
773
|
var dateFormatRules = [{
|
package/esm/url/UrlUtil.d.ts
CHANGED
|
@@ -20,11 +20,11 @@ declare namespace UrlUtil {
|
|
|
20
20
|
* @example
|
|
21
21
|
* getUrlRequest('https://ss.cn?sdf=213&bdl=231111'); => {sdf: "213", bdl: "231111"}
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
function getUrlRequest<T extends Record<string, string>>(href?: string): T;
|
|
24
24
|
/**
|
|
25
25
|
* 不刷新改变url参数
|
|
26
26
|
* @param obj 对象
|
|
27
27
|
*/
|
|
28
|
-
function setUrlParamsNotRefresh
|
|
28
|
+
function setUrlParamsNotRefresh<T extends Record<string, any>>(obj: T): void;
|
|
29
29
|
}
|
|
30
30
|
export default UrlUtil;
|
package/esm/url/UrlUtil.js
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
var __read = this && this.__read || function (o, n) {
|
|
2
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
+
if (!m) return o;
|
|
4
|
+
var i = m.call(o),
|
|
5
|
+
r,
|
|
6
|
+
ar = [],
|
|
7
|
+
e;
|
|
8
|
+
try {
|
|
9
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
10
|
+
} catch (error) {
|
|
11
|
+
e = {
|
|
12
|
+
error: error
|
|
13
|
+
};
|
|
14
|
+
} finally {
|
|
15
|
+
try {
|
|
16
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
17
|
+
} finally {
|
|
18
|
+
if (e) throw e.error;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return ar;
|
|
22
|
+
};
|
|
1
23
|
/**
|
|
2
24
|
* url工具
|
|
3
25
|
* @description
|
|
@@ -44,7 +66,7 @@ var UrlUtil;
|
|
|
44
66
|
var _a;
|
|
45
67
|
(_a = urlSearch === null || urlSearch === void 0 ? void 0 : urlSearch['delete']) === null || _a === void 0 ? void 0 : _a.call(urlSearch, param);
|
|
46
68
|
});
|
|
47
|
-
return (urlSearch === null || urlSearch === void 0 ? void 0 : urlSearch.toString()) ? "".concat(hostAndPath, "?").concat(urlSearch
|
|
69
|
+
return (urlSearch === null || urlSearch === void 0 ? void 0 : urlSearch.toString()) ? "".concat(hostAndPath, "?").concat(urlSearch) : hostAndPath;
|
|
48
70
|
}
|
|
49
71
|
UrlUtil.deleteUrlParam = deleteUrlParam;
|
|
50
72
|
/**
|
|
@@ -53,29 +75,45 @@ var UrlUtil;
|
|
|
53
75
|
* @example
|
|
54
76
|
* getUrlRequest('https://ss.cn?sdf=213&bdl=231111'); => {sdf: "213", bdl: "231111"}
|
|
55
77
|
*/
|
|
56
|
-
|
|
78
|
+
function getUrlRequest(href) {
|
|
57
79
|
if (href === void 0) {
|
|
58
80
|
href = window.location.href;
|
|
59
81
|
}
|
|
60
|
-
|
|
82
|
+
href = "".concat(href === null || href === void 0 ? void 0 : href.slice(-1)) === '/' ? href === null || href === void 0 ? void 0 : href.slice(0, href.length - 1) : href;
|
|
61
83
|
var theRequest = {};
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
|
|
84
|
+
if (href.includes('#/')) {
|
|
85
|
+
//hash
|
|
86
|
+
href = "".concat(href.split('/').slice(-1));
|
|
87
|
+
}
|
|
88
|
+
if (href === null || href === void 0 ? void 0 : href.includes('?')) {
|
|
89
|
+
var strs = href === null || href === void 0 ? void 0 : href.split('?').slice(-1).toString().split('&');
|
|
65
90
|
for (var i = 0; i < strs.length; i++) {
|
|
66
|
-
|
|
91
|
+
var _a = __read(strs[i].split('='), 2),
|
|
92
|
+
key = _a[0],
|
|
93
|
+
value = _a[1];
|
|
94
|
+
if (key) theRequest[key] = decodeURIComponent(value);
|
|
67
95
|
}
|
|
68
96
|
}
|
|
69
97
|
return theRequest;
|
|
70
|
-
}
|
|
98
|
+
}
|
|
99
|
+
UrlUtil.getUrlRequest = getUrlRequest;
|
|
71
100
|
/**
|
|
72
101
|
* 不刷新改变url参数
|
|
73
102
|
* @param obj 对象
|
|
74
103
|
*/
|
|
75
104
|
function setUrlParamsNotRefresh(obj) {
|
|
76
|
-
var urlParams =
|
|
105
|
+
var urlParams = getUrlRequest();
|
|
77
106
|
var str = objToUrlParam(ObjectUtil.mergeParams(obj, urlParams));
|
|
78
|
-
var
|
|
107
|
+
var href = window.location.href;
|
|
108
|
+
if (href.includes('#/') && !"".concat(href.split('/').slice(-1)).includes('?')) {
|
|
109
|
+
var url_1 = "".concat(href).concat(str ? "?".concat(str) : '');
|
|
110
|
+
window.history.replaceState({
|
|
111
|
+
url: url_1
|
|
112
|
+
}, '', url_1);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
var _arr = window.location.href.split('?');
|
|
116
|
+
var url = "".concat(_arr.slice(0, _arr.length - 1).join('?')).concat(str ? "?".concat(str) : '');
|
|
79
117
|
window.history.replaceState({
|
|
80
118
|
url: url
|
|
81
119
|
}, '', url);
|
package/lib/date/DateUtil.d.ts
CHANGED
|
@@ -108,15 +108,15 @@ declare namespace DateUtil {
|
|
|
108
108
|
* isLeapYear(2001) = false
|
|
109
109
|
* isLeapYear(2004) = true
|
|
110
110
|
*/
|
|
111
|
-
const isLeapYear: (year: number) => boolean;
|
|
111
|
+
const isLeapYear: (year: string | number) => boolean;
|
|
112
112
|
/**
|
|
113
113
|
* 计算在给定的年份中,给定的月份有多少天(会自动判断是否为闰年)
|
|
114
114
|
* @param {Number} year 年份
|
|
115
|
-
* @param {Number} month 月份 (
|
|
115
|
+
* @param {Number} month 月份 (1-12)
|
|
116
116
|
* @example
|
|
117
117
|
* getDaysInMonth(2012,2) => 31
|
|
118
118
|
*/
|
|
119
|
-
const getDaysInMonth: (year: number, month: number) => number;
|
|
119
|
+
const getDaysInMonth: (year: string | number, month: string | number) => number;
|
|
120
120
|
/**
|
|
121
121
|
* 获取时间的开头
|
|
122
122
|
* @param date 日期
|
|
@@ -250,7 +250,7 @@ declare namespace DateUtil {
|
|
|
250
250
|
* @param {string} day2 '2024'
|
|
251
251
|
* @returns ['2022','2023','2024']
|
|
252
252
|
*/
|
|
253
|
-
const getSectionYearList: (day1: string, day2: string) => string[];
|
|
253
|
+
const getSectionYearList: (day1: string | number, day2: string | number) => (string | number)[];
|
|
254
254
|
/**
|
|
255
255
|
* 后端给的时间修复
|
|
256
256
|
* @param t
|
|
@@ -264,5 +264,15 @@ declare namespace DateUtil {
|
|
|
264
264
|
* @returns ['2024-01-01',...]
|
|
265
265
|
*/
|
|
266
266
|
function getDatesOfMonth(yearMonth: string, format?: string): string[];
|
|
267
|
+
/**
|
|
268
|
+
* 判断日期字符串是否在指定的年月内。
|
|
269
|
+
*
|
|
270
|
+
* @param date 日期
|
|
271
|
+
* @param yearStr 指定的年份,字符串格式
|
|
272
|
+
* @param month 指定的月份,整型(1-12)
|
|
273
|
+
* @param format 目标字符串格式,支持的字符有:y,M,d,q,w,H,h,m,S,默认:yyyy-MM-dd
|
|
274
|
+
* @return 如果在指定的年月内返回true,否则返回false
|
|
275
|
+
*/
|
|
276
|
+
const isDateInYearAndMonth: (date: Date | string | number, yearStr: string, month: number, format?: string) => boolean;
|
|
267
277
|
}
|
|
268
278
|
export default DateUtil;
|
package/lib/date/DateUtil.js
CHANGED
|
@@ -348,17 +348,18 @@ var DateUtil;
|
|
|
348
348
|
* isLeapYear(2004) = true
|
|
349
349
|
*/
|
|
350
350
|
DateUtil.isLeapYear = function (year) {
|
|
351
|
-
|
|
351
|
+
var _year = Number(year);
|
|
352
|
+
return _year % 4 === 0 && _year % 100 !== 0 || _year % 400 === 0;
|
|
352
353
|
};
|
|
353
354
|
/**
|
|
354
355
|
* 计算在给定的年份中,给定的月份有多少天(会自动判断是否为闰年)
|
|
355
356
|
* @param {Number} year 年份
|
|
356
|
-
* @param {Number} month 月份 (
|
|
357
|
+
* @param {Number} month 月份 (1-12)
|
|
357
358
|
* @example
|
|
358
359
|
* getDaysInMonth(2012,2) => 31
|
|
359
360
|
*/
|
|
360
361
|
DateUtil.getDaysInMonth = function (year, month) {
|
|
361
|
-
return [31, DateUtil.isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
|
|
362
|
+
return [31, DateUtil.isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][Number(month) - 1];
|
|
362
363
|
};
|
|
363
364
|
/**
|
|
364
365
|
* 获取时间的开头
|
|
@@ -489,11 +490,11 @@ var DateUtil;
|
|
|
489
490
|
format = 'yyyy-MM-dd';
|
|
490
491
|
}
|
|
491
492
|
try {
|
|
492
|
-
date = DateUtil.parseDate(date);
|
|
493
|
+
date = DateUtil.parseDate(date, format);
|
|
493
494
|
} catch (_a) {
|
|
494
495
|
date = new Date();
|
|
495
496
|
}
|
|
496
|
-
var init = DateUtil.getDateStart(date, 'YEAR');
|
|
497
|
+
var init = DateUtil.getDateStart(date, 'YEAR', format);
|
|
497
498
|
return Math.floor((date.getTime() - init.getTime()) / (24 * 60 * 60 * 1000)) + 1;
|
|
498
499
|
};
|
|
499
500
|
/**
|
|
@@ -510,11 +511,11 @@ var DateUtil;
|
|
|
510
511
|
format = 'yyyy-MM-dd';
|
|
511
512
|
}
|
|
512
513
|
try {
|
|
513
|
-
date = DateUtil.parseDate(date);
|
|
514
|
+
date = DateUtil.parseDate(date, format);
|
|
514
515
|
} catch (_a) {
|
|
515
516
|
date = new Date();
|
|
516
517
|
}
|
|
517
|
-
var init = DateUtil.getDateStart(date, 'YEAR');
|
|
518
|
+
var init = DateUtil.getDateStart(date, 'YEAR', format);
|
|
518
519
|
return Math.floor((date.getTime() - init.getTime()) / (7 * 24 * 60 * 60 * 1000)) + 1;
|
|
519
520
|
};
|
|
520
521
|
/**
|
|
@@ -531,11 +532,11 @@ var DateUtil;
|
|
|
531
532
|
format = 'yyyy-MM-dd';
|
|
532
533
|
}
|
|
533
534
|
try {
|
|
534
|
-
date = DateUtil.parseDate(date);
|
|
535
|
+
date = DateUtil.parseDate(date, format);
|
|
535
536
|
} catch (_a) {
|
|
536
537
|
date = new Date();
|
|
537
538
|
}
|
|
538
|
-
var init = DateUtil.getDateStart(date, 'MONTH');
|
|
539
|
+
var init = DateUtil.getDateStart(date, 'MONTH', format);
|
|
539
540
|
return Math.floor((date.getTime() - init.getTime()) / (7 * 24 * 60 * 60 * 1000)) + 1;
|
|
540
541
|
};
|
|
541
542
|
/**
|
|
@@ -560,22 +561,12 @@ var DateUtil;
|
|
|
560
561
|
} catch (_b) {
|
|
561
562
|
date2 = new Date();
|
|
562
563
|
}
|
|
563
|
-
var
|
|
564
|
-
var timestampDiff = isFirstMore ? date1.getTime() - date2.getTime() : date2.getTime() - date1.getTime();
|
|
564
|
+
var timestampDiff = Math.abs(date1.getTime() - date2.getTime());
|
|
565
565
|
var day = Math.floor(timestampDiff / (24 * 60 * 60 * 1000));
|
|
566
566
|
var hour = Math.floor(timestampDiff % (24 * 60 * 60 * 1000) / (60 * 60 * 1000));
|
|
567
567
|
var minute = Math.floor((timestampDiff - day * 24 * 60 * 60 * 1000 - hour * 60 * 60 * 1000) / (60 * 1000));
|
|
568
568
|
var second = Math.floor((timestampDiff - day * 24 * 60 * 60 * 1000 - hour * 60 * 60 * 1000 - minute * 60 * 1000) / 1000);
|
|
569
569
|
var ms = timestampDiff - day * 24 * 60 * 60 * 1000 - hour * 60 * 60 * 1000 - minute * 60 * 1000 - second * 1000;
|
|
570
|
-
if (isFirstMore) {
|
|
571
|
-
return {
|
|
572
|
-
Day: day === 0 ? 0 : -day,
|
|
573
|
-
Hour: hour === 0 ? 0 : -hour,
|
|
574
|
-
Minute: minute === 0 ? 0 : -minute,
|
|
575
|
-
Second: second === 0 ? 0 : -second,
|
|
576
|
-
Millsecond: ms === 0 ? 0 : -ms
|
|
577
|
-
};
|
|
578
|
-
}
|
|
579
570
|
return {
|
|
580
571
|
Day: day,
|
|
581
572
|
Hour: hour,
|
|
@@ -767,6 +758,26 @@ var DateUtil;
|
|
|
767
758
|
return dates;
|
|
768
759
|
}
|
|
769
760
|
DateUtil.getDatesOfMonth = getDatesOfMonth;
|
|
761
|
+
/**
|
|
762
|
+
* 判断日期字符串是否在指定的年月内。
|
|
763
|
+
*
|
|
764
|
+
* @param date 日期
|
|
765
|
+
* @param yearStr 指定的年份,字符串格式
|
|
766
|
+
* @param month 指定的月份,整型(1-12)
|
|
767
|
+
* @param format 目标字符串格式,支持的字符有:y,M,d,q,w,H,h,m,S,默认:yyyy-MM-dd
|
|
768
|
+
* @return 如果在指定的年月内返回true,否则返回false
|
|
769
|
+
*/
|
|
770
|
+
DateUtil.isDateInYearAndMonth = function (date, yearStr, month, format) {
|
|
771
|
+
if (format === void 0) {
|
|
772
|
+
format = 'yyyy-MM-dd';
|
|
773
|
+
}
|
|
774
|
+
try {
|
|
775
|
+
date = DateUtil.parseDate(date, format);
|
|
776
|
+
} catch (_a) {
|
|
777
|
+
date = new Date();
|
|
778
|
+
}
|
|
779
|
+
return date.getFullYear() == Number(yearStr) && date.getMonth() + 1 == month;
|
|
780
|
+
};
|
|
770
781
|
})(DateUtil || (DateUtil = {}));
|
|
771
782
|
exports.default = DateUtil;
|
|
772
783
|
var dateFormatRules = [{
|
package/lib/url/UrlUtil.d.ts
CHANGED
|
@@ -20,11 +20,11 @@ declare namespace UrlUtil {
|
|
|
20
20
|
* @example
|
|
21
21
|
* getUrlRequest('https://ss.cn?sdf=213&bdl=231111'); => {sdf: "213", bdl: "231111"}
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
function getUrlRequest<T extends Record<string, string>>(href?: string): T;
|
|
24
24
|
/**
|
|
25
25
|
* 不刷新改变url参数
|
|
26
26
|
* @param obj 对象
|
|
27
27
|
*/
|
|
28
|
-
function setUrlParamsNotRefresh
|
|
28
|
+
function setUrlParamsNotRefresh<T extends Record<string, any>>(obj: T): void;
|
|
29
29
|
}
|
|
30
30
|
export default UrlUtil;
|
package/lib/url/UrlUtil.js
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var __read = this && this.__read || function (o, n) {
|
|
4
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
5
|
+
if (!m) return o;
|
|
6
|
+
var i = m.call(o),
|
|
7
|
+
r,
|
|
8
|
+
ar = [],
|
|
9
|
+
e;
|
|
10
|
+
try {
|
|
11
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
12
|
+
} catch (error) {
|
|
13
|
+
e = {
|
|
14
|
+
error: error
|
|
15
|
+
};
|
|
16
|
+
} finally {
|
|
17
|
+
try {
|
|
18
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
19
|
+
} finally {
|
|
20
|
+
if (e) throw e.error;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
3
25
|
var __importDefault = this && this.__importDefault || function (mod) {
|
|
4
26
|
return mod && mod.__esModule ? mod : {
|
|
5
27
|
"default": mod
|
|
@@ -54,7 +76,7 @@ var UrlUtil;
|
|
|
54
76
|
var _a;
|
|
55
77
|
(_a = urlSearch === null || urlSearch === void 0 ? void 0 : urlSearch['delete']) === null || _a === void 0 ? void 0 : _a.call(urlSearch, param);
|
|
56
78
|
});
|
|
57
|
-
return (urlSearch === null || urlSearch === void 0 ? void 0 : urlSearch.toString()) ? "".concat(hostAndPath, "?").concat(urlSearch
|
|
79
|
+
return (urlSearch === null || urlSearch === void 0 ? void 0 : urlSearch.toString()) ? "".concat(hostAndPath, "?").concat(urlSearch) : hostAndPath;
|
|
58
80
|
}
|
|
59
81
|
UrlUtil.deleteUrlParam = deleteUrlParam;
|
|
60
82
|
/**
|
|
@@ -63,29 +85,45 @@ var UrlUtil;
|
|
|
63
85
|
* @example
|
|
64
86
|
* getUrlRequest('https://ss.cn?sdf=213&bdl=231111'); => {sdf: "213", bdl: "231111"}
|
|
65
87
|
*/
|
|
66
|
-
|
|
88
|
+
function getUrlRequest(href) {
|
|
67
89
|
if (href === void 0) {
|
|
68
90
|
href = window.location.href;
|
|
69
91
|
}
|
|
70
|
-
|
|
92
|
+
href = "".concat(href === null || href === void 0 ? void 0 : href.slice(-1)) === '/' ? href === null || href === void 0 ? void 0 : href.slice(0, href.length - 1) : href;
|
|
71
93
|
var theRequest = {};
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
|
|
94
|
+
if (href.includes('#/')) {
|
|
95
|
+
//hash
|
|
96
|
+
href = "".concat(href.split('/').slice(-1));
|
|
97
|
+
}
|
|
98
|
+
if (href === null || href === void 0 ? void 0 : href.includes('?')) {
|
|
99
|
+
var strs = href === null || href === void 0 ? void 0 : href.split('?').slice(-1).toString().split('&');
|
|
75
100
|
for (var i = 0; i < strs.length; i++) {
|
|
76
|
-
|
|
101
|
+
var _a = __read(strs[i].split('='), 2),
|
|
102
|
+
key = _a[0],
|
|
103
|
+
value = _a[1];
|
|
104
|
+
if (key) theRequest[key] = decodeURIComponent(value);
|
|
77
105
|
}
|
|
78
106
|
}
|
|
79
107
|
return theRequest;
|
|
80
|
-
}
|
|
108
|
+
}
|
|
109
|
+
UrlUtil.getUrlRequest = getUrlRequest;
|
|
81
110
|
/**
|
|
82
111
|
* 不刷新改变url参数
|
|
83
112
|
* @param obj 对象
|
|
84
113
|
*/
|
|
85
114
|
function setUrlParamsNotRefresh(obj) {
|
|
86
|
-
var urlParams =
|
|
115
|
+
var urlParams = getUrlRequest();
|
|
87
116
|
var str = objToUrlParam(ObjectUtil_1.default.mergeParams(obj, urlParams));
|
|
88
|
-
var
|
|
117
|
+
var href = window.location.href;
|
|
118
|
+
if (href.includes('#/') && !"".concat(href.split('/').slice(-1)).includes('?')) {
|
|
119
|
+
var url_1 = "".concat(href).concat(str ? "?".concat(str) : '');
|
|
120
|
+
window.history.replaceState({
|
|
121
|
+
url: url_1
|
|
122
|
+
}, '', url_1);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
var _arr = window.location.href.split('?');
|
|
126
|
+
var url = "".concat(_arr.slice(0, _arr.length - 1).join('?')).concat(str ? "?".concat(str) : '');
|
|
89
127
|
window.history.replaceState({
|
|
90
128
|
url: url
|
|
91
129
|
}, '', url);
|