mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-05 05:18:34 +08:00
整理 closeOnSelect 逻辑
This commit is contained in:
parent
de42efad01
commit
d7e2852915
@ -229,9 +229,13 @@ export interface DatePickerState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class DatePicker extends React.Component<DateProps, DatePickerState> {
|
export class DatePicker extends React.Component<DateProps, DatePickerState> {
|
||||||
static defaultProps: Pick<DateProps, 'viewMode' | 'shortcuts'> = {
|
static defaultProps: Pick<
|
||||||
|
DateProps,
|
||||||
|
'viewMode' | 'shortcuts' | 'closeOnSelect'
|
||||||
|
> = {
|
||||||
viewMode: 'days',
|
viewMode: 'days',
|
||||||
shortcuts: ''
|
shortcuts: '',
|
||||||
|
closeOnSelect: true
|
||||||
};
|
};
|
||||||
state: DatePickerState = {
|
state: DatePickerState = {
|
||||||
isOpened: false,
|
isOpened: false,
|
||||||
@ -342,7 +346,8 @@ export class DatePicker extends React.Component<DateProps, DatePickerState> {
|
|||||||
minTime,
|
minTime,
|
||||||
maxTime,
|
maxTime,
|
||||||
dateFormat,
|
dateFormat,
|
||||||
timeFormat
|
timeFormat,
|
||||||
|
closeOnSelect
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
if (!moment.isMoment(value)) {
|
if (!moment.isMoment(value)) {
|
||||||
@ -357,15 +362,17 @@ export class DatePicker extends React.Component<DateProps, DatePickerState> {
|
|||||||
|
|
||||||
onChange(value.format(format));
|
onChange(value.format(format));
|
||||||
|
|
||||||
if (dateFormat && !timeFormat) {
|
if (closeOnSelect && dateFormat && !timeFormat) {
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
selectRannge(item: any) {
|
selectRannge(item: any) {
|
||||||
|
const {closeOnSelect} = this.props;
|
||||||
const now = moment();
|
const now = moment();
|
||||||
this.handleChange(item.date(now));
|
this.handleChange(item.date(now));
|
||||||
this.close();
|
|
||||||
|
closeOnSelect && this.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
checkIsValidDate(currentDate: moment.Moment) {
|
checkIsValidDate(currentDate: moment.Moment) {
|
||||||
@ -465,7 +472,8 @@ export class DatePicker extends React.Component<DateProps, DatePickerState> {
|
|||||||
popOverContainer,
|
popOverContainer,
|
||||||
clearable,
|
clearable,
|
||||||
shortcuts,
|
shortcuts,
|
||||||
utc
|
utc,
|
||||||
|
closeOnSelect
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
const isOpened = this.state.isOpened;
|
const isOpened = this.state.isOpened;
|
||||||
|
@ -172,7 +172,7 @@ export class DateRangePicker extends React.Component<
|
|||||||
ranges: 'yesterday,7daysago,prevweek,thismonth,prevmonth,prevquarter',
|
ranges: 'yesterday,7daysago,prevweek,thismonth,prevmonth,prevquarter',
|
||||||
iconClassName: 'fa fa-calendar',
|
iconClassName: 'fa fa-calendar',
|
||||||
resetValue: '',
|
resetValue: '',
|
||||||
closeOnSelect: false
|
closeOnSelect: true
|
||||||
};
|
};
|
||||||
|
|
||||||
innerDom: any;
|
innerDom: any;
|
||||||
@ -389,7 +389,7 @@ export class DateRangePicker extends React.Component<
|
|||||||
startDate: range.startDate(now.clone()),
|
startDate: range.startDate(now.clone()),
|
||||||
endDate: range.endDate(now.clone())
|
endDate: range.endDate(now.clone())
|
||||||
},
|
},
|
||||||
closeOnSelect ? this.close : noop
|
closeOnSelect ? this.confirm : noop
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,11 +4,13 @@ import cx from 'classnames';
|
|||||||
import {filterDate} from '../../utils/tpl-builtin';
|
import {filterDate} from '../../utils/tpl-builtin';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import 'moment/locale/zh-cn';
|
import 'moment/locale/zh-cn';
|
||||||
import DateRangePicker from '../../components/DateRangePicker';
|
import DateRangePicker, {
|
||||||
|
DateRangePicker as BaseDateRangePicker
|
||||||
|
} from '../../components/DateRangePicker';
|
||||||
|
|
||||||
export interface DateRangeProps extends FormControlProps {
|
export interface DateRangeProps extends FormControlProps {
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
disabled?: boolean;
|
disabled: boolean;
|
||||||
format: string;
|
format: string;
|
||||||
joinValues: boolean;
|
joinValues: boolean;
|
||||||
delimiter: string;
|
delimiter: string;
|
||||||
@ -59,7 +61,7 @@ export default class DateRangeControl extends React.Component<
|
|||||||
? defaultValue.split(delimiter)
|
? defaultValue.split(delimiter)
|
||||||
: defaultValue;
|
: defaultValue;
|
||||||
setPrinstineValue(
|
setPrinstineValue(
|
||||||
DateRangePicker.formatValue(
|
BaseDateRangePicker.formatValue(
|
||||||
{
|
{
|
||||||
startDate: filterDate(arr[0], data),
|
startDate: filterDate(arr[0], data),
|
||||||
endDate: filterDate(arr[1], data)
|
endDate: filterDate(arr[1], data)
|
||||||
@ -106,7 +108,7 @@ export default class DateRangeControl extends React.Component<
|
|||||||
|
|
||||||
setPrinstineValue(
|
setPrinstineValue(
|
||||||
arr
|
arr
|
||||||
? DateRangePicker.formatValue(
|
? BaseDateRangePicker.formatValue(
|
||||||
{
|
{
|
||||||
startDate: filterDate(arr[0], data),
|
startDate: filterDate(arr[0], data),
|
||||||
endDate: filterDate(arr[1], data)
|
endDate: filterDate(arr[1], data)
|
||||||
|
Loading…
Reference in New Issue
Block a user