@@ -13,6 +13,8 @@ const MIDDLE_INDEX = Math.floor(DATE_LENGTH / 2); // 日期数组中间值
13
13
const MIDDLE_Y = - DATE_HEIGHT * MIDDLE_INDEX ; // translateY值
14
14
15
15
const 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]' ;
16
18
17
19
/**
18
20
* 根据格式获取时间滑动的类别
@@ -44,7 +46,7 @@ type Props = {
44
46
value : Object ,
45
47
min : Object ,
46
48
max : Object ,
47
- format : string ,
49
+ format : string | Array < * > ,
48
50
step : number ,
49
51
onSelect : Function ,
50
52
}
@@ -73,7 +75,19 @@ class DatePickerItem extends Component<void, Props, State> {
73
75
} ;
74
76
75
77
// 设置时间选择器单元的类别
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
+
77
91
this . renderDatepickerItem = this . renderDatepickerItem . bind ( this ) ;
78
92
this . handleContentTouch = this . handleContentTouch . bind ( this ) ;
79
93
this . handleContentMouseDown = this . handleContentMouseDown . bind ( this ) ;
@@ -311,11 +325,16 @@ class DatePickerItem extends Component<void, Props, State> {
311
325
( date < this . props . min || date > this . props . max ) ?
312
326
'disabled' : '' ;
313
327
328
+ let formatDate = TimeUtil . convertDate ( date , this . format ) ;
329
+ if ( this . formatTransform ) {
330
+ formatDate = this . formatTransform ( formatDate ) ;
331
+ }
332
+
314
333
return (
315
334
< li
316
335
key = { index }
317
336
className = { className } >
318
- { TimeUtil . convertDate ( date , this . props . format ) }
337
+ { formatDate }
319
338
</ li >
320
339
) ;
321
340
}
0 commit comments