From 8075af69f22e1489ad0c727d44b083de511537b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=8E=86=E6=95=8F?= Date: Thu, 29 Oct 2020 00:12:37 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E9=80=9A?= =?UTF-8?q?=E8=BF=87inputFormat=E6=8E=A7=E5=88=B6=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E6=98=BE=E7=A4=BA=E5=B9=B4=E4=BB=BD=EF=BC=8C?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E5=B9=B4=E4=BB=BD=E6=98=AF=E5=90=A6=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E7=82=B9=E5=87=BB=E5=87=BA=E7=8E=B0=E5=B9=B4=E4=BB=BD?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/components/Form/Full.jsx | 14 ++++++++++- src/components/DatePicker.tsx | 1 + src/components/calendar/Calendar.tsx | 7 ++++-- src/components/calendar/MonthsView.tsx | 35 ++++++++++++++++++++------ 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/examples/components/Form/Full.jsx b/examples/components/Form/Full.jsx index ba399d2b0..b9e5f4037 100644 --- a/examples/components/Form/Full.jsx +++ b/examples/components/Form/Full.jsx @@ -577,12 +577,24 @@ export default { { type: 'divider' }, + { + type: 'month', + name: 'year-month', + inline: true, + label: '年月', + "value": "-1month", + "inputFormat": "YYYY-MM" + }, + { + type: 'divider' + }, { type: 'month', name: 'month', inline: true, label: '月份', - "value": "-1month" + "value": "-1month", + "inputFormat": "MM" }, { type: 'divider' diff --git a/src/components/DatePicker.tsx b/src/components/DatePicker.tsx index 6acd05880..0c884b621 100644 --- a/src/components/DatePicker.tsx +++ b/src/components/DatePicker.tsx @@ -576,6 +576,7 @@ export class DatePicker extends React.Component { onChange={this.handleChange} requiredConfirm={!!(dateFormat && timeFormat)} dateFormat={dateFormat} + inputFormat={inputFormat} timeFormat={timeFormat} isValidDate={this.checkIsValidDate} viewMode={viewMode} diff --git a/src/components/calendar/Calendar.tsx b/src/components/calendar/Calendar.tsx index 06c4118ca..354ef810f 100644 --- a/src/components/calendar/Calendar.tsx +++ b/src/components/calendar/Calendar.tsx @@ -8,6 +8,7 @@ import cx from 'classnames'; import moment from 'moment'; interface BaseDatePickerProps extends ReactDatePicker.DatetimepickerProps { + inputFormat: string; onViewModeChange?: (type: string) => void; requiredConfirm?: boolean; onClose?: () => void; @@ -29,6 +30,7 @@ class BaseDatePicker extends ReactDatePicker { props.setDateTimeState = this.setState.bind(this); [ + 'inputFormat', 'onChange', 'onClose', 'requiredConfirm', @@ -43,9 +45,10 @@ class BaseDatePicker extends ReactDatePicker { })((this as any).getComponentProps); setDate = (type: 'month' | 'year') => { + const currentShould = this.props.viewMode === 'months' && this.props.inputFormat.toUpperCase() !== 'MM' const nextViews = { - month: 'days', - year: 'days' + month: currentShould?'months':'days', + year: currentShould?'months':'days' }; return (e: any) => { diff --git a/src/components/calendar/MonthsView.tsx b/src/components/calendar/MonthsView.tsx index 8fb8d60c3..9c282374c 100644 --- a/src/components/calendar/MonthsView.tsx +++ b/src/components/calendar/MonthsView.tsx @@ -2,7 +2,11 @@ import MonthsView from 'react-datetime/src/MonthsView'; import moment from 'moment'; import React from 'react'; -import {LocaleProps, localeable} from '../../locale'; +import {LocaleProps, localeable, TranslateFn} from '../../locale'; + +export interface OtherProps { + inputFormat: string; +} export class CustomMonthsView extends MonthsView { props: { @@ -17,7 +21,8 @@ export class CustomMonthsView extends MonthsView { type: string, toSelected?: moment.Moment ) => () => void; - } & LocaleProps; + showView: (view: string) => () => void; + } & LocaleProps & OtherProps; renderMonths: () => JSX.Element; renderMonth = (props: any, month: number) => { var localMoment = this.props.viewDate; @@ -36,11 +41,14 @@ export class CustomMonthsView extends MonthsView { }; render() { const __ = this.props.translate; - + console.log('CustomMonthsView',this.props); + const showYearHead = this.props.inputFormat.toUpperCase() !== 'MM' + const canClick = this.props.inputFormat.toUpperCase() === 'YYYY-MM' + console.log('canClick',canClick); return (
- + {showYearHead&& - + { + canClick + ? + + : + + } + {/**/} - + }
« - {this.props.viewDate.format(__('YYYY年'))} - + {this.props.viewDate.format(__('YYYY年'))} + + {this.props.viewDate.format(__('YYYY年'))} + */} + {/* {this.props.viewDate.format(__('YYYY年'))}*/} + {/* »
{this.renderMonths()} From 52e745de4c1186b35c57921e015c4e2a4bedb044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=8E=86=E6=95=8F?= Date: Thu, 29 Oct 2020 00:15:39 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E5=8E=BB=E6=8E=89console?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/calendar/MonthsView.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/components/calendar/MonthsView.tsx b/src/components/calendar/MonthsView.tsx index 9c282374c..d6c65ac75 100644 --- a/src/components/calendar/MonthsView.tsx +++ b/src/components/calendar/MonthsView.tsx @@ -41,10 +41,8 @@ export class CustomMonthsView extends MonthsView { }; render() { const __ = this.props.translate; - console.log('CustomMonthsView',this.props); const showYearHead = this.props.inputFormat.toUpperCase() !== 'MM' const canClick = this.props.inputFormat.toUpperCase() === 'YYYY-MM' - console.log('canClick',canClick); return (
@@ -67,9 +65,7 @@ export class CustomMonthsView extends MonthsView { {this.props.viewDate.format(__('YYYY年'))} } - {/**/} +
*/} - {/* {this.props.viewDate.format(__('YYYY年'))}*/} - {/* »