mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
feat: 移动端日期选择器显示年月日单位 & 月份选择器显示年月日单位
This commit is contained in:
parent
ac4e748c9c
commit
07758e6b14
@ -222,7 +222,7 @@ export class CustomDaysView extends React.Component<CustomDaysViewProps> {
|
|||||||
const dateBoundary = this.props.getDateBoundary(currentDate);
|
const dateBoundary = this.props.getDateBoundary(currentDate);
|
||||||
const columns = this.props.getColumns(types, dateBoundary);
|
const columns = this.props.getColumns(types, dateBoundary);
|
||||||
this.state = {
|
this.state = {
|
||||||
columns,
|
columns: this.getColumnsWithUnit(columns),
|
||||||
types,
|
types,
|
||||||
pickerValue: currentDate.toArray(),
|
pickerValue: currentDate.toArray(),
|
||||||
uniqueTag: new Date().valueOf()
|
uniqueTag: new Date().valueOf()
|
||||||
@ -260,6 +260,19 @@ export class CustomDaysView extends React.Component<CustomDaysViewProps> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getColumnsWithUnit(columns: {options: PickerOption[]}[]) {
|
||||||
|
return this.props.locale === 'zh-CN' && columns.length === 3
|
||||||
|
? columns.map((item, index) => {
|
||||||
|
item.options?.map((option: any) => {
|
||||||
|
option.text =
|
||||||
|
option.text + (index === 0 ? '年' : index === 1 ? '月' : '日');
|
||||||
|
return option;
|
||||||
|
});
|
||||||
|
return item;
|
||||||
|
})
|
||||||
|
: columns;
|
||||||
|
}
|
||||||
|
|
||||||
updateSelectedDate = (event: React.MouseEvent<any>) => {
|
updateSelectedDate = (event: React.MouseEvent<any>) => {
|
||||||
// need confirm
|
// need confirm
|
||||||
if (this.props.requiredConfirm) {
|
if (this.props.requiredConfirm) {
|
||||||
@ -748,7 +761,9 @@ export class CustomDaysView extends React.Component<CustomDaysViewProps> {
|
|||||||
);
|
);
|
||||||
const dateBoundary = this.props.getDateBoundary(selectDate);
|
const dateBoundary = this.props.getDateBoundary(selectDate);
|
||||||
this.setState({
|
this.setState({
|
||||||
columns: this.props.getColumns(this.state.types, dateBoundary),
|
columns: this.getColumnsWithUnit(
|
||||||
|
this.props.getColumns(this.state.types, dateBoundary)
|
||||||
|
),
|
||||||
pickerValue: value
|
pickerValue: value
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ export class CustomMonthsView extends React.Component<CustomMonthsViewProps> {
|
|||||||
const dateBoundary = this.props.getDateBoundary(currentDate);
|
const dateBoundary = this.props.getDateBoundary(currentDate);
|
||||||
const columns = this.props.getColumns(['year', 'month'], dateBoundary);
|
const columns = this.props.getColumns(['year', 'month'], dateBoundary);
|
||||||
this.state = {
|
this.state = {
|
||||||
columns,
|
columns: this.getColumnsWithUnit(columns),
|
||||||
pickerValue: currentDate.toArray()
|
pickerValue: currentDate.toArray()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -148,6 +148,18 @@ export class CustomMonthsView extends React.Component<CustomMonthsViewProps> {
|
|||||||
this.props.updateSelectedDate(event);
|
this.props.updateSelectedDate(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getColumnsWithUnit(columns: {options: PickerOption[]}[]) {
|
||||||
|
return this.props.locale === 'zh-CN' && columns.length === 2
|
||||||
|
? columns.map((item, index) => {
|
||||||
|
item.options?.map((option: any) => {
|
||||||
|
option.text = option.text + (index === 0 ? '年' : '月');
|
||||||
|
return option;
|
||||||
|
});
|
||||||
|
return item;
|
||||||
|
})
|
||||||
|
: columns;
|
||||||
|
}
|
||||||
|
|
||||||
renderMonth = (
|
renderMonth = (
|
||||||
props: any,
|
props: any,
|
||||||
month: number,
|
month: number,
|
||||||
@ -212,7 +224,10 @@ export class CustomMonthsView extends React.Component<CustomMonthsViewProps> {
|
|||||||
};
|
};
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
this.setState({columns, pickerValue: value});
|
this.setState({
|
||||||
|
columns: this.getColumnsWithUnit(columns),
|
||||||
|
pickerValue: value
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user