hy-app 0.2.13 → 0.2.15
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 +81 -13
- package/components/hy-action-sheet/typing.d.ts +1 -3
- package/components/hy-address-picker/hy-address-picker.vue +109 -8
- package/components/hy-address-picker/index.scss +2 -2
- package/components/hy-address-picker/typing.d.ts +39 -30
- package/components/hy-avatar/hy-avatar.vue +78 -4
- package/components/hy-avatar/typing.d.ts +21 -16
- package/components/hy-back-top/hy-back-top.vue +86 -28
- package/components/hy-back-top/typing.d.ts +17 -12
- package/components/hy-badge/hy-badge.vue +114 -43
- package/components/hy-badge/typing.d.ts +20 -15
- package/components/hy-button/HyButton.docgen.js +6 -0
- package/components/hy-button/hy-button.vue +70 -77
- package/components/hy-button/props.ts +40 -41
- package/components/hy-calendar/hy-calendar.vue +290 -143
- package/components/hy-calendar/typing.d.ts +38 -31
- package/components/hy-card/hy-card.vue +139 -36
- package/components/hy-card/typing.d.ts +39 -28
- package/components/hy-cell/hy-cell.vue +131 -67
- package/components/hy-cell/typing.d.ts +6 -1
- package/components/hy-check-button/hy-check-button.vue +101 -32
- package/components/hy-check-button/typing.d.ts +26 -19
- package/components/hy-checkbox/hy-checkbox.vue +167 -78
- package/components/hy-checkbox/typing.d.ts +26 -19
- package/components/hy-code-input/hy-code-input.vue +101 -5
- package/components/hy-code-input/typing.d.ts +9 -0
- package/components/hy-config-provider/hy-config-provider.vue +44 -24
- package/components/hy-config-provider/typing.d.ts +0 -4
- package/components/hy-count-down/hy-count-down.vue +99 -62
- package/components/hy-count-down/typing.d.ts +18 -5
- package/components/hy-count-to/hy-count-to.vue +165 -113
- package/components/hy-count-to/typing.d.ts +15 -11
- package/components/hy-datetime-picker/hy-datetime-picker.vue +338 -232
- package/components/hy-datetime-picker/typing.d.ts +49 -39
- package/components/hy-divider/hy-divider.vue +128 -64
- package/components/hy-divider/typing.d.ts +16 -16
- package/components/hy-dropdown/hy-dropdown.vue +57 -19
- package/components/hy-dropdown/typing.d.ts +14 -14
- package/components/hy-dropdown-item/hy-dropdown-item.vue +34 -5
- package/components/hy-dropdown-item/typing.d.ts +13 -6
- package/components/hy-empty/hy-empty.vue +64 -6
- package/components/hy-empty/typing.d.ts +5 -0
- package/components/hy-float-button/hy-float-button.vue +117 -5
- package/components/hy-float-button/typing.d.ts +7 -0
- package/components/hy-folding-panel/hy-folding-panel.vue +87 -25
- package/components/hy-folding-panel/typing.d.ts +24 -15
- package/components/hy-grid/hy-grid.vue +95 -35
- package/components/hy-grid/typing.d.ts +24 -19
- package/components/hy-icon/hy-icon.vue +84 -6
- package/components/hy-icon/typing.d.ts +5 -0
- package/components/hy-image/hy-image.vue +105 -6
- package/components/hy-image/typing.d.ts +9 -0
- package/components/hy-input/hy-input.vue +277 -130
- package/components/hy-input/props.ts +13 -14
- package/components/hy-input/typing.d.ts +59 -38
- package/components/hy-line/hy-line.vue +65 -25
- package/components/hy-line-progress/hy-line-progress.vue +68 -35
- package/components/hy-list/hy-list.vue +127 -61
- package/components/hy-list/typing.d.ts +19 -12
- package/components/hy-loading/hy-loading.vue +79 -25
- package/components/hy-menu/hy-menu.vue +69 -45
- package/components/hy-menu/typing.d.ts +22 -15
- package/components/hy-modal/hy-modal.vue +91 -4
- package/components/hy-modal/typing.d.ts +11 -0
- package/components/hy-navbar/hy-navbar.vue +105 -25
- package/components/hy-navbar/typing.d.ts +25 -20
- package/components/hy-notice-bar/hy-notice-bar.vue +97 -19
- package/components/hy-notice-bar/typing.d.ts +22 -17
- package/components/hy-notify/hy-notify.vue +106 -54
- package/components/hy-number-step/hy-number-step.vue +211 -120
- package/components/hy-number-step/typing.d.ts +45 -28
- package/components/hy-overlay/hy-overlay.vue +60 -16
- package/components/hy-overlay/typing.d.ts +11 -6
- package/components/hy-pagination/hy-pagination.vue +94 -37
- package/components/hy-pagination/typing.d.ts +20 -11
- package/components/hy-picker/hy-picker.vue +225 -160
- package/components/hy-picker/typing.d.ts +51 -28
- package/components/hy-popover/hy-popover.vue +55 -7
- package/components/hy-popover/typing.d.ts +21 -1
- package/components/hy-popup/hy-popup.vue +164 -99
- package/components/hy-popup/typing.d.ts +11 -0
- package/components/hy-price/hy-price.vue +77 -30
- package/components/hy-price/typing.d.ts +10 -10
- package/components/hy-qrcode/hy-qrcode.vue +75 -5
- package/components/hy-qrcode/typing.d.ts +25 -16
- package/components/hy-radio/hy-radio.vue +169 -88
- package/components/hy-radio/typing.d.ts +29 -22
- package/components/hy-rate/hy-rate.vue +155 -104
- package/components/hy-rate/typing.d.ts +23 -16
- package/components/hy-read-more/hy-read-more.vue +83 -56
- package/components/hy-read-more/typing.d.ts +18 -11
- package/components/hy-scroll-list/hy-scroll-list.vue +69 -58
- package/components/hy-scroll-list/typing.d.ts +14 -7
- package/components/hy-search/hy-search.vue +168 -62
- package/components/hy-search/typing.d.ts +47 -26
- package/components/hy-signature/hy-signature.vue +354 -272
- package/components/hy-signature/typing.d.ts +65 -52
- package/components/hy-slider/hy-slider.vue +208 -160
- package/components/hy-slider/typing.d.ts +28 -17
- package/components/hy-steps/hy-steps.vue +125 -99
- package/components/hy-steps/typing.d.ts +21 -14
- package/components/hy-submit-bar/hy-submit-bar.vue +129 -48
- package/components/hy-submit-bar/typing.d.ts +30 -23
- package/components/hy-subsection/hy-subsection.vue +139 -96
- package/components/hy-subsection/typing.d.ts +23 -16
- package/components/hy-swipe-action/hy-swipe-action.vue +161 -135
- package/components/hy-swipe-action/typing.d.ts +26 -17
- package/components/hy-swiper/hy-swiper.vue +178 -73
- package/components/hy-swiper/typing.d.ts +37 -28
- package/components/hy-switch/hy-switch.vue +107 -60
- package/components/hy-switch/typing.d.ts +25 -18
- package/components/hy-tabs/hy-tabs.vue +170 -160
- package/components/hy-tabs/typing.d.ts +36 -22
- package/components/hy-tag/hy-tag.vue +133 -58
- package/components/hy-tag/typing.d.ts +26 -18
- package/components/hy-text/hy-text.vue +106 -6
- package/components/hy-text/typing.d.ts +31 -26
- package/components/hy-textarea/hy-textarea.vue +183 -89
- package/components/hy-textarea/typing.d.ts +41 -24
- package/components/hy-tooltip/hy-tooltip.vue +145 -101
- package/components/hy-tooltip/typing.d.ts +18 -13
- package/components/hy-transition/hy-transition.vue +48 -13
- package/components/hy-transition/typing.d.ts +17 -0
- package/components/hy-upload/hy-upload.vue +113 -148
- package/components/hy-upload/typing.d.ts +71 -71
- package/components/hy-warn/hy-warn.vue +79 -36
- package/components/hy-warn/typing.d.ts +18 -11
- package/components/hy-waterfall/hy-waterfall.vue +90 -77
- package/components/hy-watermark/hy-watermark.vue +82 -5
- package/components/hy-watermark/typing.d.ts +20 -20
- package/global.d.ts +39 -59
- package/package.json +5 -13
- package/utils/inspect.ts +3 -1
- package/web-types.json +1 -1
- package/component-helper.ts +0 -177
- package/components.json +0 -3287
- package/dist/attributes.json +0 -1
- package/dist/docs/components/hy-action-sheet/hy-action-sheet.md +0 -41
- package/dist/docs/components/hy-address-picker/hy-address-picker.md +0 -25
- package/dist/docs/components/hy-avatar/hy-avatar.md +0 -19
- package/dist/docs/components/hy-back-top/hy-back-top.md +0 -19
- package/dist/docs/components/hy-badge/hy-badge.md +0 -13
- package/dist/docs/components/hy-button/hy-button.md +0 -61
- package/dist/docs/components/hy-calendar/header.md +0 -17
- package/dist/docs/components/hy-calendar/hy-calendar.md +0 -27
- package/dist/docs/components/hy-calendar/month.md +0 -38
- package/dist/docs/components/hy-card/hy-card.md +0 -24
- package/dist/docs/components/hy-cell/hy-cell.md +0 -26
- package/dist/docs/components/hy-check-button/hy-check-button.md +0 -14
- package/dist/docs/components/hy-checkbox/hy-checkbox.md +0 -21
- package/dist/docs/components/hy-code-input/hy-code-input.md +0 -15
- package/dist/docs/components/hy-config-provider/hy-config-provider.md +0 -13
- package/dist/docs/components/hy-count-down/hy-count-down.md +0 -34
- package/dist/docs/components/hy-count-to/hy-count-to.md +0 -31
- package/dist/docs/components/hy-datetime-picker/hy-datetime-picker.md +0 -25
- package/dist/docs/components/hy-divider/hy-divider.md +0 -13
- package/dist/docs/components/hy-dropdown/hy-dropdown.md +0 -13
- package/dist/docs/components/hy-dropdown-item/hy-dropdown-item.md +0 -20
- package/dist/docs/components/hy-empty/hy-empty.md +0 -20
- package/dist/docs/components/hy-float-button/hy-float-button.md +0 -20
- package/dist/docs/components/hy-folding-panel/hy-folding-panel.md +0 -24
- package/dist/docs/components/hy-form/hy-form.md +0 -29
- package/dist/docs/components/hy-grid/hy-grid.md +0 -19
- package/dist/docs/components/hy-icon/hy-icon.md +0 -13
- package/dist/docs/components/hy-image/hy-image.md +0 -22
- package/dist/docs/components/hy-input/hy-input.md +0 -29
- package/dist/docs/components/hy-line/hy-line.md +0 -7
- package/dist/docs/components/hy-line-progress/hy-line-progress.md +0 -13
- package/dist/docs/components/hy-list/hy-list.md +0 -25
- package/dist/docs/components/hy-loading/hy-loading.md +0 -14
- package/dist/docs/components/hy-login/ThePhoneLogin.md +0 -20
- package/dist/docs/components/hy-login/TheUserLogin.md +0 -44
- package/dist/docs/components/hy-login/hy-login.md +0 -14
- package/dist/docs/components/hy-menu/hy-menu.md +0 -21
- package/dist/docs/components/hy-modal/hy-modal.md +0 -23
- package/dist/docs/components/hy-navbar/hy-navbar.md +0 -22
- package/dist/docs/components/hy-notice-bar/hy-column-notice.md +0 -20
- package/dist/docs/components/hy-notice-bar/hy-notice-bar.md +0 -14
- package/dist/docs/components/hy-notice-bar/hy-row-notice.md +0 -20
- package/dist/docs/components/hy-notify/hy-notify.md +0 -23
- package/dist/docs/components/hy-number-step/hy-number-step.md +0 -27
- package/dist/docs/components/hy-overlay/hy-overlay.md +0 -19
- package/dist/docs/components/hy-pagination/hy-pagination.md +0 -14
- package/dist/docs/components/hy-parse/hy-parse.md +0 -46
- package/dist/docs/components/hy-parse/node/node.md +0 -7
- package/dist/docs/components/hy-picker/hy-picker.md +0 -32
- package/dist/docs/components/hy-popover/hy-popover.md +0 -34
- package/dist/docs/components/hy-popup/hy-popup.md +0 -22
- package/dist/docs/components/hy-price/hy-price.md +0 -13
- package/dist/docs/components/hy-qrcode/hy-qrcode.md +0 -15
- package/dist/docs/components/hy-radio/hy-radio.md +0 -21
- package/dist/docs/components/hy-rate/hy-rate.md +0 -14
- package/dist/docs/components/hy-read-more/hy-read-more.md +0 -21
- package/dist/docs/components/hy-scroll-list/hy-scroll-list.md +0 -21
- package/dist/docs/components/hy-search/hy-search.md +0 -27
- package/dist/docs/components/hy-signature/hy-signature.md +0 -45
- package/dist/docs/components/hy-slider/hy-slider.md +0 -24
- package/dist/docs/components/hy-status-bar/hy-status-bar.md +0 -13
- package/dist/docs/components/hy-steps/hy-steps.md +0 -23
- package/dist/docs/components/hy-submit-bar/hy-submit-bar.md +0 -21
- package/dist/docs/components/hy-subsection/hy-subsection.md +0 -14
- package/dist/docs/components/hy-swipe-action/hy-swipe-action.md +0 -29
- package/dist/docs/components/hy-swiper/hy-swiper-indicator.md +0 -23
- package/dist/docs/components/hy-swiper/hy-swiper.md +0 -22
- package/dist/docs/components/hy-switch/hy-switch.md +0 -20
- package/dist/docs/components/hy-tabBar/hy-tabBar.md +0 -13
- package/dist/docs/components/hy-tabs/hy-tabs.md +0 -27
- package/dist/docs/components/hy-tag/hy-tag.md +0 -21
- package/dist/docs/components/hy-text/hy-text.md +0 -13
- package/dist/docs/components/hy-textarea/hy-textarea.md +0 -19
- package/dist/docs/components/hy-toast/hy-toast.md +0 -17
- package/dist/docs/components/hy-tooltip/hy-tooltip.md +0 -13
- package/dist/docs/components/hy-transition/hy-transition.md +0 -25
- package/dist/docs/components/hy-upload/hy-upload.md +0 -25
- package/dist/docs/components/hy-warn/hy-warn.md +0 -14
- package/dist/docs/components/hy-waterfall/hy-waterfall.md +0 -30
- package/dist/docs/components/hy-watermark/hy-watermark.md +0 -7
- package/dist/docs/components/message/TheMessage.md +0 -17
- package/dist/docs/components/yk-dialog/yk-dialog.md +0 -7
- package/dist/tags.json +0 -1
- package/dist/web-types.json +0 -1
- package/docgen.config.js +0 -14
- package/web-types.config.js +0 -7
|
@@ -65,29 +65,184 @@
|
|
|
65
65
|
</template>
|
|
66
66
|
|
|
67
67
|
<script lang="ts">
|
|
68
|
+
/**
|
|
69
|
+
* 用于单个选择日期,范围选择日期等,日历被包裹在底部弹起的容器中。
|
|
70
|
+
* @displayName hy-calendar
|
|
71
|
+
*/
|
|
72
|
+
defineOptions({})
|
|
68
73
|
export default {
|
|
69
|
-
name:
|
|
74
|
+
name: 'hy-calendar',
|
|
70
75
|
options: {
|
|
71
76
|
virtualHost: true,
|
|
72
|
-
styleIsolation:
|
|
77
|
+
styleIsolation: 'shared',
|
|
73
78
|
},
|
|
74
|
-
}
|
|
79
|
+
}
|
|
75
80
|
</script>
|
|
76
81
|
<script setup lang="ts">
|
|
77
|
-
import type
|
|
78
|
-
import
|
|
79
|
-
import {
|
|
80
|
-
import
|
|
81
|
-
import
|
|
82
|
-
import dayjs from "dayjs/esm";
|
|
82
|
+
import type { ICalendarEmit } from './typing'
|
|
83
|
+
import { computed, nextTick, onMounted, type PropType, ref, toRefs, watch } from 'vue'
|
|
84
|
+
import { addUnit, error, isNumericString, padZero, range } from '../../utils'
|
|
85
|
+
import Calendar from '../../utils/calendar.js'
|
|
86
|
+
import dayjs from 'dayjs/esm'
|
|
83
87
|
|
|
84
88
|
// 组件
|
|
85
|
-
import HyMount from
|
|
86
|
-
import HyHeader from
|
|
87
|
-
import HyPopup from
|
|
88
|
-
import HyButton from
|
|
89
|
+
import HyMount from './month.vue'
|
|
90
|
+
import HyHeader from './header.vue'
|
|
91
|
+
import HyPopup from '../hy-popup/hy-popup.vue'
|
|
92
|
+
import HyButton from '../hy-button/hy-button.vue'
|
|
89
93
|
|
|
90
|
-
const props = withDefaults(defineProps<IProps>(), defaultProps);
|
|
94
|
+
// const props = withDefaults(defineProps<IProps>(), defaultProps);
|
|
95
|
+
const props = defineProps({
|
|
96
|
+
/** 是否显示日历弹窗 */
|
|
97
|
+
show: {
|
|
98
|
+
type: Boolean,
|
|
99
|
+
default: false,
|
|
100
|
+
required: true,
|
|
101
|
+
},
|
|
102
|
+
/** 标题内容 */
|
|
103
|
+
title: {
|
|
104
|
+
type: String,
|
|
105
|
+
default: '日期选选择',
|
|
106
|
+
},
|
|
107
|
+
/** 是否显示标题 */
|
|
108
|
+
showTitle: {
|
|
109
|
+
type: Boolean,
|
|
110
|
+
default: true,
|
|
111
|
+
},
|
|
112
|
+
/** 是否显示副标题 */
|
|
113
|
+
showSubtitle: {
|
|
114
|
+
type: Boolean,
|
|
115
|
+
default: true,
|
|
116
|
+
},
|
|
117
|
+
/**
|
|
118
|
+
* 日期类型选择
|
|
119
|
+
* @values single,range,multiple
|
|
120
|
+
* */
|
|
121
|
+
mode: {
|
|
122
|
+
type: String,
|
|
123
|
+
default: 'single',
|
|
124
|
+
},
|
|
125
|
+
/** mode=range时,第一个日期底部的提示文字 */
|
|
126
|
+
startText: {
|
|
127
|
+
type: String,
|
|
128
|
+
default: '开始',
|
|
129
|
+
},
|
|
130
|
+
/** mode=range时,最后一个日期底部的提示文字 */
|
|
131
|
+
endText: {
|
|
132
|
+
type: String,
|
|
133
|
+
default: '结束',
|
|
134
|
+
},
|
|
135
|
+
/** 自定义列表 */
|
|
136
|
+
customList: {
|
|
137
|
+
type: Array as unknown as any[],
|
|
138
|
+
default: [],
|
|
139
|
+
},
|
|
140
|
+
/** 主题色,对底部按钮和选中日期有效 */
|
|
141
|
+
color: String,
|
|
142
|
+
/** 最小的可选日期 */
|
|
143
|
+
minDate: {
|
|
144
|
+
type: Number,
|
|
145
|
+
default: 0,
|
|
146
|
+
},
|
|
147
|
+
/** 最大可选日期 */
|
|
148
|
+
maxDate: {
|
|
149
|
+
type: Number,
|
|
150
|
+
default: 0,
|
|
151
|
+
},
|
|
152
|
+
/** 默认选中的日期,mode为multiple或range是必须为数组格式 */
|
|
153
|
+
defaultDate: [Date, String, Array<string>],
|
|
154
|
+
/** mode=multiple时,最多可选多少个日期 */
|
|
155
|
+
maxCount: {
|
|
156
|
+
type: Number,
|
|
157
|
+
default: Number.MAX_SAFE_INTEGER,
|
|
158
|
+
},
|
|
159
|
+
/** 日期行高 */
|
|
160
|
+
rowHeight: {
|
|
161
|
+
type: Number,
|
|
162
|
+
default: 56,
|
|
163
|
+
},
|
|
164
|
+
/** 日期格式化函数 */
|
|
165
|
+
formatter: {
|
|
166
|
+
type: Function as PropType<(date: Date) => string>,
|
|
167
|
+
},
|
|
168
|
+
/** 是否显示农历 */
|
|
169
|
+
showLunar: {
|
|
170
|
+
type: Boolean,
|
|
171
|
+
default: false,
|
|
172
|
+
},
|
|
173
|
+
/** 是否显示月份背景色 */
|
|
174
|
+
showMark: {
|
|
175
|
+
type: Boolean,
|
|
176
|
+
default: true,
|
|
177
|
+
},
|
|
178
|
+
/** 确定按钮的文字 */
|
|
179
|
+
confirmText: {
|
|
180
|
+
type: String,
|
|
181
|
+
default: '确定',
|
|
182
|
+
},
|
|
183
|
+
/** 确认按钮处于禁用状态时的文字 */
|
|
184
|
+
confirmDisabledText: {
|
|
185
|
+
type: String,
|
|
186
|
+
default: '确定',
|
|
187
|
+
},
|
|
188
|
+
/** 是否允许点击遮罩关闭日历 */
|
|
189
|
+
closeOnClickOverlay: {
|
|
190
|
+
type: Boolean,
|
|
191
|
+
default: false,
|
|
192
|
+
},
|
|
193
|
+
/** 是否为只读状态,只读状态下禁止选择日期 */
|
|
194
|
+
readonly: {
|
|
195
|
+
type: Boolean,
|
|
196
|
+
default: false,
|
|
197
|
+
},
|
|
198
|
+
/** 是否展示确认按钮 */
|
|
199
|
+
showConfirm: {
|
|
200
|
+
type: Boolean,
|
|
201
|
+
default: true,
|
|
202
|
+
},
|
|
203
|
+
/** 日期区间最多可选天数,默认无限制,mode = range时有效 */
|
|
204
|
+
maxRange: {
|
|
205
|
+
type: Number,
|
|
206
|
+
default: Number.MAX_SAFE_INTEGER,
|
|
207
|
+
},
|
|
208
|
+
/** 范围选择超过最多可选天数时的提示文案,mode = range时有效 */
|
|
209
|
+
rangePrompt: String,
|
|
210
|
+
/** 范围选择超过最多可选天数时,是否展示提示文案,mode = range时有效 */
|
|
211
|
+
showRangePrompt: {
|
|
212
|
+
type: Boolean,
|
|
213
|
+
default: true,
|
|
214
|
+
},
|
|
215
|
+
/** 是否允许日期范围的起止时间为同一天,mode = range时有效 */
|
|
216
|
+
allowSameDay: {
|
|
217
|
+
type: Boolean,
|
|
218
|
+
default: false,
|
|
219
|
+
},
|
|
220
|
+
/** 圆角值,默认无圆角 */
|
|
221
|
+
round: {
|
|
222
|
+
type: Number,
|
|
223
|
+
default: 0,
|
|
224
|
+
},
|
|
225
|
+
/** 最多展示的月份数量 */
|
|
226
|
+
monthNum: {
|
|
227
|
+
type: Number,
|
|
228
|
+
default: 3,
|
|
229
|
+
},
|
|
230
|
+
/** 星期文案 */
|
|
231
|
+
weekText: {
|
|
232
|
+
type: Array as unknown as string[],
|
|
233
|
+
default: ['一', '二', '三', '四', '五', '六', '日'],
|
|
234
|
+
},
|
|
235
|
+
/** 单选与多选禁止选中的日期列表,mode!=range时有效。 */
|
|
236
|
+
forbidDays: {
|
|
237
|
+
type: Array as unknown as Date[],
|
|
238
|
+
default: [],
|
|
239
|
+
},
|
|
240
|
+
/** 单选与多选禁止选中的日期选择时提示 */
|
|
241
|
+
forbidDaysToast: {
|
|
242
|
+
type: String,
|
|
243
|
+
default: '该日期已禁用',
|
|
244
|
+
},
|
|
245
|
+
})
|
|
91
246
|
const {
|
|
92
247
|
show,
|
|
93
248
|
maxDate,
|
|
@@ -99,37 +254,37 @@ const {
|
|
|
99
254
|
monthNum,
|
|
100
255
|
formatter,
|
|
101
256
|
showLunar,
|
|
102
|
-
} = toRefs(props)
|
|
103
|
-
const emit = defineEmits([
|
|
257
|
+
} = toRefs(props)
|
|
258
|
+
const emit = defineEmits<ICalendarEmit>(['confirm', 'close'])
|
|
104
259
|
|
|
105
260
|
// 需要显示的月份的数组
|
|
106
|
-
const months = ref<any[]>([])
|
|
261
|
+
const months = ref<any[]>([])
|
|
107
262
|
// 在月份滚动区域中,当前视图中月份的index索引
|
|
108
|
-
const monthIndex = ref(0)
|
|
263
|
+
const monthIndex = ref(0)
|
|
109
264
|
// 月份滚动区域的高度
|
|
110
|
-
const listHeight = ref(0)
|
|
265
|
+
const listHeight = ref(0)
|
|
111
266
|
// month组件中选择的日期数组
|
|
112
|
-
const selected = ref<string[]>([])
|
|
113
|
-
const scrollIntoView = ref(
|
|
114
|
-
const scrollIntoViewScroll = ref(
|
|
115
|
-
const scrollTop = ref(0)
|
|
267
|
+
const selected = ref<string[]>([])
|
|
268
|
+
const scrollIntoView = ref('')
|
|
269
|
+
const scrollIntoViewScroll = ref('')
|
|
270
|
+
const scrollTop = ref(0)
|
|
116
271
|
// 过滤处理方法
|
|
117
|
-
let innerFormatter = (value: string) => value
|
|
272
|
+
let innerFormatter = (value: string) => value
|
|
118
273
|
|
|
119
274
|
// 由于maxDate和minDate可以为字符串(2021-10-10),或者数值(时间戳),但是dayjs如果接受字符串形式的时间戳会有问题,这里进行处理
|
|
120
275
|
const innerMaxDate = computed(() => {
|
|
121
|
-
return isNumericString(maxDate.value) ? Number(maxDate.value) : maxDate.value
|
|
122
|
-
})
|
|
276
|
+
return isNumericString(maxDate.value) ? Number(maxDate.value) : maxDate.value
|
|
277
|
+
})
|
|
123
278
|
const innerMinDate = computed(() => {
|
|
124
|
-
return isNumericString(minDate.value) ? Number(minDate.value) : minDate.value
|
|
125
|
-
})
|
|
279
|
+
return isNumericString(minDate.value) ? Number(minDate.value) : minDate.value
|
|
280
|
+
})
|
|
126
281
|
|
|
127
282
|
/**
|
|
128
283
|
* @description 多个条件的变化,会引起选中日期的变化,这里统一管理监听
|
|
129
284
|
* */
|
|
130
285
|
const selectedChange = computed(() => {
|
|
131
|
-
return [innerMinDate.value, innerMaxDate.value, defaultDate.value]
|
|
132
|
-
})
|
|
286
|
+
return [innerMinDate.value, innerMaxDate.value, defaultDate.value]
|
|
287
|
+
})
|
|
133
288
|
|
|
134
289
|
/**
|
|
135
290
|
* @description 获得两个日期之间的月份数
|
|
@@ -137,175 +292,167 @@ const selectedChange = computed(() => {
|
|
|
137
292
|
* @param maxDate 最大日期
|
|
138
293
|
* */
|
|
139
294
|
const getMonths = (minDate: number | string, maxDate: number | string) => {
|
|
140
|
-
const minYear = dayjs(minDate).year()
|
|
141
|
-
const minMonth = dayjs(minDate).month() + 1
|
|
142
|
-
const maxYear = dayjs(maxDate).year()
|
|
143
|
-
const maxMonth = dayjs(maxDate).month() + 1
|
|
144
|
-
return (maxYear - minYear) * 12 + (maxMonth - minMonth) + 1
|
|
145
|
-
}
|
|
295
|
+
const minYear = dayjs(minDate).year()
|
|
296
|
+
const minMonth = dayjs(minDate).month() + 1
|
|
297
|
+
const maxYear = dayjs(maxDate).year()
|
|
298
|
+
const maxMonth = dayjs(maxDate).month() + 1
|
|
299
|
+
return (maxYear - minYear) * 12 + (maxMonth - minMonth) + 1
|
|
300
|
+
}
|
|
146
301
|
|
|
147
302
|
/**
|
|
148
303
|
* @description 设置月份数据
|
|
149
304
|
* */
|
|
150
305
|
const setMonth = () => {
|
|
151
306
|
// 最小日期的毫秒数
|
|
152
|
-
const minDate = innerMinDate.value || dayjs().valueOf()
|
|
307
|
+
const minDate = innerMinDate.value || dayjs().valueOf()
|
|
153
308
|
// 如果没有指定最大日期,则往后推3个月
|
|
154
309
|
const maxDate =
|
|
155
310
|
innerMaxDate.value ||
|
|
156
311
|
dayjs(minDate)
|
|
157
|
-
.add(monthNum.value - 1,
|
|
158
|
-
.valueOf()
|
|
312
|
+
.add(monthNum.value - 1, 'month')
|
|
313
|
+
.valueOf()
|
|
159
314
|
// 最大最小月份之间的共有多少个月份,
|
|
160
|
-
const monthList = range(1, monthNum.value, getMonths(minDate, maxDate))
|
|
315
|
+
const monthList = range(1, monthNum.value, getMonths(minDate, maxDate))
|
|
161
316
|
// 先清空数组
|
|
162
|
-
months.value = []
|
|
317
|
+
months.value = []
|
|
163
318
|
for (let i = 0; i < monthList; i++) {
|
|
164
319
|
months.value.push({
|
|
165
|
-
date: new Array(dayjs(minDate).add(i,
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
.
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
month: dayjs(minDate).add(i, "month").month() + 1,
|
|
198
|
-
};
|
|
199
|
-
const format = formatter.value || innerFormatter;
|
|
200
|
-
return format(config as any);
|
|
201
|
-
}),
|
|
320
|
+
date: new Array(dayjs(minDate).add(i, 'month').daysInMonth()).fill(1).map((item, index) => {
|
|
321
|
+
// 日期,取值1-31
|
|
322
|
+
let day = index + 1
|
|
323
|
+
// 星期,0-6,0为周日
|
|
324
|
+
const week = dayjs(minDate).add(i, 'month').date(day).day()
|
|
325
|
+
const date = dayjs(minDate).add(i, 'month').date(day).format('YYYY-MM-DD')
|
|
326
|
+
let bottomInfo = ''
|
|
327
|
+
if (showLunar.value) {
|
|
328
|
+
// 将日期转为农历格式
|
|
329
|
+
const lunar = Calendar.solar2lunar(
|
|
330
|
+
dayjs(date).year(),
|
|
331
|
+
dayjs(date).month() + 1,
|
|
332
|
+
dayjs(date).date(),
|
|
333
|
+
)
|
|
334
|
+
bottomInfo = lunar.IDayCn
|
|
335
|
+
}
|
|
336
|
+
let config = {
|
|
337
|
+
day,
|
|
338
|
+
week,
|
|
339
|
+
// 小于最小允许的日期,或者大于最大的日期,则设置为disabled状态
|
|
340
|
+
disabled:
|
|
341
|
+
dayjs(date).isBefore(dayjs(minDate).format('YYYY-MM-DD')) ||
|
|
342
|
+
dayjs(date).isAfter(dayjs(maxDate).format('YYYY-MM-DD')),
|
|
343
|
+
// 返回一个日期对象,供外部的formatter获取当前日期的年月日等信息,进行加工处理
|
|
344
|
+
date: new Date(date),
|
|
345
|
+
bottomInfo,
|
|
346
|
+
dot: false,
|
|
347
|
+
month: dayjs(minDate).add(i, 'month').month() + 1,
|
|
348
|
+
}
|
|
349
|
+
const format = formatter.value || innerFormatter
|
|
350
|
+
return format(config as any)
|
|
351
|
+
}),
|
|
202
352
|
// 当前所属的月份
|
|
203
|
-
month: dayjs(minDate).add(i,
|
|
353
|
+
month: dayjs(minDate).add(i, 'month').month() + 1,
|
|
204
354
|
// 当前年份
|
|
205
|
-
year: dayjs(minDate).add(i,
|
|
206
|
-
})
|
|
355
|
+
year: dayjs(minDate).add(i, 'month').year(),
|
|
356
|
+
})
|
|
207
357
|
}
|
|
208
|
-
}
|
|
358
|
+
}
|
|
209
359
|
|
|
210
360
|
watch(
|
|
211
361
|
() => selectedChange.value,
|
|
212
362
|
() => setMonth(),
|
|
213
363
|
{ immediate: true },
|
|
214
|
-
)
|
|
364
|
+
)
|
|
215
365
|
|
|
216
366
|
watch(
|
|
217
367
|
() => show.value,
|
|
218
368
|
(newVal: boolean) => {
|
|
219
369
|
if (newVal) {
|
|
220
|
-
setMonth()
|
|
370
|
+
setMonth()
|
|
221
371
|
} else {
|
|
222
372
|
// 关闭时重置scrollIntoView,否则会出现二次打开日历,当前月份数据显示不正确。
|
|
223
373
|
// scrollIntoView需要有一个值变动过程,才会产生作用。
|
|
224
|
-
scrollIntoView.value =
|
|
374
|
+
scrollIntoView.value = ''
|
|
225
375
|
}
|
|
226
376
|
},
|
|
227
377
|
{ immediate: true },
|
|
228
|
-
)
|
|
378
|
+
)
|
|
229
379
|
|
|
230
380
|
const subtitle = computed(() => {
|
|
231
381
|
// 初始化时,this.months为空数组,所以需要特别判断处理
|
|
232
382
|
if (months.value.length) {
|
|
233
|
-
return `${months.value[monthIndex.value].year}年${
|
|
234
|
-
months.value[monthIndex.value].month
|
|
235
|
-
}月`;
|
|
383
|
+
return `${months.value[monthIndex.value].year}年${months.value[monthIndex.value].month}月`
|
|
236
384
|
} else {
|
|
237
|
-
return
|
|
385
|
+
return ''
|
|
238
386
|
}
|
|
239
|
-
})
|
|
387
|
+
})
|
|
240
388
|
|
|
241
389
|
const buttonDisabled = computed(() => {
|
|
242
390
|
// 如果为range类型,且选择的日期个数不足1个时,让底部的按钮出于disabled状态
|
|
243
|
-
if (mode.value ===
|
|
244
|
-
return selected.value.length <= 1
|
|
391
|
+
if (mode.value === 'range') {
|
|
392
|
+
return selected.value.length <= 1
|
|
245
393
|
} else {
|
|
246
|
-
return false
|
|
394
|
+
return false
|
|
247
395
|
}
|
|
248
|
-
})
|
|
396
|
+
})
|
|
249
397
|
|
|
250
398
|
onMounted(() => {
|
|
251
399
|
// start.value = Date.now();
|
|
252
|
-
init()
|
|
253
|
-
})
|
|
400
|
+
init()
|
|
401
|
+
})
|
|
254
402
|
|
|
255
403
|
// 在微信小程序中,不支持将函数当做props参数,故只能通过ref形式调用
|
|
256
404
|
const setFormatter = (e: (value: string) => string) => {
|
|
257
|
-
innerFormatter = e
|
|
258
|
-
}
|
|
405
|
+
innerFormatter = e
|
|
406
|
+
}
|
|
259
407
|
|
|
260
408
|
/**
|
|
261
409
|
* @description month组件内部选择日期后,通过事件通知给父组件
|
|
262
410
|
*/
|
|
263
|
-
const monthSelected = (e: string[], scene =
|
|
264
|
-
selected.value = e
|
|
411
|
+
const monthSelected = (e: string[], scene = 'init') => {
|
|
412
|
+
selected.value = e
|
|
265
413
|
if (!showConfirm.value) {
|
|
266
414
|
// 在不需要确认按钮的情况下,如果为单选,或者范围多选且已选长度大于2,则直接进行返还
|
|
267
415
|
if (
|
|
268
|
-
mode.value ===
|
|
269
|
-
mode.value ===
|
|
270
|
-
(mode.value ===
|
|
416
|
+
mode.value === 'multiple' ||
|
|
417
|
+
mode.value === 'single' ||
|
|
418
|
+
(mode.value === 'range' && selected.value.length >= 2)
|
|
271
419
|
) {
|
|
272
|
-
if (scene ===
|
|
273
|
-
return
|
|
420
|
+
if (scene === 'init') {
|
|
421
|
+
return
|
|
274
422
|
}
|
|
275
|
-
if (scene ===
|
|
276
|
-
emit(
|
|
423
|
+
if (scene === 'tap') {
|
|
424
|
+
emit('confirm', selected.value)
|
|
277
425
|
}
|
|
278
426
|
}
|
|
279
427
|
}
|
|
280
|
-
}
|
|
428
|
+
}
|
|
281
429
|
|
|
282
430
|
const init = () => {
|
|
283
431
|
// 校验maxDate,不能小于minDate。
|
|
284
432
|
if (
|
|
285
433
|
innerMaxDate.value &&
|
|
286
434
|
innerMinDate.value &&
|
|
287
|
-
new Date(innerMaxDate.value).getTime() <
|
|
288
|
-
new Date(innerMinDate.value).getTime()
|
|
435
|
+
new Date(innerMaxDate.value).getTime() < new Date(innerMinDate.value).getTime()
|
|
289
436
|
) {
|
|
290
|
-
return error(
|
|
437
|
+
return error('maxDate不能小于minDate时间')
|
|
291
438
|
}
|
|
292
439
|
// 滚动区域的高度
|
|
293
|
-
listHeight.value = rowHeight.value * 5 + 30
|
|
294
|
-
setMonth()
|
|
295
|
-
}
|
|
440
|
+
listHeight.value = rowHeight.value * 5 + 30
|
|
441
|
+
setMonth()
|
|
442
|
+
}
|
|
296
443
|
|
|
297
444
|
const close = () => {
|
|
298
|
-
emit(
|
|
299
|
-
}
|
|
445
|
+
emit('close')
|
|
446
|
+
}
|
|
300
447
|
|
|
301
448
|
/**
|
|
302
449
|
* @description 点击确定按钮
|
|
303
450
|
* */
|
|
304
451
|
const confirm = () => {
|
|
305
452
|
if (!buttonDisabled.value) {
|
|
306
|
-
emit(
|
|
453
|
+
emit('confirm', selected.value)
|
|
307
454
|
}
|
|
308
|
-
}
|
|
455
|
+
}
|
|
309
456
|
|
|
310
457
|
/**
|
|
311
458
|
* @description 滚动到默认设置的月份
|
|
@@ -314,62 +461,62 @@ const confirm = () => {
|
|
|
314
461
|
const scrollIntoDefaultMonth = (selected: string) => {
|
|
315
462
|
// 查询默认日期在可选列表的下标
|
|
316
463
|
const _index = months.value.findIndex(({ year, month }) => {
|
|
317
|
-
month = padZero(month)
|
|
318
|
-
return `${year}-${month}` === selected
|
|
319
|
-
})
|
|
464
|
+
month = padZero(month)
|
|
465
|
+
return `${year}-${month}` === selected
|
|
466
|
+
})
|
|
320
467
|
if (_index !== -1) {
|
|
321
468
|
// #ifndef MP-WEIXIN
|
|
322
469
|
nextTick(() => {
|
|
323
|
-
scrollIntoView.value = `month-${_index}
|
|
324
|
-
scrollIntoViewScroll.value = scrollIntoView.value
|
|
325
|
-
})
|
|
470
|
+
scrollIntoView.value = `month-${_index}`
|
|
471
|
+
scrollIntoViewScroll.value = scrollIntoView.value
|
|
472
|
+
})
|
|
326
473
|
// #endif
|
|
327
474
|
// #ifdef MP-WEIXIN
|
|
328
|
-
scrollTop.value = months.value[_index].top || 0
|
|
475
|
+
scrollTop.value = months.value[_index].top || 0
|
|
329
476
|
// #endif
|
|
330
477
|
}
|
|
331
|
-
}
|
|
478
|
+
}
|
|
332
479
|
// scroll-view滚动监听
|
|
333
480
|
const onScroll = (event: any) => {
|
|
334
481
|
// 不允许小于0的滚动值,如果scroll-view到顶了,继续下拉,会出现负数值
|
|
335
|
-
const scrollTop = Math.max(0, event.detail.scrollTop)
|
|
482
|
+
const scrollTop = Math.max(0, event.detail.scrollTop)
|
|
336
483
|
// 将当前滚动条数值,除以滚动区域的高度,可以得出当前滚动到了哪一个月份的索引
|
|
337
484
|
for (let i = 0; i < months.value.length; i++) {
|
|
338
485
|
if (scrollTop >= (months.value[i].top || listHeight.value)) {
|
|
339
|
-
monthIndex.value = i
|
|
340
|
-
scrollIntoViewScroll.value = `month-${i}
|
|
486
|
+
monthIndex.value = i
|
|
487
|
+
scrollIntoViewScroll.value = `month-${i}`
|
|
341
488
|
}
|
|
342
489
|
}
|
|
343
|
-
}
|
|
490
|
+
}
|
|
344
491
|
// 更新月份的top值
|
|
345
492
|
const updateMonthTop = (topArr = []) => {
|
|
346
493
|
// 设置对应月份的top值,用于onScroll方法更新月份
|
|
347
494
|
topArr.map((item, index) => {
|
|
348
|
-
months.value[index].top = item
|
|
349
|
-
})
|
|
495
|
+
months.value[index].top = item
|
|
496
|
+
})
|
|
350
497
|
|
|
351
498
|
// 获取默认日期的下标
|
|
352
499
|
if (!defaultDate.value) {
|
|
353
500
|
// 如果没有设置默认日期,则将当天日期设置为默认选中的日期
|
|
354
|
-
const selected = dayjs().format(
|
|
355
|
-
scrollIntoDefaultMonth(selected)
|
|
356
|
-
return
|
|
501
|
+
const selected = dayjs().format('YYYY-MM')
|
|
502
|
+
scrollIntoDefaultMonth(selected)
|
|
503
|
+
return
|
|
357
504
|
}
|
|
358
|
-
let selected = dayjs().format(
|
|
505
|
+
let selected = dayjs().format('YYYY-MM')
|
|
359
506
|
// 单选模式,可以是字符串或数组,Date对象等
|
|
360
507
|
if (!Array.isArray(defaultDate.value)) {
|
|
361
|
-
selected = dayjs(defaultDate.value).format(
|
|
508
|
+
selected = dayjs(defaultDate.value).format('YYYY-MM')
|
|
362
509
|
} else {
|
|
363
|
-
selected = dayjs(defaultDate.value[0]).format(
|
|
510
|
+
selected = dayjs(defaultDate.value[0]).format('YYYY-MM')
|
|
364
511
|
}
|
|
365
|
-
scrollIntoDefaultMonth(selected)
|
|
366
|
-
}
|
|
512
|
+
scrollIntoDefaultMonth(selected)
|
|
513
|
+
}
|
|
367
514
|
|
|
368
515
|
defineExpose({
|
|
369
516
|
setFormatter,
|
|
370
|
-
})
|
|
517
|
+
})
|
|
371
518
|
</script>
|
|
372
519
|
|
|
373
520
|
<style scoped lang="scss">
|
|
374
|
-
@import
|
|
521
|
+
@import './index.scss';
|
|
375
522
|
</style>
|