Commit 8783c3e9 authored by cinwell.li's avatar cinwell.li Committed by FuryBean

DatePicker: improve test (#659)

parent 32d3ad53
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<input <input
placeholder="开始日期" placeholder="开始日期"
class="el-date-range-picker__editor" class="el-date-range-picker__editor"
v-model.lazy="leftVisibleDate" :value="leftVisibleDate"
@input="handleDateInput($event, 'min')" @input="handleDateInput($event, 'min')"
@change="handleDateChange($event, 'min')"/> @change="handleDateChange($event, 'min')"/>
</span> </span>
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
<input <input
placeholder="开始时间" placeholder="开始时间"
class="el-date-range-picker__editor" class="el-date-range-picker__editor"
v-model.lazy="leftVisibleTime" :value="leftVisibleTime"
@focus="leftTimePickerVisible = !leftTimePickerVisible" @focus="leftTimePickerVisible = !leftTimePickerVisible"
@change="handleTimeChange($event, 'min')"/> @change="handleTimeChange($event, 'min')"/>
<time-picker <time-picker
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
ref="leftInput" ref="leftInput"
placeholder="结束日期" placeholder="结束日期"
class="el-date-range-picker__editor" class="el-date-range-picker__editor"
v-model.lazy="rightVisibleDate" :value="rightVisibleDate"
:readonly="!minDate" :readonly="!minDate"
@input="handleDateInput($event, 'max')" @input="handleDateInput($event, 'max')"
@change="handleDateChange($event, 'max')" /> @change="handleDateChange($event, 'max')" />
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
ref="rightInput" ref="rightInput"
placeholder="结束时间" placeholder="结束时间"
class="el-date-range-picker__editor" class="el-date-range-picker__editor"
v-model.lazy="rightVisibleTime" :value="rightVisibleTime"
@focus="minDate && (rightTimePickerVisible = !rightTimePickerVisible)" @focus="minDate && (rightTimePickerVisible = !rightTimePickerVisible)"
:readonly="!minDate" :readonly="!minDate"
@change="handleTimeChange($event, 'max')" /> @change="handleTimeChange($event, 'max')" />
...@@ -177,7 +177,7 @@ ...@@ -177,7 +177,7 @@
}, },
rightVisibleDate() { rightVisibleDate() {
return formatDate(this.maxDate); return formatDate(this.maxDate || this.minDate);
}, },
leftVisibleTime() { leftVisibleTime() {
...@@ -188,60 +188,6 @@ ...@@ -188,60 +188,6 @@
return formatDate(this.maxDate, 'HH:mm:ss'); return formatDate(this.maxDate, 'HH:mm:ss');
}, },
leftHours: {
get() {
return this.date.getHours();
},
set(hours) {
this.date.setHours(hours);
}
},
leftMinutes: {
get() {
return this.date.getMinutes();
},
set(minutes) {
this.date.setMinutes(minutes);
}
},
leftSeconds: {
get() {
return this.date.getSeconds();
},
set(seconds) {
this.date.setSeconds(seconds);
}
},
rightHours: {
get() {
return this.rightDate.getHours();
},
set(hours) {
this.rightDate.setHours(hours);
}
},
rightMinutes: {
get() {
return this.rightDate.getMinutes();
},
set(minutes) {
this.rightDate.setMinutes(minutes);
}
},
rightSeconds: {
get() {
return this.rightDate.getSeconds();
},
set(seconds) {
this.rightDate.setSeconds(seconds);
}
},
rightDate() { rightDate() {
const newDate = new Date(this.date); const newDate = new Date(this.date);
const month = newDate.getMonth(); const month = newDate.getMonth();
...@@ -396,6 +342,10 @@ ...@@ -396,6 +342,10 @@
this.maxDate = new Date(target.getTime()); this.maxDate = new Date(target.getTime());
} }
} }
const l2r = type === 'min' ? 'left' : 'right';
this.$refs[l2r + 'timepicker'].value = target;
this[l2r + 'TimePickerVisible'] = false;
} }
}, },
......
...@@ -111,7 +111,7 @@ ...@@ -111,7 +111,7 @@
<a <a
href="JavaScript:" href="JavaScript:"
class="el-picker-panel__link-btn" class="el-picker-panel__link-btn"
@click="changeToToday">{{ $t('datepicker.now') }}</a> @click="changeToNow">{{ $t('datepicker.now') }}</a>
<button <button
type="button" type="button"
class="el-picker-panel__btn" class="el-picker-panel__btn"
...@@ -127,6 +127,7 @@ ...@@ -127,6 +127,7 @@
export default { export default {
watch: { watch: {
showTime(val) { showTime(val) {
/* istanbul ignore if */
if (!val) return; if (!val) return;
this.$nextTick(_ => { this.$nextTick(_ => {
const inputElm = this.$refs.input; const inputElm = this.$refs.input;
...@@ -156,6 +157,7 @@ ...@@ -156,6 +157,7 @@
selectionMode(newVal) { selectionMode(newVal) {
if (newVal === 'month') { if (newVal === 'month') {
/* istanbul ignore next */
if (this.currentView !== 'year' || this.currentView !== 'month') { if (this.currentView !== 'year' || this.currentView !== 'month') {
this.currentView = 'month'; this.currentView = 'month';
} }
...@@ -163,6 +165,7 @@ ...@@ -163,6 +165,7 @@
}, },
date(newVal) { date(newVal) {
/* istanbul ignore next */
if (!this.year) { if (!this.year) {
this.year = newVal.getFullYear(); this.year = newVal.getFullYear();
this.month = newVal.getMonth(); this.month = newVal.getMonth();
...@@ -187,13 +190,14 @@ ...@@ -187,13 +190,14 @@
this.currentView = 'year'; this.currentView = 'year';
}, },
handleLabelClick() { // XXX: 没用到
if (this.currentView === 'date') { // handleLabelClick() {
this.showMonthPicker(); // if (this.currentView === 'date') {
} else if (this.currentView === 'month') { // this.showMonthPicker();
this.showYearPicker(); // } else if (this.currentView === 'month') {
} // this.showYearPicker();
}, // }
// },
prevMonth() { prevMonth() {
this.month--; this.month--;
...@@ -301,7 +305,7 @@ ...@@ -301,7 +305,7 @@
this.resetDate(); this.resetDate();
}, },
changeToToday() { changeToNow() {
this.date.setTime(+new Date()); this.date.setTime(+new Date());
this.$emit('pick', new Date(this.date.getTime())); this.$emit('pick', new Date(this.date.getTime()));
this.resetDate(); this.resetDate();
...@@ -416,50 +420,6 @@ ...@@ -416,50 +420,6 @@
return startYear + ' ' + yearTranslation + '-' + (startYear + 9) + ' ' + yearTranslation; return startYear + ' ' + yearTranslation + '-' + (startYear + 9) + ' ' + yearTranslation;
} }
return this.year + ' ' + yearTranslation; return this.year + ' ' + yearTranslation;
},
hours: {
get() {
return this.date.getHours();
},
set(hours) {
this.date.setHours(hours);
}
},
minutes: {
get() {
return this.date.getMinutes();
},
set(minutes) {
this.date.setMinutes(minutes);
}
},
seconds: {
get() {
return this.date.getSeconds();
},
set(seconds) {
this.date.setSeconds(seconds);
}
},
timeText() {
const hours = this.hours;
const minutes = this.minutes;
return (hours < 10 ? '0' + hours : hours) + ':' + (minutes < 10 ? '0' + minutes : minutes);
},
label() {
const year = this.year;
const month = this.month + 1;
if (this.currentView === 'date') {
return year + ' / ' + month;
}
return year;
} }
} }
}; };
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
v-model.lazy="visualValue" /> v-model.lazy="visualValue" />
<span <span
@click="togglePicker" @click="pickerVisible = !pickerVisible"
class="el-date-editor__trigger el-icon" class="el-date-editor__trigger el-icon"
:class="[triggerClass]" :class="[triggerClass]"
v-if="haveTrigger"> v-if="haveTrigger">
...@@ -353,10 +353,6 @@ export default { ...@@ -353,10 +353,6 @@ export default {
} }
}, },
togglePicker() {
!this.pickerVisible ? this.showPicker() : this.hidePicker();
},
hidePicker() { hidePicker() {
if (this.picker) { if (this.picker) {
this.picker.resetView && this.picker.resetView(); this.picker.resetView && this.picker.resetView();
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment