uview-pro 0.0.18 → 0.0.19

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