feat: 时间类的事件和动作补充

This commit is contained in:
sqzhou 2022-02-07 22:29:10 +08:00
parent be000fb38a
commit 15c36bc608
5 changed files with 38 additions and 39 deletions

View File

@ -417,25 +417,29 @@ export default class DateControl extends React.PureComponent<
@autobind
dispatchEvent(event: React.SyntheticEvent<HTMLElement> | string, data: any = {}) {
const {dispatchEvent} = this.props;
dispatchEvent(event, createObject(data));
const dispatcher = dispatchEvent(event, createObject(data));
if (dispatcher?.prevented) {
return;
}
}
// 动作
doAction(action: Action, data: object, throwErrors: boolean) {
const {resetValue, onChange} = this.props;
if (action.actionType === 'clear') {
onChange('');
}
if (action.actionType === 'reset') {
onChange(resetValue || '');
onChange(resetValue ?? '');
}
}
// 值的变化
@autobind
handleChange(data: any) {
async handleChange(data: any) {
const {dispatchEvent} = this.props;
const dispatcher = dispatchEvent('change', createObject(data));
if (dispatcher?.prevented) {
return;
}
this.props.onChange(data);
this.dispatchEvent('change', data);
}
render() {

View File

@ -167,22 +167,29 @@ export default class DateRangeControl extends React.Component<DateRangeProps> {
@autobind
dispatchEvent(event: React.SyntheticEvent<HTMLElement> | string, data: any = {}) {
const {dispatchEvent} = this.props;
dispatchEvent(event, createObject(data));
const dispatcher = dispatchEvent(event, createObject(data));
if (dispatcher?.prevented) {
return;
}
}
// 动作
doAction(action: Action, data: object, throwErrors: boolean) {
const {resetValue, onChange} = this.props;
if (includes(['clear', 'reset'], action.actionType)) {
onChange(resetValue || '');
if (action.actionType === 'clear') {
onChange(resetValue ?? '');
}
}
// 值的变化
@autobind
handleChange(data: any) {
async handleChange(data: any) {
const {dispatchEvent} = this.props;
const dispatcher = dispatchEvent('change', createObject(data));
if (dispatcher?.prevented) {
return;
}
this.props.onChange(data);
this.dispatchEvent('change', data);
}
render() {

View File

@ -164,22 +164,29 @@ export default class MonthRangeControl extends React.Component<MonthRangeProps>
@autobind
dispatchEvent(event: React.SyntheticEvent<HTMLElement> | string, data: any = {}) {
const {dispatchEvent} = this.props;
dispatchEvent(event, createObject(data));
const dispatcher = dispatchEvent(event, createObject(data));
if (dispatcher?.prevented) {
return;
}
}
// 动作
doAction(action: Action, data: object, throwErrors: boolean) {
const {resetValue, onChange} = this.props;
if (includes(['clear', 'reset'], action.actionType)) {
onChange(resetValue || '');
if (action.actionType === 'clear') {
onChange(resetValue ?? '');
}
}
// 值的变化
@autobind
handleChange(data: any) {
async handleChange(data: any) {
const {dispatchEvent} = this.props;
const dispatcher = dispatchEvent('change', createObject(data));
if (dispatcher?.prevented) {
return;
}
this.props.onChange(data);
this.dispatchEvent('change', data);
}
render() {

View File

@ -45,6 +45,9 @@ export default class QuarterRangeControl extends InputDateRange {
maxDate={maxDate ? filterDate(maxDate, data, format) : undefined}
minDuration={minDuration ? parseDuration(minDuration) : undefined}
maxDuration={maxDuration ? parseDuration(maxDuration) : undefined}
onChange={this.handleChange}
onFocus={this.dispatchEvent}
onBlur={this.dispatchEvent}
/>
</div>
);

View File

@ -18,28 +18,6 @@ export interface YearRangeControlSchema
export default class YearRangeControl extends InputDateRange {
// 派发有event的事件
@autobind
dispatchEvent(event: React.SyntheticEvent<HTMLElement> | string, data: any = {}) {
const {dispatchEvent} = this.props;
dispatchEvent(event, createObject(data));
}
// 动作
doAction(action: Action, data: object, throwErrors: boolean) {
const {resetValue, onChange} = this.props;
if (includes(['clear', 'reset'], action.actionType)) {
onChange(resetValue || '');
}
}
// 值的变化
@autobind
handleChange(data: any) {
this.props.onChange(data);
this.dispatchEvent('change', data);
}
render() {
const {
className,