@gmcb/uv-ui 0.2.27 → 0.3.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.
- package/CHANGELOG.md +8 -0
- package/LICENSE +21 -0
- package/README.md +95 -141
- package/docs/api/configs/color.md +52 -0
- package/docs/api/index.md +77 -0
- package/docs/api/mixins/mpShare.md +95 -0
- package/docs/api/request/apiManage.md +88 -0
- package/docs/api/request/http.md +451 -0
- package/docs/api/utils/colorSwitch.md +78 -0
- package/docs/api/utils/debounce.md +104 -0
- package/docs/api/utils/fastUse.md +246 -0
- package/docs/api/utils/getRect.md +238 -0
- package/docs/api/utils/guid.md +41 -0
- package/docs/api/utils/index.md +55 -0
- package/docs/api/utils/intro.md +25 -0
- package/docs/api/utils/object.md +171 -0
- package/docs/api/utils/queryParams.md +68 -0
- package/docs/api/utils/random.md +23 -0
- package/docs/api/utils/randomArray.md +28 -0
- package/docs/api/utils/route.md +121 -0
- package/docs/api/utils/test.md +237 -0
- package/docs/api/utils/time.md +81 -0
- package/docs/api/utils/trim.md +24 -0
- package/docs/components/actionSheet.md +236 -0
- package/docs/components/addQQGroup.md +5 -0
- package/docs/components/album.md +91 -0
- package/docs/components/alert.md +83 -0
- package/docs/components/avatar.md +152 -0
- package/docs/components/backTop.md +181 -0
- package/docs/components/badge.md +117 -0
- package/docs/components/button.md +196 -0
- package/docs/components/calendar.md +398 -0
- package/docs/components/calendars.md +294 -0
- package/docs/components/cell.md +185 -0
- package/docs/components/checkbox.md +281 -0
- package/docs/components/circleProgress.md +5 -0
- package/docs/components/code.md +162 -0
- package/docs/components/codeInput.md +175 -0
- package/docs/components/collapse.md +250 -0
- package/docs/components/color.md +324 -0
- package/docs/components/common.md +126 -0
- package/docs/components/countDown.md +166 -0
- package/docs/components/countTo.md +140 -0
- package/docs/components/datetimePicker.md +283 -0
- package/docs/components/diff1.x.md +190 -0
- package/docs/components/divider.md +88 -0
- package/docs/components/downloadSetting.md +54 -0
- package/docs/components/dropDown.md +375 -0
- package/docs/components/empty.md +99 -0
- package/docs/components/feature.md +261 -0
- package/docs/components/form.md +736 -0
- package/docs/components/gap.md +49 -0
- package/docs/components/grid.md +225 -0
- package/docs/components/icon.md +101 -0
- package/docs/components/image.md +182 -0
- package/docs/components/index.md +110 -0
- package/docs/components/indexList.md +133 -0
- package/docs/components/input.md +250 -0
- package/docs/components/install.md +59 -0
- package/docs/components/intro.md +32 -0
- package/docs/components/keyboard.md +226 -0
- package/docs/components/layout.md +310 -0
- package/docs/components/line.md +85 -0
- package/docs/components/lineProgress.md +141 -0
- package/docs/components/link.md +89 -0
- package/docs/components/list.md +223 -0
- package/docs/components/loadMore.md +140 -0
- package/docs/components/loadingIcon.md +144 -0
- package/docs/components/loadingPage.md +92 -0
- package/docs/components/modal.md +230 -0
- package/docs/components/more.md +13 -0
- package/docs/components/navbar.md +192 -0
- package/docs/components/noNetwork.md +116 -0
- package/docs/components/noticeBar.md +131 -0
- package/docs/components/notify.md +204 -0
- package/docs/components/npmSetting.md +64 -0
- package/docs/components/numberBox.md +257 -0
- package/docs/components/nvue.md +170 -0
- package/docs/components/overlay.md +117 -0
- package/docs/components/parse.md +204 -0
- package/docs/components/pickColor.md +112 -0
- package/docs/components/picker.md +357 -0
- package/docs/components/popup.md +221 -0
- package/docs/components/problem.md +300 -0
- package/docs/components/qrcode.md +169 -0
- package/docs/components/quickstart.md +33 -0
- package/docs/components/radio.md +256 -0
- package/docs/components/rate.md +128 -0
- package/docs/components/read.md +163 -0
- package/docs/components/readMore.md +227 -0
- package/docs/components/resource.md +17 -0
- package/docs/components/scrollList.md +218 -0
- package/docs/components/search.md +160 -0
- package/docs/components/setting.md +111 -0
- package/docs/components/settingDesc.md +66 -0
- package/docs/components/skeleton.md +105 -0
- package/docs/components/skeletons.md +323 -0
- package/docs/components/slider.md +157 -0
- package/docs/components/steps.md +189 -0
- package/docs/components/sticky.md +76 -0
- package/docs/components/subsection.md +183 -0
- package/docs/components/swipeAction.md +279 -0
- package/docs/components/swiper.md +352 -0
- package/docs/components/switch.md +216 -0
- package/docs/components/tabbar.md +263 -0
- package/docs/components/table.md +5 -0
- package/docs/components/tabs.md +364 -0
- package/docs/components/tag.md +227 -0
- package/docs/components/testPic.md +20 -0
- package/docs/components/text.md +157 -0
- package/docs/components/textarea.md +121 -0
- package/docs/components/toast.md +124 -0
- package/docs/components/tooltip.md +98 -0
- package/docs/components/transition.md +404 -0
- package/docs/components/upload.md +253 -0
- package/docs/components/vtabs.md +332 -0
- package/docs/components/vueUse.md +45 -0
- package/docs/components/vuexDetail.md +103 -0
- package/docs/components/waterfall.md +651 -0
- package/docs/faq/index.md +53 -0
- package/docs/guide/codeHint.md +44 -0
- package/docs/guide/customIcon.md +168 -0
- package/docs/guide/demo.md +92 -0
- package/docs/guide/design.md +56 -0
- package/docs/guide/globalVariable.md +239 -0
- package/docs/guide/i18n.md +194 -0
- package/docs/guide/index.md +28 -0
- package/docs/guide/note.md +74 -0
- package/docs/guide/safeAreaInset.md +64 -0
- package/docs/guide/theme.md +67 -0
- package/docs/index.md +88 -0
- package/libs/config/config.js +0 -10
- package/libs/css/color.scss +15 -14
- package/package.json +7 -2
- package/theme.scss +2 -1
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
## Calendar 日历 <to-api/>
|
|
2
|
+
|
|
3
|
+
<demo-model url="/pages/componentsB/calendar/calendar"></demo-model>
|
|
4
|
+
|
|
5
|
+
::: tip ✈
|
|
6
|
+
|
|
7
|
+
**组件名:uv-calendar**
|
|
8
|
+
|
|
9
|
+
[点击下载&安装](https://ext.dcloud.net.cn/plugin?name=uv-calendar)
|
|
10
|
+
|
|
11
|
+
:::
|
|
12
|
+
|
|
13
|
+
此组件用于单个选择日期,范围选择日期等,日历被包裹在底部弹起的容器中。
|
|
14
|
+
|
|
15
|
+
**注意:** 此组件与[Picker 选择器](/components/picker.html)的日期选择模式有一定的重合之处,区别在于本组件为更专业的日期选择场景,能选择日期范围等。
|
|
16
|
+
另外`Picker`组件的日期模式可以配置更多的参数,如时、分、秒等,可以根据不同的使用场景进行选择。
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### 平台兼容性
|
|
20
|
+
|
|
21
|
+
|App(vue)|App(nvue)|H5|小程序|VUE2|VUE3|
|
|
22
|
+
|:-:|:-:|:-:|:-:|:-:|:-:|
|
|
23
|
+
|√|√|√|√|√|√|
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### 基本使用
|
|
27
|
+
|
|
28
|
+
- 通过`ref`调用`open()`和`close()`控制日历的打开和关闭
|
|
29
|
+
- 通过`mode`参数指定选择日期模式,包含单选 / 多选 / 范围选择。
|
|
30
|
+
|
|
31
|
+
```vue
|
|
32
|
+
<template>
|
|
33
|
+
<view>
|
|
34
|
+
<uv-calendar ref="calendar" @confirm="confirm"></uv-calendar>
|
|
35
|
+
<button @click="open">打开</button>
|
|
36
|
+
</view>
|
|
37
|
+
</template>
|
|
38
|
+
<script setup>
|
|
39
|
+
import { ref } from 'vue';
|
|
40
|
+
|
|
41
|
+
const calendar = ref(null);
|
|
42
|
+
function open() {
|
|
43
|
+
calendar.value.open();
|
|
44
|
+
}
|
|
45
|
+
function confirm(e) {
|
|
46
|
+
console.log('日历选择:', e);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
</script>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 日历模式
|
|
53
|
+
|
|
54
|
+
- `mode`为`single`只能选择单个日期
|
|
55
|
+
- `mode`为`multiple`可以选择多个日期
|
|
56
|
+
- `mode`为`range`可以选择日期范围
|
|
57
|
+
|
|
58
|
+
### 单个日期模式
|
|
59
|
+
|
|
60
|
+
选择日期后,需要点击底部的`确定`按钮才能触发回调事件,回调参数为一个数组,有如下属性:
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
["2021-07-01"]
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
示例代码:
|
|
67
|
+
|
|
68
|
+
```vue
|
|
69
|
+
<template>
|
|
70
|
+
<view>
|
|
71
|
+
<uv-calendar ref="calendar" mode="single" @confirm="confirm"></uv-calendar>
|
|
72
|
+
<button @click="open">打开</button>
|
|
73
|
+
</view>
|
|
74
|
+
</template>
|
|
75
|
+
<script setup>
|
|
76
|
+
import { ref } from 'vue';
|
|
77
|
+
|
|
78
|
+
const calendar = ref(null);
|
|
79
|
+
function open() {
|
|
80
|
+
calendar.value.open();
|
|
81
|
+
}
|
|
82
|
+
function confirm(e) {
|
|
83
|
+
console.log('日历选择:', e);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
</script>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 多个日期模式
|
|
90
|
+
|
|
91
|
+
选择日期后,需要点击底部的`确定`按钮才能触发回调事件,回调参数为一个数组,有如下属性:
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
["2021-07-27", "2021-07-29", "2021-07-30"]
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
示例代码:
|
|
98
|
+
|
|
99
|
+
```vue
|
|
100
|
+
<template>
|
|
101
|
+
<view>
|
|
102
|
+
<uv-calendar ref="calendar" mode="multiple" @confirm="confirm"></uv-calendar>
|
|
103
|
+
<button @click="open">打开</button>
|
|
104
|
+
</view>
|
|
105
|
+
</template>
|
|
106
|
+
<script setup>
|
|
107
|
+
import { ref } from 'vue';
|
|
108
|
+
|
|
109
|
+
const calendar = ref(null);
|
|
110
|
+
function open() {
|
|
111
|
+
calendar.value.open();
|
|
112
|
+
}
|
|
113
|
+
function confirm(e) {
|
|
114
|
+
console.log('日历选择:', e);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
</script>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### 日期范围模式
|
|
121
|
+
|
|
122
|
+
此模式用于选择一个日期范围,比如住酒店的入住到离店的日期范围,
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
此模式的返回参数如下:
|
|
126
|
+
|
|
127
|
+
```js
|
|
128
|
+
["2021-07-27", "2021-07-28", "2021-07-29", "2021-07-30", "2021-07-31"]
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
示例代码:
|
|
132
|
+
|
|
133
|
+
```vue
|
|
134
|
+
<template>
|
|
135
|
+
<view>
|
|
136
|
+
<uv-calendar ref="calendar" mode="range" @confirm="confirm"></uv-calendar>
|
|
137
|
+
<button @click="open">打开</button>
|
|
138
|
+
</view>
|
|
139
|
+
</template>
|
|
140
|
+
<script setup>
|
|
141
|
+
import { ref } from 'vue';
|
|
142
|
+
|
|
143
|
+
const calendar = ref(null);
|
|
144
|
+
function open() {
|
|
145
|
+
calendar.value.open();
|
|
146
|
+
}
|
|
147
|
+
function confirm(e) {
|
|
148
|
+
console.log('日历选择:', e);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
</script>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### 自定义主题颜色
|
|
155
|
+
|
|
156
|
+
组件可传入`color`参数,更改组件主题色
|
|
157
|
+
|
|
158
|
+
示例代码:
|
|
159
|
+
|
|
160
|
+
```vue
|
|
161
|
+
<template>
|
|
162
|
+
<view>
|
|
163
|
+
<uv-calendar ref="calendar" mode="range" color="#f56c6c" @confirm="confirm"></uv-calendar>
|
|
164
|
+
<button @click="open">打开</button>
|
|
165
|
+
</view>
|
|
166
|
+
</template>
|
|
167
|
+
<script setup>
|
|
168
|
+
import { ref } from 'vue';
|
|
169
|
+
|
|
170
|
+
const calendar = ref(null);
|
|
171
|
+
function open() {
|
|
172
|
+
calendar.value.open();
|
|
173
|
+
}
|
|
174
|
+
function confirm(e) {
|
|
175
|
+
console.log('日历选择:', e);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
</script>
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### 自定义文案
|
|
182
|
+
|
|
183
|
+
- 组件可以通过`formatter`以函数的方式定义日期文案
|
|
184
|
+
|
|
185
|
+
- 可以通过`setFormatter`返回的`day`参数,进行当天的日期参数设置,比如设置日期下方提示`bottomInfo`,禁止点击`disabled`等,具体根据`day`返回的值进行配置,如下示例:
|
|
186
|
+
|
|
187
|
+
```
|
|
188
|
+
day: {
|
|
189
|
+
bottomInfo: "打8折",
|
|
190
|
+
date: Sat Jul 22 2023 08:00:00 GMT+0800 (中国标准时间) {},
|
|
191
|
+
day: 22,
|
|
192
|
+
disabled: true,
|
|
193
|
+
dot: true,
|
|
194
|
+
month: 7,
|
|
195
|
+
topInfo: "",
|
|
196
|
+
week: 6
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
:::warning 注意:
|
|
201
|
+
注意在页面的`onReady`生命周期获取`ref`再操作。
|
|
202
|
+
:::
|
|
203
|
+
|
|
204
|
+
```vue
|
|
205
|
+
<template>
|
|
206
|
+
<view>
|
|
207
|
+
<uv-calendar
|
|
208
|
+
ref="calendar"
|
|
209
|
+
mode="range"
|
|
210
|
+
startText="住店"
|
|
211
|
+
endText="离店"
|
|
212
|
+
confirmDisabledText="请选择离店日期"
|
|
213
|
+
></uv-calendar>
|
|
214
|
+
<button @click="open">打开</button>
|
|
215
|
+
</view>
|
|
216
|
+
</template>
|
|
217
|
+
<script setup>
|
|
218
|
+
import { ref } from 'vue';
|
|
219
|
+
import { onReady } from '@dcloudio/uni-app';
|
|
220
|
+
|
|
221
|
+
const calendar = ref(null);
|
|
222
|
+
onReady(() => {
|
|
223
|
+
calendar.value.setFormatter(formatter);
|
|
224
|
+
});
|
|
225
|
+
function open() {
|
|
226
|
+
calendar.value.open();
|
|
227
|
+
}
|
|
228
|
+
function confirm(e) {
|
|
229
|
+
console.log('日历选择:', e);
|
|
230
|
+
}
|
|
231
|
+
function formatter(day) {
|
|
232
|
+
const d = new Date();
|
|
233
|
+
let month = d.getMonth() + 1;
|
|
234
|
+
const date = d.getDate();
|
|
235
|
+
if (day.month == month && day.day == date + 3) {
|
|
236
|
+
day.bottomInfo = '打8折';
|
|
237
|
+
day.dot = true;
|
|
238
|
+
day.disabled = true;
|
|
239
|
+
console.log(day);
|
|
240
|
+
}
|
|
241
|
+
return day;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
</script>
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### 日期最大范围
|
|
248
|
+
|
|
249
|
+
组件可以通过`maxDate`定义日期文案
|
|
250
|
+
|
|
251
|
+
```vue
|
|
252
|
+
<template>
|
|
253
|
+
<view>
|
|
254
|
+
<uv-calendar ref="calendar" :maxDate="maxDate" @confirm="confirm"></uv-calendar>
|
|
255
|
+
<button @click="open">打开</button>
|
|
256
|
+
</view>
|
|
257
|
+
</template>
|
|
258
|
+
<script setup>
|
|
259
|
+
import { ref } from 'vue';
|
|
260
|
+
|
|
261
|
+
const d = new Date();
|
|
262
|
+
const year = d.getFullYear();
|
|
263
|
+
let month = d.getMonth() + 1;
|
|
264
|
+
month = month < 10 ? `0${month}` : month;
|
|
265
|
+
const date = d.getDate();
|
|
266
|
+
const calendar = ref(null);
|
|
267
|
+
const maxDate = ref(`${year}-${month}-${date + 10}`);
|
|
268
|
+
function open() {
|
|
269
|
+
calendar.value.open();
|
|
270
|
+
}
|
|
271
|
+
function confirm(e) {
|
|
272
|
+
console.log('日历选择:', e);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
</script>
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### 是否显示农历
|
|
279
|
+
|
|
280
|
+
组件可以通过`showLunar`定义是否显示农历
|
|
281
|
+
|
|
282
|
+
```vue
|
|
283
|
+
<template>
|
|
284
|
+
<view>
|
|
285
|
+
<uv-calendar ref="calendar" showLunar @confirm="confirm"></uv-calendar>
|
|
286
|
+
<button @click="open">打开</button>
|
|
287
|
+
</view>
|
|
288
|
+
</template>
|
|
289
|
+
<script setup>
|
|
290
|
+
import { ref } from 'vue';
|
|
291
|
+
|
|
292
|
+
const calendar = ref(null);
|
|
293
|
+
function open() {
|
|
294
|
+
calendar.value.open();
|
|
295
|
+
}
|
|
296
|
+
function confirm(e) {
|
|
297
|
+
console.log('日历选择:', e);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
</script>
|
|
301
|
+
|
|
302
|
+
```
|
|
303
|
+
### 默认日期
|
|
304
|
+
|
|
305
|
+
组件可以通过`defaultDate`定义默认日期
|
|
306
|
+
|
|
307
|
+
```vue
|
|
308
|
+
<template>
|
|
309
|
+
<view>
|
|
310
|
+
<uv-calendar ref="calendar" mode="multiple" :defaultDate="defaultDateMultiple" @confirm="confirm"></uv-calendar>
|
|
311
|
+
<button @click="open">打开</button>
|
|
312
|
+
</view>
|
|
313
|
+
</template>
|
|
314
|
+
<script setup>
|
|
315
|
+
import { ref } from 'vue';
|
|
316
|
+
|
|
317
|
+
const d = new Date();
|
|
318
|
+
const year = d.getFullYear();
|
|
319
|
+
let month = d.getMonth() + 1;
|
|
320
|
+
month = month < 10 ? `0${month}` : month;
|
|
321
|
+
const date = d.getDate();
|
|
322
|
+
const calendar = ref(null);
|
|
323
|
+
const defaultDateMultiple = ref([`${year}-${month}-${date}`, `${year}-${month}-${date + 1}`, `${year}-${month}-${date + 2}`]);
|
|
324
|
+
function open() {
|
|
325
|
+
calendar.value.open();
|
|
326
|
+
}
|
|
327
|
+
function confirm(e) {
|
|
328
|
+
console.log('日历选择:', e);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
</script>
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### 完整示例
|
|
335
|
+
|
|
336
|
+
::: tip 完整示例下载地址
|
|
337
|
+
|
|
338
|
+
[https://ext.dcloud.net.cn/plugin?name=uv-ui](https://ext.dcloud.net.cn/plugin?name=uv-ui)
|
|
339
|
+
|
|
340
|
+
:::
|
|
341
|
+
|
|
342
|
+
### API
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
### Calendar Props
|
|
346
|
+
|
|
347
|
+
| 参数 | 说明 | 类型 | 默认值 | 可选值 |
|
|
348
|
+
| :- | :- | :- | :- | :- |
|
|
349
|
+
| title | 标题内容 | String | 日期选择 | - |
|
|
350
|
+
| showTitle | 是否显示标题 | Boolean | true | true | false |
|
|
351
|
+
| showSubtitle | 是否显示副标题 | Boolean | true | true | false |
|
|
352
|
+
| mode | 日期类型选择 | String | single | multiple-可以选择多个日期,range-选择日期范围(多个月需配合`monthNum`属性使用) |
|
|
353
|
+
| startText | mode=range时,第一个日期底部的提示文字 | String | 开始 | - |
|
|
354
|
+
| endText | mode=range时,最后一个日期底部的提示文字 | String | 结束 | - |
|
|
355
|
+
| customList | 自定义列表 | Array | [] | [] |
|
|
356
|
+
| color | 主题色,对底部按钮和选中日期有效 | String | #3c9cff | - |
|
|
357
|
+
| minDate | 最小的可选日期 | Number | String | 0 | - |
|
|
358
|
+
| maxDate | 最大可选日期 | Number | String | 0 | - |
|
|
359
|
+
| defaultDate | 默认选中的日期,mode为multiple或range是必须为数组格式 | Array | String | Date | null | - |
|
|
360
|
+
| maxCount | mode=multiple时,最多可选多少个日期 | Number | String | Number.MAX_SAFE_INTEGER | - |
|
|
361
|
+
| rowHeight | 日期行高 | Number |String | 56 | - |
|
|
362
|
+
| showLunar | 是否显示农历 | Boolean | false | true | false |
|
|
363
|
+
| showMark | 是否显示月份背景色 | Boolean | true | true | false |
|
|
364
|
+
| confirmText | 确定按钮的文字 | String | 确定 | - |
|
|
365
|
+
| confirmDisabledText | 确认按钮处于禁用状态时的文字 | String | 确定 | - |
|
|
366
|
+
| closeOnClickOverlay | 是否允许点击遮罩关闭日历 (注意:关闭事件需要自行处理,只会在开启closeOnClickOverlay后点击遮罩层执行close回调) | Boolean | false | true | false |
|
|
367
|
+
| closeOnClickConfirm | 是否允许点击确认按钮关闭日历,设置为`false`不影响`confirm`事件返回 | Boolean | true | true | false |
|
|
368
|
+
| readonly | 是否为只读状态,只读状态下禁止选择日期 | Boolean | false | true | false |
|
|
369
|
+
| maxRange | 日期区间最多可选天数,默认无限制,mode = range时有效 | Number | String | 无限制 | - |
|
|
370
|
+
| rangePrompt | 范围选择超过最多可选天数时的提示文案,mode = range时有效 | String | null | 选择天数不能超过 xx 天 | - |
|
|
371
|
+
| showRangePrompt | 范围选择超过最多可选天数时,是否展示提示文案,mode = range时有效 | Boolean | true | true | false |
|
|
372
|
+
| allowSameDay | 是否允许日期范围的起止时间为同一天,mode = range时有效 | Boolean | false | true | false |
|
|
373
|
+
| round | 圆角值,默认无圆角 | String | Number | 0 | - |
|
|
374
|
+
| monthNum | 最大展示的月份数量 | String | Number | 3 | - |
|
|
375
|
+
|
|
376
|
+
### Calendar Methods
|
|
377
|
+
| 方法名 | 说明 |
|
|
378
|
+
| :- | :- |
|
|
379
|
+
| open | 弹出日历组件 | -|
|
|
380
|
+
| close | 关闭日历组件,可能在`:confirmClosePopup = "false"`用到 | -|
|
|
381
|
+
| setFormatter | 日期格式化函数,使用方法及参数配置请参考[自定义文案](/components/calendar.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%87%E6%A1%88) |
|
|
382
|
+
|
|
383
|
+
### Calendar Events
|
|
384
|
+
|
|
385
|
+
| 事件名 | 说明 | 回调参数 |
|
|
386
|
+
| :- | :- | :- |
|
|
387
|
+
| @confirm | 日期选择完成后触发,若`show-confirm`为`true`,则点击确认按钮后触发 | 选择日期相关的返回参数 |
|
|
388
|
+
| @close | 日历关闭时触发 | 可定义页面关闭时的回调事件 |
|
|
389
|
+
| @change | 点击日期触发 | {day:'点击的日期',selected:'选中的日期'} |
|
|
390
|
+
|
|
391
|
+
<style scoped>
|
|
392
|
+
h3[id=calendar-methods] + table thead tr th:nth-child(2){
|
|
393
|
+
width: 70%;
|
|
394
|
+
}
|
|
395
|
+
h3[id=calendar-events] + table thead tr th:nth-child(2){
|
|
396
|
+
width: 50%;
|
|
397
|
+
}
|
|
398
|
+
</style>
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
## Calendars 新版日历(推荐) <to-api/>
|
|
2
|
+
|
|
3
|
+
<demo-model url="/pages/componentsB/calendars/calendars"></demo-model>
|
|
4
|
+
|
|
5
|
+
::: tip ✈
|
|
6
|
+
|
|
7
|
+
**组件名:uv-calendars**
|
|
8
|
+
|
|
9
|
+
[点击下载&安装](https://ext.dcloud.net.cn/plugin?name=uv-calendars)
|
|
10
|
+
|
|
11
|
+
:::
|
|
12
|
+
|
|
13
|
+
为了解决老版本`uv-calendar`性能问题,特别是对日期选择范围有很大限制,体验不友好等缺点。于是有了新版日历组件。
|
|
14
|
+
|
|
15
|
+
新版本`uv-calendars`,不仅拥有老版本的所有功能,还增加了更加适用的插入页面等强大功能,且更加简洁。查看日期、选择单个或多个或任意范围日期,打点操作,自定义文案,自定义主题等强大功能。
|
|
16
|
+
|
|
17
|
+
常用场景:酒店日期预订、火车机票选择购买日期、上下班打卡等。
|
|
18
|
+
|
|
19
|
+
### 平台兼容性
|
|
20
|
+
|
|
21
|
+
|App(vue)|App(nvue)|H5|小程序|VUE2|VUE3|
|
|
22
|
+
|:-:|:-:|:-:|:-:|:-:|:-:|
|
|
23
|
+
|√|√|√|√|√|√|
|
|
24
|
+
|
|
25
|
+
:::warning 注意事项
|
|
26
|
+
|
|
27
|
+
> 为了避免错误使用,给大家带来不好的开发体验,请在使用组件前仔细阅读下面的注意事项,可以帮你避免一些错误。
|
|
28
|
+
1. 本组件农历转换使用的js是 [@1900-2100区间内的公历、农历互转](https://github.com/jjonline/calendar.js)
|
|
29
|
+
2. `date`属性传入的应该是一个 String ,如: 2023-08-03 ,而不是 new Date()
|
|
30
|
+
3. 通过 `insert` 属性来确定当前的事件是 @change 还是 @confirm 。理应合并为一个事件,但是为了区分模式,现使用两个事件,这里需要注意
|
|
31
|
+
4. 弹窗模式下无法阻止后面的元素滚动,如有需要阻止,请在弹窗弹出后,手动设置滚动元素为不可滚动,参考[uv-popup等组件怎么禁止滚动穿透
|
|
32
|
+
](https://www.uvui.cn/components/problem.html#%E5%9B%9B%E3%80%81uv-popup%E7%AD%89%E7%BB%84%E4%BB%B6%E6%80%8E%E4%B9%88%E7%A6%81%E6%AD%A2%E6%BB%9A%E5%8A%A8%E7%A9%BF%E9%80%8F)
|
|
33
|
+
:::
|
|
34
|
+
|
|
35
|
+
### 基本使用
|
|
36
|
+
|
|
37
|
+
通过 `ref` 调用 `open()` 方法打开日历
|
|
38
|
+
|
|
39
|
+
```vue
|
|
40
|
+
<template>
|
|
41
|
+
<view>
|
|
42
|
+
<uv-calendars ref="calendars" @confirm="confirm" />
|
|
43
|
+
<button @click="open">打开日历</button>
|
|
44
|
+
</view>
|
|
45
|
+
</template>
|
|
46
|
+
<script setup>
|
|
47
|
+
import { ref } from "vue";
|
|
48
|
+
const calendars = ref(null);
|
|
49
|
+
function open() {
|
|
50
|
+
calendars.value.open();
|
|
51
|
+
}
|
|
52
|
+
function confirm(e) {
|
|
53
|
+
console.log(e);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
</script>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 插入模式
|
|
60
|
+
|
|
61
|
+
通过设置 `insert` 属性为 `true`
|
|
62
|
+
|
|
63
|
+
```vue
|
|
64
|
+
<template>
|
|
65
|
+
<view>
|
|
66
|
+
<uv-calendars insert @change="change" />
|
|
67
|
+
</view>
|
|
68
|
+
</template>
|
|
69
|
+
<script setup>
|
|
70
|
+
function change(e) {
|
|
71
|
+
console.log(e);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
</script>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 多个日期模式
|
|
78
|
+
|
|
79
|
+
- 通过设置 `mode` 属性为 `multiple`
|
|
80
|
+
- 该模式的默认值可通过 `date` 设置,eg:`['2023-08-26','2023-08-27','2023-08-28']`
|
|
81
|
+
|
|
82
|
+
```vue
|
|
83
|
+
<template>
|
|
84
|
+
<view>
|
|
85
|
+
<uv-calendars ref="calendars" mode="multiple" @confirm="confirm" />
|
|
86
|
+
<button @click="open">打开日历</button>
|
|
87
|
+
</view>
|
|
88
|
+
</template>
|
|
89
|
+
<script setup>
|
|
90
|
+
import { ref } from "vue";
|
|
91
|
+
const calendars = ref(null);
|
|
92
|
+
function open() {
|
|
93
|
+
calendars.value.open();
|
|
94
|
+
}
|
|
95
|
+
function confirm(e) {
|
|
96
|
+
console.log(e);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
</script>
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### 日期范围模式
|
|
104
|
+
|
|
105
|
+
- 通过设置 `mode` 属性为 `range`
|
|
106
|
+
- 该模式的默认值可通过 `date` 设置,eg:`['2023-08-26','2023-08-29']`
|
|
107
|
+
|
|
108
|
+
```vue
|
|
109
|
+
<template>
|
|
110
|
+
<view>
|
|
111
|
+
<uv-calendars ref="calendars" mode="range" @confirm="confirm" />
|
|
112
|
+
<button @click="open">打开日历</button>
|
|
113
|
+
</view>
|
|
114
|
+
</template>
|
|
115
|
+
<script setup>
|
|
116
|
+
import { ref } from "vue";
|
|
117
|
+
const calendars = ref(null);
|
|
118
|
+
function open() {
|
|
119
|
+
calendars.value.open();
|
|
120
|
+
}
|
|
121
|
+
function confirm(e) {
|
|
122
|
+
console.log(e);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
</script>
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### 自定义主题颜色
|
|
130
|
+
|
|
131
|
+
通过设置 `color` 属性,更改组件主题色,该值建议传16进制颜色值,如:`#ff0000`。
|
|
132
|
+
|
|
133
|
+
```vue
|
|
134
|
+
<template>
|
|
135
|
+
<view>
|
|
136
|
+
<uv-calendars
|
|
137
|
+
ref="calendars"
|
|
138
|
+
mode="range"
|
|
139
|
+
color="#ff0000"
|
|
140
|
+
:date="['2023-08-08','2023-08-27']"
|
|
141
|
+
@confirm="confirm" />
|
|
142
|
+
<button @click="open">打开日历</button>
|
|
143
|
+
</view>
|
|
144
|
+
</template>
|
|
145
|
+
<script setup>
|
|
146
|
+
import { ref } from "vue";
|
|
147
|
+
const calendars = ref(null);
|
|
148
|
+
function open() {
|
|
149
|
+
calendars.value.open();
|
|
150
|
+
}
|
|
151
|
+
function confirm(e) {
|
|
152
|
+
console.log(e);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
</script>
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### 自定义文案
|
|
160
|
+
|
|
161
|
+
通过设置 `selected` 属性,该属性是一个json数组,具体参数参考[selected-options](/components/calendars.html#selected-options)。
|
|
162
|
+
|
|
163
|
+
```vue
|
|
164
|
+
<template>
|
|
165
|
+
<view>
|
|
166
|
+
<uv-calendars
|
|
167
|
+
ref="calendars"
|
|
168
|
+
mode="range"
|
|
169
|
+
title="选择日期"
|
|
170
|
+
start-text="住店"
|
|
171
|
+
end-text="离店"
|
|
172
|
+
:selected="selected"
|
|
173
|
+
@confirm="confirm"
|
|
174
|
+
/>
|
|
175
|
+
<button @click="open">打开日历</button>
|
|
176
|
+
</view>
|
|
177
|
+
</template>
|
|
178
|
+
<script setup>
|
|
179
|
+
import { ref } from "vue";
|
|
180
|
+
const selected = ref([{
|
|
181
|
+
date: `${year}-${month}-02`,
|
|
182
|
+
info: '签到',
|
|
183
|
+
badge: true,
|
|
184
|
+
infoColor: '#ff0000'
|
|
185
|
+
}, {
|
|
186
|
+
date: `${year}-${month}-06`,
|
|
187
|
+
info: '余10',
|
|
188
|
+
infoColor: '#19be6b',
|
|
189
|
+
topinfo: '¥100',
|
|
190
|
+
topinfoColor: '#19be6b'
|
|
191
|
+
}]);
|
|
192
|
+
const calendars = ref(null);
|
|
193
|
+
function open() {
|
|
194
|
+
calendars.value.open();
|
|
195
|
+
}
|
|
196
|
+
function confirm(e) {
|
|
197
|
+
console.log(e);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
</script>
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### 完整示例
|
|
204
|
+
|
|
205
|
+
::: tip 完整示例下载地址
|
|
206
|
+
|
|
207
|
+
[https://ext.dcloud.net.cn/plugin?name=uv-ui](https://ext.dcloud.net.cn/plugin?name=uv-ui)
|
|
208
|
+
|
|
209
|
+
:::
|
|
210
|
+
|
|
211
|
+
### API
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
### Calendars Props
|
|
215
|
+
|
|
216
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
217
|
+
|:-|:-|:-|:-|
|
|
218
|
+
| date | String | 今天 | 自定义默认选中日期,不传默认为今天。mode="multiple"或mode="range"时,该值为数组,例 `['2023-08-26','2023-08-29']`。mode不传或字符串,例如`2023-08-26`,即为单日期模式 |
|
|
219
|
+
| lunar | Boolean | false | 显示农历 |
|
|
220
|
+
| mode `1.0.7` | String | - | 日期类型选择,可选值:不填 | multiple | range,分别为单日期选择,多日期选择,范围选择 |
|
|
221
|
+
| insert | Boolean | false | 插入模式,可选值,ture:插入模式;false:弹窗模式;默认为插入模式 |
|
|
222
|
+
| clearDate | Boolean | true | 弹窗模式是否清空上次选择内容 |
|
|
223
|
+
| selected | Array | - | 打点,期待格式[{date: '2019-06-27', info: '签到', disable: false}],更多设置参考[自定义文案](/components/calendars.html#自定义文案),更多参数参考[Selected Options](/components/calendars.html#selected-options) |
|
|
224
|
+
| startDate | String | - | 限制日期选择范围-开始日期,格式如:"2023-01-01",禁用该日期之前的日期 |
|
|
225
|
+
| endDate | String | - | 限制日期选择范围-结束日期,格式如:"2023-02-01",禁用该日期之后的日期 |
|
|
226
|
+
| showMonth | Boolean | true | 是否显示月份为背景 |
|
|
227
|
+
| round | String|Number | 8px | 弹窗模式,圆角 |
|
|
228
|
+
| color | String | #3c9cff | 主题颜色,建议16进制颜色(如:`#ff0000`),否则range模式下区间颜色会显示异常 |
|
|
229
|
+
| confirmColor | String | #3c9cff | 确认按钮颜色 |
|
|
230
|
+
| cancelColor | String | #909193 | 取消按钮颜色 |
|
|
231
|
+
| closeOnClickOverlay | Boolean | true | 点击遮罩是否关闭弹窗 |
|
|
232
|
+
| startText | String | 开始 | range为true时,第一个日期底部的提示文字 |
|
|
233
|
+
| endText | String | 结束 | range为true时,最后一个日期底部的提示文字 |
|
|
234
|
+
| allowSameDay `1.0.11`| Boolean | false | 是否允许日期范围的起止时间为同一天,mode = range时有效 |
|
|
235
|
+
| readonly `1.0.15` | Boolean | false | 是否为只读状态,只读状态下禁止选择日期 |
|
|
236
|
+
|
|
237
|
+
#### Selected Options
|
|
238
|
+
|
|
239
|
+
示例参考[自定义文案](/components/calendars.html#自定义文案)
|
|
240
|
+
|
|
241
|
+
| 属性名 | 说明 |
|
|
242
|
+
|:-|:-|
|
|
243
|
+
| date | 日期,格式:YYYY-mm-dd |
|
|
244
|
+
| info | 底部文案 |
|
|
245
|
+
| infoColor | 底部文案颜色 |
|
|
246
|
+
| topinfo | 头部文案 |
|
|
247
|
+
| topinfoColor | 头部文案颜色 |
|
|
248
|
+
| badge | 是否显示右上角红点 |
|
|
249
|
+
| disable | 是否禁止点击该日期 |
|
|
250
|
+
|
|
251
|
+
### Calendars Methods
|
|
252
|
+
| 方法名 | 说明 |
|
|
253
|
+
| :- | :- |
|
|
254
|
+
| open | `insert` 为 `false` 时,调用此方法弹出日历组件 |
|
|
255
|
+
|
|
256
|
+
### Calendars Events
|
|
257
|
+
|
|
258
|
+
| 事件名 | 说明 | 返回参数 |
|
|
259
|
+
| :- | :- | :- |
|
|
260
|
+
| @confirm | 点击确定按钮触发 | 返回日期相关参数,fulldate - 单日期;multiple - 多日期;range - 范围选择;其他相关参数 |
|
|
261
|
+
| @close | 关闭日历时触发 | - |
|
|
262
|
+
| @change | 点击日期时触发 | 返回日期相关参数,fulldate - 单日期;multiple - 多日期;range - 范围选择;其他相关参数;insert为true时生效 |
|
|
263
|
+
| @monthSwitch | 选择年月确认时触发 | `{ year: 2030, month: '08' }` |
|
|
264
|
+
|
|
265
|
+
:::warning 注意
|
|
266
|
+
示例依赖了 `uv-popup` `uv-toolbar` `uv-ui` 等多个组件,直接拷贝示例代码将无法正常运行。
|
|
267
|
+
请到 [组件下载页面](https://ext.dcloud.net.cn/plugin?name=uv-calendars) ,在页面右侧选择 使用 `HBuilderX导入示例项目` 。
|
|
268
|
+
:::
|
|
269
|
+
|
|
270
|
+
<style scoped>
|
|
271
|
+
h3[id=calendars-props] + table thead tr th:nth-child(1),
|
|
272
|
+
h3[id=calendars-props] + table thead tr th:nth-child(2),
|
|
273
|
+
h3[id=calendars-props] + table thead tr th:nth-child(3)
|
|
274
|
+
{
|
|
275
|
+
width: 18%;
|
|
276
|
+
}
|
|
277
|
+
h3[id=calendars-methods] + table thead tr th:nth-child(2)
|
|
278
|
+
{
|
|
279
|
+
width: 70%;
|
|
280
|
+
}
|
|
281
|
+
h3[id=calendars-events] + table thead tr th:nth-child(2),
|
|
282
|
+
h3[id=calendars-events] + table thead tr th:nth-child(3)
|
|
283
|
+
{
|
|
284
|
+
width: 40%;
|
|
285
|
+
}
|
|
286
|
+
h4[id=selected-options] + p + table {
|
|
287
|
+
width: 50%;
|
|
288
|
+
}
|
|
289
|
+
h4[id=selected-options] + p + table thead tr th:nth-child(1),
|
|
290
|
+
h4[id=selected-options] + p + table thead tr th:nth-child(2)
|
|
291
|
+
{
|
|
292
|
+
width: 50%;
|
|
293
|
+
}
|
|
294
|
+
</style>
|