Skip to content

Commit 143eb7b

Browse files
二一7insummer
authored andcommitted
feat:countdown组件纪念日模式示例代码 (#272)
1 parent f12a304 commit 143eb7b

File tree

4 files changed

+53
-25
lines changed

4 files changed

+53
-25
lines changed

dist/behaviors/countdown.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ module.exports = Behavior({
114114
this.init.call(this);
115115
}
116116

117-
} else if (countdownType === "anniversary") { // 当当countdownType === anniversary时,为纪念日模式
117+
} else if (countdownType === "anniversary") { // 当countdownType === anniversary时,为纪念日模式
118118
if (timeType === "second") { // 纪念日模式不能设置timeType === second
119119
console.error(`countdownType为${countdownType}类型时,不可设置timeType值为second`)
120120
} else {

examples/dist/behaviors/countdown.js

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ module.exports = Behavior({
3232
isZeroPadd: {
3333
type: Boolean,
3434
value: true,
35+
},
36+
countdownType: {
37+
type: String,
38+
value: "normal"
3539
}
3640
},
3741
data: {
@@ -78,33 +82,53 @@ module.exports = Behavior({
7882
time,
7983
status,
8084
timeType,
81-
initAddTime
85+
initAddTime,
86+
countdownType,
8287
} = this.data;
8388
// IOS不支持2019-04-23 的日期格式
8489
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+
}
9595

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
103100
}
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类型")
108132
}
109133
},
110134

@@ -181,6 +205,6 @@ module.exports = Behavior({
181205

182206
CountdownEnd() {
183207
this.triggerEvent("linend", {});
184-
}
208+
},
185209
}
186210
});

examples/pages/components/view/pages/countdown/index.wxml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
<l-button bind:lintap="toggleStatus" l-class="btn-toggle">{{!status?'播放':'暂停'}}</l-button>
2424
</content-card>
2525

26+
<content-card l-content="content" name="纪念日模式计时">
27+
<l-countdown time="2019-04-24" countdownType="anniversary" />
28+
</content-card>
29+
2630
<content-card l-content="content" name="自定义样式">
2731
<l-countdown l-class-time="countdown-blue" time="30" time-type="second" l-class="countdown-text" status="{{status}}" bind:linend="countdownEnd" />
2832
</content-card>

src/behaviors/countdown.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ module.exports = Behavior({
114114
this.init.call(this);
115115
}
116116

117-
} else if (countdownType === "anniversary") { // 当当countdownType === anniversary时,为纪念日模式
117+
} else if (countdownType === "anniversary") { // 当countdownType === anniversary时,为纪念日模式
118118
if (timeType === "second") { // 纪念日模式不能设置timeType === second
119119
console.error(`countdownType为${countdownType}类型时,不可设置timeType值为second`)
120120
} else {

0 commit comments

Comments
 (0)