mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
chore(Calendar): add computed range
This commit is contained in:
parent
13bbd73141
commit
b8a6b67975
@ -90,6 +90,10 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
|
range() {
|
||||||
|
return this.type === 'range';
|
||||||
|
},
|
||||||
|
|
||||||
months() {
|
months() {
|
||||||
const months = [];
|
const months = [];
|
||||||
const cursor = new Date(this.minDate);
|
const cursor = new Date(this.minDate);
|
||||||
@ -105,14 +109,11 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
buttonDisabled() {
|
buttonDisabled() {
|
||||||
if (this.type === 'single') {
|
if (this.range) {
|
||||||
return !this.currentDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* istanbul ignore else */
|
|
||||||
if (this.type === 'range') {
|
|
||||||
return !this.currentDate[0] || !this.currentDate[1];
|
return !this.currentDate[0] || !this.currentDate[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return !this.currentDate;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -155,8 +156,8 @@ export default createComponent({
|
|||||||
// scroll to current month
|
// scroll to current month
|
||||||
scrollIntoView() {
|
scrollIntoView() {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
const { type, currentDate } = this;
|
const { currentDate } = this;
|
||||||
const targetDate = type === 'range' ? currentDate[0] : currentDate;
|
const targetDate = this.range ? currentDate[0] : currentDate;
|
||||||
|
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (!targetDate) {
|
if (!targetDate) {
|
||||||
@ -177,15 +178,12 @@ export default createComponent({
|
|||||||
getInitialDate() {
|
getInitialDate() {
|
||||||
const { type, defaultDate, minDate } = this;
|
const { type, defaultDate, minDate } = this;
|
||||||
|
|
||||||
if (type === 'single') {
|
|
||||||
return defaultDate || minDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* istanbul ignore else */
|
|
||||||
if (type === 'range') {
|
if (type === 'range') {
|
||||||
const [startDay, endDay] = defaultDate || [];
|
const [startDay, endDay] = defaultDate || [];
|
||||||
return [startDay || minDate, endDay || getNextDay(minDate)];
|
return [startDay || minDate, endDay || getNextDay(minDate)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return defaultDate || minDate;
|
||||||
},
|
},
|
||||||
|
|
||||||
// calculate the position of the elements
|
// calculate the position of the elements
|
||||||
@ -226,11 +224,7 @@ export default createComponent({
|
|||||||
onClickDay(item) {
|
onClickDay(item) {
|
||||||
const { date } = item;
|
const { date } = item;
|
||||||
|
|
||||||
if (this.type === 'single') {
|
if (this.range) {
|
||||||
this.select(date, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.type === 'range') {
|
|
||||||
const [startDay, endDay] = this.currentDate;
|
const [startDay, endDay] = this.currentDate;
|
||||||
|
|
||||||
if (startDay && !endDay) {
|
if (startDay && !endDay) {
|
||||||
@ -244,6 +238,8 @@ export default createComponent({
|
|||||||
} else {
|
} else {
|
||||||
this.select([date, null]);
|
this.select([date, null]);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.select(date, true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -255,7 +251,7 @@ export default createComponent({
|
|||||||
this.currentDate = date;
|
this.currentDate = date;
|
||||||
this.$emit('select', this.currentDate);
|
this.$emit('select', this.currentDate);
|
||||||
|
|
||||||
if (complete && this.type === 'range') {
|
if (complete && this.range) {
|
||||||
const valid = this.checkRange();
|
const valid = this.checkRange();
|
||||||
|
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
@ -385,5 +381,3 @@ export default createComponent({
|
|||||||
return this.genCalendar();
|
return this.genCalendar();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// todo
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user