diff --git a/src/components/date-picker/base/time-spinner.vue b/src/components/date-picker/base/time-spinner.vue index 185f2b1..c6ab25a 100644 --- a/src/components/date-picker/base/time-spinner.vue +++ b/src/components/date-picker/base/time-spinner.vue @@ -27,15 +27,15 @@ mixins: [Options], props: { hours: { - type: Number, + type: [Number, String], default: 0 }, minutes: { - type: Number, + type: [Number, String], default: 0 }, seconds: { - type: Number, + type: [Number, String], default: 0 }, showSeconds: { diff --git a/src/components/date-picker/panel/time.vue b/src/components/date-picker/panel/time.vue index 1b1ad60..1bfd029 100644 --- a/src/components/date-picker/panel/time.vue +++ b/src/components/date-picker/panel/time.vue @@ -26,6 +26,8 @@ import Mixin from './mixin'; + import { initTimeDate } from '../util'; + const prefixCls = 'ivu-picker-panel'; const timePrefixCls = 'ivu-time-picker'; @@ -37,11 +39,11 @@ prefixCls: prefixCls, timePrefixCls: timePrefixCls, format: 'HH:mm:ss', - date: new Date(), + date: initTimeDate(), value: '', - hours: 0, - minutes: 0, - seconds: 0, + hours: '', + minutes: '', + seconds: '', disabledHours: [], disabledMinutes: [], disabledSeconds: [], @@ -68,6 +70,13 @@ } }, methods: { + handleClear() { + this.date = initTimeDate(); + this.hours = ''; + this.minutes = ''; + this.seconds = ''; + this.$emit('on-pick', ''); + }, handleChange (date, emit = true) { if (date.hours !== undefined) { this.date.setHours(date.hours); diff --git a/src/components/date-picker/picker.vue b/src/components/date-picker/picker.vue index caf25c0..50bb0aa 100644 --- a/src/components/date-picker/picker.vue +++ b/src/components/date-picker/picker.vue @@ -30,7 +30,7 @@ import Drop from '../../components/select/dropdown.vue'; import clickoutside from '../../directives/clickoutside'; import { oneOf } from '../../utils/assist'; - import { formatDate, parseDate } from './util'; + import { formatDate, parseDate, initTimeDate } from './util'; const prefixCls = 'ivu-date-picker'; @@ -413,6 +413,15 @@ value: { immediate: true, handler (val) { + const type = this.type; + if (type === 'time') { + const parser = ( + TYPE_VALUE_RESOLVER_MAP[type] || + TYPE_VALUE_RESOLVER_MAP['default'] + ).parser; + + val = parser(val, this.format || DEFAULT_FORMATS[type]); + } this.internalValue = val; } }, diff --git a/src/components/date-picker/util.js b/src/components/date-picker/util.js index 29ee8d9..84b1fe9 100644 --- a/src/components/date-picker/util.js +++ b/src/components/date-picker/util.js @@ -74,4 +74,12 @@ export const nextMonth = function(src) { src.setFullYear(newYear); return new Date(src.getTime()); +}; + +export const initTimeDate = function (time) { + const date = new Date(); + date.setHours(0); + date.setMinutes(0); + date.setSeconds(0); + return date; }; \ No newline at end of file diff --git a/test/routers/date.vue b/test/routers/date.vue index 9b8c143..f66ef31 100644 --- a/test/routers/date.vue +++ b/test/routers/date.vue @@ -12,12 +12,14 @@ + 123,{{value}},456 @@ -26,7 +28,14 @@ export default { data () { return { - value: '2016-12-12 03:03:03' +// value: '2016-12-12 03:03:03' + value: '15:12:01' + } + }, + methods: { + c (s) { + console.log(s) + this.value = s; } } } -- libgit2 0.21.4