@@ -7,6 +7,7 @@ import ClText from "../../text";
7
7
import ClFlex from "../../flex" ;
8
8
import ClLayout from "../../layout" ;
9
9
import ClCard from "../../card" ;
10
+ import ClIcon from "../../icon" ;
10
11
import { classNames } from "../../../lib" ;
11
12
import { BG_COLOR_LIST , TEXT_COLOR_LIST } from "../../../lib/model" ;
12
13
import ClButton from "../../button" ;
@@ -27,6 +28,7 @@ interface IState {
27
28
currentActiveLines : number ;
28
29
showMonths : boolean ;
29
30
today : string ;
31
+ currentYear : number ;
30
32
}
31
33
32
34
const FORMAT_DATE = "YYYY-MM-DD" ;
@@ -59,6 +61,7 @@ export default class Calendar_h5 extends Taro.Component<IProps, IState> {
59
61
thisMonth : [ ] ,
60
62
nextMonth : [ ] ,
61
63
preMonth : [ ] ,
64
+ currentYear : dayjs ( ) . year ( ) ,
62
65
chooseDate : today ,
63
66
currentDate : dealYearMonth ( dayjs ( today ) ) ,
64
67
currentActive : 1 ,
@@ -68,11 +71,12 @@ export default class Calendar_h5 extends Taro.Component<IProps, IState> {
68
71
} as IState ;
69
72
}
70
73
selectDate ( month ) {
71
- const year = this . state . currentDate . split ( "年" ) [ 0 ] ;
74
+ const year = this . state . currentYear ;
72
75
const date = `${ year } -${ month + 1 } -01` ;
73
76
this . changeMonth ( date ) ;
74
77
this . setState ( {
75
- showMonths : false
78
+ showMonths : false ,
79
+ currentDate : dealYearMonth ( dayjs ( date ) )
76
80
} ) ;
77
81
}
78
82
clickDate ( { item } ) {
@@ -145,7 +149,7 @@ export default class Calendar_h5 extends Taro.Component<IProps, IState> {
145
149
}
146
150
return current ;
147
151
}
148
- changeDate ( ) {
152
+ changeDate ( e ) {
149
153
let arrayIndex = e . detail . current ;
150
154
if ( render ) {
151
155
arrayIndex = 1 ;
@@ -477,7 +481,8 @@ export default class Calendar_h5 extends Taro.Component<IProps, IState> {
477
481
nextMonth,
478
482
showMonths,
479
483
currentDate,
480
- currentActiveLines
484
+ currentActiveLines,
485
+ currentYear
481
486
} = this . state ;
482
487
const {
483
488
highlightWeekend,
@@ -515,7 +520,6 @@ export default class Calendar_h5 extends Taro.Component<IProps, IState> {
515
520
) ) ;
516
521
const BGClassName = BG_COLOR_LIST [ activeColor || "blue" ] ;
517
522
const oldTextClassName = TEXT_COLOR_LIST [ "gray" ] ;
518
- console . log ( 'render' )
519
523
const weeksComponent = preWeek . length
520
524
? [ preWeek , thisWeek , nextWeek ] . map ( ( week , index ) => (
521
525
< SwiperItem key = { week [ 3 ] . date } >
@@ -709,36 +713,58 @@ export default class Calendar_h5 extends Taro.Component<IProps, IState> {
709
713
< ClFlex justify = { "between" } align = { "center" } >
710
714
< ClTip
711
715
renderMessage = {
712
- < ClGrid col = { 4 } >
713
- { months . map ( ( item , index ) => (
714
- < View
715
- key = { item }
716
- className = { classNames ( [
717
- "flex justify-center align-center"
718
- ] ) }
719
- >
720
- < ClLayout margin = { "small" } marginDirection = { "vertical" } >
721
- < ClButton
722
- size = { "small" }
723
- bgColor = { "light-gray" }
724
- shadow = { false }
725
- long
726
- text = { item }
727
- onClick = { ( ) => {
728
- this . selectDate ( index ) ;
729
- } }
730
- />
731
- </ ClLayout >
732
- </ View >
733
- ) ) }
734
- </ ClGrid >
716
+ < View >
717
+ < ClLayout >
718
+ < ClFlex align = { "center" } justify = { "between" } >
719
+ < View onClick = { ( ) => {
720
+ this . setState ( {
721
+ currentYear : currentYear - 1
722
+ } )
723
+ } } >
724
+ < ClIcon iconName = { "pullleft" } />
725
+ </ View >
726
+ < ClText text = { currentYear + "" } />
727
+ < View onClick = { ( ) => {
728
+ this . setState ( {
729
+ currentYear : currentYear + 1
730
+ } )
731
+ } } >
732
+ < ClIcon iconName = { "pullright" } />
733
+ </ View >
734
+ </ ClFlex >
735
+ </ ClLayout >
736
+ < ClGrid col = { 4 } >
737
+ { months . map ( ( item , index ) => (
738
+ < View
739
+ key = { item }
740
+ className = { classNames ( [
741
+ "flex justify-center align-center"
742
+ ] ) }
743
+ >
744
+ < ClLayout margin = { "small" } marginDirection = { "vertical" } >
745
+ < ClButton
746
+ size = { "small" }
747
+ bgColor = { "light-gray" }
748
+ shadow = { false }
749
+ long
750
+ text = { item }
751
+ onClick = { ( ) => {
752
+ this . selectDate ( index ) ;
753
+ } }
754
+ />
755
+ </ ClLayout >
756
+ </ View >
757
+ ) ) }
758
+ </ ClGrid >
759
+ </ View >
735
760
}
736
761
mode = { "click" }
737
762
width = { 300 }
738
763
show = { this . state . showMonths }
739
764
onChange = { ( ) => {
765
+ const currentShow = ! showMonths
740
766
this . setState ( {
741
- showMonths : ! showMonths
767
+ showMonths : currentShow
742
768
} ) ;
743
769
} }
744
770
>
@@ -783,8 +809,8 @@ export default class Calendar_h5 extends Taro.Component<IProps, IState> {
783
809
? pxTransform ( 120 )
784
810
: pxTransform ( 120 * currentActiveLines )
785
811
} }
786
- onChange = { ( ) => {
787
- this . changeDate . bind ( this )
812
+ onChange = { ( e ) => {
813
+ if ( this . state . currentActive !== e . detail . current ) this . changeDate ( e )
788
814
} }
789
815
>
790
816
{ calendarType === "week" ? weeksComponent : monthsComponent }
0 commit comments