feat(Calendar): add cancel event (#2990)

* feat(Calendar): add cancel event

* feat(Calendar): rename  cancel event
This commit is contained in:
Lindy 2020-04-10 23:02:08 +08:00 committed by GitHub
parent 0bad228027
commit a6f2d4e668
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 1 deletions

View File

@ -48,6 +48,10 @@ Page({
console.log(event);
},
onUnselect(event) {
console.log(event);
},
onClose() {
this.setData({ showCalendar: false });
},

View File

@ -131,6 +131,7 @@
confirm-disabled-text="{{ confirmDisabledText }}"
bind:confirm="onConfirm"
bind:select="onSelect"
bind:unselect="onUnselect"
bind:open="onOpen"
bind:opened="onOpened"
bind:close="onClose"

View File

@ -308,6 +308,7 @@ Page({
| 事件名 | 说明 | 回调参数 |
| ------- | ------------------------------------------------------------------ | ----------------------- |
| select | 点击任意日期时触发 | _value: Date \| Date[]_ |
| unselect | 当 Canlendar 的 `type``multiple` 时,点击已选中的日期时触发 | _value: Date_ |
| confirm | 日期选择完成后触发,若`show-confirm``true`,则点击确认按钮后触发 | _value: Date \| Date[]_ |
| open | 打开弹出层时触发 | - |
| close | 关闭弹出层时触发 | - |

View File

@ -247,8 +247,9 @@ VantComponent({
});
if (selected) {
currentDate.splice(selectedIndex, 1);
const cancelDate = currentDate.splice(selectedIndex, 1);
this.setData({ currentDate });
this.unselect(cancelDate);
} else {
this.select([...currentDate, date]);
}
@ -257,6 +258,13 @@ VantComponent({
}
},
unselect(dateArray) {
const date = dateArray[0];
if (date) {
this.$emit('unselect', copyDates(date));
}
},
select(date, complete) {
const getTime = (date: Date | number) =>
(date instanceof Date ? date.getTime() : date);