@@ -13,6 +13,8 @@ const MIDDLE_INDEX = Math.floor(DATE_LENGTH / 2); // 日期数组中间值
1313const MIDDLE_Y = - DATE_HEIGHT * MIDDLE_INDEX ; // translateY值
1414
1515const isUndefined = val => typeof val === 'undefined' ;
16+ const isArray = val => Object . prototype . toString . apply ( val ) === '[object Array]' ;
17+ const isFunction = val => Object . prototype . toString . apply ( val ) === '[object Function]' ;
1618
1719/**
1820 * 根据格式获取时间滑动的类别
@@ -44,7 +46,7 @@ type Props = {
4446 value : Object ,
4547 min : Object ,
4648 max : Object ,
47- format : string ,
49+ format : string | Array < * > ,
4850 step : number ,
4951 onSelect : Function ,
5052}
@@ -73,7 +75,19 @@ class DatePickerItem extends Component<void, Props, State> {
7375 } ;
7476
7577 // 设置时间选择器单元的类别
76- this . typeName = getTimeType ( props . format ) ;
78+ if ( isArray ( props . format ) ) {
79+ this . typeName = getTimeType ( props . format [ 0 ] ) ;
80+ this . format = props . format [ 0 ] ;
81+ if ( isFunction ( props . format [ 1 ] ) ) {
82+ this . formatTransform = props . format [ 1 ] ;
83+ }
84+ }
85+
86+ else {
87+ this . format = props . format ;
88+ this . typeName = getTimeType ( props . format ) ;
89+ }
90+
7791 this . renderDatepickerItem = this . renderDatepickerItem . bind ( this ) ;
7892 this . handleContentTouch = this . handleContentTouch . bind ( this ) ;
7993 this . handleContentMouseDown = this . handleContentMouseDown . bind ( this ) ;
@@ -311,11 +325,16 @@ class DatePickerItem extends Component<void, Props, State> {
311325 ( date < this . props . min || date > this . props . max ) ?
312326 'disabled' : '' ;
313327
328+ let formatDate = TimeUtil . convertDate ( date , this . format ) ;
329+ if ( this . formatTransform ) {
330+ formatDate = this . formatTransform ( formatDate ) ;
331+ }
332+
314333 return (
315334 < li
316335 key = { index }
317336 className = { className } >
318- { TimeUtil . convertDate ( date , this . props . format ) }
337+ { formatDate }
319338 </ li >
320339 ) ;
321340 }
0 commit comments