From 344131a7af7e70a30eba662aea0f77cb03d8d21e Mon Sep 17 00:00:00 2001 From: 梁灏 Date: Thu, 15 Dec 2016 23:41:06 +0800 Subject: [PATCH] update DatePicker --- src/components/date-picker/base/year-table.vue | 1 + src/components/date-picker/panel/date.vue | 2 +- src/components/date-picker/picker.vue | 7 ++++++- test/routers/date.vue | 4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/components/date-picker/base/year-table.vue b/src/components/date-picker/base/year-table.vue index 47b551e..490d0d7 100644 --- a/src/components/date-picker/base/year-table.vue +++ b/src/components/date-picker/base/year-table.vue @@ -67,6 +67,7 @@ if (target.tagName === 'EM') { const cell = this.cells[parseInt(event.target.getAttribute('index'))]; if (cell.disabled) return; + this.$emit('on-pick', cell.text); } } diff --git a/src/components/date-picker/panel/date.vue b/src/components/date-picker/panel/date.vue index c8f24d9..818accd 100644 --- a/src/components/date-picker/panel/date.vue +++ b/src/components/date-picker/panel/date.vue @@ -178,7 +178,7 @@ this.date.setFullYear(year); if (this.selectionMode === 'year') { - this.$emit('on-pick', new Date(year)); + this.$emit('on-pick', new Date(year, 0, 1)); } else { this.currentView = 'month'; } diff --git a/src/components/date-picker/picker.vue b/src/components/date-picker/picker.vue index 6da5b12..3e734ea 100644 --- a/src/components/date-picker/picker.vue +++ b/src/components/date-picker/picker.vue @@ -269,6 +269,8 @@ this.visualValue = correctValue; event.target.value = correctValue; this.internalValue = correctDate; + + if (correctValue !== oldValue) this.emitChange(correctDate); }, handleInputMouseenter () { if (this.readonly || this.disabled) return; @@ -298,7 +300,7 @@ } this.picker.$on('on-pick', (date, visible = false) => { - this.$emit('on-change', formatDate(date, this.format || DEFAULT_FORMATS[this.type])); + this.emitChange(date); this.value = date; this.visible = visible; this.picker.value = date; @@ -313,6 +315,9 @@ this.picker.value = this.internalValue; } this.picker.resetView && this.picker.resetView(); + }, + emitChange (date) { + this.$emit('on-change', formatDate(date, this.format || DEFAULT_FORMATS[this.type])); } }, watch: { diff --git a/test/routers/date.vue b/test/routers/date.vue index eaf2ebd..3313f1a 100644 --- a/test/routers/date.vue +++ b/test/routers/date.vue @@ -33,13 +33,13 @@ // return time && time.valueOf() < Date.now(); } }, - format: 'yyyy/MM/dd' + format: 'yyyy年MM月dd日' } }, computed: {}, methods: { change (date) { -// console.log(date) + console.log(date) }, change2 (s) { // console.log(s) -- libgit2 0.21.4