mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
parent
e054aafa2d
commit
ad30ba60e9
@ -7,7 +7,8 @@ import {
|
|||||||
calcDateNum,
|
calcDateNum,
|
||||||
formatMonthTitle,
|
formatMonthTitle,
|
||||||
compareMonth,
|
compareMonth,
|
||||||
getMonths
|
getMonths,
|
||||||
|
getDayByOffset
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
|
||||||
import Toast from '../toast/toast';
|
import Toast from '../toast/toast';
|
||||||
@ -266,6 +267,28 @@ VantComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
select(date, complete) {
|
select(date, complete) {
|
||||||
|
if (complete && this.data.type === 'range') {
|
||||||
|
const valid = this.checkRange(date);
|
||||||
|
|
||||||
|
if (!valid) {
|
||||||
|
// auto selected to max range if showConfirm
|
||||||
|
if (this.data.showConfirm) {
|
||||||
|
this.emit([date[0], getDayByOffset(date[0], this.data.maxRange - 1)]);
|
||||||
|
} else {
|
||||||
|
this.emit(date);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.emit(date);
|
||||||
|
|
||||||
|
if (complete && !this.data.showConfirm) {
|
||||||
|
this.onConfirm();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
emit(date) {
|
||||||
const getTime = (date: Date | number) =>
|
const getTime = (date: Date | number) =>
|
||||||
(date instanceof Date ? date.getTime() : date);
|
(date instanceof Date ? date.getTime() : date);
|
||||||
|
|
||||||
@ -273,25 +296,16 @@ VantComponent({
|
|||||||
currentDate: Array.isArray(date) ? date.map(getTime) : getTime(date)
|
currentDate: Array.isArray(date) ? date.map(getTime) : getTime(date)
|
||||||
});
|
});
|
||||||
this.$emit('select', copyDates(date));
|
this.$emit('select', copyDates(date));
|
||||||
|
|
||||||
if (complete && this.data.type === 'range') {
|
|
||||||
const valid = this.checkRange();
|
|
||||||
|
|
||||||
if (!valid) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (complete && !this.data.showConfirm) {
|
|
||||||
this.onConfirm();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
checkRange() {
|
checkRange(date) {
|
||||||
const { maxRange, currentDate, rangePrompt } = this.data;
|
const { maxRange, rangePrompt } = this.data;
|
||||||
|
|
||||||
if (maxRange && calcDateNum(currentDate) > maxRange) {
|
if (maxRange && calcDateNum(date) > maxRange) {
|
||||||
Toast(rangePrompt || `选择天数不能超过 ${maxRange} 天`);
|
Toast({
|
||||||
|
context: this,
|
||||||
|
message: rangePrompt || `选择天数不能超过 ${maxRange} 天`
|
||||||
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,3 +27,5 @@
|
|||||||
is="calendar"
|
is="calendar"
|
||||||
data="{{ title, subtitle, showTitle, showSubtitle, minDate, maxDate, type, color, showMark, formatter, rowHeight, currentDate, safeAreaInsetBottom, showConfirm, confirmDisabledText, confirmText, scrollIntoView, allowSameDay }}"
|
data="{{ title, subtitle, showTitle, showSubtitle, minDate, maxDate, type, color, showMark, formatter, rowHeight, currentDate, safeAreaInsetBottom, showConfirm, confirmDisabledText, confirmText, scrollIntoView, allowSameDay }}"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<van-toast id="van-toast" />
|
||||||
|
@ -49,7 +49,7 @@ export function compareDay(day1: Date | number, day2: Date | number) {
|
|||||||
return compareMonthResult;
|
return compareMonthResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDayByOffset(date: Date, offset: number) {
|
export function getDayByOffset(date: Date, offset: number) {
|
||||||
date = new Date(date);
|
date = new Date(date);
|
||||||
date.setDate(date.getDate() + offset);
|
date.setDate(date.getDate() + offset);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user