Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 为了适配,datepicker组件新增取消禁用日期选择限制的能力,在获取日期的方法中,新增一个参数用于取消禁用日期选择限制 #1674

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/web/api/date-picker.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ You can use `DatePickerPanel` and `DateRangePickerPanel` separately. You can ass

{{ panel }}

### An unbounded date range selector。

{{ cancel-range-limit }}

## FAQ

### The backend data format is special. How can I format the date quickly?
Expand Down
4 changes: 4 additions & 0 deletions docs/web/api/date-picker.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ spline: form

{{ panel }}

### 不限制日期区间选择范围的选择器。

{{ cancel-range-limit }}

## FAQ

### 后端数据格式要求比较特殊,如何快捷格式化日期?
Expand Down
18 changes: 11 additions & 7 deletions js/date-picker/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export interface OptionsType {
dayjsLocale?: string;
monthLocal?: string[];
quarterLocal?: string[];
cancelRangeSelectLimit?: boolean;
}

export function getWeeks(
Expand All @@ -215,6 +216,7 @@ export function getWeeks(
minDate,
maxDate,
dayjsLocale = 'zh-cn',
cancelRangeSelectLimit = false,
}: OptionsType,
) {
const prependDay = getFirstDayOfMonth({ year, month });
Expand All @@ -230,7 +232,7 @@ export function getWeeks(
active: false,
value: currentDay,
disabled: (isFunction(disableDate) && disableDate(currentDay))
|| outOfRanges(currentDay, minDate, maxDate),
|| (!cancelRangeSelectLimit && outOfRanges(currentDay, minDate, maxDate)),
now: isSame(today, currentDay),
firstDayOfMonth: i === 1,
lastDayOfMonth: i === maxDays,
Expand All @@ -246,7 +248,7 @@ export function getWeeks(
text: prependDay.getDate().toString(),
active: false,
value: new Date(prependDay),
disabled: (isFunction(disableDate) && disableDate(prependDay)) || outOfRanges(prependDay, minDate, maxDate),
disabled: (isFunction(disableDate) && disableDate(prependDay)) || (!cancelRangeSelectLimit && outOfRanges(prependDay, minDate, maxDate)),
additional: true, // 非当前月
type: 'prev-month',
dayjsObj: dayjs(prependDay).locale(dayjsLocale),
Expand All @@ -263,7 +265,7 @@ export function getWeeks(
text: appendDay.getDate(),
active: false,
value: new Date(appendDay),
disabled: (isFunction(disableDate) && disableDate(appendDay)) || outOfRanges(appendDay, minDate, maxDate),
disabled: (isFunction(disableDate) && disableDate(appendDay)) || (!cancelRangeSelectLimit && outOfRanges(appendDay, minDate, maxDate)),
additional: true, // 非当前月
type: 'next-month',
dayjsObj: dayjs(appendDay).locale(dayjsLocale),
Expand Down Expand Up @@ -295,6 +297,7 @@ export function getQuarters(
maxDate,
quarterLocal,
dayjsLocale = 'zh-cn',
cancelRangeSelectLimit = false,
}: OptionsType,
) {
const quarterArr = [];
Expand All @@ -306,7 +309,7 @@ export function getQuarters(
quarterArr.push({
value: date,
now: isSame(date, today, 'quarter'),
disabled: (isFunction(disableDate) && disableDate(date)) || outOfRanges(date, minDate, maxDate),
disabled: (isFunction(disableDate) && disableDate(date)) || (!cancelRangeSelectLimit && outOfRanges(date, minDate, maxDate)),
active: false,
text: quarterLocal[i - 1],
dayjsObj: dayjs(date).locale(dayjsLocale),
Expand All @@ -323,6 +326,7 @@ export function getYears(
minDate,
maxDate,
dayjsLocale = 'zh-cn',
cancelRangeSelectLimit = false,
}: OptionsType,
) {
const startYear = parseInt((year / 10).toString(), 10) * 10;
Expand All @@ -338,7 +342,7 @@ export function getYears(
yearArr.push({
value: date,
now: isSame(date, today, 'year'),
disabled: (isFunction(disableDate) && disableDate(date)) || outOfRanges(date, minDate, maxDate),
disabled: (isFunction(disableDate) && disableDate(date)) || (!cancelRangeSelectLimit && outOfRanges(date, minDate, maxDate)),
active: false,
text: `${date.getFullYear()}`,
dayjsObj: dayjs(date).locale(dayjsLocale),
Expand All @@ -350,7 +354,7 @@ export function getYears(

export function getMonths(year: number, params: OptionsType) {
const {
disableDate = () => false, minDate, maxDate, monthLocal, dayjsLocale = 'zh-cn',
disableDate = () => false, minDate, maxDate, monthLocal, dayjsLocale = 'zh-cn', cancelRangeSelectLimit = false,
} = params;
const MonthArr = [];
const today = getToday();
Expand All @@ -361,7 +365,7 @@ export function getMonths(year: number, params: OptionsType) {
MonthArr.push({
value: date,
now: isSame(date, today, 'month'),
disabled: (isFunction(disableDate) && disableDate(date)) || outOfRanges(date, minDate, maxDate),
disabled: (isFunction(disableDate) && disableDate(date)) || (!cancelRangeSelectLimit && outOfRanges(date, minDate, maxDate)),
active: false,
text: monthLocal[date.getMonth()], // `${date.getMonth() + 1} ${monthText || '月'}`,
dayjsObj: dayjs(date).locale(dayjsLocale),
Expand Down
Loading