update DateTimePicker
update DateTimePicker
This commit is contained in:
parent
d596b9e4f8
commit
5cc9b892b8
8 changed files with 98 additions and 21 deletions
|
@ -1,5 +1,9 @@
|
||||||
<template>
|
<template>
|
||||||
<div :class="[prefixCls + '-confirm']">
|
<div :class="[prefixCls + '-confirm']">
|
||||||
|
<span v-if="showTime" @click="handleToggleTime">
|
||||||
|
<template v-if="isTime">选择日期</template>
|
||||||
|
<template v-else>选择时间</template>
|
||||||
|
</span>
|
||||||
<i-button size="small" type="text" @click="handleClear">清空</i-button>
|
<i-button size="small" type="text" @click="handleClear">清空</i-button>
|
||||||
<i-button size="small" type="primary" @click="handleSuccess">确定</i-button>
|
<i-button size="small" type="primary" @click="handleSuccess">确定</i-button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -11,6 +15,10 @@
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: { iButton },
|
components: { iButton },
|
||||||
|
props: {
|
||||||
|
showTime: false,
|
||||||
|
isTime: false
|
||||||
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
prefixCls: prefixCls
|
prefixCls: prefixCls
|
||||||
|
@ -22,6 +30,9 @@
|
||||||
},
|
},
|
||||||
handleSuccess () {
|
handleSuccess () {
|
||||||
this.$emit('on-pick-success');
|
this.$emit('on-pick-success');
|
||||||
|
},
|
||||||
|
handleToggleTime () {
|
||||||
|
this.$emit('on-pick-toggle-time');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -168,6 +168,11 @@
|
||||||
let month = this.month;
|
let month = this.month;
|
||||||
let day = cell.text;
|
let day = cell.text;
|
||||||
|
|
||||||
|
const date = this.date;
|
||||||
|
const hours = date.getHours();
|
||||||
|
const minutes = date.getMinutes();
|
||||||
|
const seconds = date.getSeconds();
|
||||||
|
|
||||||
if (cell.type === 'prev-month') {
|
if (cell.type === 'prev-month') {
|
||||||
if (month === 0) {
|
if (month === 0) {
|
||||||
month = 11;
|
month = 11;
|
||||||
|
@ -184,7 +189,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Date(year, month, day);
|
return new Date(year, month, day, hours, minutes, seconds);
|
||||||
},
|
},
|
||||||
handleClick (event) {
|
handleClick (event) {
|
||||||
const target = event.target;
|
const target = event.target;
|
||||||
|
|
|
@ -126,7 +126,7 @@
|
||||||
import YearTable from '../base/year-table.vue';
|
import YearTable from '../base/year-table.vue';
|
||||||
import MonthTable from '../base/month-table.vue';
|
import MonthTable from '../base/month-table.vue';
|
||||||
import Confirm from '../base/confirm.vue';
|
import Confirm from '../base/confirm.vue';
|
||||||
import { toDate, prevMonth, nextMonth } from '../util';
|
import { toDate, prevMonth, nextMonth, initTimeDate } from '../util';
|
||||||
|
|
||||||
import Mixin from './mixin';
|
import Mixin from './mixin';
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@
|
||||||
prefixCls: prefixCls,
|
prefixCls: prefixCls,
|
||||||
datePrefixCls: datePrefixCls,
|
datePrefixCls: datePrefixCls,
|
||||||
shortcuts: [],
|
shortcuts: [],
|
||||||
date: new Date(),
|
date: initTimeDate(),
|
||||||
value: '',
|
value: '',
|
||||||
minDate: '',
|
minDate: '',
|
||||||
maxDate: '',
|
maxDate: '',
|
||||||
|
|
|
@ -59,9 +59,18 @@
|
||||||
:disabled-date="disabledDate"
|
:disabled-date="disabledDate"
|
||||||
@on-pick="handleMonthPick"
|
@on-pick="handleMonthPick"
|
||||||
@on-pick-click="handlePickClick"></month-table>
|
@on-pick-click="handlePickClick"></month-table>
|
||||||
|
<time-picker
|
||||||
|
v-show="currentView === 'time'"
|
||||||
|
v-ref:time-picker
|
||||||
|
:date="date"
|
||||||
|
:value="value"
|
||||||
|
@on-pick="handleTimePick"></time-picker>
|
||||||
</div>
|
</div>
|
||||||
<Confirm
|
<Confirm
|
||||||
v-if="confirm"
|
v-if="confirm"
|
||||||
|
:show-time="showTime"
|
||||||
|
:is-time="isTime"
|
||||||
|
@on-pick-toggle-time="handleToggleTime"
|
||||||
@on-pick-clear="handlePickClear"
|
@on-pick-clear="handlePickClear"
|
||||||
@on-pick-success="handlePickSuccess"></Confirm>
|
@on-pick-success="handlePickSuccess"></Confirm>
|
||||||
</div>
|
</div>
|
||||||
|
@ -72,30 +81,34 @@
|
||||||
import DateTable from '../base/date-table.vue';
|
import DateTable from '../base/date-table.vue';
|
||||||
import YearTable from '../base/year-table.vue';
|
import YearTable from '../base/year-table.vue';
|
||||||
import MonthTable from '../base/month-table.vue';
|
import MonthTable from '../base/month-table.vue';
|
||||||
|
import TimePicker from './time.vue';
|
||||||
import Confirm from '../base/confirm.vue';
|
import Confirm from '../base/confirm.vue';
|
||||||
|
|
||||||
import Mixin from './mixin';
|
import Mixin from './mixin';
|
||||||
|
|
||||||
|
import { initTimeDate } from '../util';
|
||||||
|
|
||||||
const prefixCls = 'ivu-picker-panel';
|
const prefixCls = 'ivu-picker-panel';
|
||||||
const datePrefixCls = 'ivu-date-picker';
|
const datePrefixCls = 'ivu-date-picker';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
mixins: [Mixin],
|
mixins: [Mixin],
|
||||||
components: { Icon, DateTable, YearTable, MonthTable, Confirm },
|
components: { Icon, DateTable, YearTable, MonthTable, TimePicker, Confirm },
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
prefixCls: prefixCls,
|
prefixCls: prefixCls,
|
||||||
datePrefixCls: datePrefixCls,
|
datePrefixCls: datePrefixCls,
|
||||||
shortcuts: [],
|
shortcuts: [],
|
||||||
currentView: 'date',
|
currentView: 'date',
|
||||||
date: new Date(),
|
date: initTimeDate(),
|
||||||
value: '',
|
value: '',
|
||||||
showTime: false,
|
showTime: false,
|
||||||
selectionMode: 'day',
|
selectionMode: 'day',
|
||||||
disabledDate: '',
|
disabledDate: '',
|
||||||
year: null,
|
year: null,
|
||||||
month: null,
|
month: null,
|
||||||
confirm: false
|
confirm: false,
|
||||||
|
isTime: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -126,23 +139,29 @@
|
||||||
this.year = newVal.getFullYear();
|
this.year = newVal.getFullYear();
|
||||||
this.month = newVal.getMonth();
|
this.month = newVal.getMonth();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
currentView (val) {
|
||||||
|
if (val === 'time') this.$refs.timePicker.updateScroll();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
resetDate () {
|
resetDate () {
|
||||||
this.date = new Date(this.date);
|
this.date = new Date(this.date);
|
||||||
},
|
},
|
||||||
handleClear() {
|
handleClear () {
|
||||||
this.date = new Date();
|
this.date = new Date();
|
||||||
this.$emit('on-pick', '');
|
this.$emit('on-pick', '');
|
||||||
|
if (this.showTime) this.$refs.timePicker.handleClear();
|
||||||
},
|
},
|
||||||
resetView() {
|
resetView (reset = false) {
|
||||||
if (this.selectionMode === 'month') {
|
if (this.currentView !== 'time' || reset) {
|
||||||
this.currentView = 'month';
|
if (this.selectionMode === 'month') {
|
||||||
} else if (this.selectionMode === 'year') {
|
this.currentView = 'month';
|
||||||
this.currentView = 'year';
|
} else if (this.selectionMode === 'year') {
|
||||||
} else {
|
this.currentView = 'year';
|
||||||
this.currentView = 'date';
|
} else {
|
||||||
|
this.currentView = 'date';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.year = this.date.getFullYear();
|
this.year = this.date.getFullYear();
|
||||||
|
@ -186,6 +205,15 @@
|
||||||
showMonthPicker () {
|
showMonthPicker () {
|
||||||
this.currentView = 'month';
|
this.currentView = 'month';
|
||||||
},
|
},
|
||||||
|
handleToggleTime () {
|
||||||
|
if (this.currentView === 'date') {
|
||||||
|
this.currentView = 'time';
|
||||||
|
this.isTime = true;
|
||||||
|
} else if (this.currentView === 'time') {
|
||||||
|
this.currentView = 'date';
|
||||||
|
this.isTime = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
handleYearPick(year, close = true) {
|
handleYearPick(year, close = true) {
|
||||||
this.year = year;
|
this.year = year;
|
||||||
if (!close) return;
|
if (!close) return;
|
||||||
|
@ -216,15 +244,16 @@
|
||||||
},
|
},
|
||||||
handleDatePick (value) {
|
handleDatePick (value) {
|
||||||
if (this.selectionMode === 'day') {
|
if (this.selectionMode === 'day') {
|
||||||
if (!this.showTime) {
|
this.$emit('on-pick', new Date(value.getTime()));
|
||||||
this.$emit('on-pick', new Date(value.getTime()));
|
|
||||||
}
|
|
||||||
this.date.setFullYear(value.getFullYear());
|
this.date.setFullYear(value.getFullYear());
|
||||||
this.date.setMonth(value.getMonth());
|
this.date.setMonth(value.getMonth());
|
||||||
this.date.setDate(value.getDate());
|
this.date.setDate(value.getDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.resetDate();
|
this.resetDate();
|
||||||
|
},
|
||||||
|
handleTimePick (date) {
|
||||||
|
this.handleDatePick(date);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
compiled () {
|
compiled () {
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
<div :class="[prefixCls + '-body']">
|
<div :class="[prefixCls + '-body']">
|
||||||
<div :class="[prefixCls + '-content']">
|
<div :class="[prefixCls + '-content']">
|
||||||
<time-spinner
|
<time-spinner
|
||||||
|
v-ref:time-spinner
|
||||||
:show-seconds="showSeconds"
|
:show-seconds="showSeconds"
|
||||||
:hours="hours"
|
:hours="hours"
|
||||||
:minutes="minutes"
|
:minutes="minutes"
|
||||||
|
@ -35,13 +36,21 @@
|
||||||
export default {
|
export default {
|
||||||
mixins: [Mixin],
|
mixins: [Mixin],
|
||||||
components: { TimeSpinner, Confirm },
|
components: { TimeSpinner, Confirm },
|
||||||
|
props: {
|
||||||
|
date: {
|
||||||
|
default () {
|
||||||
|
return initTimeDate()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
default: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
prefixCls: prefixCls,
|
prefixCls: prefixCls,
|
||||||
timePrefixCls: timePrefixCls,
|
timePrefixCls: timePrefixCls,
|
||||||
format: 'HH:mm:ss',
|
format: 'HH:mm:ss',
|
||||||
date: initTimeDate(),
|
|
||||||
value: '',
|
|
||||||
hours: '',
|
hours: '',
|
||||||
minutes: '',
|
minutes: '',
|
||||||
seconds: '',
|
seconds: '',
|
||||||
|
@ -92,6 +101,9 @@
|
||||||
this.seconds = this.date.getSeconds();
|
this.seconds = this.date.getSeconds();
|
||||||
}
|
}
|
||||||
if (emit) this.$emit('on-pick', this.date, true);
|
if (emit) this.$emit('on-pick', this.date, true);
|
||||||
|
},
|
||||||
|
updateScroll () {
|
||||||
|
this.$refs.timeSpinner.updateScroll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -362,7 +362,13 @@
|
||||||
},
|
},
|
||||||
showPicker () {
|
showPicker () {
|
||||||
if (!this.picker) {
|
if (!this.picker) {
|
||||||
|
const type = this.type;
|
||||||
|
|
||||||
this.picker = new Vue(this.panel).$mount(this.$els.picker);
|
this.picker = new Vue(this.panel).$mount(this.$els.picker);
|
||||||
|
if (type === 'datetime' || type === 'datetimerange') {
|
||||||
|
this.confirm = true;
|
||||||
|
this.picker.showTime = true;
|
||||||
|
}
|
||||||
this.picker.value = this.internalValue;
|
this.picker.value = this.internalValue;
|
||||||
this.picker.confirm = this.confirm;
|
this.picker.confirm = this.confirm;
|
||||||
this.picker.selectionMode = this.selectionMode;
|
this.picker.selectionMode = this.selectionMode;
|
||||||
|
@ -430,7 +436,7 @@
|
||||||
this.$refs.drop.update();
|
this.$refs.drop.update();
|
||||||
if (this.open === null) this.$emit('on-open-change', true);
|
if (this.open === null) this.$emit('on-open-change', true);
|
||||||
} else {
|
} else {
|
||||||
if (this.picker) this.picker.resetView && this.picker.resetView();
|
if (this.picker) this.picker.resetView && this.picker.resetView(true);
|
||||||
this.$refs.drop.destroy();
|
this.$refs.drop.destroy();
|
||||||
if (this.open === null) this.$emit('on-open-change', false);
|
if (this.open === null) this.$emit('on-open-change', false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,5 +244,19 @@
|
||||||
text-align: right;
|
text-align: right;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
clear: both;
|
clear: both;
|
||||||
|
& > span{
|
||||||
|
color: @link-color;
|
||||||
|
cursor: pointer;
|
||||||
|
user-select: none;
|
||||||
|
float: left;
|
||||||
|
padding: 2px 0;
|
||||||
|
transition: all @transition-time @ease-in-out;
|
||||||
|
&:hover{
|
||||||
|
color: @link-hover-color;
|
||||||
|
}
|
||||||
|
&:active{
|
||||||
|
color: @link-active-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -24,7 +24,7 @@
|
||||||
<!--style="width: 168px"></time-picker>-->
|
<!--style="width: 168px"></time-picker>-->
|
||||||
<!--</i-col>-->
|
<!--</i-col>-->
|
||||||
<i-col span="12">
|
<i-col span="12">
|
||||||
<Time-picker type="timerange" confirm placeholder="选择时间" style="width: 168px"></Time-picker>
|
<Date-picker type="datetime" placeholder="选择日期时间" style="width: 200px" @on-change="c"></Date-picker>
|
||||||
<!--<time-picker-->
|
<!--<time-picker-->
|
||||||
<!--:value="value2"-->
|
<!--:value="value2"-->
|
||||||
<!--type="timerange"-->
|
<!--type="timerange"-->
|
||||||
|
|
Loading…
Add table
Reference in a new issue