2016-12-26 14:50:39 +08:00
|
|
|
<template>
|
2017-09-21 08:22:05 +02:00
|
|
|
<div :class="[prefixCls + '-body-wrapper']" @mousedown.prevent>
|
2016-12-26 14:50:39 +08:00
|
|
|
<div :class="[prefixCls + '-body']">
|
2016-12-30 11:34:01 +08:00
|
|
|
<div :class="[timePrefixCls + '-header']" v-if="showDate">{{ visibleDate }}</div>
|
2016-12-26 14:50:39 +08:00
|
|
|
<div :class="[prefixCls + '-content']">
|
|
|
|
<time-spinner
|
2017-03-07 18:06:56 +08:00
|
|
|
ref="timeSpinner"
|
2016-12-26 14:50:39 +08:00
|
|
|
:show-seconds="showSeconds"
|
2017-08-13 09:12:53 +02:00
|
|
|
:steps="steps"
|
2018-01-16 22:24:21 +01:00
|
|
|
:hours="date.getHours()"
|
|
|
|
:minutes="date.getMinutes()"
|
|
|
|
:seconds="date.getSeconds()"
|
2016-12-26 15:57:12 +08:00
|
|
|
:disabled-hours="disabledHours"
|
|
|
|
:disabled-minutes="disabledMinutes"
|
|
|
|
:disabled-seconds="disabledSeconds"
|
|
|
|
:hide-disabled-options="hideDisabledOptions"
|
2016-12-26 14:50:39 +08:00
|
|
|
@on-change="handleChange"
|
|
|
|
@on-pick-click="handlePickClick"></time-spinner>
|
|
|
|
</div>
|
|
|
|
<Confirm
|
2016-12-29 18:09:16 +08:00
|
|
|
v-if="confirm"
|
2016-12-26 14:50:39 +08:00
|
|
|
@on-pick-clear="handlePickClear"
|
|
|
|
@on-pick-success="handlePickSuccess"></Confirm>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2018-01-16 22:24:21 +01:00
|
|
|
import TimeSpinner from '../../base/time-spinner.vue';
|
|
|
|
import Confirm from '../../base/confirm.vue';
|
|
|
|
import Options from '../../time-mixins';
|
2016-12-26 14:50:39 +08:00
|
|
|
|
|
|
|
|
2018-01-16 22:24:21 +01:00
|
|
|
import Mixin from '../panel-mixin';
|
|
|
|
import Locale from '../../../../mixins/locale';
|
|
|
|
|
|
|
|
import { initTimeDate } from '../../util';
|
2016-12-27 17:16:11 +08:00
|
|
|
|
2016-12-26 14:50:39 +08:00
|
|
|
const prefixCls = 'ivu-picker-panel';
|
|
|
|
const timePrefixCls = 'ivu-time-picker';
|
|
|
|
|
2018-01-16 22:24:21 +01:00
|
|
|
const capitalize = (str) => str[0].toUpperCase() + str.slice(1);
|
|
|
|
|
2016-12-26 14:50:39 +08:00
|
|
|
export default {
|
2018-01-16 22:24:21 +01:00
|
|
|
name: 'TimePickerPanel',
|
|
|
|
mixins: [ Mixin, Locale, Options ],
|
2016-12-26 14:50:39 +08:00
|
|
|
components: { TimeSpinner, Confirm },
|
2017-08-13 09:12:53 +02:00
|
|
|
props: {
|
|
|
|
steps: {
|
|
|
|
type: Array,
|
|
|
|
default: () => []
|
2018-01-16 22:24:21 +01:00
|
|
|
},
|
|
|
|
format: {
|
|
|
|
type: String,
|
|
|
|
default: 'HH:mm:ss'
|
|
|
|
},
|
|
|
|
value: {
|
|
|
|
type: Array,
|
|
|
|
required: true
|
|
|
|
},
|
2017-08-13 09:12:53 +02:00
|
|
|
},
|
2016-12-26 14:50:39 +08:00
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
prefixCls: prefixCls,
|
|
|
|
timePrefixCls: timePrefixCls,
|
2018-01-16 22:24:21 +01:00
|
|
|
date: this.value[0] || initTimeDate(),
|
2016-12-30 17:54:27 +08:00
|
|
|
showDate: false,
|
2016-12-29 18:09:16 +08:00
|
|
|
confirm: false
|
2016-12-26 14:50:39 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
showSeconds () {
|
2018-01-24 13:34:02 +01:00
|
|
|
return !(this.format || '').match(/mm$/);
|
2016-12-30 11:34:01 +08:00
|
|
|
},
|
2018-01-16 22:24:21 +01:00
|
|
|
visibleDate () { // TODO
|
2016-12-30 11:34:01 +08:00
|
|
|
const date = this.date;
|
2017-01-11 21:02:55 +08:00
|
|
|
const month = date.getMonth() + 1;
|
|
|
|
const tYear = this.t('i.datepicker.year');
|
|
|
|
const tMonth = this.t(`i.datepicker.month${month}`);
|
|
|
|
return `${date.getFullYear()}${tYear} ${tMonth}`;
|
2016-12-26 14:50:39 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
2018-01-16 22:24:21 +01:00
|
|
|
value (dates) {
|
|
|
|
let newVal = dates[0] || initTimeDate();
|
2016-12-26 14:50:39 +08:00
|
|
|
newVal = new Date(newVal);
|
2018-01-16 22:24:21 +01:00
|
|
|
this.date = newVal;
|
2016-12-26 14:50:39 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2016-12-27 15:15:29 +08:00
|
|
|
handleChange (date, emit = true) {
|
2018-01-16 22:24:21 +01:00
|
|
|
|
|
|
|
const newDate = new Date(this.date);
|
|
|
|
Object.keys(date).forEach(
|
|
|
|
type => newDate[`set${capitalize(type)}`](date[type])
|
|
|
|
);
|
|
|
|
|
|
|
|
if (emit) this.$emit('on-pick', newDate, true);
|
2016-12-30 10:57:10 +08:00
|
|
|
},
|
2016-12-30 17:54:27 +08:00
|
|
|
},
|
2017-03-07 18:06:56 +08:00
|
|
|
mounted () {
|
2016-12-30 17:54:27 +08:00
|
|
|
if (this.$parent && this.$parent.$options.name === 'DatePicker') this.showDate = true;
|
2016-12-26 14:50:39 +08:00
|
|
|
}
|
|
|
|
};
|
2017-08-13 09:12:53 +02:00
|
|
|
</script>
|