Skip to content

Commit 8babba6

Browse files
committed
fixed: uni-countdown start and stop bug
1 parent 3d72aa6 commit 8babba6

File tree

3 files changed

+55
-16
lines changed

3 files changed

+55
-16
lines changed

pages/nvue/countdown/countdown.nvue

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
<uni-section title="一般用法" type="line"></uni-section>
55
<view class="example-body">
66
<uni-countdown :day="1" :hour="1" :minute="12" :second="40" />
7+
</view>
8+
<uni-section title="自由控制开始/暂停" type="line"></uni-section>
9+
<view class="example-body">
10+
<uni-countdown :start="start" :day="1" :hour="1" :minute="12" :second="40" />
711
</view>
8-
<uni-section title="不显示天数" type="line"></uni-section>
12+
<!--<uni-section title="不显示天数" type="line"></uni-section>
913
<view class="example-body">
1014
<uni-countdown :show-day="false" :hour="12" :minute="12" :second="12" />
1115
</view>
@@ -24,7 +28,7 @@
2428
<uni-section title="动态赋值" type="line"></uni-section>
2529
<view class="example-body">
2630
<uni-countdown :show-day="false" :hour="testHour" :minute="testMinute" :second="testSecond" />
27-
</view>
31+
</view> -->
2832
</view>
2933
</template>
3034
<script>
@@ -34,15 +38,20 @@
3438
return {
3539
testHour: 0,
3640
testMinute: 0,
37-
testSecond: 0
41+
testSecond: 0,
42+
start: false
3843
}
3944
},
4045
created() {
4146
setTimeout(() => {
4247
this.testHour = 1
4348
this.testMinute = 1
44-
this.testSecond = 0
45-
}, 2000)
49+
this.testSecond = 0
50+
this.start = true
51+
}, 3000)
52+
setTimeout(() => {
53+
this.start = false
54+
}, 10000)
4655
},
4756
methods: {
4857
timeup() {

pages/vue/countdown/countdown.vue

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
<uni-section title="一般用法" type="line"></uni-section>
55
<view class="example-body">
66
<uni-countdown :day="1" :hour="1" :minute="12" :second="40" />
7+
</view>
8+
<uni-section title="自由控制开始/暂停" type="line"></uni-section>
9+
<view class="example-body">
10+
<uni-countdown :start="start" :day="1" :hour="1" :minute="12" :second="40" />
711
</view>
8-
<uni-section title="不显示天数" type="line"></uni-section>
12+
<!--<uni-section title="不显示天数" type="line"></uni-section>
913
<view class="example-body">
1014
<uni-countdown :show-day="false" :hour="12" :minute="12" :second="12" />
1115
</view>
@@ -24,7 +28,7 @@
2428
<uni-section title="动态赋值" type="line"></uni-section>
2529
<view class="example-body">
2630
<uni-countdown :show-day="false" :hour="testHour" :minute="testMinute" :second="testSecond" />
27-
</view>
31+
</view> -->
2832
</view>
2933
</template>
3034
<script>
@@ -34,15 +38,20 @@
3438
return {
3539
testHour: 0,
3640
testMinute: 0,
37-
testSecond: 0
41+
testSecond: 0,
42+
start: false
3843
}
3944
},
4045
created() {
4146
setTimeout(() => {
4247
this.testHour = 1
4348
this.testMinute = 1
44-
this.testSecond = 0
45-
}, 2000)
49+
this.testSecond = 0
50+
this.start = true
51+
}, 3000)
52+
setTimeout(() => {
53+
this.start = false
54+
}, 10000)
4655
},
4756
methods: {
4857
timeup() {

uni_modules/uni-countdown/components/uni-countdown/uni-countdown.vue

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<template>
22
<view class="uni-countdown">
3-
<text v-if="showDay" :style="{ borderColor: borderColor, color: color, backgroundColor: backgroundColor }" class="uni-countdown__number">{{ d }}</text>
3+
<text v-if="showDay" :style="{ borderColor: borderColor, color: color, backgroundColor: backgroundColor }"
4+
class="uni-countdown__number">{{ d }}</text>
45
<text v-if="showDay" :style="{ color: splitorColor }" class="uni-countdown__splitor">天</text>
5-
<text :style="{ borderColor: borderColor, color: color, backgroundColor: backgroundColor }" class="uni-countdown__number">{{ h }}</text>
6+
<text :style="{ borderColor: borderColor, color: color, backgroundColor: backgroundColor }"
7+
class="uni-countdown__number">{{ h }}</text>
68
<text :style="{ color: splitorColor }" class="uni-countdown__splitor">{{ showColon ? ':' : '时' }}</text>
7-
<text :style="{ borderColor: borderColor, color: color, backgroundColor: backgroundColor }" class="uni-countdown__number">{{ i }}</text>
9+
<text :style="{ borderColor: borderColor, color: color, backgroundColor: backgroundColor }"
10+
class="uni-countdown__number">{{ i }}</text>
811
<text :style="{ color: splitorColor }" class="uni-countdown__splitor">{{ showColon ? ':' : '分' }}</text>
9-
<text :style="{ borderColor: borderColor, color: color, backgroundColor: backgroundColor }" class="uni-countdown__number">{{ s }}</text>
12+
<text :style="{ borderColor: borderColor, color: color, backgroundColor: backgroundColor }"
13+
class="uni-countdown__number">{{ s }}</text>
1014
<text v-if="!showColon" :style="{ color: splitorColor }" class="uni-countdown__splitor">秒</text>
1115
</view>
1216
</template>
@@ -39,6 +43,10 @@
3943
type: Boolean,
4044
default: true
4145
},
46+
start: {
47+
type: Boolean,
48+
default: true
49+
},
4250
backgroundColor: {
4351
type: String,
4452
default: '#FFFFFF'
@@ -100,10 +108,23 @@
100108
},
101109
second(val) {
102110
this.changeFlag()
111+
},
112+
start: {
113+
immediate: true,
114+
handler(newVal, oldVal) {
115+
if (newVal) {
116+
this.startData();
117+
} else {
118+
if (!oldVal) return
119+
clearInterval(this.timer)
120+
}
121+
}
122+
103123
}
104124
},
105125
created: function(e) {
106-
this.startData();
126+
this.seconds = this.toSeconds(this.timestamp, this.day, this.hour, this.minute, this.second)
127+
this.countDown()
107128
},
108129
beforeDestroy() {
109130
clearInterval(this.timer)
@@ -208,4 +229,4 @@
208229
text-align: center;
209230
font-size: $uni-font-size-sm;
210231
}
211-
</style>
232+
</style>

0 commit comments

Comments
 (0)