@@ -48,12 +48,21 @@ const lunnarFestivals = {
4848 '腊月廿三' : '小年'
4949} ;
5050
51+ const dateRange = {
52+ preMinDate : new Date ( 1900 , 1 , 1 ) ,
53+ preMaxDate : new Date ( ( new Date ( ) ) . getFullYear ( ) + 30 , 11 , 1 ) ,
54+ minDate : new Date ( 1900 , 0 , 1 ) , // 闭
55+ maxDate : new Date ( ( new Date ( ) ) . getFullYear ( ) + 31 , 0 , 1 ) // 开
56+ } ;
57+
58+ const MIN_YEAR = 1900 ;
59+ const MAX_YEAR = new Date ( ) . getFullYear ( ) + 30 ;
60+
5161
5262const yearList = ( function ( ) {
53- const end = new Date ( ) . getFullYear ( ) + 30 ,
54- result = [ ] ;
63+ const result = [ ] ;
5564
56- for ( let i = 1900 ; i <= end ; i += 1 ) {
65+ for ( let i = MIN_YEAR ; i <= MAX_YEAR ; i += 1 ) {
5766 result . push ( i + '' ) ;
5867 }
5968
@@ -99,10 +108,25 @@ export default class DatePickerCtrl {
99108 return this . DISPLAY_FORMAT [ this . displayFormat ] === 2 ;
100109 }
101110
111+ setLGButtonStatus ( ) {
112+ if ( this . parts . month === '0' && this . parts . year === MIN_YEAR + '' ) {
113+ this . disabledL = true ;
114+ } else {
115+ this . disabledL = false ;
116+ }
117+
118+ if ( this . parts . month === '11' && this . parts . year === MAX_YEAR + '' ) {
119+ this . disabledG = true ;
120+ } else {
121+ this . disabledG = false ;
122+ }
123+ }
124+
102125 /**
103126 * 改变月份
104127 */
105128 changeMonth ( ) {
129+ this . setLGButtonStatus ( ) ;
106130 this . value = new Date ( new Date ( this . value ) . setMonth ( this . parts . month ) ) ;
107131 }
108132
@@ -111,6 +135,7 @@ export default class DatePickerCtrl {
111135 * 改变年份
112136 */
113137 changeYear ( ) {
138+ this . setLGButtonStatus ( ) ;
114139 this . value = new Date ( new Date ( this . value ) . setFullYear ( this . parts . year ) ) ;
115140 }
116141
@@ -273,7 +298,23 @@ export default class DatePickerCtrl {
273298 */
274299 switchMonth ( delta ) {
275300 if ( this . disableYear || this . disableMonth ) return ;
276- this . value = new Date ( new Date ( this . value ) . setMonth ( this . value . getMonth ( ) + delta ) ) ;
301+ const newDate = new Date ( new Date ( this . value ) . setMonth ( this . value . getMonth ( ) + delta ) ) ;
302+
303+ if ( newDate < dateRange . preMinDate ) {
304+ this . disabledL = true ;
305+ } else {
306+ this . disabledL = false ;
307+ }
308+
309+ if ( newDate >= dateRange . preMaxDate ) {
310+ this . disabledG = true ;
311+ } else {
312+ this . disabledG = false ;
313+ }
314+
315+ if ( newDate >= dateRange . minDate && newDate < dateRange . maxDate ) {
316+ this . value = newDate ;
317+ }
277318 } ;
278319
279320
0 commit comments