update TimePicker

update TimePicker
This commit is contained in:
梁灏 2016-12-28 17:30:34 +08:00
parent d609ba8682
commit 0dd7b94a4d
3 changed files with 32 additions and 29 deletions

View file

@ -85,9 +85,8 @@
}, },
watch: { watch: {
value (newVal) { value (newVal) {
if (!newVal) { if (!newVal) return;
return; if (Array.isArray(newVal)) {
} else if (Array.isArray(newVal)) {
const valStart = newVal[0] ? toDate(newVal[0]) : false; const valStart = newVal[0] ? toDate(newVal[0]) : false;
const valEnd = newVal[1] ? toDate(newVal[1]) : false; const valEnd = newVal[1] ? toDate(newVal[1]) : false;

View file

@ -444,15 +444,18 @@
immediate: true, immediate: true,
handler (val) { handler (val) {
const type = this.type; const type = this.type;
if ((type === 'time' || type === 'timerange') && !(val instanceof Date)) {
const parser = ( const parser = (
TYPE_VALUE_RESOLVER_MAP[type] || TYPE_VALUE_RESOLVER_MAP[type] ||
TYPE_VALUE_RESOLVER_MAP['default'] TYPE_VALUE_RESOLVER_MAP['default']
).parser; ).parser;
if (type === 'timerange') val = val.join(RANGE_SEPARATOR);
if (type === 'time' && !(val instanceof Date)) {
val = parser(val, this.format || DEFAULT_FORMATS[type]);
} else if (type === 'timerange' && Array.isArray(val) && val.length === 2 && !(val[0] instanceof Date) && !(val[1] instanceof Date)) {
val = val.join(RANGE_SEPARATOR);
val = parser(val, this.format || DEFAULT_FORMATS[type]); val = parser(val, this.format || DEFAULT_FORMATS[type]);
} }
this.internalValue = val; this.internalValue = val;
} }
}, },

View file

@ -5,29 +5,30 @@
</style> </style>
<template> <template>
<row> <row>
<i-col span="12"> <!--<i-col span="12">-->
<date-picker type="date" placeholder="选择日期" style="width: 200px" @on-ok="ok" confirm @on-clear="clear"></date-picker> <!--<date-picker type="date" placeholder="选择日期" style="width: 200px" @on-ok="ok" confirm @on-clear="clear"></date-picker>-->
</i-col> <!--</i-col>-->
<i-col span="12"> <!--<i-col span="12">-->
<date-picker :value="value3" type="daterange" placement="bottom-start" placeholder="选择日期" style="width: 200px"></date-picker> <!--<date-picker :value="value3" type="daterange" placement="bottom-start" placeholder="选择日期" style="width: 200px"></date-picker>-->
</i-col> <!--</i-col>-->
<i-col span="12"> <!--<i-col span="12">-->
<time-picker <!--<time-picker-->
:value="value" <!--:value="value"-->
placeholder="选择时间" <!--placeholder="选择时间"-->
format="HH:mm:ss" <!--format="HH:mm:ss"-->
:hide-disabled-options="false" <!--:hide-disabled-options="false"-->
:disabled-hours="[1,2,10,11]" <!--:disabled-hours="[1,2,10,11]"-->
@on-change="c" <!--@on-change="c"-->
@on-ok="ok" <!--@on-ok="ok"-->
@on-clear="clear" <!--@on-clear="clear"-->
style="width: 168px"></time-picker> <!--style="width: 168px"></time-picker>-->
</i-col> <!--</i-col>-->
<i-col span="12"> <i-col span="12">
<time-picker <time-picker
:value="value2" :value="value2"
type="timerange" type="timerange"
placeholder="选择时间" placeholder="选择时间"
format="HH:mm:ss"
:hide-disabled-options="false" :hide-disabled-options="false"
@on-change="c" @on-change="c"
@on-ok="ok" @on-ok="ok"
@ -49,8 +50,8 @@
}, },
methods: { methods: {
c (s) { c (s) {
console.log(1,s); // console.log(1,s);
this.value2 = s; // this.value2 = s;
}, },
ok () { ok () {
console.log('ok'); console.log('ok');