hy-app 0.4.13 → 0.5.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/components/hy-action-sheet/hy-action-sheet.vue +155 -238
- package/components/hy-action-sheet/props.ts +68 -15
- package/components/hy-action-sheet/typing.d.ts +115 -115
- package/components/hy-address-picker/hy-address-picker.vue +185 -289
- package/components/hy-address-picker/props.ts +97 -21
- package/components/hy-address-picker/typing.d.ts +90 -89
- package/components/hy-avatar/hy-avatar.vue +121 -204
- package/components/hy-avatar/props.ts +76 -18
- package/components/hy-avatar/typing.d.ts +63 -62
- package/components/hy-back-top/hy-back-top.vue +65 -120
- package/components/hy-back-top/props.ts +57 -16
- package/components/hy-back-top/typing.d.ts +43 -42
- package/components/hy-badge/hy-badge.vue +66 -138
- package/components/hy-badge/props.ts +73 -17
- package/components/hy-badge/typing.d.ts +59 -58
- package/components/hy-button/hy-button.vue +226 -375
- package/components/hy-button/props.ts +129 -158
- package/components/hy-calendar/header.vue +48 -64
- package/components/hy-calendar/hy-calendar.vue +274 -438
- package/components/hy-calendar/month.vue +508 -516
- package/components/hy-calendar/props.ts +157 -35
- package/components/hy-calendar/typing.d.ts +129 -128
- package/components/hy-card/hy-card.vue +118 -240
- package/components/hy-card/index.scss +1 -2
- package/components/hy-card/props.ts +122 -27
- package/components/hy-card/typing.d.ts +119 -118
- package/components/hy-cell/hy-cell.vue +176 -258
- package/components/hy-cell/props.ts +71 -17
- package/components/hy-cell/typing.d.ts +87 -86
- package/components/hy-check-button/hy-check-button.vue +69 -139
- package/components/hy-check-button/props.ts +72 -18
- package/components/hy-check-button/typing.d.ts +74 -73
- package/components/hy-checkbox/hy-checkbox.vue +170 -263
- package/components/hy-checkbox/props.ts +94 -24
- package/components/hy-checkbox/typing.d.ts +72 -72
- package/components/hy-checkbox-group/hy-checkbox-group.vue +25 -100
- package/components/hy-checkbox-group/props.ts +80 -0
- package/components/hy-checkbox-group/typing.d.ts +65 -65
- package/components/hy-checkbox-item/hy-checkbox-item.vue +140 -177
- package/components/hy-checkbox-item/props.ts +24 -0
- package/components/hy-checkbox-item/typing.d.ts +4 -3
- package/components/hy-code-input/hy-code-input.vue +179 -262
- package/components/hy-code-input/props.ts +84 -18
- package/components/hy-code-input/typing.d.ts +71 -71
- package/components/hy-config-provider/hy-config-provider.vue +28 -50
- package/components/hy-config-provider/props.ts +26 -11
- package/components/hy-config-provider/typing.d.ts +20 -20
- package/components/hy-count-down/hy-count-down.vue +103 -131
- package/components/hy-count-down/props.ts +30 -8
- package/components/hy-count-down/typing.d.ts +25 -25
- package/components/hy-count-to/hy-count-to.vue +148 -213
- package/components/hy-count-to/props.ts +60 -15
- package/components/hy-count-to/typing.d.ts +46 -46
- package/components/hy-coupon/README.md +133 -0
- package/components/hy-coupon/hy-coupon.vue +180 -0
- package/components/hy-coupon/index.scss +553 -0
- package/components/hy-coupon/props.ts +129 -0
- package/components/hy-coupon/typing.d.ts +146 -0
- package/components/hy-datetime-picker/hy-datetime-picker.vue +415 -580
- package/components/hy-datetime-picker/props.ts +142 -32
- package/components/hy-datetime-picker/typing.d.ts +132 -132
- package/components/hy-divider/hy-divider.vue +90 -169
- package/components/hy-divider/props.ts +78 -19
- package/components/hy-divider/typing.d.ts +60 -60
- package/components/hy-dropdown/hy-dropdown.vue +37 -71
- package/components/hy-dropdown/props.ts +38 -15
- package/components/hy-dropdown/typing.d.ts +44 -44
- package/components/hy-dropdown-item/hy-dropdown-item.vue +141 -173
- package/components/hy-dropdown-item/props.ts +19 -8
- package/components/hy-empty/hy-empty.vue +75 -129
- package/components/hy-empty/props.ts +57 -15
- package/components/hy-empty/typing.d.ts +84 -84
- package/components/hy-flex/hy-flex.vue +33 -88
- package/components/hy-flex/props.ts +58 -0
- package/components/hy-flex/typing.d.ts +14 -16
- package/components/hy-float-button/hy-float-button.vue +289 -406
- package/components/hy-float-button/props.ts +109 -25
- package/components/hy-folding-panel/hy-folding-panel.vue +86 -374
- package/components/hy-folding-panel/props.ts +40 -15
- package/components/hy-folding-panel/typing.d.ts +52 -63
- package/components/hy-folding-panel-item/hy-folding-panel-item.vue +186 -228
- package/components/hy-folding-panel-item/index.scss +87 -0
- package/components/hy-folding-panel-item/props.ts +81 -0
- package/components/hy-folding-panel-item/typing.d.ts +23 -0
- package/components/hy-form/hy-form.vue +172 -212
- package/components/hy-form/props.ts +37 -0
- package/components/hy-form/typing.d.ts +68 -61
- package/components/hy-form-group/typing.d.ts +74 -74
- package/components/hy-form-item/hy-form-item.vue +100 -129
- package/components/hy-form-item/props.ts +25 -0
- package/components/hy-form-item/typing.d.ts +40 -37
- package/components/hy-grid/hy-grid.vue +76 -132
- package/components/hy-grid/props.ts +58 -16
- package/components/hy-grid/typing.d.ts +66 -66
- package/components/hy-icon/hy-icon.vue +84 -161
- package/components/hy-icon/props.ts +76 -22
- package/components/hy-icon/typing.d.ts +83 -82
- package/components/hy-image/hy-image.vue +142 -272
- package/components/hy-image/props.ts +105 -23
- package/components/hy-image/typing.d.ts +84 -87
- package/components/hy-input/hy-input.vue +230 -421
- package/components/hy-input/props.ts +183 -35
- package/components/hy-input/typing.d.ts +169 -169
- package/components/hy-line/hy-line.vue +34 -72
- package/components/hy-line/props.ts +41 -10
- package/components/hy-line/typing.d.ts +29 -29
- package/components/hy-line-progress/hy-line-progress.vue +66 -101
- package/components/hy-line-progress/props.ts +31 -10
- package/components/hy-line-progress/typing.d.ts +29 -29
- package/components/hy-list/hy-list.vue +151 -220
- package/components/hy-list/props.ts +67 -16
- package/components/hy-list/typing.d.ts +52 -52
- package/components/hy-loading/hy-loading.vue +63 -119
- package/components/hy-loading/props.ts +63 -15
- package/components/hy-loading/typing.d.ts +49 -49
- package/components/hy-menu/hy-menu.vue +124 -166
- package/components/hy-menu/props.ts +42 -10
- package/components/hy-menu/typing.d.ts +60 -60
- package/components/hy-modal/hy-modal.vue +127 -218
- package/components/hy-modal/props.ts +89 -24
- package/components/hy-navbar/hy-navbar.vue +104 -177
- package/components/hy-navbar/props.ts +76 -22
- package/components/hy-navbar/typing.d.ts +81 -81
- package/components/hy-notice-bar/hy-notice-bar.vue +67 -144
- package/components/hy-notice-bar/props.ts +80 -19
- package/components/hy-notice-bar/typing.d.ts +62 -62
- package/components/hy-notify/hy-notify.vue +128 -177
- package/components/hy-notify/props.ts +49 -12
- package/components/hy-notify/typing.d.ts +45 -41
- package/components/hy-number-step/hy-number-step.vue +281 -394
- package/components/hy-number-step/props.ts +110 -27
- package/components/hy-number-step/typing.d.ts +120 -120
- package/components/hy-overlay/hy-overlay.vue +39 -66
- package/components/hy-overlay/props.ts +31 -8
- package/components/hy-pagination/hy-pagination.vue +100 -155
- package/components/hy-pagination/props.ts +53 -13
- package/components/hy-picker/hy-picker.vue +309 -430
- package/components/hy-picker/index.scss +8 -12
- package/components/hy-picker/props.ts +110 -26
- package/components/hy-popover/hy-popover.vue +190 -252
- package/components/hy-popover/props.ts +48 -10
- package/components/hy-popup/hy-popup.vue +162 -248
- package/components/hy-popup/props.ts +82 -18
- package/components/hy-price/hy-price.vue +45 -104
- package/components/hy-price/props.ts +52 -12
- package/components/hy-price/typing.d.ts +41 -36
- package/components/hy-qrcode/hy-qrcode.vue +115 -185
- package/components/hy-qrcode/props.ts +68 -18
- package/components/hy-qrcode/typing.d.ts +67 -66
- package/components/hy-radio/hy-radio.vue +161 -259
- package/components/hy-radio/props.ts +95 -25
- package/components/hy-radio/typing.d.ts +85 -84
- package/components/hy-rate/hy-rate.vue +185 -270
- package/components/hy-rate/props.ts +76 -18
- package/components/hy-rate/typing.d.ts +61 -60
- package/components/hy-read-more/hy-read-more.vue +93 -136
- package/components/hy-read-more/props.ts +43 -13
- package/components/hy-scroll-list/hy-scroll-list.vue +81 -102
- package/components/hy-scroll-list/props.ts +22 -11
- package/components/hy-search/hy-search.vue +155 -284
- package/components/hy-search/props.ts +130 -25
- package/components/hy-signature/hy-signature.vue +491 -635
- package/components/hy-signature/props.ts +115 -26
- package/components/hy-signature/typing.d.ts +138 -138
- package/components/hy-slider/hy-slider.vue +388 -477
- package/components/hy-slider/props.ts +75 -19
- package/components/hy-steps/hy-steps.vue +212 -279
- package/components/hy-steps/props.ts +47 -13
- package/components/hy-submit-bar/hy-submit-bar.vue +137 -222
- package/components/hy-submit-bar/props.ts +89 -20
- package/components/hy-submit-bar/typing.d.ts +86 -85
- package/components/hy-subsection/hy-subsection.vue +132 -185
- package/components/hy-subsection/props.ts +50 -17
- package/components/hy-subsection/typing.d.ts +52 -52
- package/components/hy-swipe-action/hy-swipe-action.vue +228 -283
- package/components/hy-swipe-action/props.ts +43 -18
- package/components/hy-swipe-action/typing.d.ts +46 -46
- package/components/hy-swiper/hy-swiper.vue +159 -286
- package/components/hy-swiper/props.ts +126 -28
- package/components/hy-swiper/typing.d.ts +115 -115
- package/components/hy-switch/hy-switch.vue +112 -176
- package/components/hy-switch/props.ts +60 -15
- package/components/hy-switch/typing.d.ts +63 -63
- package/components/hy-tabBar/hy-tabBar.vue +64 -60
- package/components/hy-tabs/hy-tabs.vue +277 -380
- package/components/hy-tabs/props.ts +75 -18
- package/components/hy-tag/hy-tag.vue +111 -204
- package/components/hy-tag/props.ts +81 -19
- package/components/hy-text/hy-text.vue +200 -322
- package/components/hy-text/props.ts +107 -28
- package/components/hy-textarea/hy-textarea.vue +147 -256
- package/components/hy-textarea/props.ts +112 -25
- package/components/hy-textarea/typing.d.ts +42 -42
- package/components/hy-toast/hy-toast.vue +135 -143
- package/components/hy-tooltip/hy-tooltip.vue +220 -306
- package/components/hy-tooltip/props.ts +79 -15
- package/components/hy-transition/hy-transition.vue +111 -138
- package/components/hy-transition/props.ts +30 -8
- package/components/hy-upload/hy-upload.vue +320 -469
- package/components/hy-upload/props.ts +130 -27
- package/components/hy-warn/hy-warn.vue +80 -129
- package/components/hy-warn/props.ts +47 -12
- package/components/hy-waterfall/hy-waterfall.vue +139 -163
- package/components/hy-waterfall/props.ts +19 -7
- package/components/hy-watermark/hy-watermark.vue +762 -870
- package/components/hy-watermark/props.ts +103 -22
- package/global.d.ts +2 -0
- package/libs/css/theme.scss +3 -3
- package/package.json +2 -2
- package/web-types.json +1 -1
- package/components/hy-folding-panel/index.scss +0 -9
|
@@ -1,545 +1,537 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
3
|
-
<view
|
|
4
|
-
v-for="(item, index) in months"
|
|
5
|
-
:key="index"
|
|
6
|
-
:class="[`hy-calendar--month__${index}`]"
|
|
7
|
-
:ref="`hy-calendar--month__${index}`"
|
|
8
|
-
:id="`month-${index}`"
|
|
9
|
-
>
|
|
10
|
-
<text v-if="index !== 0" class="hy-calendar--month__title"
|
|
11
|
-
>{{ item.year }}年{{ item.month }}月</text
|
|
12
|
-
>
|
|
13
|
-
<view class="hy-calendar--month__days">
|
|
2
|
+
<view class="hy-calendar--month__wrapper" ref="hy-calendar--month__wrapper">
|
|
14
3
|
<view
|
|
15
|
-
|
|
16
|
-
|
|
4
|
+
v-for="(item, index) in months"
|
|
5
|
+
:key="index"
|
|
6
|
+
:class="[`hy-calendar--month__${index}`]"
|
|
7
|
+
:ref="`hy-calendar--month__${index}`"
|
|
8
|
+
:id="`month-${index}`"
|
|
17
9
|
>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}}</text>
|
|
21
|
-
</view>
|
|
22
|
-
<view
|
|
23
|
-
class="hy-calendar--month__days__day"
|
|
24
|
-
v-for="(item1, index1) in item.date"
|
|
25
|
-
:key="index1"
|
|
26
|
-
:style="[dayStyle(index, index1, item1)]"
|
|
27
|
-
@tap="clickHandler(index, index1, item1)"
|
|
28
|
-
>
|
|
29
|
-
<view
|
|
30
|
-
:class="daySelectClass(index, index1, item1)"
|
|
31
|
-
:style="[daySelectStyle(index, index1, item1)]"
|
|
32
|
-
>
|
|
33
|
-
<text
|
|
34
|
-
class="hy-calendar--month__days__day__select__info"
|
|
35
|
-
:class="[
|
|
36
|
-
item1.disabled || isForbid(item1)
|
|
37
|
-
? 'hy-calendar--month__days__day__select__info--disabled'
|
|
38
|
-
: '',
|
|
39
|
-
]"
|
|
40
|
-
:style="[textStyle(item1)]"
|
|
41
|
-
>{{ item1.day }}</text
|
|
42
|
-
>
|
|
43
|
-
<text
|
|
44
|
-
v-if="getBottomInfo(index, index1, item1)"
|
|
45
|
-
class="hy-calendar--month__days__day__select__button-info"
|
|
46
|
-
:class="[
|
|
47
|
-
item1.disabled || isForbid(item1)
|
|
48
|
-
? 'hy-calendar--month__days__day__select__button-info--disabled'
|
|
49
|
-
: '',
|
|
50
|
-
]"
|
|
51
|
-
:style="[textStyle(item1)]"
|
|
52
|
-
>{{ getBottomInfo(index, index1, item1) }}</text
|
|
10
|
+
<text v-if="index !== 0" class="hy-calendar--month__title"
|
|
11
|
+
>{{ item.year }}年{{ item.month }}月</text
|
|
53
12
|
>
|
|
54
|
-
<
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
13
|
+
<view class="hy-calendar--month__days">
|
|
14
|
+
<view v-if="showMark" class="hy-calendar--month__days__month-mark-wrapper">
|
|
15
|
+
<text class="hy-calendar--month__days__month-mark-wrapper__text">{{
|
|
16
|
+
item.month
|
|
17
|
+
}}</text>
|
|
18
|
+
</view>
|
|
19
|
+
<view
|
|
20
|
+
class="hy-calendar--month__days__day"
|
|
21
|
+
v-for="(item1, index1) in item.date"
|
|
22
|
+
:key="index1"
|
|
23
|
+
:style="[dayStyle(index, index1, item1)]"
|
|
24
|
+
@tap="clickHandler(index, index1, item1)"
|
|
25
|
+
>
|
|
26
|
+
<view
|
|
27
|
+
:class="daySelectClass(index, index1, item1)"
|
|
28
|
+
:style="[daySelectStyle(index, index1, item1)]"
|
|
29
|
+
>
|
|
30
|
+
<text
|
|
31
|
+
class="hy-calendar--month__days__day__select__info"
|
|
32
|
+
:class="[
|
|
33
|
+
item1.disabled || isForbid(item1)
|
|
34
|
+
? 'hy-calendar--month__days__day__select__info--disabled'
|
|
35
|
+
: ''
|
|
36
|
+
]"
|
|
37
|
+
:style="[textStyle(item1)]"
|
|
38
|
+
>{{ item1.day }}</text
|
|
39
|
+
>
|
|
40
|
+
<text
|
|
41
|
+
v-if="getBottomInfo(index, index1, item1)"
|
|
42
|
+
class="hy-calendar--month__days__day__select__button-info"
|
|
43
|
+
:class="[
|
|
44
|
+
item1.disabled || isForbid(item1)
|
|
45
|
+
? 'hy-calendar--month__days__day__select__button-info--disabled'
|
|
46
|
+
: ''
|
|
47
|
+
]"
|
|
48
|
+
:style="[textStyle(item1)]"
|
|
49
|
+
>{{ getBottomInfo(index, index1, item1) }}</text
|
|
50
|
+
>
|
|
51
|
+
<text
|
|
52
|
+
v-if="item1.dot"
|
|
53
|
+
class="hy-calendar--month__days__day__select__dot"
|
|
54
|
+
></text>
|
|
55
|
+
</view>
|
|
56
|
+
</view>
|
|
57
|
+
</view>
|
|
59
58
|
</view>
|
|
60
|
-
</view>
|
|
61
59
|
</view>
|
|
62
|
-
</view>
|
|
63
60
|
</template>
|
|
64
61
|
|
|
65
62
|
<script>
|
|
66
|
-
import { addUnit, colorGradient, deepClone, getRect, sleep } from
|
|
67
|
-
import dayjs from
|
|
63
|
+
import { addUnit, colorGradient, deepClone, getRect, sleep } from '../../libs'
|
|
64
|
+
import dayjs from 'dayjs/esm'
|
|
68
65
|
export default {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
},
|
|
165
|
-
data() {
|
|
166
|
-
return {
|
|
167
|
-
// 每个日期的宽度
|
|
168
|
-
width: 0,
|
|
169
|
-
// 当前选中的日期item
|
|
170
|
-
item: {},
|
|
171
|
-
selected: [],
|
|
172
|
-
};
|
|
173
|
-
},
|
|
174
|
-
watch: {
|
|
175
|
-
selectedChange: {
|
|
176
|
-
immediate: true,
|
|
177
|
-
handler(n) {
|
|
178
|
-
this.setDefaultDate();
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
computed: {
|
|
183
|
-
// 多个条件的变化,会引起选中日期的变化,这里统一管理监听
|
|
184
|
-
selectedChange() {
|
|
185
|
-
return [this.minDate, this.maxDate, this.defaultDate];
|
|
186
|
-
},
|
|
187
|
-
dayStyle() {
|
|
188
|
-
return (index1, index2, item) => {
|
|
189
|
-
const style = {};
|
|
190
|
-
let week = item.week;
|
|
191
|
-
// 不进行四舍五入的形式保留2位小数
|
|
192
|
-
const dayWidth = Number(
|
|
193
|
-
parseFloat(this.width / 7)
|
|
194
|
-
.toFixed(3)
|
|
195
|
-
.slice(0, -1),
|
|
196
|
-
);
|
|
197
|
-
// 得出每个日期的宽度
|
|
198
|
-
// #ifdef APP-NVUE
|
|
199
|
-
style.width = addUnit(dayWidth, "px");
|
|
200
|
-
// #endif
|
|
201
|
-
style.height = addUnit(this.rowHeight);
|
|
202
|
-
if (index2 === 0) {
|
|
203
|
-
// 获取当前为星期几,如果为0,则为星期天,减一为每月第一天时,需要向左偏移的item个数
|
|
204
|
-
week = (week === 0 ? 7 : week) - 1;
|
|
205
|
-
style.marginLeft = addUnit(week * dayWidth, "px");
|
|
66
|
+
name: 'hy-calendar-month',
|
|
67
|
+
|
|
68
|
+
props: {
|
|
69
|
+
// 是否显示月份背景色
|
|
70
|
+
showMark: {
|
|
71
|
+
type: Boolean,
|
|
72
|
+
default: true
|
|
73
|
+
},
|
|
74
|
+
// 主题色,对底部按钮和选中日期有效
|
|
75
|
+
color: {
|
|
76
|
+
type: String,
|
|
77
|
+
default: '#3c9cff'
|
|
78
|
+
},
|
|
79
|
+
// 月份数据
|
|
80
|
+
months: {
|
|
81
|
+
type: Array,
|
|
82
|
+
default: () => []
|
|
83
|
+
},
|
|
84
|
+
// 日期选择类型
|
|
85
|
+
mode: {
|
|
86
|
+
type: String,
|
|
87
|
+
default: 'single'
|
|
88
|
+
},
|
|
89
|
+
// 日期行高
|
|
90
|
+
rowHeight: {
|
|
91
|
+
type: [String, Number],
|
|
92
|
+
default: 58
|
|
93
|
+
},
|
|
94
|
+
// mode=multiple时,最多可选多少个日期
|
|
95
|
+
maxCount: {
|
|
96
|
+
type: [String, Number],
|
|
97
|
+
default: Infinity
|
|
98
|
+
},
|
|
99
|
+
// mode=range时,第一个日期底部的提示文字
|
|
100
|
+
startText: {
|
|
101
|
+
type: String,
|
|
102
|
+
default: '开始'
|
|
103
|
+
},
|
|
104
|
+
// mode=range时,最后一个日期底部的提示文字
|
|
105
|
+
endText: {
|
|
106
|
+
type: String,
|
|
107
|
+
default: '结束'
|
|
108
|
+
},
|
|
109
|
+
// 默认选中的日期,mode为multiple或range是必须为数组格式
|
|
110
|
+
defaultDate: {
|
|
111
|
+
type: [Array, String, Date],
|
|
112
|
+
default: null
|
|
113
|
+
},
|
|
114
|
+
// 最小的可选日期
|
|
115
|
+
minDate: {
|
|
116
|
+
type: [String, Number],
|
|
117
|
+
default: 0
|
|
118
|
+
},
|
|
119
|
+
// 最大可选日期
|
|
120
|
+
maxDate: {
|
|
121
|
+
type: [String, Number],
|
|
122
|
+
default: 0
|
|
123
|
+
},
|
|
124
|
+
// 如果没有设置maxDate,则往后推多少个月
|
|
125
|
+
maxMonth: {
|
|
126
|
+
type: [String, Number],
|
|
127
|
+
default: 2
|
|
128
|
+
},
|
|
129
|
+
// 是否为只读状态,只读状态下禁止选择日期
|
|
130
|
+
readonly: {
|
|
131
|
+
type: Boolean,
|
|
132
|
+
default: () => defProps.calendar.readonly
|
|
133
|
+
},
|
|
134
|
+
// 日期区间最多可选天数,默认无限制,mode = range时有效
|
|
135
|
+
maxRange: {
|
|
136
|
+
type: [Number, String],
|
|
137
|
+
default: Infinity
|
|
138
|
+
},
|
|
139
|
+
// 范围选择超过最多可选天数时的提示文案,mode = range时有效
|
|
140
|
+
rangePrompt: {
|
|
141
|
+
type: String,
|
|
142
|
+
default: ''
|
|
143
|
+
},
|
|
144
|
+
// 范围选择超过最多可选天数时,是否展示提示文案,mode = range时有效
|
|
145
|
+
showRangePrompt: {
|
|
146
|
+
type: Boolean,
|
|
147
|
+
default: true
|
|
148
|
+
},
|
|
149
|
+
// 是否允许日期范围的起止时间为同一天,mode = range时有效
|
|
150
|
+
allowSameDay: {
|
|
151
|
+
type: Boolean,
|
|
152
|
+
default: false
|
|
153
|
+
},
|
|
154
|
+
forbidDays: {
|
|
155
|
+
type: Array,
|
|
156
|
+
default: () => []
|
|
157
|
+
},
|
|
158
|
+
forbidDaysToast: {
|
|
159
|
+
type: String,
|
|
160
|
+
default: ''
|
|
206
161
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
162
|
+
},
|
|
163
|
+
data() {
|
|
164
|
+
return {
|
|
165
|
+
// 每个日期的宽度
|
|
166
|
+
width: 0,
|
|
167
|
+
// 当前选中的日期item
|
|
168
|
+
item: {},
|
|
169
|
+
selected: []
|
|
213
170
|
}
|
|
214
|
-
return style;
|
|
215
|
-
};
|
|
216
171
|
},
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
// 判断选中的
|
|
223
|
-
if (this.selected.some((item) => this.dateSame(item, date))) {
|
|
224
|
-
classes.push("hy-calendar--month__days__day__select--selected");
|
|
225
|
-
if (this.selected.length >= 2) {
|
|
226
|
-
// 判断非两边选中内容
|
|
227
|
-
if (
|
|
228
|
-
!this.dateSame(date, this.selected[0]) &&
|
|
229
|
-
!this.dateSame(date, this.selected[len])
|
|
230
|
-
) {
|
|
231
|
-
classes.push(
|
|
232
|
-
"hy-calendar--month__days__day__select--selected--center",
|
|
233
|
-
);
|
|
172
|
+
watch: {
|
|
173
|
+
selectedChange: {
|
|
174
|
+
immediate: true,
|
|
175
|
+
handler(n) {
|
|
176
|
+
this.setDefaultDate()
|
|
234
177
|
}
|
|
235
|
-
}
|
|
236
178
|
}
|
|
237
|
-
return classes;
|
|
238
|
-
};
|
|
239
179
|
},
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
180
|
+
computed: {
|
|
181
|
+
// 多个条件的变化,会引起选中日期的变化,这里统一管理监听
|
|
182
|
+
selectedChange() {
|
|
183
|
+
return [this.minDate, this.maxDate, this.defaultDate]
|
|
184
|
+
},
|
|
185
|
+
dayStyle() {
|
|
186
|
+
return (index1, index2, item) => {
|
|
187
|
+
const style = {}
|
|
188
|
+
let week = item.week
|
|
189
|
+
// 不进行四舍五入的形式保留2位小数
|
|
190
|
+
const dayWidth = Number(
|
|
191
|
+
parseFloat(this.width / 7)
|
|
192
|
+
.toFixed(3)
|
|
193
|
+
.slice(0, -1)
|
|
194
|
+
)
|
|
195
|
+
// 得出每个日期的宽度
|
|
196
|
+
// #ifdef APP-NVUE
|
|
197
|
+
style.width = addUnit(dayWidth, 'px')
|
|
198
|
+
// #endif
|
|
199
|
+
style.height = addUnit(this.rowHeight)
|
|
200
|
+
if (index2 === 0) {
|
|
201
|
+
// 获取当前为星期几,如果为0,则为星期天,减一为每月第一天时,需要向左偏移的item个数
|
|
202
|
+
week = (week === 0 ? 7 : week) - 1
|
|
203
|
+
style.marginLeft = addUnit(week * dayWidth, 'px')
|
|
204
|
+
}
|
|
205
|
+
if (this.mode === 'range') {
|
|
206
|
+
// 之所以需要这么写,是因为DCloud公司的iOS客户端导致的bug
|
|
207
|
+
style.paddingLeft = 0
|
|
208
|
+
style.paddingRight = 0
|
|
209
|
+
style.paddingBottom = 0
|
|
210
|
+
style.paddingTop = 0
|
|
211
|
+
}
|
|
212
|
+
return style
|
|
263
213
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
214
|
+
},
|
|
215
|
+
daySelectClass() {
|
|
216
|
+
return (index1, index2, item) => {
|
|
217
|
+
const date = dayjs(item.date).format('YYYY-MM-DD')
|
|
218
|
+
const len = this.selected.length - 1
|
|
219
|
+
const classes = ['hy-calendar--month__days__day__select']
|
|
220
|
+
// 判断选中的
|
|
221
|
+
if (this.selected.some((item) => this.dateSame(item, date))) {
|
|
222
|
+
classes.push('hy-calendar--month__days__day__select--selected')
|
|
223
|
+
if (this.selected.length >= 2) {
|
|
224
|
+
// 判断非两边选中内容
|
|
225
|
+
if (
|
|
226
|
+
!this.dateSame(date, this.selected[0]) &&
|
|
227
|
+
!this.dateSame(date, this.selected[len])
|
|
228
|
+
) {
|
|
229
|
+
classes.push('hy-calendar--month__days__day__select--selected--center')
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return classes
|
|
268
234
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
this.
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
235
|
+
},
|
|
236
|
+
daySelectStyle() {
|
|
237
|
+
return (index1, index2, item) => {
|
|
238
|
+
let date = dayjs(item.date).format('YYYY-MM-DD'),
|
|
239
|
+
style = {}
|
|
240
|
+
// 判断date是否在selected数组中,因为月份可能会需要补0,所以使用dateSame判断,而不用数组的includes判断
|
|
241
|
+
if (this.selected.some((item) => this.dateSame(item, date))) {
|
|
242
|
+
style.backgroundColor = this.color
|
|
243
|
+
}
|
|
244
|
+
if (this.mode === 'single') {
|
|
245
|
+
if (date === this.selected[0]) {
|
|
246
|
+
// 因为需要对nvue的兼容,只能这么写,无法缩写,也无法通过类名控制等等
|
|
247
|
+
style.borderTopLeftRadius = '3px'
|
|
248
|
+
style.borderBottomLeftRadius = '3px'
|
|
249
|
+
style.borderTopRightRadius = '3px'
|
|
250
|
+
style.borderBottomRightRadius = '3px'
|
|
251
|
+
}
|
|
252
|
+
} else if (this.mode === 'range') {
|
|
253
|
+
if (this.selected.length >= 2) {
|
|
254
|
+
const len = this.selected.length - 1
|
|
255
|
+
// 第一个日期设置左上角和左下角的圆角
|
|
256
|
+
if (this.dateSame(date, this.selected[0])) {
|
|
257
|
+
style.borderTopLeftRadius = '3px'
|
|
258
|
+
style.borderBottomLeftRadius = '3px'
|
|
259
|
+
}
|
|
260
|
+
// 最后一个日期设置右上角和右下角的圆角
|
|
261
|
+
if (this.dateSame(date, this.selected[len])) {
|
|
262
|
+
style.borderTopRightRadius = '3px'
|
|
263
|
+
style.borderBottomRightRadius = '3px'
|
|
264
|
+
}
|
|
265
|
+
// 处于第一和最后一个之间的日期,背景色设置为浅色,通过将对应颜色进行等分,再取其尾部的颜色值
|
|
266
|
+
if (
|
|
267
|
+
dayjs(date).isAfter(dayjs(this.selected[0])) &&
|
|
268
|
+
dayjs(date).isBefore(dayjs(this.selected[len]))
|
|
269
|
+
) {
|
|
270
|
+
style.backgroundColor = colorGradient(this.color, '#ffffff', 100)[90]
|
|
271
|
+
// 增加一个透明度,让范围区间的背景色也能看到底部的mark水印字符
|
|
272
|
+
style.opacity = 0.7
|
|
273
|
+
}
|
|
274
|
+
} else if (this.selected.length === 1) {
|
|
275
|
+
// 之所以需要这么写,是因为DCloud公司的iOS客户端的开发者能力有限导致的bug
|
|
276
|
+
// 进行还原操作,否则在nvue的iOS,uni-app有bug,会导致诡异的表现
|
|
277
|
+
style.borderTopLeftRadius = '3px'
|
|
278
|
+
style.borderBottomLeftRadius = '3px'
|
|
279
|
+
}
|
|
280
|
+
} else {
|
|
281
|
+
if (this.selected.some((item) => this.dateSame(item, date))) {
|
|
282
|
+
style.borderTopLeftRadius = '3px'
|
|
283
|
+
style.borderBottomLeftRadius = '3px'
|
|
284
|
+
style.borderTopRightRadius = '3px'
|
|
285
|
+
style.borderBottomRightRadius = '3px'
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return style
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
// 某个日期是否被选中
|
|
292
|
+
textStyle() {
|
|
293
|
+
return (item) => {
|
|
294
|
+
const date = dayjs(item.date).format('YYYY-MM-DD'),
|
|
295
|
+
style = {}
|
|
296
|
+
// 选中的日期,提示文字设置白色
|
|
297
|
+
if (this.selected.some((item) => this.dateSame(item, date))) {
|
|
298
|
+
style.color = '#ffffff'
|
|
299
|
+
}
|
|
300
|
+
if (this.mode === 'range') {
|
|
301
|
+
const len = this.selected.length - 1
|
|
302
|
+
// 如果是范围选择模式,第一个和最后一个之间的日期,文字颜色设置为高亮的主题色
|
|
303
|
+
if (
|
|
304
|
+
dayjs(date).isAfter(dayjs(this.selected[0])) &&
|
|
305
|
+
dayjs(date).isBefore(dayjs(this.selected[len]))
|
|
306
|
+
) {
|
|
307
|
+
style.color = this.color
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return style
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
// 获取底部的提示文字
|
|
314
|
+
getBottomInfo() {
|
|
315
|
+
return (index1, index2, item) => {
|
|
316
|
+
const date = dayjs(item.date).format('YYYY-MM-DD')
|
|
317
|
+
const bottomInfo = item.bottomInfo
|
|
318
|
+
// 当为日期范围模式时,且选择的日期个数大于0时
|
|
319
|
+
if (this.mode === 'range' && this.selected.length > 0) {
|
|
320
|
+
if (this.selected.length === 1) {
|
|
321
|
+
// 选择了一个日期时,如果当前日期为数组中的第一个日期,则显示底部文字为“开始”
|
|
322
|
+
if (this.dateSame(date, this.selected[0])) return this.startText
|
|
323
|
+
else return bottomInfo
|
|
324
|
+
} else {
|
|
325
|
+
const len = this.selected.length - 1
|
|
326
|
+
// 如果数组中的日期大于2个时,第一个和最后一个显示为开始和结束日期
|
|
327
|
+
if (
|
|
328
|
+
this.dateSame(date, this.selected[0]) &&
|
|
329
|
+
this.dateSame(date, this.selected[1]) &&
|
|
330
|
+
len === 1
|
|
331
|
+
) {
|
|
332
|
+
// 如果长度为2,且第一个等于第二个日期,则提示语放在同一个item中
|
|
333
|
+
return `${this.startText}/${this.endText}`
|
|
334
|
+
} else if (this.dateSame(date, this.selected[0])) {
|
|
335
|
+
return this.startText
|
|
336
|
+
} else if (this.dateSame(date, this.selected[len])) {
|
|
337
|
+
return this.endText
|
|
338
|
+
} else {
|
|
339
|
+
return bottomInfo
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
} else {
|
|
343
|
+
return bottomInfo
|
|
344
|
+
}
|
|
281
345
|
}
|
|
282
|
-
} else if (this.selected.length === 1) {
|
|
283
|
-
// 之所以需要这么写,是因为DCloud公司的iOS客户端的开发者能力有限导致的bug
|
|
284
|
-
// 进行还原操作,否则在nvue的iOS,uni-app有bug,会导致诡异的表现
|
|
285
|
-
style.borderTopLeftRadius = "3px";
|
|
286
|
-
style.borderBottomLeftRadius = "3px";
|
|
287
|
-
}
|
|
288
|
-
} else {
|
|
289
|
-
if (this.selected.some((item) => this.dateSame(item, date))) {
|
|
290
|
-
style.borderTopLeftRadius = "3px";
|
|
291
|
-
style.borderBottomLeftRadius = "3px";
|
|
292
|
-
style.borderTopRightRadius = "3px";
|
|
293
|
-
style.borderBottomRightRadius = "3px";
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
return style;
|
|
297
|
-
};
|
|
298
|
-
},
|
|
299
|
-
// 某个日期是否被选中
|
|
300
|
-
textStyle() {
|
|
301
|
-
return (item) => {
|
|
302
|
-
const date = dayjs(item.date).format("YYYY-MM-DD"),
|
|
303
|
-
style = {};
|
|
304
|
-
// 选中的日期,提示文字设置白色
|
|
305
|
-
if (this.selected.some((item) => this.dateSame(item, date))) {
|
|
306
|
-
style.color = "#ffffff";
|
|
307
|
-
}
|
|
308
|
-
if (this.mode === "range") {
|
|
309
|
-
const len = this.selected.length - 1;
|
|
310
|
-
// 如果是范围选择模式,第一个和最后一个之间的日期,文字颜色设置为高亮的主题色
|
|
311
|
-
if (
|
|
312
|
-
dayjs(date).isAfter(dayjs(this.selected[0])) &&
|
|
313
|
-
dayjs(date).isBefore(dayjs(this.selected[len]))
|
|
314
|
-
) {
|
|
315
|
-
style.color = this.color;
|
|
316
|
-
}
|
|
317
346
|
}
|
|
318
|
-
return style;
|
|
319
|
-
};
|
|
320
347
|
},
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
)
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
348
|
+
mounted() {
|
|
349
|
+
this.init()
|
|
350
|
+
},
|
|
351
|
+
methods: {
|
|
352
|
+
dayjs,
|
|
353
|
+
init() {
|
|
354
|
+
// 初始化默认选中
|
|
355
|
+
this.$emit('monthSelected', this.selected)
|
|
356
|
+
this.$nextTick(() => {
|
|
357
|
+
// 这里需要另一个延时,因为获取宽度后,会进行月份数据渲染,只有渲染完成之后,才有真正的高度
|
|
358
|
+
// 因为nvue下,$nextTick并不是100%可靠的
|
|
359
|
+
sleep(10).then(() => {
|
|
360
|
+
this.getWrapperWidth()
|
|
361
|
+
this.getMonthRect()
|
|
362
|
+
})
|
|
363
|
+
})
|
|
364
|
+
},
|
|
365
|
+
isForbid(item) {
|
|
366
|
+
let date = dayjs(item.date).format('YYYY-MM-DD')
|
|
367
|
+
if (this.mode !== 'range' && this.forbidDays.includes(date)) {
|
|
368
|
+
return true
|
|
369
|
+
}
|
|
370
|
+
return false
|
|
371
|
+
},
|
|
372
|
+
// 判断两个日期是否相等
|
|
373
|
+
dateSame(date1, date2) {
|
|
374
|
+
return dayjs(date1).isSame(dayjs(date2))
|
|
375
|
+
},
|
|
376
|
+
// 获取月份数据区域的宽度,因为nvue不支持百分比,所以无法通过css设置每个日期item的宽度
|
|
377
|
+
getWrapperWidth() {
|
|
378
|
+
// #ifndef APP-NVUE
|
|
379
|
+
getRect('.hy-calendar--month__wrapper', false, this).then((size) => {
|
|
380
|
+
this.width = size.width
|
|
381
|
+
})
|
|
382
|
+
// #endif
|
|
383
|
+
},
|
|
384
|
+
getMonthRect() {
|
|
385
|
+
// 获取每个月份数据的尺寸,用于父组件在scroll-view滚动事件中,监听当前滚动到了第几个月份
|
|
386
|
+
const promiseAllArr = this.months.map((item, index) =>
|
|
387
|
+
this.getMonthRectByPromise(`hy-calendar--month__${index}`)
|
|
388
|
+
)
|
|
389
|
+
// 一次性返回
|
|
390
|
+
Promise.all(promiseAllArr).then((sizes) => {
|
|
391
|
+
let height = 1
|
|
392
|
+
const topArr = []
|
|
393
|
+
for (let i = 0; i < this.months.length; i++) {
|
|
394
|
+
// 添加到months数组中,供scroll-view滚动事件中,判断当前滚动到哪个月份
|
|
395
|
+
topArr[i] = height
|
|
396
|
+
height += sizes[i].height
|
|
397
|
+
}
|
|
398
|
+
// 由于微信下,无法通过this.months[i].top的形式(引用类型)去修改父组件的month的top值,所以使用事件形式对外发出
|
|
399
|
+
this.$emit('updateMonthTop', topArr)
|
|
400
|
+
})
|
|
401
|
+
},
|
|
402
|
+
// 获取每个月份区域的尺寸
|
|
403
|
+
getMonthRectByPromise(el) {
|
|
404
|
+
// #ifndef APP-NVUE
|
|
405
|
+
// $uGetRect为uView自带的节点查询简化方法,详见文档介绍:https://ijry.github.io/uview-plus/js/getRect.html
|
|
406
|
+
// 组件内部一般用this.$uGetRect,对外的为uni.$u.getRect,二者功能一致,名称不同
|
|
407
|
+
return new Promise((resolve) => {
|
|
408
|
+
getRect(`.${el}`, false, this).then((size) => {
|
|
409
|
+
resolve(size)
|
|
410
|
+
})
|
|
411
|
+
})
|
|
412
|
+
// #endif
|
|
413
|
+
},
|
|
414
|
+
// 点击某一个日期
|
|
415
|
+
clickHandler(index1, index2, item) {
|
|
416
|
+
if (this.readonly) {
|
|
417
|
+
return
|
|
418
|
+
}
|
|
419
|
+
this.item = item
|
|
420
|
+
const date = dayjs(item.date).format('YYYY-MM-DD')
|
|
421
|
+
if (item.disabled) return
|
|
422
|
+
if (this.isForbid(item)) {
|
|
423
|
+
uni.showToast({
|
|
424
|
+
title: this.forbidDaysToast
|
|
425
|
+
})
|
|
426
|
+
return
|
|
427
|
+
}
|
|
428
|
+
// 对上一次选择的日期数组进行深度克隆
|
|
429
|
+
let selected = deepClone(this.selected)
|
|
430
|
+
if (this.mode === 'single') {
|
|
431
|
+
// 单选情况下,让数组中的元素为当前点击的日期
|
|
432
|
+
selected = [date]
|
|
433
|
+
} else if (this.mode === 'multiple') {
|
|
434
|
+
if (selected.some((item) => this.dateSame(item, date))) {
|
|
435
|
+
// 如果点击的日期已在数组中,则进行移除操作,也就是达到反选的效果
|
|
436
|
+
const itemIndex = selected.findIndex((item) => item === date)
|
|
437
|
+
selected.splice(itemIndex, 1)
|
|
438
|
+
} else {
|
|
439
|
+
// 如果点击的日期不在数组中,且已有的长度小于总可选长度时,则添加到数组中去
|
|
440
|
+
if (selected.length < this.maxCount) selected.push(date)
|
|
441
|
+
}
|
|
346
442
|
} else {
|
|
347
|
-
|
|
443
|
+
// 选择区间形式
|
|
444
|
+
if (selected.length === 0 || selected.length >= 2) {
|
|
445
|
+
// 如果原来就为0或者大于2的长度,则当前点击的日期,就是开始日期
|
|
446
|
+
selected = [date]
|
|
447
|
+
} else if (selected.length === 1) {
|
|
448
|
+
// 如果已经选择了开始日期
|
|
449
|
+
const existsDate = selected[0]
|
|
450
|
+
// 如果当前选择的日期小于上一次选择的日期,则当前的日期定为开始日期
|
|
451
|
+
if (dayjs(date).isBefore(existsDate)) {
|
|
452
|
+
selected = [date]
|
|
453
|
+
} else if (dayjs(date).isAfter(existsDate)) {
|
|
454
|
+
// 当前日期减去最大可选的日期天数,如果大于起始时间,则进行提示
|
|
455
|
+
if (
|
|
456
|
+
dayjs(dayjs(date).subtract(this.maxRange, 'day')).isAfter(
|
|
457
|
+
dayjs(selected[0])
|
|
458
|
+
) &&
|
|
459
|
+
this.showRangePrompt
|
|
460
|
+
) {
|
|
461
|
+
if (this.rangePrompt) {
|
|
462
|
+
toast(this.rangePrompt)
|
|
463
|
+
} else {
|
|
464
|
+
toast(`选择天数不能超过 ${this.maxRange} 天`)
|
|
465
|
+
}
|
|
466
|
+
return
|
|
467
|
+
}
|
|
468
|
+
// 如果当前日期大于已有日期,将当前的添加到数组尾部
|
|
469
|
+
selected.push(date)
|
|
470
|
+
const startDate = selected[0]
|
|
471
|
+
const endDate = selected[1]
|
|
472
|
+
const arr = []
|
|
473
|
+
let i = 0
|
|
474
|
+
do {
|
|
475
|
+
// 将开始和结束日期之间的日期添加到数组中
|
|
476
|
+
arr.push(dayjs(startDate).add(i, 'day').format('YYYY-MM-DD'))
|
|
477
|
+
i++
|
|
478
|
+
// 累加的日期小于结束日期时,继续下一次的循环
|
|
479
|
+
} while (dayjs(startDate).add(i, 'day').isBefore(dayjs(endDate)))
|
|
480
|
+
// 为了一次性修改数组,避免computed中多次触发,这里才用arr变量一次性赋值的方式,同时将最后一个日期添加近来
|
|
481
|
+
arr.push(endDate)
|
|
482
|
+
selected = arr
|
|
483
|
+
} else {
|
|
484
|
+
// 选择区间时,只有一个日期的情况下,且不允许选择起止为同一天的话,不允许选择自己
|
|
485
|
+
if (selected[0] === date && !this.allowSameDay) return
|
|
486
|
+
selected.push(date)
|
|
487
|
+
}
|
|
488
|
+
}
|
|
348
489
|
}
|
|
349
|
-
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
this.init();
|
|
358
|
-
},
|
|
359
|
-
methods: {
|
|
360
|
-
dayjs,
|
|
361
|
-
init() {
|
|
362
|
-
// 初始化默认选中
|
|
363
|
-
this.$emit("monthSelected", this.selected);
|
|
364
|
-
this.$nextTick(() => {
|
|
365
|
-
// 这里需要另一个延时,因为获取宽度后,会进行月份数据渲染,只有渲染完成之后,才有真正的高度
|
|
366
|
-
// 因为nvue下,$nextTick并不是100%可靠的
|
|
367
|
-
sleep(10).then(() => {
|
|
368
|
-
this.getWrapperWidth();
|
|
369
|
-
this.getMonthRect();
|
|
370
|
-
});
|
|
371
|
-
});
|
|
372
|
-
},
|
|
373
|
-
isForbid(item) {
|
|
374
|
-
let date = dayjs(item.date).format("YYYY-MM-DD");
|
|
375
|
-
if (this.mode !== "range" && this.forbidDays.includes(date)) {
|
|
376
|
-
return true;
|
|
377
|
-
}
|
|
378
|
-
return false;
|
|
379
|
-
},
|
|
380
|
-
// 判断两个日期是否相等
|
|
381
|
-
dateSame(date1, date2) {
|
|
382
|
-
return dayjs(date1).isSame(dayjs(date2));
|
|
383
|
-
},
|
|
384
|
-
// 获取月份数据区域的宽度,因为nvue不支持百分比,所以无法通过css设置每个日期item的宽度
|
|
385
|
-
getWrapperWidth() {
|
|
386
|
-
// #ifndef APP-NVUE
|
|
387
|
-
getRect(".hy-calendar--month__wrapper", false, this).then((size) => {
|
|
388
|
-
this.width = size.width;
|
|
389
|
-
});
|
|
390
|
-
// #endif
|
|
391
|
-
},
|
|
392
|
-
getMonthRect() {
|
|
393
|
-
// 获取每个月份数据的尺寸,用于父组件在scroll-view滚动事件中,监听当前滚动到了第几个月份
|
|
394
|
-
const promiseAllArr = this.months.map((item, index) =>
|
|
395
|
-
this.getMonthRectByPromise(`hy-calendar--month__${index}`),
|
|
396
|
-
);
|
|
397
|
-
// 一次性返回
|
|
398
|
-
Promise.all(promiseAllArr).then((sizes) => {
|
|
399
|
-
let height = 1;
|
|
400
|
-
const topArr = [];
|
|
401
|
-
for (let i = 0; i < this.months.length; i++) {
|
|
402
|
-
// 添加到months数组中,供scroll-view滚动事件中,判断当前滚动到哪个月份
|
|
403
|
-
topArr[i] = height;
|
|
404
|
-
height += sizes[i].height;
|
|
405
|
-
}
|
|
406
|
-
// 由于微信下,无法通过this.months[i].top的形式(引用类型)去修改父组件的month的top值,所以使用事件形式对外发出
|
|
407
|
-
this.$emit("updateMonthTop", topArr);
|
|
408
|
-
});
|
|
409
|
-
},
|
|
410
|
-
// 获取每个月份区域的尺寸
|
|
411
|
-
getMonthRectByPromise(el) {
|
|
412
|
-
// #ifndef APP-NVUE
|
|
413
|
-
// $uGetRect为uView自带的节点查询简化方法,详见文档介绍:https://ijry.github.io/uview-plus/js/getRect.html
|
|
414
|
-
// 组件内部一般用this.$uGetRect,对外的为uni.$u.getRect,二者功能一致,名称不同
|
|
415
|
-
return new Promise((resolve) => {
|
|
416
|
-
getRect(`.${el}`, false, this).then((size) => {
|
|
417
|
-
resolve(size);
|
|
418
|
-
});
|
|
419
|
-
});
|
|
420
|
-
// #endif
|
|
421
|
-
},
|
|
422
|
-
// 点击某一个日期
|
|
423
|
-
clickHandler(index1, index2, item) {
|
|
424
|
-
if (this.readonly) {
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
this.item = item;
|
|
428
|
-
const date = dayjs(item.date).format("YYYY-MM-DD");
|
|
429
|
-
if (item.disabled) return;
|
|
430
|
-
if (this.isForbid(item)) {
|
|
431
|
-
uni.showToast({
|
|
432
|
-
title: this.forbidDaysToast,
|
|
433
|
-
});
|
|
434
|
-
return;
|
|
435
|
-
}
|
|
436
|
-
// 对上一次选择的日期数组进行深度克隆
|
|
437
|
-
let selected = deepClone(this.selected);
|
|
438
|
-
if (this.mode === "single") {
|
|
439
|
-
// 单选情况下,让数组中的元素为当前点击的日期
|
|
440
|
-
selected = [date];
|
|
441
|
-
} else if (this.mode === "multiple") {
|
|
442
|
-
if (selected.some((item) => this.dateSame(item, date))) {
|
|
443
|
-
// 如果点击的日期已在数组中,则进行移除操作,也就是达到反选的效果
|
|
444
|
-
const itemIndex = selected.findIndex((item) => item === date);
|
|
445
|
-
selected.splice(itemIndex, 1);
|
|
446
|
-
} else {
|
|
447
|
-
// 如果点击的日期不在数组中,且已有的长度小于总可选长度时,则添加到数组中去
|
|
448
|
-
if (selected.length < this.maxCount) selected.push(date);
|
|
449
|
-
}
|
|
450
|
-
} else {
|
|
451
|
-
// 选择区间形式
|
|
452
|
-
if (selected.length === 0 || selected.length >= 2) {
|
|
453
|
-
// 如果原来就为0或者大于2的长度,则当前点击的日期,就是开始日期
|
|
454
|
-
selected = [date];
|
|
455
|
-
} else if (selected.length === 1) {
|
|
456
|
-
// 如果已经选择了开始日期
|
|
457
|
-
const existsDate = selected[0];
|
|
458
|
-
// 如果当前选择的日期小于上一次选择的日期,则当前的日期定为开始日期
|
|
459
|
-
if (dayjs(date).isBefore(existsDate)) {
|
|
460
|
-
selected = [date];
|
|
461
|
-
} else if (dayjs(date).isAfter(existsDate)) {
|
|
462
|
-
// 当前日期减去最大可选的日期天数,如果大于起始时间,则进行提示
|
|
463
|
-
if (
|
|
464
|
-
dayjs(dayjs(date).subtract(this.maxRange, "day")).isAfter(
|
|
465
|
-
dayjs(selected[0]),
|
|
466
|
-
) &&
|
|
467
|
-
this.showRangePrompt
|
|
468
|
-
) {
|
|
469
|
-
if (this.rangePrompt) {
|
|
470
|
-
toast(this.rangePrompt);
|
|
471
|
-
} else {
|
|
472
|
-
toast(`选择天数不能超过 ${this.maxRange} 天`);
|
|
473
|
-
}
|
|
474
|
-
return;
|
|
490
|
+
this.setSelected(selected)
|
|
491
|
+
},
|
|
492
|
+
// 设置默认日期
|
|
493
|
+
setDefaultDate() {
|
|
494
|
+
if (!this.defaultDate) {
|
|
495
|
+
// 如果没有设置默认日期,则将当天日期设置为默认选中的日期
|
|
496
|
+
const selected = [dayjs().format('YYYY-MM-DD')]
|
|
497
|
+
return this.setSelected(selected, false)
|
|
475
498
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
const
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
let defaultDate = [];
|
|
508
|
-
const minDate = this.minDate || dayjs().format("YYYY-MM-DD");
|
|
509
|
-
const maxDate =
|
|
510
|
-
this.maxDate ||
|
|
511
|
-
dayjs(minDate)
|
|
512
|
-
.add(this.maxMonth - 1, "month")
|
|
513
|
-
.format("YYYY-MM-DD");
|
|
514
|
-
if (this.mode === "single") {
|
|
515
|
-
// 单选模式,可以是字符串或数组,Date对象等
|
|
516
|
-
if (!Array.isArray(this.defaultDate)) {
|
|
517
|
-
defaultDate = [dayjs(this.defaultDate).format("YYYY-MM-DD")];
|
|
518
|
-
} else {
|
|
519
|
-
defaultDate = [this.defaultDate[0]];
|
|
499
|
+
let defaultDate = []
|
|
500
|
+
const minDate = this.minDate || dayjs().format('YYYY-MM-DD')
|
|
501
|
+
const maxDate =
|
|
502
|
+
this.maxDate ||
|
|
503
|
+
dayjs(minDate)
|
|
504
|
+
.add(this.maxMonth - 1, 'month')
|
|
505
|
+
.format('YYYY-MM-DD')
|
|
506
|
+
if (this.mode === 'single') {
|
|
507
|
+
// 单选模式,可以是字符串或数组,Date对象等
|
|
508
|
+
if (!Array.isArray(this.defaultDate)) {
|
|
509
|
+
defaultDate = [dayjs(this.defaultDate).format('YYYY-MM-DD')]
|
|
510
|
+
} else {
|
|
511
|
+
defaultDate = [this.defaultDate[0]]
|
|
512
|
+
}
|
|
513
|
+
} else {
|
|
514
|
+
// 如果为非数组,则不执行
|
|
515
|
+
if (!Array.isArray(this.defaultDate)) return
|
|
516
|
+
defaultDate = this.defaultDate
|
|
517
|
+
}
|
|
518
|
+
// 过滤用户传递的默认数组,取出只在可允许最大值与最小值之间的元素
|
|
519
|
+
defaultDate = defaultDate.filter((item) => {
|
|
520
|
+
return (
|
|
521
|
+
dayjs(item).isAfter(dayjs(minDate).subtract(1, 'day')) &&
|
|
522
|
+
dayjs(item).isBefore(dayjs(maxDate).add(1, 'day'))
|
|
523
|
+
)
|
|
524
|
+
})
|
|
525
|
+
this.setSelected(defaultDate, false)
|
|
526
|
+
},
|
|
527
|
+
setSelected(selected, event = true) {
|
|
528
|
+
this.selected = selected
|
|
529
|
+
event && this.$emit('monthSelected', this.selected, 'tap')
|
|
520
530
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
if (!Array.isArray(this.defaultDate)) return;
|
|
524
|
-
defaultDate = this.defaultDate;
|
|
525
|
-
}
|
|
526
|
-
// 过滤用户传递的默认数组,取出只在可允许最大值与最小值之间的元素
|
|
527
|
-
defaultDate = defaultDate.filter((item) => {
|
|
528
|
-
return (
|
|
529
|
-
dayjs(item).isAfter(dayjs(minDate).subtract(1, "day")) &&
|
|
530
|
-
dayjs(item).isBefore(dayjs(maxDate).add(1, "day"))
|
|
531
|
-
);
|
|
532
|
-
});
|
|
533
|
-
this.setSelected(defaultDate, false);
|
|
534
|
-
},
|
|
535
|
-
setSelected(selected, event = true) {
|
|
536
|
-
this.selected = selected;
|
|
537
|
-
event && this.$emit("monthSelected", this.selected, "tap");
|
|
538
|
-
},
|
|
539
|
-
},
|
|
540
|
-
};
|
|
531
|
+
}
|
|
532
|
+
}
|
|
541
533
|
</script>
|
|
542
534
|
|
|
543
535
|
<style lang="scss" scoped>
|
|
544
|
-
@import
|
|
536
|
+
@import './index.scss';
|
|
545
537
|
</style>
|