payStatus.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. Page({
  2. data: {
  3. id: 1 , // 初始ID值
  4. // isLoading: true,//授权加载
  5. countdown: 120,
  6. progressWidth: 100, // 初始进度条宽度为100%
  7. totalSeconds: 120, // 总秒数
  8. currentSeconds: 120 // 当前剩余秒数
  9. },
  10. onLoad() {
  11. //id=1计时器
  12. // this.setData({
  13. // isLoading: false
  14. // });
  15. // setTimeout(() => {
  16. // this.setData({
  17. // isLoading: false
  18. // });
  19. // }, );
  20. //id=2计算器
  21. this.countDown();
  22. },
  23. countDown() {
  24. let timer = setInterval(() => {
  25. let { currentSeconds, totalSeconds } = this.data;
  26. currentSeconds--;
  27. if (currentSeconds < 0) {
  28. currentSeconds = totalSeconds;
  29. }
  30. let aprogressWidth = (currentSeconds / totalSeconds) * 100;
  31. this.setData({
  32. currentSeconds: currentSeconds,
  33. progressWidth: aprogressWidth
  34. });
  35. }, 1000);
  36. this.data.timer = timer; // 保存定时器,以便在onUnload中清除
  37. },
  38. onUnload() {
  39. if (this.data.timer) {
  40. clearInterval(this.data.timer);
  41. }
  42. }
  43. });