From 5cdba7be8c4c2eee79b8409396cce229cc4d0dbb Mon Sep 17 00:00:00 2001 From: mxie <15623530290@163.com> Date: Fri, 5 Oct 2018 08:26:58 +0800 Subject: [PATCH] feat: add panel-change event --- README.md | 5 +++++ README.zh-CN.md | 4 ++++ src/calendar.vue | 38 ++++++++++++++++++++++++-------------- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 17ebba76..035f9cdc 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,11 @@ export default { | confirm | When click 'OK' button | the currentValue | | clear | When click 'clear' button | | | input-error | When user type a invalid Date| the input text | +| panel-change | When change the panel | panel, oldPanel | + +#### panel value +`['NONE', 'DATE', 'YEAR', 'MONTH', 'TIME']` + ### Slots diff --git a/README.zh-CN.md b/README.zh-CN.md index 79a86cf9..e0269ad1 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -154,6 +154,10 @@ export default { | input | 日期改变的时候触发 | 选择的日期 | | confirm | 点击确认按钮触发的事件 | 选择的日期 | | input-error | 当用户输入的值无效时候触发 | 用户输入的字符串 | +| panel-change | 切换面板时触发 | 当前面板,过去的面板| + +#### panel value +`['NONE', 'DATE', 'YEAR', 'MONTH', 'TIME']` ## 许可证 diff --git a/src/calendar.vue b/src/calendar.vue index d8673583..9a65157c 100644 --- a/src/calendar.vue +++ b/src/calendar.vue @@ -146,7 +146,7 @@ export default { const calendarMonth = now.getMonth() const firstYear = Math.floor(calendarYear / 10) * 10 return { - panel: 'DATE', + panel: 'NONE', dates: [], calendarMonth, calendarYear, @@ -198,12 +198,12 @@ export default { handler: 'init' }, panel: { - immediate: true, handler: 'handelPanelChange' } }, methods: { - handelPanelChange (panel) { + handelPanelChange (panel, oldPanel) { + this.$parent.$emit('panel-change', panel, oldPanel) if (panel === 'YEAR') { this.firstYear = Math.floor(this.calendarYear / 10) * 10 } else if (panel === 'TIME') { @@ -216,16 +216,20 @@ export default { }) } }, - init () { - const type = this.type - if (type === 'month') { - this.panel = 'MONTH' - } else if (type === 'year') { - this.panel = 'YEAR' - } else if (type === 'time') { - this.panel = 'TIME' + init (val) { + if (val) { + const type = this.type + if (type === 'month') { + this.showPanelMonth() + } else if (type === 'year') { + this.showPanelYear() + } else if (type === 'time') { + this.showPanelTime() + } else { + this.showPanelDate() + } } else { - this.panel = 'DATE' + this.showPanelNone() } this.updateNow(this.value) }, @@ -303,8 +307,8 @@ export default { time = new Date(this.startAt) } } - this.$emit('select-time', time) - this.panel = 'TIME' + this.selectTime(time) + this.showPanelTime() return } this.$emit('select-date', date) @@ -380,6 +384,12 @@ export default { changePanelYears (flag) { this.firstYear = this.firstYear + flag * 10 }, + showPanelNone () { + this.panel = 'NONE' + }, + showPanelTime () { + this.panel = 'TIME' + }, showPanelDate () { this.panel = 'DATE' },