fix: 修复日期时间范围选择组件bug (#9470)

* fix: 修复日期时间范围选择组件bug

* fix: 修复事件动作未国际化问题

---------

Co-authored-by: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com>
This commit is contained in:
qkiroc 2024-01-19 10:11:31 +08:00 committed by GitHub
parent e365d1cb76
commit 27015316de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 47 additions and 18 deletions

View File

@ -21,7 +21,8 @@ import {
JSONPipeIn,
JSONPipeOut,
JSONUpdate,
getFixDialogType
getFixDialogType,
appTranslate
} from '../util';
import {createObjectFromChain} from 'amis-core';
import {ErrorBoundary} from 'amis-core';
@ -106,7 +107,7 @@ export function makeWrapper(
manager.dataSchema.addScope([], this.scopeId);
if (info.name) {
const nodeSchema = manager.store.getNodeById(info.id)?.schema;
const tag = nodeSchema?.title ?? nodeSchema?.name;
const tag = appTranslate(nodeSchema?.title ?? nodeSchema?.name);
manager.dataSchema.current.tag = `${info.name}${
tag ? ` : ${tag}` : ''
}`;

View File

@ -525,7 +525,8 @@ export class DateRangePicker extends React.Component<
value: any,
format: string,
joinValues: boolean,
delimiter: string
delimiter: string,
data: any
) {
if (!value) {
return {
@ -538,8 +539,8 @@ export class DateRangePicker extends React.Component<
value = value.split(delimiter);
}
const startDate = moment(value?.[0], format);
const endDate = moment(value?.[1], format);
const startDate = filterDate(value?.[0], data, format);
const endDate = filterDate(value?.[1], data, format);
/**
* value输入都丢弃
@ -604,13 +605,15 @@ export class DateRangePicker extends React.Component<
inputFormat,
displayFormat,
dateFormat,
timeFormat
timeFormat,
data
} = this.props;
const {startDate, endDate} = DateRangePicker.unFormatValue(
value,
valueFormat || (format as string),
joinValues,
delimiter
delimiter,
data
);
let curDateFormat = dateFormat ?? '';
@ -684,7 +687,8 @@ export class DateRangePicker extends React.Component<
displayFormat,
dateFormat,
timeFormat,
delimiter
delimiter,
data
} = props;
if (
prevProps.displayFormat != displayFormat ||
@ -719,7 +723,8 @@ export class DateRangePicker extends React.Component<
value,
valueFormat || (format as string),
joinValues,
delimiter
delimiter,
data
);
this.setState({
startDate,
@ -809,13 +814,15 @@ export class DateRangePicker extends React.Component<
joinValues,
delimiter,
inputFormat,
displayFormat
displayFormat,
data
} = this.props;
const {startDate, endDate} = DateRangePicker.unFormatValue(
value,
valueFormat || (format as string),
joinValues,
delimiter
delimiter,
data
);
this.setState({
startDate,
@ -1436,7 +1443,8 @@ export class DateRangePicker extends React.Component<
joinValues,
delimiter,
inputFormat,
displayFormat
displayFormat,
data
} = this.props;
if (!resetValue) {
return;
@ -1445,7 +1453,8 @@ export class DateRangePicker extends React.Component<
resetValue,
valueFormat || (format as string),
joinValues,
delimiter
delimiter,
data
);
onChange(resetValue);
this.setState({
@ -1537,6 +1546,11 @@ export class DateRangePicker extends React.Component<
props.className += ' rdtBetween';
}
// 如果已经选择了开始时间和结束时间,那么中间的时间都不应该高亮
if (startDate && endDate && props.className.includes('rdtActive')) {
props.className = props.className.replace('rdtActive', '');
}
if (startDate && currentDate.isSame(startDate, 'day')) {
props.className += ' rdtActive rdtStartDay';
}

View File

@ -113,17 +113,29 @@ export class MonthRangePicker extends React.Component<
this.state = {
isOpened: false,
isFocused: false,
...DateRangePicker.unFormatValue(value, format, joinValues, delimiter)
...DateRangePicker.unFormatValue(
value,
format,
joinValues,
delimiter,
this.props.data
)
};
}
componentDidUpdate(prevProps: MonthRangePickerProps) {
const props = this.props;
const {value, format, joinValues, delimiter} = props;
const {value, format, joinValues, delimiter, data} = props;
if (prevProps.value !== value) {
this.setState({
...DateRangePicker.unFormatValue(value, format, joinValues, delimiter)
...DateRangePicker.unFormatValue(
value,
format,
joinValues,
delimiter,
data
)
});
}
}
@ -577,14 +589,16 @@ export class MonthRangePicker extends React.Component<
ranges,
shortcuts,
label,
translate: __
translate: __,
data
} = this.props;
const {isOpened, isFocused, startDate, endDate} = this.state;
const selectedDate = DateRangePicker.unFormatValue(
value,
format,
joinValues,
delimiter
delimiter,
data
);
const startViewValue = selectedDate.startDate
? selectedDate.startDate.format(inputFormat)