uview-pro 0.0.1

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 (149) hide show
  1. package/changelog.md +6 -0
  2. package/components/u-action-sheet/u-action-sheet.vue +205 -0
  3. package/components/u-alert-tips/u-alert-tips.vue +241 -0
  4. package/components/u-avatar/u-avatar.vue +220 -0
  5. package/components/u-avatar-cropper/u-avatar-cropper.vue +329 -0
  6. package/components/u-avatar-cropper/weCropper.d.ts +54 -0
  7. package/components/u-avatar-cropper/weCropper.js +1267 -0
  8. package/components/u-avatar-cropper/weCropper.ts +1254 -0
  9. package/components/u-back-top/u-back-top.vue +156 -0
  10. package/components/u-badge/u-badge.vue +189 -0
  11. package/components/u-button/u-button.vue +562 -0
  12. package/components/u-calendar/u-calendar.vue +725 -0
  13. package/components/u-car-keyboard/u-car-keyboard.vue +236 -0
  14. package/components/u-card/u-card.vue +240 -0
  15. package/components/u-cell-group/u-cell-group.vue +56 -0
  16. package/components/u-cell-item/u-cell-item.vue +245 -0
  17. package/components/u-checkbox/u-checkbox.vue +310 -0
  18. package/components/u-checkbox-group/u-checkbox-group.vue +134 -0
  19. package/components/u-circle-progress/u-circle-progress.vue +210 -0
  20. package/components/u-col/u-col.vue +135 -0
  21. package/components/u-collapse/u-collapse.vue +82 -0
  22. package/components/u-collapse-item/u-collapse-item.vue +190 -0
  23. package/components/u-column-notice/u-column-notice.vue +264 -0
  24. package/components/u-count-down/u-count-down.vue +333 -0
  25. package/components/u-count-to/u-count-to.vue +297 -0
  26. package/components/u-divider/u-divider.vue +141 -0
  27. package/components/u-dropdown/u-dropdown.vue +311 -0
  28. package/components/u-dropdown-item/u-dropdown-item.vue +135 -0
  29. package/components/u-empty/u-empty.vue +111 -0
  30. package/components/u-field/u-field.vue +469 -0
  31. package/components/u-form/u-form.vue +162 -0
  32. package/components/u-form-item/u-form-item.vue +476 -0
  33. package/components/u-full-screen/u-full-screen.vue +80 -0
  34. package/components/u-gap/u-gap.vue +48 -0
  35. package/components/u-grid/u-grid.vue +101 -0
  36. package/components/u-grid-item/u-grid-item.vue +136 -0
  37. package/components/u-icon/u-icon.vue +389 -0
  38. package/components/u-image/types.ts +48 -0
  39. package/components/u-image/u-image.vue +218 -0
  40. package/components/u-index-anchor/u-index-anchor.vue +101 -0
  41. package/components/u-index-list/u-index-list.vue +376 -0
  42. package/components/u-input/u-input.vue +462 -0
  43. package/components/u-keyboard/u-keyboard.vue +188 -0
  44. package/components/u-lazy-load/u-lazy-load.vue +288 -0
  45. package/components/u-line/u-line.vue +71 -0
  46. package/components/u-line-progress/u-line-progress.vue +128 -0
  47. package/components/u-link/u-link.vue +87 -0
  48. package/components/u-loading/u-loading.vue +111 -0
  49. package/components/u-loadmore/u-loadmore.vue +205 -0
  50. package/components/u-mask/u-mask.vue +137 -0
  51. package/components/u-message-input/u-message-input.vue +315 -0
  52. package/components/u-modal/u-modal.vue +284 -0
  53. package/components/u-navbar/u-navbar.vue +314 -0
  54. package/components/u-no-network/image.ts +2 -0
  55. package/components/u-no-network/u-no-network.vue +311 -0
  56. package/components/u-notice-bar/u-notice-bar.vue +274 -0
  57. package/components/u-number-box/u-number-box.vue +344 -0
  58. package/components/u-number-keyboard/u-number-keyboard.vue +170 -0
  59. package/components/u-parse/libs/CssHandler.js +100 -0
  60. package/components/u-parse/libs/MpHtmlParser.js +580 -0
  61. package/components/u-parse/libs/config.js +80 -0
  62. package/components/u-parse/libs/handler.wxs +22 -0
  63. package/components/u-parse/libs/trees.vue +505 -0
  64. package/components/u-parse/u-parse.vue +645 -0
  65. package/components/u-picker/u-picker.vue +808 -0
  66. package/components/u-popup/u-popup.vue +404 -0
  67. package/components/u-radio/u-radio.vue +272 -0
  68. package/components/u-radio-group/u-radio-group.vue +116 -0
  69. package/components/u-rate/u-rate.vue +349 -0
  70. package/components/u-read-more/u-read-more.vue +199 -0
  71. package/components/u-row/u-row.vue +95 -0
  72. package/components/u-row-notice/u-row-notice.vue +273 -0
  73. package/components/u-search/u-search.vue +298 -0
  74. package/components/u-section/u-section.vue +175 -0
  75. package/components/u-select/u-select.vue +387 -0
  76. package/components/u-skeleton/u-skeleton.vue +230 -0
  77. package/components/u-slider/u-slider.vue +293 -0
  78. package/components/u-steps/u-steps.vue +200 -0
  79. package/components/u-sticky/u-sticky.vue +189 -0
  80. package/components/u-subsection/u-subsection.vue +388 -0
  81. package/components/u-swipe-action/u-swipe-action.vue +289 -0
  82. package/components/u-swiper/u-swiper.vue +305 -0
  83. package/components/u-switch/u-switch.vue +146 -0
  84. package/components/u-tabbar/u-tabbar.vue +347 -0
  85. package/components/u-table/u-table.vue +104 -0
  86. package/components/u-tabs/u-tabs.vue +322 -0
  87. package/components/u-tabs-swiper/u-tabs-swiper.vue +426 -0
  88. package/components/u-tag/u-tag.vue +270 -0
  89. package/components/u-td/u-td.vue +76 -0
  90. package/components/u-th/u-th.vue +70 -0
  91. package/components/u-time-line/u-time-line.vue +39 -0
  92. package/components/u-time-line-item/u-time-line-item.vue +88 -0
  93. package/components/u-toast/types.ts +4 -0
  94. package/components/u-toast/u-toast.vue +238 -0
  95. package/components/u-top-tips/u-top-tips.vue +118 -0
  96. package/components/u-tr/u-tr.vue +24 -0
  97. package/components/u-upload/u-upload.vue +600 -0
  98. package/components/u-verification-code/u-verification-code.vue +194 -0
  99. package/components/u-waterfall/u-waterfall.vue +186 -0
  100. package/iconfont.css +910 -0
  101. package/index.scss +23 -0
  102. package/index.ts +166 -0
  103. package/libs/config/config.ts +26 -0
  104. package/libs/config/zIndex.ts +37 -0
  105. package/libs/css/color.scss +155 -0
  106. package/libs/css/common.scss +176 -0
  107. package/libs/css/style.components.scss +7 -0
  108. package/libs/css/style.h5.scss +8 -0
  109. package/libs/css/style.mp.scss +72 -0
  110. package/libs/css/style.nvue.scss +3 -0
  111. package/libs/css/style.vue.scss +175 -0
  112. package/libs/function/$parent.ts +22 -0
  113. package/libs/function/addUnit.ts +13 -0
  114. package/libs/function/color.ts +37 -0
  115. package/libs/function/colorGradient.ts +123 -0
  116. package/libs/function/debounce.ts +28 -0
  117. package/libs/function/deepClone.ts +39 -0
  118. package/libs/function/deepMerge.ts +34 -0
  119. package/libs/function/getParent.ts +59 -0
  120. package/libs/function/getRect.ts +26 -0
  121. package/libs/function/guid.ts +42 -0
  122. package/libs/function/md5.ts +397 -0
  123. package/libs/function/parent.ts +21 -0
  124. package/libs/function/queryParams.ts +60 -0
  125. package/libs/function/random.ts +16 -0
  126. package/libs/function/randomArray.ts +11 -0
  127. package/libs/function/route.ts +118 -0
  128. package/libs/function/sys.ts +15 -0
  129. package/libs/function/test.ts +229 -0
  130. package/libs/function/throttle.ts +31 -0
  131. package/libs/function/timeFormat.ts +54 -0
  132. package/libs/function/timeFrom.ts +48 -0
  133. package/libs/function/toast.ts +14 -0
  134. package/libs/function/trim.ts +21 -0
  135. package/libs/function/type2icon.ts +36 -0
  136. package/libs/hooks/useEmitter.ts +77 -0
  137. package/libs/hooks/useParent.ts +29 -0
  138. package/libs/request/index.ts +237 -0
  139. package/libs/store/index.ts +88 -0
  140. package/libs/util/area.ts +1 -0
  141. package/libs/util/async-validator.js +1356 -0
  142. package/libs/util/city.ts +1 -0
  143. package/libs/util/emitter.ts +112 -0
  144. package/libs/util/mitt.ts +118 -0
  145. package/libs/util/parent.ts +20 -0
  146. package/libs/util/province.ts +1 -0
  147. package/package.json +98 -0
  148. package/readme.md +165 -0
  149. package/theme.scss +38 -0
@@ -0,0 +1,725 @@
1
+ <template>
2
+ <u-popup
3
+ :maskCloseAble="maskCloseAble"
4
+ mode="bottom"
5
+ :popup="false"
6
+ v-model="popupValue"
7
+ length="auto"
8
+ :safeAreaInsetBottom="safeAreaInsetBottom"
9
+ @close="close"
10
+ :z-index="uZIndex"
11
+ :border-radius="borderRadius"
12
+ :closeable="closeable"
13
+ >
14
+ <view class="u-calendar">
15
+ <view class="u-calendar__header">
16
+ <view class="u-calendar__header__text" v-if="!slots.tooltip">
17
+ {{ toolTip }}
18
+ </view>
19
+ <slot v-else name="tooltip" />
20
+ </view>
21
+ <view class="u-calendar__action u-flex u-row-center">
22
+ <view class="u-calendar__action__icon">
23
+ <u-icon v-if="changeYear" name="arrow-left-double" :color="yearArrowColor" @click="changeYearHandler(0)"></u-icon>
24
+ </view>
25
+ <view class="u-calendar__action__icon">
26
+ <u-icon v-if="changeMonth" name="arrow-left" :color="monthArrowColor" @click="changeMonthHandler(0)"></u-icon>
27
+ </view>
28
+ <view class="u-calendar__action__text">{{ showTitle }}</view>
29
+ <view class="u-calendar__action__icon">
30
+ <u-icon v-if="changeMonth" name="arrow-right" :color="monthArrowColor" @click="changeMonthHandler(1)"></u-icon>
31
+ </view>
32
+ <view class="u-calendar__action__icon">
33
+ <u-icon v-if="changeYear" name="arrow-right-double" :color="yearArrowColor" @click="changeYearHandler(1)"></u-icon>
34
+ </view>
35
+ </view>
36
+ <view class="u-calendar__week-day">
37
+ <view class="u-calendar__week-day__text" v-for="(item, index) in weekDayZh" :key="index">{{ item }}</view>
38
+ </view>
39
+ <view class="u-calendar__content">
40
+ <!-- 前置空白部分 -->
41
+ <block v-for="(item, index) in weekdayArr" :key="index">
42
+ <view class="u-calendar__content__item"></view>
43
+ </block>
44
+ <view
45
+ class="u-calendar__content__item"
46
+ :class="{
47
+ 'u-hover-class': openDisAbled(year, month, index + 1),
48
+ 'u-calendar__content--start-date': (mode == 'range' && startDate == `${year}-${month}-${index + 1}`) || mode == 'date',
49
+ 'u-calendar__content--end-date': (mode == 'range' && endDate == `${year}-${month}-${index + 1}`) || mode == 'date'
50
+ }"
51
+ :style="{ backgroundColor: getColor(index, 1) }"
52
+ v-for="(item, index) in daysArr"
53
+ :key="index"
54
+ @tap="dateClick(index)"
55
+ >
56
+ <view class="u-calendar__content__item__inner" :style="{ color: getColor(index, 2) }">
57
+ <view>{{ index + 1 }}</view>
58
+ </view>
59
+ <view
60
+ class="u-calendar__content__item__tips"
61
+ :style="{ color: activeColor }"
62
+ v-if="mode == 'range' && startDate == `${year}-${month}-${index + 1}` && startDate != endDate"
63
+ >{{ startText }}</view
64
+ >
65
+ <view class="u-calendar__content__item__tips" :style="{ color: activeColor }" v-if="mode == 'range' && endDate == `${year}-${month}-${index + 1}`">{{
66
+ endText
67
+ }}</view>
68
+ </view>
69
+ <view class="u-calendar__content__bg-month">{{ month }}</view>
70
+ </view>
71
+ <view class="u-calendar__bottom">
72
+ <view class="u-calendar__bottom__choose">
73
+ <text>{{ mode == 'date' ? activeDate : startDate }}</text>
74
+ <text v-if="endDate">至{{ endDate }}</text>
75
+ </view>
76
+ <view class="u-calendar__bottom__btn">
77
+ <u-button :type="btnType" shape="circle" size="default" @click="btnFix(false)">确定</u-button>
78
+ </view>
79
+ </view>
80
+ </view>
81
+ </u-popup>
82
+ </template>
83
+
84
+ <script setup lang="ts">
85
+ import { ref, computed, watch, onMounted, useSlots } from 'vue';
86
+ import { $u } from '../..';
87
+
88
+ defineOptions({
89
+ name: 'u-calendar'
90
+ });
91
+ /**
92
+ * calendar 日历
93
+ * @description 此组件用于单个选择日期,范围选择日期等,日历被包裹在底部弹起的容器中。
94
+ * @tutorial http://uviewui.com/components/calendar.html
95
+ * @property {String} mode 选择日期的模式,date-为单个日期,range-为选择日期范围
96
+ * @property {Boolean} v-model 布尔值变量,用于控制日历的弹出与收起
97
+ * @property {Boolean} safe-area-inset-bottom 是否开启底部安全区适配(默认false)
98
+ * @property {Boolean} change-year 是否显示顶部的切换年份方向的按钮(默认true)
99
+ * @property {Boolean} change-month 是否显示顶部的切换月份方向的按钮(默认true)
100
+ * @property {String Number} max-year 可切换的最大年份(默认2050)
101
+ * @property {String Number} min-year 可切换的最小年份(默认1950)
102
+ * @property {String Number} min-date 最小可选日期(默认1950-01-01)
103
+ * @property {String Number} max-date 最大可选日期(默认当前日期)
104
+ * @property {String Number} 弹窗顶部左右两边的圆角值,单位rpx(默认20)
105
+ * @property {Boolean} mask-close-able 是否允许通过点击遮罩关闭日历(默认true)
106
+ * @property {String} month-arrow-color 月份切换按钮箭头颜色(默认#606266)
107
+ * @property {String} year-arrow-color 年份切换按钮箭头颜色(默认#909399)
108
+ * @property {String} color 日期字体的默认颜色(默认#303133)
109
+ * @property {String} active-bg-color 起始/结束日期按钮的背景色(默认#2979ff)
110
+ * @property {String Number} z-index 弹出时的z-index值(默认10075)
111
+ * @property {String} active-color 起始/结束日期按钮的字体颜色(默认#ffffff)
112
+ * @property {String} range-bg-color 起始/结束日期之间的区域的背景颜色(默认rgba(41,121,255,0.13))
113
+ * @property {String} range-color 选择范围内字体颜色(默认#2979ff)
114
+ * @property {String} start-text 起始日期底部的提示文字(默认 '开始')
115
+ * @property {String} end-text 结束日期底部的提示文字(默认 '结束')
116
+ * @property {String} btn-type 底部确定按钮的主题(默认 'primary')
117
+ * @property {String} toolTip 顶部提示文字,如设置名为tooltip的slot,此参数将失效(默认 '选择日期')
118
+ * @property {Boolean} closeable 是否显示右上角的关闭图标(默认true)
119
+ * @example <u-calendar v-model="show" :mode="mode"></u-calendar>
120
+ */
121
+
122
+ const props = defineProps({
123
+ safeAreaInsetBottom: {
124
+ type: Boolean,
125
+ default: false
126
+ },
127
+ // 是否允许通过点击遮罩关闭Picker
128
+ maskCloseAble: {
129
+ type: Boolean,
130
+ default: true
131
+ },
132
+ // 通过双向绑定控制组件的弹出与收起
133
+ modelValue: {
134
+ type: Boolean,
135
+ default: false
136
+ },
137
+ // 弹出的z-index值
138
+ zIndex: {
139
+ type: [String, Number],
140
+ default: 0
141
+ },
142
+ // 是否允许切换年份
143
+ changeYear: {
144
+ type: Boolean,
145
+ default: true
146
+ },
147
+ // 是否允许切换月份
148
+ changeMonth: {
149
+ type: Boolean,
150
+ default: true
151
+ },
152
+ // date-单个日期选择,range-开始日期+结束日期选择
153
+ mode: {
154
+ type: String,
155
+ default: 'date'
156
+ },
157
+ // 可切换的最大年份
158
+ maxYear: {
159
+ type: [Number, String],
160
+ default: 2050
161
+ },
162
+ // 可切换的最小年份
163
+ minYear: {
164
+ type: [Number, String],
165
+ default: 1950
166
+ },
167
+ // 最小可选日期(不在范围内日期禁用不可选)
168
+ minDate: {
169
+ type: [Number, String],
170
+ default: '1950-01-01'
171
+ },
172
+ /**
173
+ * 最大可选日期
174
+ * 默认最大值为今天,之后的日期不可选
175
+ * 2030-12-31
176
+ * */
177
+ maxDate: {
178
+ type: [Number, String],
179
+ default: ''
180
+ },
181
+ // 弹窗顶部左右两边的圆角值
182
+ borderRadius: {
183
+ type: [String, Number],
184
+ default: 20
185
+ },
186
+ // 月份切换按钮箭头颜色
187
+ monthArrowColor: {
188
+ type: String,
189
+ default: '#606266'
190
+ },
191
+ // 年份切换按钮箭头颜色
192
+ yearArrowColor: {
193
+ type: String,
194
+ default: '#909399'
195
+ },
196
+ // 默认日期字体颜色
197
+ color: {
198
+ type: String,
199
+ default: '#303133'
200
+ },
201
+ // 选中|起始结束日期背景色
202
+ activeBgColor: {
203
+ type: String,
204
+ default: '#2979ff'
205
+ },
206
+ // 选中|起始结束日期字体颜色
207
+ activeColor: {
208
+ type: String,
209
+ default: '#ffffff'
210
+ },
211
+ // 范围内日期背景色
212
+ rangeBgColor: {
213
+ type: String,
214
+ default: 'rgba(41,121,255,0.13)'
215
+ },
216
+ // 范围内日期字体颜色
217
+ rangeColor: {
218
+ type: String,
219
+ default: '#2979ff'
220
+ },
221
+ // mode=range时生效,起始日期自定义文案
222
+ startText: {
223
+ type: String,
224
+ default: '开始'
225
+ },
226
+ // mode=range时生效,结束日期自定义文案
227
+ endText: {
228
+ type: String,
229
+ default: '结束'
230
+ },
231
+ //按钮样式类型
232
+ btnType: {
233
+ type: String,
234
+ default: 'primary'
235
+ },
236
+ // 当前选中日期带选中效果
237
+ isActiveCurrent: {
238
+ type: Boolean,
239
+ default: true
240
+ },
241
+ // 切换年月是否触发事件 mode=date时生效
242
+ isChange: {
243
+ type: Boolean,
244
+ default: false
245
+ },
246
+ // 是否显示右上角的关闭图标
247
+ closeable: {
248
+ type: Boolean,
249
+ default: true
250
+ },
251
+ // 顶部的提示文字
252
+ toolTip: {
253
+ type: String,
254
+ default: '选择日期'
255
+ }
256
+ });
257
+ const emit = defineEmits(['update:modelValue', 'input', 'change']);
258
+ const slots = useSlots();
259
+
260
+ // 组件内部状态
261
+ // 星期几,值为1-7
262
+ const weekday = ref(1);
263
+ const weekdayArr = ref<number[]>([]);
264
+ const days = ref(0);
265
+ const daysArr = ref<number[]>([]);
266
+ const showTitle = ref('');
267
+ const year = ref(2020);
268
+ const month = ref(0);
269
+ // 当前月有多少天
270
+ const day = ref(0);
271
+ const startYear = ref(0);
272
+ const startMonth = ref(0);
273
+ const startDay = ref(0);
274
+ const endYear = ref(0);
275
+ const endMonth = ref(0);
276
+ const endDay = ref(0);
277
+ const today = ref('');
278
+ const activeDate = ref('');
279
+ const startDate = ref('');
280
+ const endDate = ref('');
281
+ const isStart = ref(true);
282
+ const min = ref<{ year: number; month: number; day: number } | null>(null);
283
+ const max = ref<{ year: number; month: number; day: number } | null>(null);
284
+ const weekDayZh = ref(['日', '一', '二', '三', '四', '五', '六']);
285
+
286
+ const dataChange = computed(() => `${props.mode}-${props.minDate}-${props.maxDate}`);
287
+ // 如果用户有传递z-index值,优先使用
288
+ const uZIndex = computed(() => (props.zIndex ? props.zIndex : $u.zIndex.popup));
289
+ const popupValue = computed({
290
+ get: () => props.modelValue,
291
+ set: (val: boolean) => emit('update:modelValue', val)
292
+ });
293
+
294
+ watch(dataChange, () => {
295
+ init();
296
+ });
297
+
298
+ onMounted(() => {
299
+ init();
300
+ });
301
+
302
+ /**
303
+ * 获取日期颜色
304
+ * @param index
305
+ * @param type 1 背景色 2 字体色
306
+ */
307
+ function getColor(index: number, type: number) {
308
+ let color = type == 1 ? '' : props.color;
309
+ let dayNum = index + 1;
310
+ let date = `${year.value}-${month.value}-${dayNum}`;
311
+ let timestamp = new Date(date.replace(/\-/g, '/')).getTime();
312
+ let start = startDate.value.replace(/\-/g, '/');
313
+ let end = endDate.value.replace(/\-/g, '/');
314
+ if ((props.isActiveCurrent && activeDate.value == date) || startDate.value == date || endDate.value == date) {
315
+ color = type == 1 ? props.activeBgColor : props.activeColor;
316
+ } else if (endDate.value && timestamp > new Date(start).getTime() && timestamp < new Date(end).getTime()) {
317
+ color = type == 1 ? props.rangeBgColor : props.rangeColor;
318
+ }
319
+ return color;
320
+ }
321
+
322
+ /**
323
+ * 初始化日历数据
324
+ */
325
+ function init() {
326
+ let now = new Date();
327
+ let minDateObj = new Date(String(props.minDate));
328
+ let maxDateObj = new Date(String(props.maxDate || ''));
329
+ if (isNaN(maxDateObj.getTime())) maxDateObj = new Date();
330
+ if (now < minDateObj) now = minDateObj;
331
+ if (now > maxDateObj) now = maxDateObj;
332
+ year.value = now.getFullYear();
333
+ month.value = now.getMonth() + 1;
334
+ day.value = now.getDate();
335
+ today.value = `${now.getFullYear()}-${month.value}-${day.value}`;
336
+ activeDate.value = today.value;
337
+ min.value = initDate(String(props.minDate));
338
+ max.value = initDate(String(props.maxDate) || today.value);
339
+ startDate.value = '';
340
+ startYear.value = 0;
341
+ startMonth.value = 0;
342
+ startDay.value = 0;
343
+ endYear.value = 0;
344
+ endMonth.value = 0;
345
+ endDay.value = 0;
346
+ endDate.value = '';
347
+ isStart.value = true;
348
+ changeData();
349
+ }
350
+
351
+ /**
352
+ * 日期字符串转对象
353
+ */
354
+ function initDate(date: string) {
355
+ let fdate = date.split('-');
356
+ return {
357
+ year: Number(fdate[0] || 1920),
358
+ month: Number(fdate[1] || 1),
359
+ day: Number(fdate[2] || 1)
360
+ };
361
+ }
362
+
363
+ /**
364
+ * 判断日期是否可选
365
+ */
366
+ function openDisAbled(yearNum: number, monthNum: number, dayNum: number) {
367
+ let bool = true;
368
+ let date = `${yearNum}/${monthNum}/${dayNum}`;
369
+ // let today = this.today.replace(/\-/g, '/');
370
+ let minStr = min.value ? `${min.value.year}/${min.value.month}/${min.value.day}` : '';
371
+ let maxStr = max.value ? `${max.value.year}/${max.value.month}/${max.value.day}` : '';
372
+ let timestamp = new Date(date).getTime();
373
+ if (min.value && max.value && timestamp >= new Date(minStr).getTime() && timestamp <= new Date(maxStr).getTime()) {
374
+ bool = false;
375
+ }
376
+ return bool;
377
+ }
378
+
379
+ /**
380
+ * 生成数组
381
+ */
382
+ function generateArray(start: number, end: number) {
383
+ return Array.from(new Array(end + 1).keys()).slice(start);
384
+ }
385
+
386
+ /**
387
+ * 格式化数字
388
+ */
389
+ function formatNum(num: number) {
390
+ return num < 10 ? '0' + num : num + '';
391
+ }
392
+
393
+ /**
394
+ * 获取某月天数
395
+ */
396
+ function getMonthDay(yearNum: number, monthNum: number) {
397
+ return new Date(yearNum, monthNum, 0).getDate();
398
+ }
399
+
400
+ /**
401
+ * 获取某月第一天星期几
402
+ */
403
+ function getWeekday(yearNum: number, monthNum: number) {
404
+ let date = new Date(`${yearNum}/${monthNum}/01 00:00:00`);
405
+ return date.getDay();
406
+ }
407
+
408
+ /**
409
+ * 检查年份是否超出范围
410
+ */
411
+ function checkRange(yearNum: number) {
412
+ let overstep = false;
413
+ if (yearNum < Number(props.minYear) || yearNum > Number(props.maxYear)) {
414
+ uni.showToast({ title: '日期超出范围啦~', icon: 'none' });
415
+ overstep = true;
416
+ }
417
+ return overstep;
418
+ }
419
+
420
+ /**
421
+ * 切换月份
422
+ */
423
+ function changeMonthHandler(isAdd: number) {
424
+ if (isAdd) {
425
+ let m = month.value + 1;
426
+ let y = m > 12 ? year.value + 1 : year.value;
427
+ if (!checkRange(y)) {
428
+ month.value = m > 12 ? 1 : m;
429
+ year.value = y;
430
+ changeData();
431
+ }
432
+ } else {
433
+ let m = month.value - 1;
434
+ let y = m < 1 ? year.value - 1 : year.value;
435
+ if (!checkRange(y)) {
436
+ month.value = m < 1 ? 12 : m;
437
+ year.value = y;
438
+ changeData();
439
+ }
440
+ }
441
+ }
442
+
443
+ /**
444
+ * 切换年份
445
+ */
446
+ function changeYearHandler(isAdd: number) {
447
+ let y = isAdd ? year.value + 1 : year.value - 1;
448
+ if (!checkRange(y)) {
449
+ year.value = y;
450
+ changeData();
451
+ }
452
+ }
453
+
454
+ /**
455
+ * 更新日历数据
456
+ */
457
+ function changeData() {
458
+ days.value = getMonthDay(year.value, month.value);
459
+ daysArr.value = generateArray(1, days.value);
460
+ weekday.value = getWeekday(year.value, month.value);
461
+ weekdayArr.value = generateArray(1, weekday.value);
462
+ showTitle.value = `${year.value}年${month.value}月`;
463
+ if (props.isChange && props.mode == 'date') {
464
+ btnFix(true);
465
+ }
466
+ }
467
+
468
+ /**
469
+ * 日期点击事件
470
+ */
471
+ function dateClick(dayIdx: number) {
472
+ const d = dayIdx + 1;
473
+ if (!openDisAbled(year.value, month.value, d)) {
474
+ day.value = d;
475
+ let date = `${year.value}-${month.value}-${d}`;
476
+ if (props.mode == 'date') {
477
+ activeDate.value = date;
478
+ } else {
479
+ let compare = new Date(date.replace(/\-/g, '/')).getTime() < new Date(startDate.value.replace(/\-/g, '/')).getTime();
480
+ if (isStart.value || compare) {
481
+ startDate.value = date;
482
+ startYear.value = year.value;
483
+ startMonth.value = month.value;
484
+ startDay.value = day.value;
485
+ endYear.value = 0;
486
+ endMonth.value = 0;
487
+ endDay.value = 0;
488
+ endDate.value = '';
489
+ activeDate.value = '';
490
+ isStart.value = false;
491
+ } else {
492
+ endDate.value = date;
493
+ endYear.value = year.value;
494
+ endMonth.value = month.value;
495
+ endDay.value = day.value;
496
+ isStart.value = true;
497
+ }
498
+ }
499
+ }
500
+ }
501
+
502
+ /**
503
+ * 关闭弹窗
504
+ */
505
+ function close() {
506
+ emit('input', false);
507
+ emit('update:modelValue', false);
508
+ }
509
+
510
+ /**
511
+ * 获取星期文本
512
+ */
513
+ function getWeekText(date: string) {
514
+ const d = new Date(`${date.replace(/\-/g, '/')} 00:00:00`);
515
+ let week = d.getDay();
516
+ return '星期' + ['日', '一', '二', '三', '四', '五', '六'][week];
517
+ }
518
+
519
+ /**
520
+ * 确定按钮事件
521
+ */
522
+ function btnFix(show: boolean) {
523
+ if (!show) {
524
+ close();
525
+ }
526
+ if (props.mode == 'date') {
527
+ let arr = activeDate.value.split('-');
528
+ let y = props.isChange ? year.value : Number(arr[0]);
529
+ let m = props.isChange ? month.value : Number(arr[1]);
530
+ let d = props.isChange ? day.value : Number(arr[2]);
531
+ let daysNum = getMonthDay(y, m);
532
+ let result = `${y}-${formatNum(m)}-${formatNum(d)}`;
533
+ let weekText = getWeekText(result);
534
+ let isToday = false;
535
+ if (`${y}-${m}-${d}` == today.value) {
536
+ // 今天
537
+ isToday = true;
538
+ }
539
+ emit('change', {
540
+ year: y,
541
+ month: m,
542
+ day: d,
543
+ days: daysNum,
544
+ result: result,
545
+ week: weekText,
546
+ isToday: isToday
547
+ // switch: show //是否是切换年月操作
548
+ });
549
+ } else {
550
+ if (!startDate.value || !endDate.value) return;
551
+ let startMonthStr = formatNum(startMonth.value);
552
+ let startDayStr = formatNum(startDay.value);
553
+ let startDateStr = `${startYear.value}-${startMonthStr}-${startDayStr}`;
554
+ let startWeek = getWeekText(startDateStr);
555
+ let endMonthStr = formatNum(endMonth.value);
556
+ let endDayStr = formatNum(endDay.value);
557
+ let endDateStr = `${endYear.value}-${endMonthStr}-${endDayStr}`;
558
+ let endWeek = getWeekText(endDateStr);
559
+ emit('change', {
560
+ startYear: startYear.value,
561
+ startMonth: startMonth.value,
562
+ startDay: startDay.value,
563
+ startDate: startDateStr,
564
+ startWeek: startWeek,
565
+ endYear: endYear.value,
566
+ endMonth: endMonth.value,
567
+ endDay: endDay.value,
568
+ endDate: endDateStr,
569
+ endWeek: endWeek
570
+ });
571
+ }
572
+ }
573
+ </script>
574
+
575
+ <style scoped lang="scss">
576
+ @import '../../libs/css/style.components.scss';
577
+
578
+ .u-calendar {
579
+ color: $u-content-color;
580
+
581
+ &__header {
582
+ width: 100%;
583
+ box-sizing: border-box;
584
+ font-size: 30rpx;
585
+ background-color: #fff;
586
+ color: $u-main-color;
587
+
588
+ &__text {
589
+ margin-top: 30rpx;
590
+ padding: 0 60rpx;
591
+ @include vue-flex;
592
+ justify-content: center;
593
+ align-items: center;
594
+ }
595
+ }
596
+
597
+ &__action {
598
+ padding: 40rpx 0 40rpx 0;
599
+
600
+ &__icon {
601
+ margin: 0 16rpx;
602
+ }
603
+
604
+ &__text {
605
+ padding: 0 16rpx;
606
+ color: $u-main-color;
607
+ font-size: 32rpx;
608
+ line-height: 32rpx;
609
+ font-weight: bold;
610
+ }
611
+ }
612
+
613
+ &__week-day {
614
+ @include vue-flex;
615
+ align-items: center;
616
+ justify-content: center;
617
+ padding: 6px 0;
618
+ overflow: hidden;
619
+
620
+ &__text {
621
+ flex: 1;
622
+ text-align: center;
623
+ }
624
+ }
625
+
626
+ &__content {
627
+ width: 100%;
628
+ @include vue-flex;
629
+ flex-wrap: wrap;
630
+ padding: 6px 0;
631
+ box-sizing: border-box;
632
+ background-color: #fff;
633
+ position: relative;
634
+
635
+ &--end-date {
636
+ border-top-right-radius: 8rpx;
637
+ border-bottom-right-radius: 8rpx;
638
+ }
639
+
640
+ &--start-date {
641
+ border-top-left-radius: 8rpx;
642
+ border-bottom-left-radius: 8rpx;
643
+ }
644
+
645
+ &__item {
646
+ width: 14.2857%;
647
+ @include vue-flex;
648
+ align-items: center;
649
+ justify-content: center;
650
+ padding: 6px 0;
651
+ overflow: hidden;
652
+ position: relative;
653
+ z-index: 2;
654
+
655
+ &__inner {
656
+ height: 84rpx;
657
+ @include vue-flex;
658
+ align-items: center;
659
+ justify-content: center;
660
+ flex-direction: column;
661
+ font-size: 32rpx;
662
+ position: relative;
663
+ border-radius: 50%;
664
+
665
+ &__desc {
666
+ width: 100%;
667
+ font-size: 24rpx;
668
+ line-height: 24rpx;
669
+ transform: scale(0.75);
670
+ transform-origin: center center;
671
+ position: absolute;
672
+ left: 0;
673
+ text-align: center;
674
+ bottom: 2rpx;
675
+ }
676
+ }
677
+
678
+ &__tips {
679
+ width: 100%;
680
+ font-size: 24rpx;
681
+ line-height: 24rpx;
682
+ position: absolute;
683
+ left: 0;
684
+ transform: scale(0.8);
685
+ transform-origin: center center;
686
+ text-align: center;
687
+ bottom: 8rpx;
688
+ z-index: 2;
689
+ }
690
+ }
691
+
692
+ &__bg-month {
693
+ position: absolute;
694
+ font-size: 130px;
695
+ line-height: 130px;
696
+ left: 50%;
697
+ top: 50%;
698
+ transform: translate(-50%, -50%);
699
+ color: #e4e7ed;
700
+ z-index: 1;
701
+ }
702
+ }
703
+
704
+ &__bottom {
705
+ width: 100%;
706
+ @include vue-flex;
707
+ align-items: center;
708
+ justify-content: center;
709
+ flex-direction: column;
710
+ background-color: #fff;
711
+ padding: 0 40rpx 30rpx;
712
+ box-sizing: border-box;
713
+ font-size: 24rpx;
714
+ color: $u-tips-color;
715
+
716
+ &__choose {
717
+ height: 50rpx;
718
+ }
719
+
720
+ &__btn {
721
+ width: 100%;
722
+ }
723
+ }
724
+ }
725
+ </style>