123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- Page({
- data: {
- id: 1 ,
-
- countdown: 120,
- progressWidth: 100,
- totalSeconds: 120,
- currentSeconds: 120
- },
- onLoad() {
-
-
-
-
-
-
-
-
-
-
- this.countDown();
- },
- countDown() {
- let timer = setInterval(() => {
- let { currentSeconds, totalSeconds } = this.data;
- currentSeconds--;
- if (currentSeconds < 0) {
- currentSeconds = totalSeconds;
- }
- let aprogressWidth = (currentSeconds / totalSeconds) * 100;
- this.setData({
- currentSeconds: currentSeconds,
- progressWidth: aprogressWidth
- });
- }, 1000);
- this.data.timer = timer;
- },
- onUnload() {
- if (this.data.timer) {
- clearInterval(this.data.timer);
- }
- }
- });
|