hy-app 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/README.md +1 -1
  2. package/api/http.ts +8 -8
  3. package/components/dialog/index.ts +2 -2
  4. package/components/hy-address-picker/hy-address-picker.vue +3 -29
  5. package/components/hy-address-picker/index.scss +27 -0
  6. package/components/hy-avatar/hy-avatar.vue +1 -45
  7. package/components/hy-avatar/index.scss +45 -0
  8. package/components/hy-avatar/typing.d.ts +1 -1
  9. package/components/hy-back-top/hy-back-top.vue +7 -22
  10. package/components/hy-back-top/index.scss +16 -0
  11. package/components/hy-back-top/props.ts +4 -4
  12. package/components/hy-back-top/typing.d.ts +2 -3
  13. package/components/hy-badge/hy-badge.vue +1 -72
  14. package/components/hy-badge/index.scss +72 -0
  15. package/components/hy-button/hy-button.vue +17 -128
  16. package/components/hy-button/index.scss +116 -0
  17. package/components/hy-button/typing.d.ts +1 -1
  18. package/components/hy-calendar/header.vue +76 -0
  19. package/components/hy-calendar/hy-calendar.vue +366 -0
  20. package/components/hy-calendar/index.scss +171 -0
  21. package/components/hy-calendar/month.vue +524 -0
  22. package/components/hy-calendar/props.ts +37 -0
  23. package/components/hy-calendar/typing.d.ts +126 -0
  24. package/components/hy-card/hy-card.vue +21 -84
  25. package/components/hy-card/index.scss +57 -0
  26. package/components/hy-card/props.ts +2 -2
  27. package/components/hy-card/typing.d.ts +1 -1
  28. package/components/hy-cell/hy-cell.vue +1 -137
  29. package/components/hy-cell/index.scss +137 -0
  30. package/components/hy-check-button/hy-check-button.vue +1 -0
  31. package/components/hy-check-button/index.scss +5 -0
  32. package/components/hy-checkbox/hy-checkbox.vue +2 -95
  33. package/components/hy-checkbox/index.scss +94 -0
  34. package/components/hy-checkbox/typing.d.ts +1 -2
  35. package/components/hy-count-down/hy-count-down.vue +150 -0
  36. package/components/hy-count-down/index.scss +6 -0
  37. package/components/hy-count-down/index.ts +52 -0
  38. package/components/hy-count-down/props.ts +10 -0
  39. package/components/hy-count-down/typing.d.ts +20 -0
  40. package/components/hy-count-to/hy-count-to.vue +213 -0
  41. package/components/hy-count-to/index.scss +6 -0
  42. package/components/hy-count-to/props.ts +17 -0
  43. package/components/hy-count-to/typing.d.ts +48 -0
  44. package/components/hy-datetime-picker/hy-datetime-picker.vue +2 -28
  45. package/components/hy-datetime-picker/index.scss +28 -0
  46. package/components/hy-divider/hy-divider.vue +24 -49
  47. package/components/hy-divider/index.scss +26 -0
  48. package/components/hy-divider/props.ts +2 -2
  49. package/components/hy-divider/typing.d.ts +1 -1
  50. package/components/hy-dropdown/hy-dropdown.vue +43 -0
  51. package/components/hy-dropdown/index.scss +17 -0
  52. package/components/hy-dropdown/props.ts +17 -0
  53. package/components/hy-dropdown/typing.d.ts +48 -0
  54. package/components/hy-dropdown-item/hy-dropdown-item.vue +194 -0
  55. package/components/hy-dropdown-item/index.scss +96 -0
  56. package/components/hy-dropdown-item/props.ts +10 -0
  57. package/components/hy-dropdown-item/typing.d.ts +31 -0
  58. package/components/hy-empty/hy-empty.vue +8 -26
  59. package/components/hy-empty/index.scss +19 -0
  60. package/components/hy-empty/props.ts +2 -2
  61. package/components/hy-empty/typing.d.ts +1 -1
  62. package/components/hy-float-button/hy-float-button.vue +217 -0
  63. package/components/hy-float-button/index.scss +67 -0
  64. package/components/hy-float-button/props.ts +25 -0
  65. package/components/hy-float-button/typing.d.ts +93 -0
  66. package/components/hy-folding-panel/hy-folding-panel.vue +9 -12
  67. package/components/hy-folding-panel/index.scss +6 -0
  68. package/components/hy-folding-panel/props.ts +2 -2
  69. package/components/hy-folding-panel/typing.d.ts +2 -2
  70. package/components/hy-form/hy-form.vue +17 -34
  71. package/components/hy-form/index.scss +30 -0
  72. package/components/hy-form/props.ts +2 -0
  73. package/components/hy-form/typing.d.ts +9 -1
  74. package/components/hy-grid/hy-grid.vue +1 -43
  75. package/components/hy-grid/index.scss +40 -0
  76. package/components/hy-icon/hy-icon.vue +1 -93
  77. package/components/hy-icon/index.scss +84 -0
  78. package/components/hy-image/hy-image.vue +216 -0
  79. package/components/hy-image/index.scss +26 -0
  80. package/components/hy-image/props.ts +24 -0
  81. package/components/hy-image/typing.d.ts +76 -0
  82. package/components/hy-input/hy-input.vue +2 -72
  83. package/components/hy-input/index.scss +65 -0
  84. package/components/hy-line/hy-line.vue +4 -8
  85. package/components/hy-line/index.scss +5 -0
  86. package/components/hy-line/props.ts +3 -3
  87. package/components/hy-line/typing.d.ts +2 -2
  88. package/components/hy-line-progress/hy-line-progress.vue +15 -44
  89. package/components/hy-line-progress/index.scss +38 -0
  90. package/components/hy-line-progress/props.ts +2 -2
  91. package/components/hy-line-progress/typing.d.ts +1 -1
  92. package/components/hy-list/hy-list.vue +11 -41
  93. package/components/hy-list/index.scss +32 -0
  94. package/components/hy-list/props.ts +2 -2
  95. package/components/hy-loading/hy-loading.vue +95 -0
  96. package/components/hy-loading/index.scss +103 -0
  97. package/components/hy-loading/props.ts +17 -0
  98. package/components/hy-loading/typing.d.ts +53 -0
  99. package/components/hy-login/TheUserLogin.vue +20 -88
  100. package/components/hy-login/hy-login.vue +9 -9
  101. package/components/hy-login/props.ts +4 -4
  102. package/components/hy-modal/hy-modal.vue +11 -89
  103. package/components/hy-modal/index.scss +77 -0
  104. package/components/hy-modal/props.ts +2 -2
  105. package/components/hy-modal/typing.d.ts +1 -1
  106. package/components/hy-navbar/hy-navbar.vue +20 -92
  107. package/components/hy-navbar/index.scss +67 -0
  108. package/components/hy-navbar/props.ts +2 -2
  109. package/components/hy-navbar/typing.d.ts +1 -1
  110. package/components/hy-notice-bar/hy-column-notice.vue +11 -39
  111. package/components/hy-notice-bar/hy-notice-bar.vue +10 -12
  112. package/components/hy-notice-bar/hy-row-notice.vue +16 -58
  113. package/components/hy-notice-bar/index.scss +93 -0
  114. package/components/hy-notice-bar/props.ts +4 -2
  115. package/components/hy-notice-bar/typing.d.ts +13 -3
  116. package/components/hy-number-step/hy-number-step.vue +1 -70
  117. package/components/hy-number-step/index.scss +71 -0
  118. package/components/hy-overlay/hy-overlay.vue +2 -14
  119. package/components/hy-overlay/index.scss +9 -0
  120. package/components/hy-parse/hy-parse.vue +499 -0
  121. package/components/hy-parse/index.scss +9 -0
  122. package/components/hy-parse/node/node.vue +584 -0
  123. package/components/hy-parse/parser.js +1337 -0
  124. package/components/hy-parse/props.ts +19 -0
  125. package/components/hy-parse/typing.d.ts +68 -0
  126. package/components/hy-picker/hy-picker.vue +1 -68
  127. package/components/hy-picker/index.scss +68 -0
  128. package/components/hy-popup/hy-popup.vue +1 -74
  129. package/components/hy-popup/index.scss +60 -0
  130. package/components/hy-price/hy-price.vue +7 -19
  131. package/components/hy-price/index.scss +11 -0
  132. package/components/hy-price/props.ts +4 -3
  133. package/components/hy-price/typing.d.ts +8 -4
  134. package/components/hy-qrcode/hy-qrcode.vue +15 -37
  135. package/components/hy-qrcode/index.scss +23 -0
  136. package/components/hy-qrcode/props.ts +2 -2
  137. package/components/hy-qrcode/typing.d.ts +2 -2
  138. package/components/hy-radio/hy-radio.vue +2 -101
  139. package/components/hy-radio/index.scss +93 -0
  140. package/components/hy-radio/typing.d.ts +1 -2
  141. package/components/hy-rate/hy-rate.vue +1 -33
  142. package/components/hy-rate/index.scss +33 -0
  143. package/components/hy-read-more/hy-read-more.vue +7 -30
  144. package/components/hy-read-more/index.scss +25 -0
  145. package/components/hy-read-more/props.ts +3 -3
  146. package/components/hy-read-more/typing.d.ts +1 -1
  147. package/components/hy-safe-bottom/hy-safe-bottom.vue +5 -9
  148. package/components/hy-safe-bottom/index.scss +5 -0
  149. package/components/hy-scroll-list/hy-scroll-list.vue +13 -43
  150. package/components/hy-scroll-list/index.scss +34 -0
  151. package/components/hy-scroll-list/props.ts +2 -2
  152. package/components/hy-scroll-list/typing.d.ts +1 -1
  153. package/components/hy-search/hy-search.vue +1 -83
  154. package/components/hy-search/index.scss +83 -0
  155. package/components/hy-slider/hy-slider.vue +18 -95
  156. package/components/hy-slider/index.scss +77 -0
  157. package/components/hy-status-bar/hy-status-bar.vue +41 -0
  158. package/components/hy-status-bar/index.scss +6 -0
  159. package/components/hy-status-bar/props.ts +8 -0
  160. package/components/hy-status-bar/typing.d.ts +12 -0
  161. package/components/hy-steps/hy-steps.vue +36 -163
  162. package/components/hy-steps/index.scss +131 -0
  163. package/components/hy-steps/props.ts +2 -2
  164. package/components/hy-steps/typing.d.ts +2 -2
  165. package/components/hy-submitBar/Index.vue +17 -0
  166. package/components/hy-submitBar/hy-submitBar.vue +216 -0
  167. package/components/hy-submitBar/index.scss +9 -0
  168. package/components/hy-submitBar/props.ts +22 -0
  169. package/components/hy-submitBar/typing.d.ts +88 -0
  170. package/components/hy-subsection/hy-subsection.vue +40 -132
  171. package/components/hy-subsection/index.scss +82 -0
  172. package/components/hy-subsection/props.ts +1 -0
  173. package/components/hy-subsection/typing.d.ts +13 -4
  174. package/components/hy-swipe-action/hy-swipe-action.vue +294 -0
  175. package/components/hy-swipe-action/index.scss +9 -0
  176. package/components/hy-swipe-action/index.wxs +235 -0
  177. package/components/hy-swipe-action/props.ts +16 -0
  178. package/components/hy-swipe-action/typing.d.ts +55 -0
  179. package/components/hy-swipe-action/wxs.js +15 -0
  180. package/components/hy-swiper/hy-swiper-indicator.vue +5 -35
  181. package/components/hy-swiper/hy-swiper.vue +1 -54
  182. package/components/hy-swiper/index.scss +82 -0
  183. package/components/hy-switch/hy-switch.vue +62 -72
  184. package/components/hy-switch/index.scss +46 -0
  185. package/components/hy-switch/props.ts +4 -1
  186. package/components/hy-switch/typing.d.ts +14 -1
  187. package/components/hy-tabs/hy-tabs.vue +22 -81
  188. package/components/hy-tabs/index.scss +63 -0
  189. package/components/hy-tabs/props.ts +5 -5
  190. package/components/hy-tabs/typing.d.ts +1 -1
  191. package/components/hy-tag/hy-tag.vue +25 -220
  192. package/components/hy-tag/index.scss +205 -0
  193. package/components/hy-text/hy-text.vue +238 -0
  194. package/components/hy-text/index.scss +70 -0
  195. package/components/hy-text/index.ts +0 -0
  196. package/components/hy-text/props.ts +30 -0
  197. package/components/hy-text/typing.d.ts +98 -0
  198. package/components/hy-textarea/hy-textarea.vue +1 -46
  199. package/components/hy-textarea/index.scss +40 -0
  200. package/components/hy-toast/hy-toast.vue +175 -0
  201. package/components/hy-toast/index.scss +77 -0
  202. package/components/hy-toast/props.ts +3 -0
  203. package/components/hy-toast/typing.d.ts +38 -0
  204. package/components/hy-tooltip/hy-tooltip.vue +42 -95
  205. package/components/hy-tooltip/index.scss +64 -0
  206. package/components/hy-tooltip/props.ts +2 -2
  207. package/components/hy-tooltip/typing.d.ts +1 -1
  208. package/components/hy-transition/hy-transition.vue +4 -2
  209. package/components/hy-transition/typing.d.ts +1 -13
  210. package/components/hy-upload/hy-upload.vue +37 -182
  211. package/components/hy-upload/index.scss +147 -0
  212. package/components/hy-upload/props.ts +2 -2
  213. package/components/hy-upload/typing.d.ts +11 -11
  214. package/components/hy-warn/hy-warn.vue +17 -144
  215. package/components/hy-warn/index.scss +109 -0
  216. package/components/hy-warn/props.ts +3 -3
  217. package/components/hy-warn/typing.d.ts +4 -3
  218. package/components/hy-waterfall/hy-waterfall.vue +168 -38
  219. package/components/hy-waterfall/index.scss +16 -0
  220. package/components/hy-waterfall/props.ts +4 -5
  221. package/components/hy-waterfall/typing.d.ts +5 -9
  222. package/components/index.ts +25 -1
  223. package/components/message/index.ts +54 -54
  224. package/composables/index.ts +1 -0
  225. package/composables/useShare.ts +27 -0
  226. package/config/color.ts +3 -2
  227. package/config/icon.ts +21 -1
  228. package/global/index.ts +6 -6
  229. package/global/register-properties.ts +2 -2
  230. package/index.scss +2 -1
  231. package/index.ts +9 -8
  232. package/libs/css/common.scss +14 -2
  233. package/package.json +3 -2
  234. package/{libs/css → public/font}/iconfont.css +4 -4
  235. package/theme.scss +6 -4
  236. package/typing/index.ts +1 -1
  237. package/typing/modules/common.d.ts +36 -1
  238. package/utils/calendar.js +1021 -0
  239. package/utils/colorGradient.ts +112 -0
  240. package/utils/index.ts +2 -0
  241. package/utils/inside.ts +80 -34
  242. package/utils/inspect.ts +115 -0
  243. package/utils/utils.ts +20 -19
  244. package/libs/css/download.zip +0 -0
  245. /package/{libs/css → public/font}/iconfont.ttf +0 -0
  246. /package/{libs/css → public/font}/iconfont.woff +0 -0
  247. /package/{libs/css → public/font}/iconfont.woff2 +0 -0
@@ -0,0 +1,366 @@
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="u-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="u-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>
63
+ </view>
64
+ </HyPopup>
65
+ </template>
66
+
67
+ <script setup lang="ts">
68
+ import type IProps from "./typing";
69
+ import defaultProps from "./props";
70
+ import { computed, nextTick, onMounted, ref, toRefs, watch } from "vue";
71
+ import { addUnit, error, isNumericString, padZero, range } from "../../utils";
72
+ import Calendar from "../../utils/calendar.js";
73
+ import dayjs from "dayjs/esm";
74
+
75
+ // 组件
76
+ import HyMount from "./month.vue";
77
+ import HyHeader from "./header.vue";
78
+ import HyPopup from "../hy-popup/hy-popup.vue";
79
+ import HyButton from "../hy-button/hy-button.vue";
80
+
81
+ const props = withDefaults(defineProps<IProps>(), defaultProps);
82
+ const {
83
+ show,
84
+ maxDate,
85
+ minDate,
86
+ defaultDate,
87
+ mode,
88
+ showConfirm,
89
+ rowHeight,
90
+ monthNum,
91
+ formatter,
92
+ showLunar,
93
+ } = toRefs(props);
94
+ const emit = defineEmits(["confirm", "change", "close"]);
95
+
96
+ // 需要显示的月份的数组
97
+ const months = ref<any[]>([]);
98
+ // 在月份滚动区域中,当前视图中月份的index索引
99
+ const monthIndex = ref(0);
100
+ // 月份滚动区域的高度
101
+ const listHeight = ref(0);
102
+ // month组件中选择的日期数组
103
+ const selected = ref<string[]>([]);
104
+ const scrollIntoView = ref("");
105
+ const scrollIntoViewScroll = ref("");
106
+ const scrollTop = ref(0);
107
+ // 过滤处理方法
108
+ let innerFormatter = (value: string) => value;
109
+
110
+ // 由于maxDate和minDate可以为字符串(2021-10-10),或者数值(时间戳),但是dayjs如果接受字符串形式的时间戳会有问题,这里进行处理
111
+ const innerMaxDate = computed(() => {
112
+ return isNumericString(maxDate.value) ? Number(maxDate.value) : maxDate.value;
113
+ });
114
+ const innerMinDate = computed(() => {
115
+ return isNumericString(minDate.value) ? Number(minDate.value) : minDate.value;
116
+ });
117
+
118
+ /**
119
+ * @description 多个条件的变化,会引起选中日期的变化,这里统一管理监听
120
+ * */
121
+ const selectedChange = computed(() => {
122
+ return [innerMinDate.value, innerMaxDate.value, defaultDate.value];
123
+ });
124
+
125
+ /**
126
+ * @description 获得两个日期之间的月份数
127
+ * @param minDate 最小日期
128
+ * @param maxDate 最大日期
129
+ * */
130
+ const getMonths = (minDate: number | string, maxDate: number | string) => {
131
+ const minYear = dayjs(minDate).year();
132
+ const minMonth = dayjs(minDate).month() + 1;
133
+ const maxYear = dayjs(maxDate).year();
134
+ const maxMonth = dayjs(maxDate).month() + 1;
135
+ return (maxYear - minYear) * 12 + (maxMonth - minMonth) + 1;
136
+ };
137
+
138
+ /**
139
+ * @description 设置月份数据
140
+ * */
141
+ const setMonth = () => {
142
+ // 最小日期的毫秒数
143
+ const minDate = innerMinDate.value || dayjs().valueOf();
144
+ // 如果没有指定最大日期,则往后推3个月
145
+ const maxDate =
146
+ innerMaxDate.value ||
147
+ dayjs(minDate)
148
+ .add(monthNum.value - 1, "month")
149
+ .valueOf();
150
+ // 最大最小月份之间的共有多少个月份,
151
+ const monthList = range(1, monthNum.value, getMonths(minDate, maxDate));
152
+ // 先清空数组
153
+ months.value = [];
154
+ for (let i = 0; i < monthList; i++) {
155
+ months.value.push({
156
+ date: new Array(dayjs(minDate).add(i, "month").daysInMonth())
157
+ .fill(1)
158
+ .map((item, index) => {
159
+ // 日期,取值1-31
160
+ let day = index + 1;
161
+ // 星期,0-6,0为周日
162
+ const week = dayjs(minDate).add(i, "month").date(day).day();
163
+ const date = dayjs(minDate)
164
+ .add(i, "month")
165
+ .date(day)
166
+ .format("YYYY-MM-DD");
167
+ let bottomInfo = "";
168
+ if (showLunar.value) {
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 = formatter.value || 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
+ };
200
+
201
+ watch(
202
+ () => selectedChange.value,
203
+ () => setMonth(),
204
+ { immediate: true },
205
+ );
206
+
207
+ watch(
208
+ () => show.value,
209
+ (newVal: boolean) => {
210
+ if (newVal) {
211
+ setMonth();
212
+ } else {
213
+ // 关闭时重置scrollIntoView,否则会出现二次打开日历,当前月份数据显示不正确。
214
+ // scrollIntoView需要有一个值变动过程,才会产生作用。
215
+ scrollIntoView.value = "";
216
+ }
217
+ },
218
+ { immediate: true },
219
+ );
220
+
221
+ const subtitle = computed(() => {
222
+ // 初始化时,this.months为空数组,所以需要特别判断处理
223
+ if (months.value.length) {
224
+ return `${months.value[monthIndex.value].year}年${
225
+ months.value[monthIndex.value].month
226
+ }月`;
227
+ } else {
228
+ return "";
229
+ }
230
+ });
231
+
232
+ const buttonDisabled = computed(() => {
233
+ // 如果为range类型,且选择的日期个数不足1个时,让底部的按钮出于disabled状态
234
+ if (mode.value === "range") {
235
+ return selected.value.length <= 1;
236
+ } else {
237
+ return false;
238
+ }
239
+ });
240
+
241
+ onMounted(() => {
242
+ // start.value = Date.now();
243
+ init();
244
+ });
245
+
246
+ // 在微信小程序中,不支持将函数当做props参数,故只能通过ref形式调用
247
+ const setFormatter = (e: (value: string) => string) => {
248
+ innerFormatter = e;
249
+ };
250
+
251
+ /**
252
+ * @description month组件内部选择日期后,通过事件通知给父组件
253
+ */
254
+ const monthSelected = (e: string[], scene = "init") => {
255
+ selected.value = e;
256
+ if (!showConfirm.value) {
257
+ // 在不需要确认按钮的情况下,如果为单选,或者范围多选且已选长度大于2,则直接进行返还
258
+ if (
259
+ mode.value === "multiple" ||
260
+ mode.value === "single" ||
261
+ (mode.value === "range" && selected.value.length >= 2)
262
+ ) {
263
+ if (scene === "init") {
264
+ return;
265
+ }
266
+ if (scene === "tap") {
267
+ emit("confirm", selected.value);
268
+ }
269
+ }
270
+ }
271
+ };
272
+
273
+ const init = () => {
274
+ // 校验maxDate,不能小于minDate。
275
+ if (
276
+ innerMaxDate.value &&
277
+ innerMinDate.value &&
278
+ new Date(innerMaxDate.value).getTime() <
279
+ new Date(innerMinDate.value).getTime()
280
+ ) {
281
+ return error("maxDate不能小于minDate时间");
282
+ }
283
+ // 滚动区域的高度
284
+ listHeight.value = rowHeight.value * 5 + 30;
285
+ setMonth();
286
+ };
287
+
288
+ const close = () => {
289
+ emit("close");
290
+ };
291
+
292
+ /**
293
+ * @description 点击确定按钮
294
+ * */
295
+ const confirm = () => {
296
+ if (!buttonDisabled.value) {
297
+ emit("confirm", selected.value);
298
+ }
299
+ };
300
+
301
+ /**
302
+ * @description 滚动到默认设置的月份
303
+ * @param selected 日期
304
+ * */
305
+ const scrollIntoDefaultMonth = (selected: string) => {
306
+ // 查询默认日期在可选列表的下标
307
+ const _index = months.value.findIndex(({ year, month }) => {
308
+ month = padZero(month);
309
+ return `${year}-${month}` === selected;
310
+ });
311
+ if (_index !== -1) {
312
+ // #ifndef MP-WEIXIN
313
+ nextTick(() => {
314
+ scrollIntoView.value = `month-${_index}`;
315
+ scrollIntoViewScroll.value = scrollIntoView.value;
316
+ });
317
+ // #endif
318
+ // #ifdef MP-WEIXIN
319
+ scrollTop.value = months.value[_index].top || 0;
320
+ // #endif
321
+ }
322
+ };
323
+ // scroll-view滚动监听
324
+ const onScroll = (event: any) => {
325
+ // 不允许小于0的滚动值,如果scroll-view到顶了,继续下拉,会出现负数值
326
+ const scrollTop = Math.max(0, event.detail.scrollTop);
327
+ // 将当前滚动条数值,除以滚动区域的高度,可以得出当前滚动到了哪一个月份的索引
328
+ for (let i = 0; i < months.value.length; i++) {
329
+ if (scrollTop >= (months.value[i].top || listHeight.value)) {
330
+ monthIndex.value = i;
331
+ scrollIntoViewScroll.value = `month-${i}`;
332
+ }
333
+ }
334
+ };
335
+ // 更新月份的top值
336
+ const updateMonthTop = (topArr = []) => {
337
+ // 设置对应月份的top值,用于onScroll方法更新月份
338
+ topArr.map((item, index) => {
339
+ months.value[index].top = item;
340
+ });
341
+
342
+ // 获取默认日期的下标
343
+ if (!defaultDate.value) {
344
+ // 如果没有设置默认日期,则将当天日期设置为默认选中的日期
345
+ const selected = dayjs().format("YYYY-MM");
346
+ scrollIntoDefaultMonth(selected);
347
+ return;
348
+ }
349
+ let selected = dayjs().format("YYYY-MM");
350
+ // 单选模式,可以是字符串或数组,Date对象等
351
+ if (!Array.isArray(defaultDate.value)) {
352
+ selected = dayjs(defaultDate.value).format("YYYY-MM");
353
+ } else {
354
+ selected = dayjs(defaultDate.value[0]).format("YYYY-MM");
355
+ }
356
+ scrollIntoDefaultMonth(selected);
357
+ };
358
+
359
+ defineExpose({
360
+ setFormatter,
361
+ });
362
+ </script>
363
+
364
+ <style scoped lang="scss">
365
+ @import "./index.scss";
366
+ </style>
@@ -0,0 +1,171 @@
1
+ @use "../../libs/css/mixin.scss" as *;
2
+ @use "../../theme.scss" as *;
3
+
4
+ /* 主样式 */
5
+ .u-calendar {
6
+ &__confirm {
7
+ padding: 7px 18px;
8
+ }
9
+ }
10
+
11
+ /* 头部样式 */
12
+ .u-calendar-header {
13
+ display: flex;
14
+ flex-direction: column;
15
+ padding-bottom: 4px;
16
+
17
+ &__title {
18
+ font-size: 16px;
19
+ color: $hy-color-title;
20
+ text-align: center;
21
+ height: 42px;
22
+ line-height: 42px;
23
+ font-weight: bold;
24
+ }
25
+
26
+ &__subtitle {
27
+ font-size: 14px;
28
+ color: $u-main-color;
29
+ height: 40px;
30
+ text-align: center;
31
+ line-height: 40px;
32
+ font-weight: bold;
33
+ }
34
+
35
+ &__weekdays {
36
+ @include flex;
37
+ justify-content: space-between;
38
+
39
+ &__weekday {
40
+ font-size: 13px;
41
+ color: $u-main-color;
42
+ line-height: 30px;
43
+ flex: 1;
44
+ text-align: center;
45
+ }
46
+ }
47
+ }
48
+
49
+ /* 内容样式 */
50
+ .u-calendar-month-wrapper {
51
+ margin-top: 4px;
52
+ }
53
+
54
+ .u-calendar-month {
55
+ &__title {
56
+ display: flex;
57
+ flex-direction: column;
58
+ font-size: 14px;
59
+ line-height: 42px;
60
+ height: 42px;
61
+ color: $u-main-color;
62
+ text-align: center;
63
+ font-weight: bold;
64
+ }
65
+
66
+ &__days {
67
+ position: relative;
68
+ @include flex;
69
+ flex-wrap: wrap;
70
+
71
+ &__month-mark-wrapper {
72
+ position: absolute;
73
+ top: 0;
74
+ bottom: 0;
75
+ left: 0;
76
+ right: 0;
77
+ @include flex;
78
+ justify-content: center;
79
+ align-items: center;
80
+
81
+ &__text {
82
+ font-size: 155px;
83
+ color: rgba(231, 232, 234, 0.83);
84
+ }
85
+ }
86
+
87
+ &__day {
88
+ @include flex;
89
+ padding: 2px;
90
+ /* #ifndef APP-NVUE */
91
+ // vue下使用css进行宽度计算,因为某些安卓机会无法进行js获取父元素宽度进行计算得出,会有偏移
92
+ width: calc(100% / 7);
93
+ box-sizing: border-box;
94
+ /* #endif */
95
+
96
+ &__select {
97
+ flex: 1;
98
+ @include flex;
99
+ align-items: center;
100
+ justify-content: center;
101
+ position: relative;
102
+
103
+ &__dot {
104
+ width: 7px;
105
+ height: 7px;
106
+ border-radius: 100px;
107
+ background-color: $u-error;
108
+ position: absolute;
109
+ top: 12px;
110
+ right: 7px;
111
+ }
112
+
113
+ &__buttom-info {
114
+ color: $u-content-color;
115
+ text-align: center;
116
+ position: absolute;
117
+ bottom: 5px;
118
+ font-size: 10px;
119
+ text-align: center;
120
+ left: 0;
121
+ right: 0;
122
+
123
+ &--selected {
124
+ color: #ffffff;
125
+ }
126
+
127
+ &--disabled {
128
+ color: #cacbcd;
129
+ }
130
+ }
131
+
132
+ &__info {
133
+ text-align: center;
134
+ font-size: 16px;
135
+
136
+ &--selected {
137
+ color: #ffffff;
138
+ }
139
+
140
+ &--disabled {
141
+ color: #cacbcd;
142
+ }
143
+ }
144
+
145
+ &--selected {
146
+ background-color: $u-primary;
147
+ @include flex;
148
+ justify-content: center;
149
+ align-items: center;
150
+ flex: 1;
151
+ border-radius: 3px;
152
+ }
153
+
154
+ &--range-selected {
155
+ opacity: 0.3;
156
+ border-radius: 0;
157
+ }
158
+
159
+ &--range-start-selected {
160
+ border-top-right-radius: 0;
161
+ border-bottom-right-radius: 0;
162
+ }
163
+
164
+ &--range-end-selected {
165
+ border-top-left-radius: 0;
166
+ border-bottom-left-radius: 0;
167
+ }
168
+ }
169
+ }
170
+ }
171
+ }