feat(Calendar): add over-range event (#4212)

* feat(Calendar): add over-range event

- forbid range-prompt toast when range-prompt is null
- emit over-range event when dateRange > maxRange

* docs(Calendar): doc typo

* feat(Calendar): add show-range-prompt prop

* docs(calendar): doc modify
This commit is contained in:
nemo-shen 2021-05-19 09:22:22 +08:00 committed by GitHub
parent e835808a39
commit 0d08ec1489
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 6 deletions

View File

@ -294,7 +294,8 @@ Page({
| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| max-range | 日期区间最多可选天数,默认无限制 | _number \| string_ | - |
| range-prompt | 范围选择超过最多可选天数时的提示文案 | _string_ | `选择天数不能超过 xx 天` |
| range-prompt | 范围选择超过最多可选天数时的提示文案 | _string \| null_ | `选择天数不能超过 xx 天` |
| show-range-prompt | 范围选择超过最多可选天数时,是否展示提示文案 | _boolean_ | `true` |
| allow-same-day | 是否允许日期范围的起止时间为同一天 | _boolean_ | `false` |
### Day 数据结构
@ -320,6 +321,7 @@ Page({
| close | 关闭弹出层时触发 | - |
| opened | 打开弹出层且动画结束后触发 | - |
| closed | 关闭弹出层且动画结束后触发 | - |
| over-range | 范围选择超过最多可选天数时触发 | - |
### Slots

View File

@ -36,6 +36,10 @@ VantComponent({
value: '确定',
},
rangePrompt: String,
showRangePrompt: {
type: Boolean,
value: true,
},
defaultDate: {
type: null,
observer(val) {
@ -308,13 +312,18 @@ VantComponent({
},
checkRange(date) {
const { maxRange, rangePrompt } = this.data;
const { maxRange, rangePrompt, showRangePrompt } = this.data;
if (maxRange && calcDateNum(date) > maxRange) {
Toast({
context: this,
message: rangePrompt || `选择天数不能超过 ${maxRange}`,
});
if (showRangePrompt) {
Toast({
duration: 0,
context: this,
message: rangePrompt || `选择天数不能超过 ${maxRange}`,
});
}
this.$emit('over-range');
return false;
}