From a6f2d4e6686fc5acc517d9202825f45cd1ddb15b Mon Sep 17 00:00:00 2001 From: Lindy <33708359+Lindysen@users.noreply.github.com> Date: Fri, 10 Apr 2020 23:02:08 +0800 Subject: [PATCH] feat(Calendar): add cancel event (#2990) * feat(Calendar): add cancel event * feat(Calendar): rename cancel event --- example/pages/calendar/index.js | 4 ++++ example/pages/calendar/index.wxml | 1 + packages/calendar/README.md | 1 + packages/calendar/index.ts | 10 +++++++++- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/example/pages/calendar/index.js b/example/pages/calendar/index.js index 3becd5b0..d66619cd 100644 --- a/example/pages/calendar/index.js +++ b/example/pages/calendar/index.js @@ -48,6 +48,10 @@ Page({ console.log(event); }, + onUnselect(event) { + console.log(event); + }, + onClose() { this.setData({ showCalendar: false }); }, diff --git a/example/pages/calendar/index.wxml b/example/pages/calendar/index.wxml index 1aeee9d9..c4a5ac99 100644 --- a/example/pages/calendar/index.wxml +++ b/example/pages/calendar/index.wxml @@ -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" diff --git a/packages/calendar/README.md b/packages/calendar/README.md index c55b9973..8195716e 100644 --- a/packages/calendar/README.md +++ b/packages/calendar/README.md @@ -308,6 +308,7 @@ Page({ | 事件名 | 说明 | 回调参数 | | ------- | ------------------------------------------------------------------ | ----------------------- | | select | 点击任意日期时触发 | _value: Date \| Date[]_ | +| unselect | 当 Canlendar 的 `type` 为 `multiple` 时,点击已选中的日期时触发 | _value: Date_ | | confirm | 日期选择完成后触发,若`show-confirm`为`true`,则点击确认按钮后触发 | _value: Date \| Date[]_ | | open | 打开弹出层时触发 | - | | close | 关闭弹出层时触发 | - | diff --git a/packages/calendar/index.ts b/packages/calendar/index.ts index d71bd2eb..30ad9a45 100644 --- a/packages/calendar/index.ts +++ b/packages/calendar/index.ts @@ -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);