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