zartui 2.1.6 → 2.1.8
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/es/action-sheet/index.js +15 -26
- package/es/area/index.js +5 -41
- package/es/avatar/index.js +3 -16
- package/es/back-top/index.js +4 -19
- package/es/badge/index.js +4 -12
- package/es/button/index.js +20 -40
- package/es/calendar/components/Header.js +3 -12
- package/es/calendar/components/Month.js +12 -65
- package/es/calendar/index.js +23 -94
- package/es/calendar/types.js +9 -15
- package/es/calendar/utils.js +5 -16
- package/es/cascader/index.js +4 -37
- package/es/cell/index.js +19 -37
- package/es/cell-group/index.js +5 -8
- package/es/checkbox/index.js +4 -11
- package/es/checkbox-group/index.js +4 -9
- package/es/col/index.js +6 -11
- package/es/collapse/index.js +2 -5
- package/es/collapse-item/index.js +19 -35
- package/es/count-down/index.js +2 -15
- package/es/count-down/utils.js +3 -10
- package/es/datetime-picker/DatePicker.js +12 -70
- package/es/datetime-picker/TimePicker.js +10 -23
- package/es/datetime-picker/index.js +2 -26
- package/es/datetime-picker/shared.js +5 -21
- package/es/datetime-picker/utils.js +0 -5
- package/es/dialog/Dialog.js +6 -21
- package/es/dialog/index.js +0 -16
- package/es/divider/index.js +5 -6
- package/es/dropdown-item/index.js +13 -39
- package/es/dropdown-menu/index.js +4 -9
- package/es/empty/images/Developing.js +0 -3
- package/es/empty/images/EmptyInterface.js +0 -3
- package/es/empty/images/EmptyResult.js +0 -3
- package/es/empty/images/FindNull.js +0 -3
- package/es/empty/images/NetworkError.js +0 -3
- package/es/empty/images/NotFound.js +0 -3
- package/es/empty/images/ReportSuccess.js +0 -3
- package/es/empty/images/Restricted.js +0 -3
- package/es/empty/images/ServerError.js +0 -3
- package/es/empty/index.js +3 -11
- package/es/field/index.js +21 -86
- package/es/fold-dialog/index.js +5 -20
- package/es/form/index.js +2 -18
- package/es/grid/index.js +2 -6
- package/es/grid-item/index.js +18 -30
- package/es/hierarchy-select/breadcrumb.js +2 -6
- package/es/hierarchy-select/index.js +4 -14
- package/es/hierarchy-select/markList.js +5 -30
- package/es/hierarchy-select/svg/SubIcon.js +0 -1
- package/es/icon/index.js +9 -13
- package/es/image/index.js +3 -19
- package/es/image-preview/ImagePreview.js +4 -8
- package/es/image-preview/ImagePreviewItem.js +14 -30
- package/es/image-preview/index.js +0 -12
- package/es/image-preview/shared.js +2 -4
- package/es/index-anchor/index.js +2 -6
- package/es/index-bar/IndexIndicate.js +0 -1
- package/es/index-bar/index.js +7 -28
- package/es/index.js +1 -4
- package/es/info/index.js +6 -8
- package/es/list/index.js +11 -27
- package/es/loading/index.js +7 -15
- package/es/locale/index.js +0 -2
- package/es/media-picker/index.js +35 -128
- package/es/media-picker/media-util.js +2 -5
- package/es/media-picker/type.js +9 -14
- package/es/media-picker/wx-util.js +0 -1
- package/es/media-player/index.js +7 -19
- package/es/mixins/bind-event.js +0 -3
- package/es/mixins/checkbox.js +5 -11
- package/es/mixins/click-outside.js +0 -2
- package/es/mixins/close-on-popstate.js +0 -1
- package/es/mixins/field.js +0 -2
- package/es/mixins/popup/index.js +12 -28
- package/es/mixins/popup/overlay.js +1 -11
- package/es/mixins/portal.js +2 -8
- package/es/mixins/relation.js +0 -8
- package/es/mixins/slots.js +1 -4
- package/es/mixins/touch.js +4 -9
- package/es/multiple-picker/MultiplePickerOptions.js +3 -20
- package/es/multiple-picker/index.js +5 -17
- package/es/nav-bar/index.js +4 -12
- package/es/notice-bar/index.js +10 -28
- package/es/number-keyboard/Key.js +2 -10
- package/es/number-keyboard/index.js +4 -19
- package/es/overlay/index.js +5 -8
- package/es/password-input/index.js +10 -16
- package/es/picker/PickerColumn.js +21 -56
- package/es/picker/index.js +12 -45
- package/es/popover/index.js +65 -90
- package/es/popup/index.js +5 -21
- package/es/pull-refresh/index.js +10 -29
- package/es/radio/index.js +2 -4
- package/es/radio-group/index.js +2 -4
- package/es/rate/index.js +12 -26
- package/es/row/index.js +3 -9
- package/es/search/index.js +9 -15
- package/es/signature/bezier.js +13 -20
- package/es/signature/force-landscape.js +0 -5
- package/es/signature/index.js +5 -24
- package/es/signature/point.js +1 -6
- package/es/signature/throttle.js +1 -10
- package/es/skeleton/index.js +5 -15
- package/es/slider/index.js +19 -55
- package/es/step/index.js +5 -12
- package/es/stepper/index.js +11 -39
- package/es/steps/index.js +2 -4
- package/es/sticky/index.js +8 -50
- package/es/swipe/index.js +19 -62
- package/es/swipe-cell/index.js +7 -23
- package/es/swipe-item/index.js +10 -19
- package/es/switch/index.js +8 -10
- package/es/switch/shared.js +1 -0
- package/es/switch-cell/index.js +7 -7
- package/es/tab/index.js +4 -15
- package/es/tabbar/index.js +4 -14
- package/es/tabbar-item/index.js +7 -15
- package/es/table/index.js +5 -28
- package/es/table/type.js +3 -4
- package/es/tabs/Content.js +5 -9
- package/es/tabs/Title.js +11 -20
- package/es/tabs/index.js +16 -51
- package/es/tabs/utils.js +0 -8
- package/es/tag/index.js +13 -17
- package/es/text-ellipsis/index.js +25 -42
- package/es/timeline/index.js +2 -25
- package/es/toast/Toast.js +11 -23
- package/es/toast/index.js +6 -33
- package/es/toast/lock-click.js +0 -2
- package/es/uploader/index.js +11 -62
- package/es/uploader/utils.js +0 -10
- package/es/utils/constant.js +2 -1
- package/es/utils/create/bem.js +1 -5
- package/es/utils/create/component.js +4 -8
- package/es/utils/create/i18n.js +0 -2
- package/es/utils/deep-assign.js +0 -4
- package/es/utils/deep-clone.js +0 -3
- package/es/utils/dom/event.js +2 -5
- package/es/utils/dom/node.js +0 -1
- package/es/utils/dom/raf.js +7 -6
- package/es/utils/dom/reset-scroll.js +2 -1
- package/es/utils/dom/scroll.js +8 -17
- package/es/utils/dom/style.js +3 -2
- package/es/utils/easings.js +2 -4
- package/es/utils/format/date-util.js +54 -122
- package/es/utils/format/number.js +2 -11
- package/es/utils/format/string.js +0 -3
- package/es/utils/format/unit.js +2 -12
- package/es/utils/functional.js +6 -9
- package/es/utils/getScroll.js +0 -5
- package/es/utils/index.js +3 -5
- package/es/utils/interceptor.js +2 -4
- package/es/utils/media/image-util.js +7 -19
- package/es/utils/raf.js +4 -12
- package/es/utils/router.js +7 -6
- package/es/utils/scrollTo.js +10 -15
- package/es/utils/validate/number.js +2 -2
- package/es/utils/vnodes.js +2 -8
- package/lib/action-sheet/index.js +12 -37
- package/lib/area/index.js +7 -48
- package/lib/avatar/index.js +5 -21
- package/lib/back-top/index.js +6 -28
- package/lib/badge/index.js +6 -18
- package/lib/button/index.js +20 -52
- package/lib/calendar/FastForwardImg.js +2 -3
- package/lib/calendar/SlowForwardImg.js +2 -3
- package/lib/calendar/components/Header.js +5 -21
- package/lib/calendar/components/Month.js +14 -74
- package/lib/calendar/index.js +23 -109
- package/lib/calendar/types.js +11 -22
- package/lib/calendar/utils.js +18 -46
- package/lib/cascader/index.js +6 -49
- package/lib/cell/index.js +19 -50
- package/lib/cell/shared.js +2 -3
- package/lib/cell-group/index.js +6 -17
- package/lib/checkbox/index.js +6 -17
- package/lib/checkbox-group/index.js +6 -16
- package/lib/col/index.js +8 -17
- package/lib/collapse/index.js +4 -11
- package/lib/collapse-item/index.js +20 -46
- package/lib/count-down/index.js +4 -22
- package/lib/count-down/utils.js +5 -17
- package/lib/datetime-picker/DatePicker.js +14 -84
- package/lib/datetime-picker/TimePicker.js +12 -33
- package/lib/datetime-picker/index.js +7 -41
- package/lib/datetime-picker/shared.js +9 -35
- package/lib/datetime-picker/utils.js +2 -11
- package/lib/dialog/Dialog.js +8 -31
- package/lib/dialog/index.js +1 -24
- package/lib/divider/index.js +6 -14
- package/lib/dropdown-item/index.js +14 -52
- package/lib/dropdown-menu/index.js +6 -18
- package/lib/empty/context.js +2 -3
- package/lib/empty/images/Developing.js +2 -9
- package/lib/empty/images/EmptyInterface.js +2 -9
- package/lib/empty/images/EmptyResult.js +2 -9
- package/lib/empty/images/FindNull.js +2 -9
- package/lib/empty/images/NetworkError.js +2 -9
- package/lib/empty/images/NotFound.js +2 -9
- package/lib/empty/images/ReportSuccess.js +2 -9
- package/lib/empty/images/Restricted.js +2 -9
- package/lib/empty/images/ServerError.js +2 -9
- package/lib/empty/index.js +5 -26
- package/lib/field/ClearIcon.js +2 -3
- package/lib/field/SearchIcon.js +2 -3
- package/lib/field/index.js +22 -99
- package/lib/fold-dialog/index.js +7 -25
- package/lib/form/index.js +4 -24
- package/lib/grid/index.js +4 -13
- package/lib/grid-item/index.js +19 -40
- package/lib/hierarchy-select/breadcrumb.js +5 -13
- package/lib/hierarchy-select/index.js +7 -25
- package/lib/hierarchy-select/markList.js +8 -39
- package/lib/hierarchy-select/svg/SubIcon.js +2 -4
- package/lib/icon/index.js +9 -21
- package/lib/image/index.js +4 -25
- package/lib/image-preview/ImagePreview.js +2 -19
- package/lib/image-preview/ImagePreviewItem.js +15 -39
- package/lib/image-preview/index.js +1 -18
- package/lib/image-preview/shared.js +3 -8
- package/lib/index-anchor/index.js +4 -14
- package/lib/index-bar/IndexIndicate.js +2 -4
- package/lib/index-bar/index.js +9 -40
- package/lib/index.js +5 -164
- package/lib/info/index.js +7 -16
- package/lib/lazyload/index.js +1 -5
- package/lib/list/index.js +12 -36
- package/lib/loading/index.js +8 -23
- package/lib/locale/index.js +2 -10
- package/lib/locale/lang/de-DE-formal.js +2 -3
- package/lib/locale/lang/de-DE.js +2 -3
- package/lib/locale/lang/en-US.js +2 -3
- package/lib/locale/lang/es-ES.js +2 -3
- package/lib/locale/lang/fr-FR.js +2 -3
- package/lib/locale/lang/ja-JP.js +2 -3
- package/lib/locale/lang/nb-NO.js +2 -3
- package/lib/locale/lang/ro-RO.js +2 -3
- package/lib/locale/lang/th-TH.js +2 -3
- package/lib/locale/lang/tr-TR.js +2 -3
- package/lib/locale/lang/zh-CN.js +2 -3
- package/lib/locale/lang/zh-HK.js +2 -3
- package/lib/locale/lang/zh-TW.js +2 -3
- package/lib/media-picker/image/DefaultAudioIcon.js +2 -3
- package/lib/media-picker/image/DefaultDocIcon.js +2 -3
- package/lib/media-picker/image/DefaultExcelIcon.js +2 -3
- package/lib/media-picker/image/DefaultFileIcon.js +2 -3
- package/lib/media-picker/image/DefaultPdfIcon.js +2 -3
- package/lib/media-picker/image/DefaultPptIcon.js +2 -3
- package/lib/media-picker/image/DefaultTextIcon.js +2 -3
- package/lib/media-picker/image/DefaultVideoIcon.js +2 -3
- package/lib/media-picker/image/DeleteIcon.js +2 -3
- package/lib/media-picker/image/Img64.js +4 -7
- package/lib/media-picker/image/PickFileIcon.js +2 -3
- package/lib/media-picker/image/PickPhotoIcon.js +2 -3
- package/lib/media-picker/image/ReUpload.js +2 -3
- package/lib/media-picker/image/TakeAudioIcon.js +2 -3
- package/lib/media-picker/image/TakePhotoIcon.js +2 -3
- package/lib/media-picker/image/TakeVideoIcon.js +2 -3
- package/lib/media-picker/index.js +33 -172
- package/lib/media-picker/media-util.js +9 -22
- package/lib/media-picker/type.js +10 -18
- package/lib/media-picker/wx-util.js +4 -15
- package/lib/media-player/index.js +8 -27
- package/lib/mixins/bind-event.js +1 -6
- package/lib/mixins/checkbox.js +8 -21
- package/lib/mixins/click-outside.js +3 -8
- package/lib/mixins/close-on-popstate.js +2 -7
- package/lib/mixins/field.js +2 -5
- package/lib/mixins/popup/context.js +2 -3
- package/lib/mixins/popup/index.js +12 -38
- package/lib/mixins/popup/overlay.js +3 -25
- package/lib/mixins/portal.js +2 -9
- package/lib/mixins/relation.js +0 -11
- package/lib/mixins/slots.js +3 -8
- package/lib/mixins/touch.js +6 -14
- package/lib/multiple-picker/MultiplePickerOptions.js +4 -26
- package/lib/multiple-picker/index.js +7 -29
- package/lib/multiple-picker/shared.js +3 -5
- package/lib/nav-bar/index.js +6 -19
- package/lib/notice-bar/CloseIcon.js +2 -3
- package/lib/notice-bar/MenuIcon.js +2 -3
- package/lib/notice-bar/NoticeIcon.js +2 -3
- package/lib/notice-bar/OpenIcon.js +2 -3
- package/lib/notice-bar/TipIcon.js +2 -3
- package/lib/notice-bar/WarningIcon.js +2 -3
- package/lib/notice-bar/index.js +12 -43
- package/lib/number-keyboard/CollapseIcon.js +2 -3
- package/lib/number-keyboard/DeleteIcon.js +2 -3
- package/lib/number-keyboard/Key.js +4 -20
- package/lib/number-keyboard/index.js +6 -29
- package/lib/overlay/index.js +6 -18
- package/lib/password-input/index.js +11 -25
- package/lib/picker/PickerColumn.js +24 -71
- package/lib/picker/index.js +14 -59
- package/lib/picker/shared.js +3 -5
- package/lib/popover/index.js +65 -104
- package/lib/popup/index.js +7 -30
- package/lib/pull-refresh/index.js +11 -38
- package/lib/radio/index.js +4 -10
- package/lib/radio-group/index.js +4 -11
- package/lib/rate/index.js +13 -34
- package/lib/row/index.js +5 -15
- package/lib/search/index.js +8 -23
- package/lib/signature/bezier.js +14 -25
- package/lib/signature/force-landscape.js +5 -19
- package/lib/signature/index.js +8 -34
- package/lib/signature/point.js +2 -11
- package/lib/signature/throttle.js +1 -11
- package/lib/skeleton/index.js +6 -23
- package/lib/slider/index.js +21 -66
- package/lib/step/index.js +7 -21
- package/lib/stepper/index.js +12 -49
- package/lib/steps/index.js +4 -10
- package/lib/sticky/index.js +10 -62
- package/lib/swipe/index.js +21 -73
- package/lib/swipe-cell/index.js +9 -32
- package/lib/swipe-item/index.js +12 -27
- package/lib/switch/index.js +9 -17
- package/lib/switch/shared.js +3 -4
- package/lib/switch-cell/index.js +7 -18
- package/lib/tab/index.js +6 -24
- package/lib/tabbar/index.js +6 -22
- package/lib/tabbar-item/index.js +7 -24
- package/lib/table/index.js +7 -38
- package/lib/table/type.js +3 -5
- package/lib/tabs/Content.js +7 -18
- package/lib/tabs/Title.js +13 -27
- package/lib/tabs/index.js +17 -68
- package/lib/tabs/utils.js +0 -13
- package/lib/tag/index.js +13 -25
- package/lib/text-ellipsis/index.js +27 -49
- package/lib/timeline/index.js +4 -35
- package/lib/timeline/svg/current.js +2 -3
- package/lib/timeline/svg/pass.js +2 -3
- package/lib/toast/Toast.js +12 -33
- package/lib/toast/index.js +7 -40
- package/lib/toast/lock-click.js +0 -3
- package/lib/toast/svg/SuccessIcon.js +2 -3
- package/lib/toast/svg/WarnIcon.js +2 -3
- package/lib/uploader/index.js +12 -75
- package/lib/uploader/utils.js +4 -21
- package/lib/utils/constant.js +12 -21
- package/lib/utils/create/bem.js +1 -6
- package/lib/utils/create/component.js +6 -17
- package/lib/utils/create/i18n.js +0 -8
- package/lib/utils/create/index.js +0 -4
- package/lib/utils/deep-assign.js +0 -6
- package/lib/utils/deep-clone.js +0 -5
- package/lib/utils/device.js +1 -3
- package/lib/utils/dom/event.js +5 -14
- package/lib/utils/dom/node.js +0 -2
- package/lib/utils/dom/raf.js +9 -13
- package/lib/utils/dom/reset-scroll.js +2 -4
- package/lib/utils/dom/scroll.js +16 -37
- package/lib/utils/dom/style.js +3 -3
- package/lib/utils/easings.js +2 -5
- package/lib/utils/format/date-util.js +88 -203
- package/lib/utils/format/number.js +4 -15
- package/lib/utils/format/string.js +0 -5
- package/lib/utils/format/unit.js +2 -16
- package/lib/utils/functional.js +7 -15
- package/lib/utils/getScroll.js +1 -8
- package/lib/utils/index.js +10 -26
- package/lib/utils/interceptor.js +2 -6
- package/lib/utils/media/image-util.js +10 -28
- package/lib/utils/raf.js +4 -13
- package/lib/utils/router.js +10 -13
- package/lib/utils/scrollTo.js +12 -24
- package/lib/utils/validate/date.js +0 -2
- package/lib/utils/validate/email.js +0 -1
- package/lib/utils/validate/mobile.js +0 -1
- package/lib/utils/validate/number.js +3 -5
- package/lib/utils/validate/system.js +0 -3
- package/lib/utils/vnodes.js +2 -9
- package/lib/zart.js +2325 -4752
- package/lib/zart.min.js +7 -1
- package/package.json +1 -1
|
@@ -2,10 +2,8 @@ var __formatNumber__ = function __formatNumber__(number) {
|
|
|
2
2
|
if (number < 10) {
|
|
3
3
|
return "0" + number;
|
|
4
4
|
}
|
|
5
|
-
|
|
6
5
|
return number;
|
|
7
6
|
};
|
|
8
|
-
|
|
9
7
|
export var weekList = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
|
|
10
8
|
export var FORMAT = {
|
|
11
9
|
//英文简写如:12:01
|
|
@@ -42,19 +40,17 @@ export var FORMAT = {
|
|
|
42
40
|
//中文全称 如:2010年12月01日 23时15分06秒
|
|
43
41
|
FORMAT_YMDHMS_CN: "yyyy年MM月dd日 HH时mm分ss秒"
|
|
44
42
|
};
|
|
43
|
+
|
|
45
44
|
/**
|
|
46
45
|
*
|
|
47
46
|
* @param timestamp 1544580660000
|
|
48
47
|
* @param formatType
|
|
49
48
|
*/
|
|
50
|
-
|
|
51
49
|
export function formatDate(timestamp, formatType) {
|
|
52
50
|
if (formatType == null) {
|
|
53
51
|
formatType = "yyyy-MM-dd HH:mm:ss";
|
|
54
52
|
}
|
|
55
|
-
|
|
56
53
|
var stamp = parseInt(timestamp, 10);
|
|
57
|
-
|
|
58
54
|
if (!isNaN(stamp)) {
|
|
59
55
|
return formatDateByDate(new Date(stamp), formatType);
|
|
60
56
|
} else {
|
|
@@ -65,21 +61,17 @@ export function formatDateByDate(date, formatType) {
|
|
|
65
61
|
if (formatType === void 0) {
|
|
66
62
|
formatType = FORMAT.FORMAT_YMDHMS;
|
|
67
63
|
}
|
|
68
|
-
|
|
69
64
|
if (typeof date != 'object') {
|
|
70
65
|
// IOS5以下无法解析'2018-01-02'这种格式,需要替换为'2018/01/02'
|
|
71
66
|
if (typeof date === 'string') {
|
|
72
67
|
date = date.replace(/-/g, '/');
|
|
73
|
-
|
|
74
68
|
if (date.length === 7) {
|
|
75
69
|
// 只有月份的日期ios无法解析,例如 2021/06 , 需转换成2021/06/01
|
|
76
70
|
date += "/01";
|
|
77
71
|
}
|
|
78
72
|
}
|
|
79
|
-
|
|
80
73
|
date = new Date(date);
|
|
81
74
|
}
|
|
82
|
-
|
|
83
75
|
var formatResult = formatType.replace("yyyy", __formatNumber__(date.getFullYear()));
|
|
84
76
|
formatResult = formatResult.replace("yy", String(date.getFullYear()).substring(2));
|
|
85
77
|
formatResult = formatResult.replace("MM", __formatNumber__(date.getMonth() + 1));
|
|
@@ -94,9 +86,7 @@ export function formatDateByDateByObject(date, formatType) {
|
|
|
94
86
|
if (formatType === void 0) {
|
|
95
87
|
formatType = FORMAT.FORMAT_YMDHMS;
|
|
96
88
|
}
|
|
97
|
-
|
|
98
89
|
var formatResult = formatType;
|
|
99
|
-
|
|
100
90
|
if (typeof date == 'object') {
|
|
101
91
|
formatResult = formatType.replace("yyyy", __formatNumber__(date.year));
|
|
102
92
|
formatResult = formatResult.replace("yy", String(date.year).substring(2));
|
|
@@ -106,7 +96,6 @@ export function formatDateByDateByObject(date, formatType) {
|
|
|
106
96
|
formatResult = formatResult.replace("mm", __formatNumber__(date.minute));
|
|
107
97
|
formatResult = formatResult.replace("ss", __formatNumber__(date.second));
|
|
108
98
|
}
|
|
109
|
-
|
|
110
99
|
return formatResult;
|
|
111
100
|
}
|
|
112
101
|
export function parseDate(dateStr) {
|
|
@@ -120,16 +109,13 @@ export function getTodayWeek() {
|
|
|
120
109
|
}
|
|
121
110
|
export function getWeekNum(date) {
|
|
122
111
|
var week = date.getDay();
|
|
123
|
-
|
|
124
112
|
if (week === 0) {
|
|
125
113
|
week = 7;
|
|
126
114
|
}
|
|
127
|
-
|
|
128
115
|
return week;
|
|
129
116
|
}
|
|
130
117
|
export function getShortDateDesc(date) {
|
|
131
118
|
var hours = date.getHours();
|
|
132
|
-
|
|
133
119
|
if (hours >= 0 && hours < 6) {
|
|
134
120
|
return "凌晨" + hours + "点";
|
|
135
121
|
} else if (hours >= 6 && hours < 12) {
|
|
@@ -147,56 +133,49 @@ export function getDateDesc(date) {
|
|
|
147
133
|
var timestamp = date.getTime();
|
|
148
134
|
var diff = nowTimestamp - timestamp;
|
|
149
135
|
var fix = "前";
|
|
150
|
-
|
|
151
136
|
if (diff < 0) {
|
|
152
137
|
fix = "后";
|
|
153
|
-
}
|
|
154
|
-
|
|
138
|
+
}
|
|
155
139
|
|
|
140
|
+
//月
|
|
156
141
|
var unit = 1000 * 60 * 60 * 24 * 30;
|
|
157
|
-
|
|
158
142
|
if (diff / unit > 1) {
|
|
159
143
|
return parseInt(diff / unit, 10) + "个月" + fix;
|
|
160
|
-
}
|
|
161
|
-
|
|
144
|
+
}
|
|
162
145
|
|
|
146
|
+
//周
|
|
163
147
|
unit = 1000 * 60 * 60 * 24 * 7;
|
|
164
|
-
|
|
165
148
|
if (diff / unit > 1) {
|
|
166
149
|
return parseInt(diff / unit, 10) + "周" + fix;
|
|
167
|
-
}
|
|
168
|
-
|
|
150
|
+
}
|
|
169
151
|
|
|
152
|
+
//日
|
|
170
153
|
unit = 1000 * 60 * 60 * 24;
|
|
171
|
-
|
|
172
154
|
if (diff / unit > 1) {
|
|
173
155
|
return parseInt(diff / unit, 10) + "天" + fix;
|
|
174
|
-
}
|
|
175
|
-
|
|
156
|
+
}
|
|
176
157
|
|
|
158
|
+
//小时
|
|
177
159
|
unit = 1000 * 60 * 60;
|
|
178
|
-
|
|
179
160
|
if (diff / unit > 1) {
|
|
180
161
|
return parseInt(diff / unit, 10) + "个小时" + fix;
|
|
181
|
-
}
|
|
182
|
-
|
|
162
|
+
}
|
|
183
163
|
|
|
164
|
+
//分钟
|
|
184
165
|
unit = 1000 * 60;
|
|
185
|
-
|
|
186
166
|
if (diff / unit > 1) {
|
|
187
167
|
return parseInt(diff / unit, 10) + "分钟" + fix;
|
|
188
|
-
}
|
|
189
|
-
|
|
168
|
+
}
|
|
190
169
|
|
|
170
|
+
//秒
|
|
191
171
|
unit = 1000;
|
|
192
|
-
|
|
193
172
|
if (diff / unit > 1) {
|
|
194
173
|
return "刚刚";
|
|
195
174
|
}
|
|
196
|
-
|
|
197
175
|
return formatDate(date.getTime(), FORMAT.FORMAT_YMDHMS);
|
|
198
|
-
}
|
|
176
|
+
}
|
|
199
177
|
|
|
178
|
+
//常规月起始日
|
|
200
179
|
export function getFirstDayOfNormalMonth(year, month) {
|
|
201
180
|
var date = new Date();
|
|
202
181
|
date.setDate(1);
|
|
@@ -207,36 +186,34 @@ export function getFirstDayOfNormalMonth(year, month) {
|
|
|
207
186
|
export function getWeekNumDefault(date) {
|
|
208
187
|
var week = date.getDay();
|
|
209
188
|
return week;
|
|
210
|
-
}
|
|
189
|
+
}
|
|
211
190
|
|
|
191
|
+
//获取当年起始日期
|
|
212
192
|
export function getFirstDayOfYear(year) {
|
|
213
193
|
var date = new Date();
|
|
214
194
|
date.setDate(1);
|
|
215
195
|
date.setYear(year);
|
|
216
196
|
date.setMonth(0);
|
|
217
197
|
return date;
|
|
218
|
-
}
|
|
219
|
-
|
|
198
|
+
}
|
|
199
|
+
//获取上月起始日期
|
|
220
200
|
export function getLastMonthStartAndEnd() {
|
|
221
201
|
var nowdays = new Date();
|
|
222
202
|
var year = nowdays.getFullYear();
|
|
223
203
|
var month = nowdays.getMonth();
|
|
224
|
-
|
|
225
204
|
if (month === 0) {
|
|
226
205
|
month = 12;
|
|
227
206
|
year = year - 1;
|
|
228
207
|
}
|
|
229
|
-
|
|
230
208
|
if (month < 10) {
|
|
231
209
|
month = '0' + month;
|
|
232
210
|
}
|
|
233
|
-
|
|
234
211
|
var myDate = new Date(year, month, 0);
|
|
235
212
|
var startDate = year + '-' + month + '-01';
|
|
236
213
|
var endDate = year + '-' + month + '-' + myDate.getDate();
|
|
237
214
|
return startDate + ',' + endDate;
|
|
238
|
-
}
|
|
239
|
-
|
|
215
|
+
}
|
|
216
|
+
//常规月结束日
|
|
240
217
|
export function getLastDayOfNormalMonth(year, month) {
|
|
241
218
|
var date = new Date();
|
|
242
219
|
date.setDate(1);
|
|
@@ -272,18 +249,17 @@ export function getDateCN(strDate) {
|
|
|
272
249
|
var date = parseDate(strDate);
|
|
273
250
|
return formatDateByDate(date, FORMAT.FORMAT_YMD_CN);
|
|
274
251
|
}
|
|
275
|
-
|
|
276
252
|
return null;
|
|
277
253
|
}
|
|
278
254
|
export function getCurMonth() {
|
|
279
255
|
return formatDateByDate(new Date(), FORMAT.FORMAT_YM);
|
|
280
|
-
}
|
|
256
|
+
}
|
|
281
257
|
|
|
258
|
+
//strdate 格式为 "2017-03" 或者 "2017-02-23" , opreation : 1 上个月 2 下个月
|
|
282
259
|
export function operateMonth(strDate, operation) {
|
|
283
260
|
var temp = strDate.split("-");
|
|
284
261
|
var year = parseInt(temp[0], 10);
|
|
285
262
|
var month = parseInt(temp[1], 10);
|
|
286
|
-
|
|
287
263
|
if (operation === 1) {
|
|
288
264
|
// 减 一个月
|
|
289
265
|
if (month > 1) {
|
|
@@ -301,44 +277,36 @@ export function operateMonth(strDate, operation) {
|
|
|
301
277
|
year += 1;
|
|
302
278
|
}
|
|
303
279
|
}
|
|
304
|
-
|
|
305
280
|
if (month < 10) {
|
|
306
281
|
return year + "-0" + month;
|
|
307
282
|
}
|
|
308
|
-
|
|
309
283
|
return year + "-" + month;
|
|
310
284
|
}
|
|
311
285
|
export function getLastDay(strDate, format) {
|
|
312
286
|
if (format === void 0) {
|
|
313
287
|
format = FORMAT.FORMAT_YMD;
|
|
314
288
|
}
|
|
315
|
-
|
|
316
289
|
if (strDate != null) {
|
|
317
290
|
var date = parseDate(strDate);
|
|
318
291
|
var lastDate = addDays(date, -1);
|
|
319
292
|
return formatDateByDate(lastDate, format);
|
|
320
293
|
}
|
|
321
|
-
|
|
322
294
|
return null;
|
|
323
295
|
}
|
|
324
296
|
export function getNextDay(strDate, format) {
|
|
325
297
|
if (format === void 0) {
|
|
326
298
|
format = FORMAT.FORMAT_YMD;
|
|
327
299
|
}
|
|
328
|
-
|
|
329
300
|
var date;
|
|
330
|
-
|
|
331
301
|
if (typeof strDate == 'object') {
|
|
332
302
|
date = strDate;
|
|
333
303
|
} else {
|
|
334
304
|
date = parseDate(strDate);
|
|
335
305
|
}
|
|
336
|
-
|
|
337
306
|
if (date != null) {
|
|
338
307
|
var lastDate = addDays(date, 1);
|
|
339
308
|
return formatDateByDate(lastDate, format);
|
|
340
309
|
}
|
|
341
|
-
|
|
342
310
|
return null;
|
|
343
311
|
}
|
|
344
312
|
export function getYear() {
|
|
@@ -353,25 +321,21 @@ export function getPeriodDesc(milliseconds) {
|
|
|
353
321
|
var h = parseInt(milliseconds / 1000 / 60 / 60 % 24, 10);
|
|
354
322
|
var d = parseInt(milliseconds / 1000 / 60 / 60 / 24, 10);
|
|
355
323
|
var desc = '';
|
|
356
|
-
|
|
357
324
|
if (d > 0) {
|
|
358
325
|
desc += d + '天';
|
|
359
326
|
}
|
|
360
|
-
|
|
361
327
|
if (h > 0) {
|
|
362
328
|
desc += h + '小时';
|
|
363
329
|
}
|
|
364
|
-
|
|
365
330
|
if (m > 0) {
|
|
366
331
|
desc += m + '分';
|
|
367
332
|
}
|
|
368
|
-
|
|
369
333
|
if (s > 0) {
|
|
370
334
|
desc += s + '秒';
|
|
371
335
|
}
|
|
372
|
-
|
|
373
336
|
return desc;
|
|
374
337
|
}
|
|
338
|
+
|
|
375
339
|
/**
|
|
376
340
|
* 将不规范书写的时间转为规范书写的
|
|
377
341
|
* 9 09:00:00
|
|
@@ -380,34 +344,26 @@ export function getPeriodDesc(milliseconds) {
|
|
|
380
344
|
* @param rawStr
|
|
381
345
|
* @returns {*}
|
|
382
346
|
*/
|
|
383
|
-
|
|
384
347
|
export function getTimeStrFromRaw(rawStr) {
|
|
385
348
|
var items = rawStr.split(':');
|
|
386
|
-
|
|
387
349
|
if (items === null) {
|
|
388
350
|
return '00:00:00';
|
|
389
351
|
}
|
|
390
|
-
|
|
391
352
|
var threeItems = [];
|
|
392
|
-
|
|
393
353
|
if (items.length >= 3) {
|
|
394
354
|
threeItems = items.slice(0, 3);
|
|
395
355
|
} else {
|
|
396
356
|
var addNum = 3 - items.length;
|
|
397
357
|
threeItems = items;
|
|
398
|
-
|
|
399
358
|
for (var i = 0; i < addNum; i++) {
|
|
400
359
|
threeItems.push('00');
|
|
401
360
|
}
|
|
402
361
|
}
|
|
403
|
-
|
|
404
362
|
threeItems = threeItems.map(function (time) {
|
|
405
363
|
var finedTime = time;
|
|
406
|
-
|
|
407
364
|
if (time.length === 1) {
|
|
408
365
|
finedTime = '0' + time;
|
|
409
366
|
}
|
|
410
|
-
|
|
411
367
|
return finedTime;
|
|
412
368
|
});
|
|
413
369
|
return threeItems.join(':');
|
|
@@ -418,7 +374,6 @@ export function formatLeftTime(leftTime) {
|
|
|
418
374
|
var nm = 60;
|
|
419
375
|
var ns = 1;
|
|
420
376
|
var seconds = leftTime || 0;
|
|
421
|
-
|
|
422
377
|
if (seconds < -(3600 * 24)) {
|
|
423
378
|
seconds = -seconds;
|
|
424
379
|
return "\u8D85\u65F6" + parseInt(seconds / nd, 10) + "\u5929";
|
|
@@ -442,6 +397,7 @@ export function formatLeftTime(leftTime) {
|
|
|
442
397
|
return null;
|
|
443
398
|
}
|
|
444
399
|
}
|
|
400
|
+
|
|
445
401
|
/**
|
|
446
402
|
* get human readable time string from time result from server no matter whether it is timestamp or human readable string
|
|
447
403
|
* dependent on FORMAT and formatDate, "import * as dateUtil from '***'" recommended
|
|
@@ -449,60 +405,48 @@ export function formatLeftTime(leftTime) {
|
|
|
449
405
|
* @param format
|
|
450
406
|
* @returns {*}
|
|
451
407
|
*/
|
|
452
|
-
|
|
453
408
|
export function getTimeString(value, format) {
|
|
454
409
|
if (format === void 0) {
|
|
455
410
|
format = FORMAT.FORMAT_YMDHMS;
|
|
456
411
|
}
|
|
457
|
-
|
|
458
412
|
var stringifiedValue = value + '';
|
|
459
|
-
|
|
460
413
|
if (stringifiedValue.indexOf(':') !== -1 || stringifiedValue.indexOf(':') !== -1) {
|
|
461
414
|
return stringifiedValue;
|
|
462
415
|
}
|
|
463
|
-
|
|
464
416
|
if (parseInt(stringifiedValue, 10) > 999999999999) {
|
|
465
417
|
return formatDate(parseInt(stringifiedValue, 10), format);
|
|
466
418
|
}
|
|
467
|
-
|
|
468
419
|
return value;
|
|
469
420
|
}
|
|
470
421
|
export function isValidTimeStamp(val) {
|
|
471
422
|
if (!val) {
|
|
472
423
|
return false;
|
|
473
424
|
}
|
|
474
|
-
|
|
475
425
|
if (Object.prototype.toString.call(val) !== '[object Number]') {
|
|
476
426
|
return false;
|
|
477
427
|
}
|
|
478
|
-
|
|
479
428
|
if (val <= 0 || isNaN(val)) {
|
|
480
429
|
return false;
|
|
481
430
|
}
|
|
482
|
-
|
|
483
431
|
if (val < 1000000000000 || val > 10000000000000) {
|
|
484
432
|
return false;
|
|
485
433
|
}
|
|
486
|
-
|
|
487
434
|
return true;
|
|
488
435
|
}
|
|
436
|
+
|
|
489
437
|
/**
|
|
490
438
|
* 将当天时间显示为”X小时前“/”X分钟前“/“X秒前”
|
|
491
439
|
* 当天之前显示“MM-dd HH:mm”
|
|
492
440
|
*
|
|
493
441
|
*/
|
|
494
|
-
|
|
495
442
|
export function todaySpecialDate(time) {
|
|
496
443
|
time = new Date(time);
|
|
497
|
-
|
|
498
444
|
if (formatDateByDate(time, FORMAT.FORMAT_YMD) === formatDateByDate(new Date(), FORMAT.FORMAT_YMD)) {
|
|
499
445
|
var lastHours = new Date().getHours() - new Date(time).getHours();
|
|
500
|
-
|
|
501
446
|
if (lastHours > 0) {
|
|
502
447
|
time = lastHours + "\u5C0F\u65F6\u524D";
|
|
503
448
|
} else {
|
|
504
449
|
var lastMinutes = new Date().getMinutes() - new Date(time).getMinutes();
|
|
505
|
-
|
|
506
450
|
if (lastMinutes > 0) {
|
|
507
451
|
time = lastMinutes + "\u5206\u949F\u524D";
|
|
508
452
|
} else {
|
|
@@ -516,94 +460,84 @@ export function todaySpecialDate(time) {
|
|
|
516
460
|
time = formatDateByDate(time, FORMAT.FORMAT_YMDHM);
|
|
517
461
|
}
|
|
518
462
|
}
|
|
519
|
-
|
|
520
463
|
return time;
|
|
521
|
-
}
|
|
464
|
+
}
|
|
522
465
|
|
|
466
|
+
// 获取日期之间的时间
|
|
523
467
|
export function getTimeDiff(firstDate, secondDate) {
|
|
524
468
|
var result = '';
|
|
525
469
|
var diff = Math.abs(firstDate.getTime() - secondDate.getTime());
|
|
526
470
|
var hours = parseInt(diff / (1000 * 60 * 60), 10);
|
|
527
471
|
var minutes = parseInt((diff - hours * 1000 * 60 * 60) / (1000 * 60), 10);
|
|
528
472
|
var seconds = parseInt((diff - hours * 1000 * 60 * 60 - minutes * 1000 * 60) / 1000, 10);
|
|
529
|
-
|
|
530
473
|
if (hours < 10) {
|
|
531
474
|
result = result + '0' + hours + ':';
|
|
532
475
|
} else {
|
|
533
476
|
result = result + hours + ':';
|
|
534
477
|
}
|
|
535
|
-
|
|
536
478
|
if (minutes < 10) {
|
|
537
479
|
result = result + '0' + minutes + ':';
|
|
538
480
|
} else {
|
|
539
481
|
result = result + minutes + ':';
|
|
540
482
|
}
|
|
541
|
-
|
|
542
483
|
if (seconds < 10) {
|
|
543
484
|
result = result + '0' + seconds;
|
|
544
485
|
} else {
|
|
545
486
|
result = result + seconds;
|
|
546
487
|
}
|
|
547
|
-
|
|
548
488
|
return result;
|
|
549
489
|
}
|
|
490
|
+
|
|
550
491
|
/**
|
|
551
492
|
*获取某年某月某天是一年的第几周
|
|
552
493
|
*第一天为周日
|
|
553
494
|
*/
|
|
554
|
-
|
|
555
495
|
export function getWeekNumber(date) {
|
|
556
496
|
var targetDay = new Date(date);
|
|
557
497
|
var year = targetDay.getFullYear();
|
|
558
498
|
var month = targetDay.getMonth();
|
|
559
|
-
var days = targetDay.getDate();
|
|
560
|
-
|
|
499
|
+
var days = targetDay.getDate();
|
|
500
|
+
//那一天是那一年中的第多少天
|
|
561
501
|
for (var i = 1; i < month + 1; i++) {
|
|
562
502
|
days += getMonthDays(year, i);
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
503
|
+
}
|
|
504
|
+
//那一年第一天是星期几
|
|
505
|
+
var yearFirstDay = new Date(year, 0, 1).getDay();
|
|
506
|
+
//计算是第几周
|
|
568
507
|
days += yearFirstDay;
|
|
569
508
|
var week = Math.ceil(days / 7);
|
|
570
509
|
return week;
|
|
571
510
|
}
|
|
511
|
+
|
|
572
512
|
/**
|
|
573
513
|
*判断年份是否为润年
|
|
574
514
|
*/
|
|
575
|
-
|
|
576
515
|
export function isLeapYear(year) {
|
|
577
516
|
return year % 400 == 0 || year % 4 == 0 && year % 100 != 0;
|
|
578
517
|
}
|
|
579
518
|
/**
|
|
580
519
|
*获取某年某月的天数
|
|
581
520
|
*/
|
|
582
|
-
|
|
583
521
|
export function getMonthDays(year, month) {
|
|
584
522
|
return [31, isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1];
|
|
585
523
|
}
|
|
586
524
|
/**
|
|
587
525
|
* 获取本周第一天
|
|
588
526
|
*/
|
|
589
|
-
|
|
590
527
|
export function getFirstDayOfWeek(date) {
|
|
591
528
|
var target = new Date(date);
|
|
592
529
|
var weekday = target.getDay() || 7; //获取星期几,getDay()返回值是 0(周日) 到 6(周六) 之间的一个整数。0||7为7,即weekday的值为1-7
|
|
593
|
-
|
|
594
530
|
return addDays(target, 1 - weekday);
|
|
595
531
|
}
|
|
596
532
|
/**
|
|
597
533
|
* 加减月份
|
|
598
534
|
*/
|
|
599
|
-
|
|
600
535
|
export function addMonths(date, months) {
|
|
601
536
|
var target = new Date(date);
|
|
602
537
|
var y = target.getFullYear();
|
|
603
538
|
var m = target.getMonth();
|
|
604
539
|
var d = target.getDate();
|
|
605
540
|
m = m + months;
|
|
606
|
-
|
|
607
541
|
if (m < 0) {
|
|
608
542
|
m = m + 12;
|
|
609
543
|
y = y - 1;
|
|
@@ -611,34 +545,32 @@ export function addMonths(date, months) {
|
|
|
611
545
|
m = m - 12;
|
|
612
546
|
y = y + 1;
|
|
613
547
|
}
|
|
614
|
-
|
|
615
548
|
return new Date(y, m, d);
|
|
616
|
-
}
|
|
617
|
-
|
|
549
|
+
}
|
|
550
|
+
//获取当前天是这个月的第几周
|
|
618
551
|
export function getMonthWeek(date) {
|
|
619
552
|
var targetDay = new Date(date);
|
|
620
553
|
var w = targetDay.getDay();
|
|
621
554
|
var d = targetDay.getDate();
|
|
622
|
-
|
|
623
555
|
if (w == 0) {
|
|
624
556
|
w = 7;
|
|
625
557
|
}
|
|
626
|
-
|
|
627
558
|
return Math.ceil((d + 6 - w) / 7);
|
|
628
559
|
}
|
|
629
|
-
;
|
|
560
|
+
;
|
|
630
561
|
|
|
562
|
+
//获取一年所有周开始日期和结束日期 , 返回 12.26-01.03 01.04-01.11
|
|
631
563
|
export function getYearWeekList(year) {
|
|
632
564
|
//获取当前年份的第一天是周几
|
|
633
565
|
var firstDay = new Date(year, 0, 1);
|
|
634
|
-
var yearFirstDay = firstDay.getDay();
|
|
635
|
-
|
|
636
|
-
var firstWeekFirstDay = subDays(firstDay, yearFirstDay);
|
|
566
|
+
var yearFirstDay = firstDay.getDay();
|
|
567
|
+
//获取当前年份第一天所在的周的第一天
|
|
568
|
+
var firstWeekFirstDay = subDays(firstDay, yearFirstDay);
|
|
637
569
|
|
|
570
|
+
//获取当前年份最后一天
|
|
638
571
|
var endDay = subDays(new Date(year + 1, 0, 1), 1);
|
|
639
572
|
var endWeekDay = firstWeekFirstDay;
|
|
640
573
|
var weekStrList = [];
|
|
641
|
-
|
|
642
574
|
while (endWeekDay < endDay) {
|
|
643
575
|
var first = endWeekDay.getMonth() + 1 + "." + (endWeekDay.getDate() + 1);
|
|
644
576
|
endWeekDay = addDays(endWeekDay, 7);
|
|
@@ -646,23 +578,23 @@ export function getYearWeekList(year) {
|
|
|
646
578
|
var str = first + "-" + end;
|
|
647
579
|
weekStrList.push(str);
|
|
648
580
|
}
|
|
649
|
-
|
|
650
581
|
console.log("weekStrList :" + JSON.stringify(weekStrList));
|
|
651
582
|
return weekStrList;
|
|
652
583
|
}
|
|
653
|
-
;
|
|
584
|
+
;
|
|
654
585
|
|
|
586
|
+
//武汉环卫获取一年所有周开始日期和结束日期,需要返回上周五到这周四
|
|
655
587
|
export function getYearWeekListWh(year) {
|
|
656
588
|
//获取当前年份的第一天是周几
|
|
657
589
|
var firstDay = new Date(year, 0, 1);
|
|
658
|
-
var yearFirstDay = firstDay.getDay();
|
|
659
|
-
|
|
660
|
-
var firstWeekFirstDay = addDays(subDays(firstDay, yearFirstDay), 4);
|
|
590
|
+
var yearFirstDay = firstDay.getDay();
|
|
591
|
+
//获取当前年份第一天所在的周的第一天
|
|
592
|
+
var firstWeekFirstDay = addDays(subDays(firstDay, yearFirstDay), 4);
|
|
661
593
|
|
|
594
|
+
//获取当前年份最后一天
|
|
662
595
|
var endDay = subDays(new Date(year + 1, 0, 1), 1);
|
|
663
596
|
var endWeekDay = firstWeekFirstDay;
|
|
664
597
|
var weekStrList = [];
|
|
665
|
-
|
|
666
598
|
while (endWeekDay < endDay) {
|
|
667
599
|
var first = endWeekDay.getMonth() + 1 + "." + (endWeekDay.getDate() + 1);
|
|
668
600
|
endWeekDay = addDays(endWeekDay, 7);
|
|
@@ -670,21 +602,21 @@ export function getYearWeekListWh(year) {
|
|
|
670
602
|
var str = first + "-" + end;
|
|
671
603
|
weekStrList.push(str);
|
|
672
604
|
}
|
|
673
|
-
|
|
674
605
|
console.log("weekStrList :" + JSON.stringify(weekStrList));
|
|
675
606
|
return weekStrList;
|
|
676
607
|
}
|
|
677
|
-
;
|
|
608
|
+
;
|
|
678
609
|
|
|
610
|
+
// 判断开始时间是否小于结束时间
|
|
679
611
|
export function isLessThanDate(startDateStr, endDateStr) {
|
|
680
612
|
if (new Date(startDateStr).getTime() > new Date(endDateStr).getTime()) {
|
|
681
613
|
return false;
|
|
682
614
|
}
|
|
683
|
-
|
|
684
615
|
return true;
|
|
685
616
|
}
|
|
686
|
-
;
|
|
617
|
+
;
|
|
687
618
|
|
|
619
|
+
// 获取日期之间天数
|
|
688
620
|
export function getDateDiff(firstDate, secondDate) {
|
|
689
621
|
var diff = Math.abs(firstDate.getTime() - secondDate.getTime());
|
|
690
622
|
var dateNum = parseInt(diff / (1000 * 60 * 60 * 24), 10);
|
|
@@ -1,51 +1,42 @@
|
|
|
1
1
|
export function range(num, min, max) {
|
|
2
2
|
return Math.min(Math.max(num, min), max);
|
|
3
3
|
}
|
|
4
|
-
|
|
5
4
|
function trimExtraChar(value, _char, regExp) {
|
|
6
5
|
var index = value.indexOf(_char);
|
|
7
6
|
var prefix = '';
|
|
8
|
-
|
|
9
7
|
if (index === -1) {
|
|
10
8
|
return value;
|
|
11
9
|
}
|
|
12
|
-
|
|
13
10
|
if (_char === '-' && index !== 0) {
|
|
14
11
|
return value.slice(0, index);
|
|
15
12
|
}
|
|
16
|
-
|
|
17
13
|
if (_char === '.' && value.match(/^(\.|-\.)/)) {
|
|
18
14
|
prefix = index ? '-0' : '0';
|
|
19
15
|
}
|
|
20
|
-
|
|
21
16
|
return prefix + value.slice(0, index + 1) + value.slice(index).replace(regExp, '');
|
|
22
17
|
}
|
|
23
|
-
|
|
24
18
|
export function formatNumber(value, allowDot, allowMinus) {
|
|
25
19
|
if (allowDot === void 0) {
|
|
26
20
|
allowDot = true;
|
|
27
21
|
}
|
|
28
|
-
|
|
29
22
|
if (allowMinus === void 0) {
|
|
30
23
|
allowMinus = true;
|
|
31
24
|
}
|
|
32
|
-
|
|
33
25
|
if (allowDot) {
|
|
34
26
|
value = trimExtraChar(value, '.', /\./g);
|
|
35
27
|
} else {
|
|
36
28
|
value = value.split('.')[0];
|
|
37
29
|
}
|
|
38
|
-
|
|
39
30
|
if (allowMinus) {
|
|
40
31
|
value = trimExtraChar(value, '-', /-/g);
|
|
41
32
|
} else {
|
|
42
33
|
value = value.replace(/-/, '');
|
|
43
34
|
}
|
|
44
|
-
|
|
45
35
|
var regExp = allowDot ? /[^-0-9.]/g : /[^-0-9]/g;
|
|
46
36
|
return value.replace(regExp, '');
|
|
47
|
-
}
|
|
37
|
+
}
|
|
48
38
|
|
|
39
|
+
// add num and avoid float number
|
|
49
40
|
export function addNumber(num1, num2) {
|
|
50
41
|
var cardinal = Math.pow(10, 10);
|
|
51
42
|
return Math.round((num1 + num2) * cardinal) / cardinal;
|