From 603e437bc23dc7e75855682a69dbc50716f0076a Mon Sep 17 00:00:00 2001 From: 梁灏 Date: Tue, 27 Dec 2016 15:15:29 +0800 Subject: [PATCH] update TimePicker --- src/components/date-picker/panel/time.vue | 7 ++++--- src/components/date-picker/util.js | 84 +----------------------------------------------------------------------------------- test/routers/date.vue | 8 +++++++- 3 files changed, 12 insertions(+), 87 deletions(-) diff --git a/src/components/date-picker/panel/time.vue b/src/components/date-picker/panel/time.vue index 6af9c7c..1b1ad60 100644 --- a/src/components/date-picker/panel/time.vue +++ b/src/components/date-picker/panel/time.vue @@ -58,17 +58,17 @@ if (!newVal) return; newVal = new Date(newVal); if (!isNaN(newVal)) { + this.date = newVal; this.handleChange({ hours: newVal.getHours(), minutes: newVal.getMinutes(), seconds: newVal.getSeconds() - }); -// this.$nextTick(() => this.scrollTop()); + }, false); } } }, methods: { - handleChange (date) { + handleChange (date, emit = true) { if (date.hours !== undefined) { this.date.setHours(date.hours); this.hours = this.date.getHours(); @@ -81,6 +81,7 @@ this.date.setSeconds(date.seconds); this.seconds = this.date.getSeconds(); } + if (emit) this.$emit('on-pick', this.date, true); } } }; diff --git a/src/components/date-picker/util.js b/src/components/date-picker/util.js index fe43963..29ee8d9 100644 --- a/src/components/date-picker/util.js +++ b/src/components/date-picker/util.js @@ -1,13 +1,5 @@ import dateUtil from '../../utils/date'; -const newArray = function(start, end) { - let result = []; - for (let i = start; i <= end; i++) { - result.push(i); - } - return result; -}; - export const toDate = function(date) { date = new Date(date); if (isNaN(date.getTime())) return null; @@ -46,32 +38,6 @@ export const getFirstDayOfMonth = function(date) { return temp.getDay(); }; -export const DAY_DURATION = 86400000; - -export const getStartDateOfMonth = function(year, month) { - const result = new Date(year, month, 1); - const day = result.getDay(); - - if (day === 0) { - result.setTime(result.getTime() - DAY_DURATION * 7); - } else { - result.setTime(result.getTime() - DAY_DURATION * day); - } - - return result; -}; - -export const getWeekNumber = function(src) { - const date = new Date(src.getTime()); - date.setHours(0, 0, 0, 0); - // Thursday in current week decides the year. - date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7); - // January 4 is always in week 1. - const week1 = new Date(date.getFullYear(), 0, 4); - // Adjust to Thursday in week 1 and count number of weeks from date to week 1. - return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 - 3 + (week1.getDay() + 6) % 7) / 7); -}; - export const prevMonth = function(src) { const year = src.getFullYear(); const month = src.getMonth(); @@ -108,52 +74,4 @@ export const nextMonth = function(src) { src.setFullYear(newYear); return new Date(src.getTime()); -}; - -export const getRangeHours = function(ranges) { - const hours = []; - let disabledHours = []; - - (ranges || []).forEach(range => { - const value = range.map(date => date.getHours()); - - disabledHours = disabledHours.concat(newArray(value[0], value[1])); - }); - - if (disabledHours.length) { - for (let i = 0; i < 24; i++) { - hours[i] = disabledHours.indexOf(i) === -1; - } - } else { - for (let i = 0; i < 24; i++) { - hours[i] = false; - } - } - - return hours; -}; - -export const limitRange = function(date, ranges) { - if (!ranges || !ranges.length) return date; - - const len = ranges.length; - const format = 'HH:mm:ss'; - - date = dateUtil.parse(dateUtil.format(date, format), format); - for (let i = 0; i < len; i++) { - const range = ranges[i]; - if (date >= range[0] && date <= range[1]) { - return date; - } - } - - let maxDate = ranges[0][0]; - let minDate = ranges[0][0]; - - ranges.forEach(range => { - minDate = new Date(Math.min(range[0], minDate)); - maxDate = new Date(Math.max(range[1], maxDate)); - }); - - return date < minDate ? minDate : maxDate; -}; +}; \ No newline at end of file diff --git a/test/routers/date.vue b/test/routers/date.vue index f5490c9..613b204 100644 --- a/test/routers/date.vue +++ b/test/routers/date.vue @@ -12,7 +12,13 @@ - + -- libgit2 0.21.4