update DateTimePicker

update DateTimePicker
This commit is contained in:
梁灏 2016-12-30 17:54:27 +08:00
parent 2dc2771349
commit a2a78c382f
4 changed files with 34 additions and 12 deletions

View file

@ -117,7 +117,8 @@
<time-picker <time-picker
v-ref:time-picker v-ref:time-picker
v-show="isTime" v-show="isTime"
@on-pick="handleTimePick"></time-picker> @on-pick="handleTimePick"
@on-pick-click="handlePickClick"></time-picker>
</div> </div>
<Confirm <Confirm
v-if="confirm" v-if="confirm"
@ -145,6 +146,7 @@
const datePrefixCls = 'ivu-date-picker'; const datePrefixCls = 'ivu-date-picker';
export default { export default {
name: 'DatePicker',
mixins: [Mixin], mixins: [Mixin],
components: { Icon, DateTable, YearTable, MonthTable, TimePicker, Confirm }, components: { Icon, DateTable, YearTable, MonthTable, TimePicker, Confirm },
data () { data () {
@ -287,12 +289,14 @@
this.handleConfirm(); this.handleConfirm();
if (this.showTime) this.$refs.timePicker.handleClear(); if (this.showTime) this.$refs.timePicker.handleClear();
}, },
resetView() { resetView(reset = false) {
this.leftCurrentView = 'date'; this.leftCurrentView = 'date';
this.rightCurrentView = 'date'; this.rightCurrentView = 'date';
this.leftTableYear = this.leftYear; this.leftTableYear = this.leftYear;
this.rightTableYear = this.rightYear; this.rightTableYear = this.rightYear;
if (reset) this.isTime = false;
}, },
prevYear (direction) { prevYear (direction) {
if (this[`${direction}CurrentView`] === 'year') { if (this[`${direction}CurrentView`] === 'year') {
@ -394,6 +398,7 @@
}, },
compiled () { compiled () {
if (this.showTime) { if (this.showTime) {
// todo
this.$refs.timePicker.date = this.minDate; this.$refs.timePicker.date = this.minDate;
this.$refs.timePicker.dateEnd = this.maxDate; this.$refs.timePicker.dateEnd = this.maxDate;
this.$refs.timePicker.value = this.value; this.$refs.timePicker.value = this.value;

View file

@ -63,7 +63,8 @@
v-ref:time-picker v-ref:time-picker
show-date show-date
v-show="currentView === 'time'" v-show="currentView === 'time'"
@on-pick="handleTimePick"></time-picker> @on-pick="handleTimePick"
@on-pick-click="handlePickClick"></time-picker>
</div> </div>
<Confirm <Confirm
v-if="confirm" v-if="confirm"
@ -91,6 +92,7 @@
const datePrefixCls = 'ivu-date-picker'; const datePrefixCls = 'ivu-date-picker';
export default { export default {
name: 'DatePicker',
mixins: [Mixin], mixins: [Mixin],
components: { Icon, DateTable, YearTable, MonthTable, TimePicker, Confirm }, components: { Icon, DateTable, YearTable, MonthTable, TimePicker, Confirm },
data () { data () {

View file

@ -2,7 +2,10 @@
<div :class="classes"> <div :class="classes">
<div :class="[prefixCls + '-body']"> <div :class="[prefixCls + '-body']">
<div :class="[prefixCls + '-content', prefixCls + '-content-left']"> <div :class="[prefixCls + '-content', prefixCls + '-content-left']">
<div :class="[timePrefixCls + '-header']">开始时间</div> <div :class="[timePrefixCls + '-header']">
<template v-if="showDate">{{ visibleDate }}</template>
<template v-else>开始时间</template>
</div>
<time-spinner <time-spinner
v-ref:time-spinner v-ref:time-spinner
:show-seconds="showSeconds" :show-seconds="showSeconds"
@ -17,7 +20,10 @@
@on-pick-click="handlePickClick"></time-spinner> @on-pick-click="handlePickClick"></time-spinner>
</div> </div>
<div :class="[prefixCls + '-content', prefixCls + '-content-right']"> <div :class="[prefixCls + '-content', prefixCls + '-content-right']">
<div :class="[timePrefixCls + '-header']">结束时间</div> <div :class="[timePrefixCls + '-header']">
<template v-if="showDate">{{ visibleDateEnd }}</template>
<template v-else>结束时间</template>
</div>
<time-spinner <time-spinner
v-ref:time-spinner-end v-ref:time-spinner-end
:show-seconds="showSeconds" :show-seconds="showSeconds"
@ -57,6 +63,7 @@
prefixCls: prefixCls, prefixCls: prefixCls,
timePrefixCls: timePrefixCls, timePrefixCls: timePrefixCls,
format: 'HH:mm:ss', format: 'HH:mm:ss',
showDate: false,
date: initTimeDate(), date: initTimeDate(),
dateEnd: initTimeDate(), dateEnd: initTimeDate(),
value: '', value: '',
@ -85,6 +92,14 @@
}, },
showSeconds () { showSeconds () {
return (this.format || '').indexOf('ss') !== -1; return (this.format || '').indexOf('ss') !== -1;
},
visibleDate () {
const date = this.date || initTimeDate();
return `${date.getFullYear()}${date.getMonth() + 1}`;
},
visibleDateEnd () {
const date = this.dateEnd || initTimeDate();
return `${date.getFullYear()}${date.getMonth() + 1}`;
} }
}, },
watch: { watch: {
@ -177,6 +192,9 @@
this.$refs.timeSpinner.updateScroll(); this.$refs.timeSpinner.updateScroll();
this.$refs.timeSpinnerEnd.updateScroll(); this.$refs.timeSpinnerEnd.updateScroll();
} }
},
compiled () {
if (this.$parent && this.$parent.$options.name === 'DatePicker') this.showDate = true;
} }
}; };
</script> </script>

View file

@ -37,19 +37,13 @@
export default { export default {
mixins: [Mixin], mixins: [Mixin],
components: { TimeSpinner, Confirm }, components: { TimeSpinner, Confirm },
props: {
showDate: {
type: Boolean,
default: false
}
},
data () { data () {
return { return {
prefixCls: prefixCls, prefixCls: prefixCls,
timePrefixCls: timePrefixCls, timePrefixCls: timePrefixCls,
date: initTimeDate(), date: initTimeDate(),
value: '', value: '',
// showDate: false, showDate: false,
format: 'HH:mm:ss', format: 'HH:mm:ss',
hours: '', hours: '',
minutes: '', minutes: '',
@ -109,6 +103,9 @@
updateScroll () { updateScroll () {
this.$refs.timeSpinner.updateScroll(); this.$refs.timeSpinner.updateScroll();
} }
},
compiled () {
if (this.$parent && this.$parent.$options.name === 'DatePicker') this.showDate = true;
} }
}; };
</script> </script>