@@ -32,6 +32,10 @@ module.exports = Behavior({
32
32
isZeroPadd : {
33
33
type : Boolean ,
34
34
value : true ,
35
+ } ,
36
+ countdownType : {
37
+ type : String ,
38
+ value : "normal"
35
39
}
36
40
} ,
37
41
data : {
@@ -78,33 +82,53 @@ module.exports = Behavior({
78
82
time,
79
83
status,
80
84
timeType,
81
- initAddTime
85
+ initAddTime,
86
+ countdownType,
82
87
} = this . data ;
83
88
// IOS不支持2019-04-23 的日期格式
84
89
let countDownTime = time
85
- if ( timeType !== 'second' ) {
86
- countDownTime = typeof time === 'string' ? countDownTime . replace ( / - / g, '/' ) :countDownTime ;
87
- countDownTime = Math . ceil ( ( new Date ( countDownTime ) . getTime ( ) - new Date ( ) . getTime ( ) ) / 1000 ) ;
88
- }
89
-
90
- if ( countDownTime < 0 && timeType !== 'second' ) {
91
- this . _getTimeValue ( 0 ) ;
92
- this . CountdownEnd ( ) ;
93
- return
94
- }
90
+ if ( countdownType === "normal" ) { //当countdownType === normal时,不影响之前的代码
91
+ if ( timeType !== 'second' ) {
92
+ countDownTime = typeof time === 'string' ? countDownTime . replace ( / - / g, '/' ) : countDownTime ;
93
+ countDownTime = Math . ceil ( ( new Date ( countDownTime ) . getTime ( ) - new Date ( ) . getTime ( ) ) / 1000 ) ;
94
+ }
95
95
96
- if ( countDownTime - initAddTime > 0 ) {
97
- this . getLatestForCountDown ( countDownTime ) ;
98
- } else if ( countDownTime - initAddTime < 0 ) {
99
- this . getLatestForAddTime ( countDownTime ) ;
100
- } else if ( countDownTime - initAddTime === 0 ) {
101
- if ( initAddTime <= 0 ) {
102
- this . _getTimeValue ( countDownTime ) ;
96
+ if ( countDownTime < 0 && timeType !== 'second' ) {
97
+ this . _getTimeValue ( 0 ) ;
98
+ this . CountdownEnd ( ) ;
99
+ return
103
100
}
104
- this . CountdownEnd ( ) ;
105
- }
106
- if ( status && countDownTime - initAddTime !== 0 ) {
107
- this . init . call ( this ) ;
101
+
102
+ if ( countDownTime - initAddTime > 0 ) {
103
+ this . getLatestForCountDown ( countDownTime ) ;
104
+ } else if ( countDownTime - initAddTime < 0 ) {
105
+ this . getLatestForAddTime ( countDownTime ) ;
106
+ } else if ( countDownTime - initAddTime === 0 ) {
107
+ if ( initAddTime <= 0 ) {
108
+ this . _getTimeValue ( countDownTime ) ;
109
+ }
110
+ this . CountdownEnd ( ) ;
111
+ }
112
+
113
+ if ( status && countDownTime - initAddTime !== 0 ) {
114
+ this . init . call ( this ) ;
115
+ }
116
+
117
+ } else if ( countdownType === "anniversary" ) { // 当countdownType === anniversary时,为纪念日模式
118
+ if ( timeType === "second" ) { // 纪念日模式不能设置timeType === second
119
+ console . error ( `countdownType为${ countdownType } 类型时,不可设置timeType值为second` )
120
+ } else {
121
+ countDownTime = typeof time === 'string' ? countDownTime . replace ( / - / g, '/' ) : countDownTime ;
122
+ countDownTime = Math . ceil ( ( new Date ( ) . getTime ( ) - new Date ( countDownTime ) . getTime ( ) ) / 1000 ) ;
123
+ if ( countDownTime >= 0 ) { // countDownTime计算结果不能为负数
124
+ this . getLatestForCountDown ( countDownTime ) ;
125
+ this . init . call ( this ) ;
126
+ } else {
127
+ console . error ( "time传值错误" )
128
+ }
129
+ }
130
+ } else { // countdownType 不能设置为 normal,anniversary 以外的值
131
+ console . error ( "错误的countdownType类型" )
108
132
}
109
133
} ,
110
134
@@ -181,6 +205,6 @@ module.exports = Behavior({
181
205
182
206
CountdownEnd ( ) {
183
207
this . triggerEvent ( "linend" , { } ) ;
184
- }
208
+ } ,
185
209
}
186
210
} ) ;
0 commit comments