mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(Calendar): add allow-same-day prop (#5688)
This commit is contained in:
parent
8d6adce9a2
commit
0a3ed53187
@ -273,6 +273,7 @@ Following props are supported when the type is range
|
|||||||
|------|------|------|------|
|
|------|------|------|------|
|
||||||
| max-range `v2.4.3` | Number of selectable days | *number \| string* | - |
|
| max-range `v2.4.3` | Number of selectable days | *number \| string* | - |
|
||||||
| range-prompt `v2.4.3` | Error message when exceeded max range | *string* | `Choose no more than xx days` |
|
| range-prompt `v2.4.3` | Error message when exceeded max range | *string* | `Choose no more than xx days` |
|
||||||
|
| allow-same-day `v2.5.6` | Whether the start and end time of the range is allowed on the same day | *boolean* | `fasle` |
|
||||||
|
|
||||||
### Data Structure of Day
|
### Data Structure of Day
|
||||||
|
|
||||||
|
@ -275,6 +275,7 @@ export default {
|
|||||||
|------|------|------|------|
|
|------|------|------|------|
|
||||||
| max-range `v2.4.3` | 日期区间最多可选天数,默认无限制 | *number \| string* | - |
|
| max-range `v2.4.3` | 日期区间最多可选天数,默认无限制 | *number \| string* | - |
|
||||||
| range-prompt `v2.4.3` | 范围选择超过最多可选天数时的提示文案 | *string* | `选择天数不能超过 xx 天` |
|
| range-prompt `v2.4.3` | 范围选择超过最多可选天数时的提示文案 | *string* | `选择天数不能超过 xx 天` |
|
||||||
|
| allow-same-day `v2.5.6` | 是否允许日期范围的起止时间为同一天 | *boolean* | `fasle` |
|
||||||
|
|
||||||
### Day 数据结构
|
### Day 数据结构
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ export default createComponent({
|
|||||||
rowHeight: [Number, String],
|
rowHeight: [Number, String],
|
||||||
formatter: Function,
|
formatter: Function,
|
||||||
currentDate: [Date, Array],
|
currentDate: [Date, Array],
|
||||||
|
allowSameDay: Boolean,
|
||||||
showSubtitle: Boolean,
|
showSubtitle: Boolean,
|
||||||
showMonthTitle: Boolean,
|
showMonthTitle: Boolean,
|
||||||
},
|
},
|
||||||
@ -125,19 +126,25 @@ export default createComponent({
|
|||||||
const [startDay, endDay] = this.currentDate;
|
const [startDay, endDay] = this.currentDate;
|
||||||
|
|
||||||
if (!startDay) {
|
if (!startDay) {
|
||||||
return;
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
const compareToStart = compareDay(day, startDay);
|
const compareToStart = compareDay(day, startDay);
|
||||||
|
|
||||||
|
if (!endDay) {
|
||||||
|
return compareToStart === 0 ? 'start' : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const compareToEnd = compareDay(day, endDay);
|
||||||
|
|
||||||
|
if (compareToStart === 0 && compareToEnd === 0 && this.allowSameDay) {
|
||||||
|
return 'start-end';
|
||||||
|
}
|
||||||
|
|
||||||
if (compareToStart === 0) {
|
if (compareToStart === 0) {
|
||||||
return 'start';
|
return 'start';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!endDay) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const compareToEnd = compareDay(day, endDay);
|
|
||||||
if (compareToEnd === 0) {
|
if (compareToEnd === 0) {
|
||||||
return 'end';
|
return 'end';
|
||||||
}
|
}
|
||||||
@ -170,11 +177,11 @@ export default createComponent({
|
|||||||
|
|
||||||
getBottomInfo(type) {
|
getBottomInfo(type) {
|
||||||
if (this.type === 'range') {
|
if (this.type === 'range') {
|
||||||
if (type === 'start') {
|
if (type === 'start' || type === 'end') {
|
||||||
return t('start');
|
return t(type);
|
||||||
}
|
}
|
||||||
if (type === 'end') {
|
if (type === 'start-end') {
|
||||||
return t('end');
|
return t('startEnd');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -254,7 +261,7 @@ export default createComponent({
|
|||||||
role="gridcell"
|
role="gridcell"
|
||||||
style={style}
|
style={style}
|
||||||
class={[bem('day'), item.className]}
|
class={[bem('day'), item.className]}
|
||||||
tabindex={disabled ? null : -1}
|
tabindex={-1}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
>
|
>
|
||||||
<div class={bem('selected-day')} style={{ background: this.color }}>
|
<div class={bem('selected-day')} style={{ background: this.color }}>
|
||||||
|
@ -30,6 +30,7 @@ export default createComponent({
|
|||||||
rangePrompt: String,
|
rangePrompt: String,
|
||||||
defaultDate: [Date, Array],
|
defaultDate: [Date, Array],
|
||||||
getContainer: [String, Function],
|
getContainer: [String, Function],
|
||||||
|
allowSameDay: Boolean,
|
||||||
closeOnPopstate: Boolean,
|
closeOnPopstate: Boolean,
|
||||||
confirmDisabledText: String,
|
confirmDisabledText: String,
|
||||||
type: {
|
type: {
|
||||||
@ -261,6 +262,8 @@ export default createComponent({
|
|||||||
this.select([startDay, date], true);
|
this.select([startDay, date], true);
|
||||||
} else if (compareToStart === -1) {
|
} else if (compareToStart === -1) {
|
||||||
this.select([date, null]);
|
this.select([date, null]);
|
||||||
|
} else if (this.allowSameDay) {
|
||||||
|
this.select([date, date]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.select([date, null]);
|
this.select([date, null]);
|
||||||
@ -342,6 +345,7 @@ export default createComponent({
|
|||||||
rowHeight={this.rowHeight}
|
rowHeight={this.rowHeight}
|
||||||
currentDate={this.currentDate}
|
currentDate={this.currentDate}
|
||||||
showSubtitle={this.showSubtitle}
|
showSubtitle={this.showSubtitle}
|
||||||
|
allowSameDay={this.allowSameDay}
|
||||||
showMonthTitle={showMonthTitle}
|
showMonthTitle={showMonthTitle}
|
||||||
onClick={this.onClickDay}
|
onClick={this.onClickDay}
|
||||||
/>
|
/>
|
||||||
|
@ -100,6 +100,7 @@
|
|||||||
|
|
||||||
&--end,
|
&--end,
|
||||||
&--start,
|
&--start,
|
||||||
|
&--start-end,
|
||||||
&--multiple-middle,
|
&--multiple-middle,
|
||||||
&--multiple-selected {
|
&--multiple-selected {
|
||||||
color: @calendar-range-edge-color;
|
color: @calendar-range-edge-color;
|
||||||
@ -114,6 +115,7 @@
|
|||||||
border-radius: 0 @border-radius-md @border-radius-md 0;
|
border-radius: 0 @border-radius-md @border-radius-md 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&--start-end,
|
||||||
&--multiple-selected {
|
&--multiple-selected {
|
||||||
border-radius: @border-radius-md;
|
border-radius: @border-radius-md;
|
||||||
}
|
}
|
||||||
|
@ -82,6 +82,7 @@ test('select event when type is multiple', async () => {
|
|||||||
const days = wrapper.findAll('.van-calendar__day');
|
const days = wrapper.findAll('.van-calendar__day');
|
||||||
days.at(15).trigger('click');
|
days.at(15).trigger('click');
|
||||||
days.at(16).trigger('click');
|
days.at(16).trigger('click');
|
||||||
|
days.at(17).trigger('click');
|
||||||
|
|
||||||
await later();
|
await later();
|
||||||
days.at(15).trigger('click');
|
days.at(15).trigger('click');
|
||||||
@ -93,7 +94,10 @@ test('select event when type is multiple', async () => {
|
|||||||
'2010/1/10,2010/1/16,2010/1/17'
|
'2010/1/10,2010/1/16,2010/1/17'
|
||||||
);
|
);
|
||||||
expect(formatMultiple(emittedSelect[2][0])).toEqual(
|
expect(formatMultiple(emittedSelect[2][0])).toEqual(
|
||||||
'2010/1/10,2010/1/17,2010/1/13'
|
'2010/1/10,2010/1/16,2010/1/17,2010/1/18'
|
||||||
|
);
|
||||||
|
expect(formatMultiple(emittedSelect[3][0])).toEqual(
|
||||||
|
'2010/1/10,2010/1/17,2010/1/18,2010/1/13'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -64,3 +64,33 @@ test('hide close icon when there is no title', () => {
|
|||||||
});
|
});
|
||||||
expect(wrapper.contains('.van-popup__close-icon')).toBeFalsy();
|
expect(wrapper.contains('.van-popup__close-icon')).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('allow-same-day prop', async () => {
|
||||||
|
const select = jest.fn();
|
||||||
|
const wrapper = mount(Calendar, {
|
||||||
|
propsData: {
|
||||||
|
type: 'range',
|
||||||
|
minDate,
|
||||||
|
maxDate,
|
||||||
|
poppable: false,
|
||||||
|
},
|
||||||
|
listeners: {
|
||||||
|
select,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await later();
|
||||||
|
|
||||||
|
const days = wrapper.findAll('.van-calendar__day');
|
||||||
|
days.at(9).trigger('click');
|
||||||
|
days.at(9).trigger('click');
|
||||||
|
|
||||||
|
expect(select).toHaveBeenLastCalledWith([minDate, null]);
|
||||||
|
|
||||||
|
wrapper.setProps({
|
||||||
|
allowSameDay: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
days.at(9).trigger('click');
|
||||||
|
expect(select).toHaveBeenLastCalledWith([minDate, minDate]);
|
||||||
|
});
|
||||||
|
@ -16,6 +16,7 @@ export default {
|
|||||||
end: 'End',
|
end: 'End',
|
||||||
start: 'Start',
|
start: 'Start',
|
||||||
title: 'Calendar',
|
title: 'Calendar',
|
||||||
|
startEnd: 'Start/End',
|
||||||
weekdays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
weekdays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
||||||
monthTitle: (year: number, month: number) => `${year}/${month}`,
|
monthTitle: (year: number, month: number) => `${year}/${month}`,
|
||||||
rangePrompt: (maxRange: number) => `Choose no more than ${maxRange} days`,
|
rangePrompt: (maxRange: number) => `Choose no more than ${maxRange} days`,
|
||||||
|
@ -14,8 +14,9 @@ export default {
|
|||||||
telInvalid: 'Teléfono inválido',
|
telInvalid: 'Teléfono inválido',
|
||||||
vanCalendar: {
|
vanCalendar: {
|
||||||
end: 'Fin',
|
end: 'Fin',
|
||||||
start: 'Comienzo',
|
start: 'Inicio',
|
||||||
title: 'Calendario',
|
title: 'Calendario',
|
||||||
|
startEnd: 'Inicio/Fin',
|
||||||
weekdays: ['Dom', 'Lun', 'Mar', 'Mié', 'Jue', 'Vie', 'Sáb'],
|
weekdays: ['Dom', 'Lun', 'Mar', 'Mié', 'Jue', 'Vie', 'Sáb'],
|
||||||
monthTitle: (year: number, month: number) => `${year}/${month}`,
|
monthTitle: (year: number, month: number) => `${year}/${month}`,
|
||||||
rangePrompt: (maxRange: number) => `Elija no más de ${maxRange} días`,
|
rangePrompt: (maxRange: number) => `Elija no más de ${maxRange} días`,
|
||||||
|
@ -16,6 +16,7 @@ export default {
|
|||||||
end: 'Son',
|
end: 'Son',
|
||||||
start: 'Başlat',
|
start: 'Başlat',
|
||||||
title: 'Takvim',
|
title: 'Takvim',
|
||||||
|
startEnd: 'Başlat/Son',
|
||||||
weekdays: ['Paz', 'Pzt', 'Sal', 'Çar', 'Per', 'Cum', 'Cmt'],
|
weekdays: ['Paz', 'Pzt', 'Sal', 'Çar', 'Per', 'Cum', 'Cmt'],
|
||||||
monthTitle: (year: number, month: number) => `${year}/${month}`,
|
monthTitle: (year: number, month: number) => `${year}/${month}`,
|
||||||
rangePrompt: (maxRange: number) => `En fazla ${maxRange} gün seçin`,
|
rangePrompt: (maxRange: number) => `En fazla ${maxRange} gün seçin`,
|
||||||
|
@ -17,6 +17,7 @@ export default {
|
|||||||
start: '开始',
|
start: '开始',
|
||||||
title: '日期选择',
|
title: '日期选择',
|
||||||
confirm: '确定',
|
confirm: '确定',
|
||||||
|
startEnd: '开始/结束',
|
||||||
weekdays: ['日', '一', '二', '三', '四', '五', '六'],
|
weekdays: ['日', '一', '二', '三', '四', '五', '六'],
|
||||||
monthTitle: (year: number, month: number) => `${year}年${month}月`,
|
monthTitle: (year: number, month: number) => `${year}年${month}月`,
|
||||||
rangePrompt: (maxRange: number) => `选择天数不能超过 ${maxRange} 天`,
|
rangePrompt: (maxRange: number) => `选择天数不能超过 ${maxRange} 天`,
|
||||||
|
@ -17,6 +17,7 @@ export default {
|
|||||||
start: '開始',
|
start: '開始',
|
||||||
title: '日期選擇',
|
title: '日期選擇',
|
||||||
confirm: '確定',
|
confirm: '確定',
|
||||||
|
startEnd: '開始/結束',
|
||||||
weekdays: ['日', '壹', '二', '三', '四', '五', '六'],
|
weekdays: ['日', '壹', '二', '三', '四', '五', '六'],
|
||||||
monthTitle: (year: number, month: number) => `${year}年${month}月`,
|
monthTitle: (year: number, month: number) => `${year}年${month}月`,
|
||||||
rangePrompt: (maxRange: number) => `選擇天數不能超過 ${maxRange} 天`,
|
rangePrompt: (maxRange: number) => `選擇天數不能超過 ${maxRange} 天`,
|
||||||
|
@ -17,6 +17,7 @@ export default {
|
|||||||
start: '開始',
|
start: '開始',
|
||||||
title: '日期選擇',
|
title: '日期選擇',
|
||||||
confirm: '確定',
|
confirm: '確定',
|
||||||
|
startEnd: '開始/結束',
|
||||||
weekdays: ['日', '壹', '二', '三', '四', '五', '六'],
|
weekdays: ['日', '壹', '二', '三', '四', '五', '六'],
|
||||||
monthTitle: (year: number, month: number) => `${year}年${month}月`,
|
monthTitle: (year: number, month: number) => `${year}年${month}月`,
|
||||||
rangePrompt: (maxRange: number) => `選擇天數不能超過 ${maxRange} 天`,
|
rangePrompt: (maxRange: number) => `選擇天數不能超過 ${maxRange} 天`,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user