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

This commit is contained in:
sqzhou 2022-02-07 23:27:53 +08:00
parent 15c36bc608
commit 5924521a39
5 changed files with 35 additions and 29 deletions

View File

@ -332,7 +332,7 @@ export class DateRangePicker extends React.Component<
isFocused: true
});
const {onFocus} = this.props;
onFocus && onFocus();
onFocus && onFocus(e);
}
handleBlur(e: React.SyntheticEvent<HTMLDivElement>) {
@ -340,7 +340,7 @@ export class DateRangePicker extends React.Component<
isFocused: false
});
const {onBlur} = this.props;
onBlur && onBlur();
onBlur && onBlur(e);
}
open() {

View File

@ -415,9 +415,9 @@ export default class DateControl extends React.PureComponent<
// 派发有event的事件
@autobind
dispatchEvent(event: React.SyntheticEvent<HTMLElement> | string, data: any = {}) {
const {dispatchEvent} = this.props;
const dispatcher = dispatchEvent(event, createObject(data));
dispatchEvent(eventName: string, e: React.SyntheticEvent<HTMLElement> | string) {
const {dispatchEvent, value} = this.props;
const dispatcher = dispatchEvent(eventName, createObject({e, value}));
if (dispatcher?.prevented) {
return;
}
@ -434,8 +434,11 @@ export default class DateControl extends React.PureComponent<
// 值的变化
@autobind
async handleChange(data: any) {
const {dispatchEvent} = this.props;
const dispatcher = dispatchEvent('change', createObject(data));
const {dispatchEvent, value} = this.props;
const dispatcher = dispatchEvent('change', createObject({
oldValue: value,
value: data
}));
if (dispatcher?.prevented) {
return;
}
@ -485,8 +488,8 @@ export default class DateControl extends React.PureComponent<
largeMode={largeMode}
onScheduleClick={this.onScheduleClick.bind(this)}
onChange={this.handleChange}
onFocus={this.dispatchEvent}
onBlur={this.dispatchEvent}
onFocus={(e: React.SyntheticEvent<HTMLDivElement>) => this.dispatchEvent('focus', e)}
onBlur={(e: React.SyntheticEvent<HTMLDivElement>) => this.dispatchEvent('blur', e)}
/>
</div>
);

View File

@ -165,9 +165,9 @@ export default class DateRangeControl extends React.Component<DateRangeProps> {
// 派发有event的事件
@autobind
dispatchEvent(event: React.SyntheticEvent<HTMLElement> | string, data: any = {}) {
const {dispatchEvent} = this.props;
const dispatcher = dispatchEvent(event, createObject(data));
dispatchEvent(eventName: string, e: React.SyntheticEvent<HTMLElement> | string) {
const {dispatchEvent, value} = this.props;
const dispatcher = dispatchEvent(eventName, createObject({e, value}));
if (dispatcher?.prevented) {
return;
}
@ -184,8 +184,11 @@ export default class DateRangeControl extends React.Component<DateRangeProps> {
// 值的变化
@autobind
async handleChange(data: any) {
const {dispatchEvent} = this.props;
const dispatcher = dispatchEvent('change', createObject(data));
const {dispatchEvent, value} = this.props;
const dispatcher = dispatchEvent('change', createObject({
oldValue: value,
value: data
}));
if (dispatcher?.prevented) {
return;
}
@ -227,8 +230,8 @@ export default class DateRangeControl extends React.Component<DateRangeProps> {
minDuration={minDuration ? parseDuration(minDuration) : undefined}
maxDuration={maxDuration ? parseDuration(maxDuration) : undefined}
onChange={this.handleChange}
onFocus={this.dispatchEvent}
onBlur={this.dispatchEvent}
onFocus={(e: React.SyntheticEvent<HTMLDivElement>) => this.dispatchEvent('focus', e)}
onBlur={(e: React.SyntheticEvent<HTMLDivElement>) => this.dispatchEvent('blur', e)}
/>
</div>
);

View File

@ -162,9 +162,9 @@ export default class MonthRangeControl extends React.Component<MonthRangeProps>
// 派发有event的事件
@autobind
dispatchEvent(event: React.SyntheticEvent<HTMLElement> | string, data: any = {}) {
const {dispatchEvent} = this.props;
const dispatcher = dispatchEvent(event, createObject(data));
dispatchEvent(eventName: string, e: React.SyntheticEvent<HTMLElement> | string) {
const {dispatchEvent, value} = this.props;
const dispatcher = dispatchEvent(eventName, createObject({e, value}));
if (dispatcher?.prevented) {
return;
}
@ -181,8 +181,11 @@ export default class MonthRangeControl extends React.Component<MonthRangeProps>
// 值的变化
@autobind
async handleChange(data: any) {
const {dispatchEvent} = this.props;
const dispatcher = dispatchEvent('change', createObject(data));
const {dispatchEvent, value} = this.props;
const dispatcher = dispatchEvent('change', createObject({
oldValue: value,
value: data
}));
if (dispatcher?.prevented) {
return;
}
@ -217,8 +220,8 @@ export default class MonthRangeControl extends React.Component<MonthRangeProps>
minDuration={minDuration ? parseDuration(minDuration) : undefined}
maxDuration={maxDuration ? parseDuration(maxDuration) : undefined}
onChange={this.handleChange}
onFocus={this.dispatchEvent}
onBlur={this.dispatchEvent}
onFocus={(e: React.SyntheticEvent<HTMLDivElement>) => this.dispatchEvent('focus', e)}
onBlur={(e: React.SyntheticEvent<HTMLDivElement>) => this.dispatchEvent('blur', e)}
/>
</div>
);

View File

@ -1,12 +1,10 @@
import React from 'react';
import {FormItem} from './Item';
import cx from 'classnames';
import includes from 'lodash/includes';
import {filterDate, parseDuration} from '../../utils/tpl-builtin';
import InputDateRange, {DateRangeControlSchema} from './InputDateRange';
import DateRangePicker from '../../components/DateRangePicker';
import {createObject, autobind} from '../../utils/helper';
import {Action} from '../../types';
/**
* YearRange
* https://baidu.gitee.io/amis/docs/components/form/input-year-range
@ -17,7 +15,6 @@ export interface YearRangeControlSchema
}
export default class YearRangeControl extends InputDateRange {
render() {
const {
className,
@ -50,8 +47,8 @@ export default class YearRangeControl extends InputDateRange {
minDuration={minDuration ? parseDuration(minDuration) : undefined}
maxDuration={maxDuration ? parseDuration(maxDuration) : undefined}
onChange={this.handleChange}
onFocus={this.dispatchEvent}
onBlur={this.dispatchEvent}
onFocus={(e: React.SyntheticEvent<HTMLDivElement>) => this.dispatchEvent('focus', e)}
onBlur={(e: React.SyntheticEvent<HTMLDivElement>) => this.dispatchEvent('blur', e)}
/>
</div>
);