index.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { $wuxCountDown } from '../../dist/index'
  2. import ad from '../index/ad'
  3. ad({
  4. data: {},
  5. onLoad() {
  6. this.c1 = new $wuxCountDown({
  7. date: 'June 7, 2087 15:03:25',
  8. render(date) {
  9. const years = this.leadingZeros(date.years, 4) + ' 年 '
  10. const days = this.leadingZeros(date.days, 3) + ' 天 '
  11. const hours = this.leadingZeros(date.hours, 2) + ' 时 '
  12. const min = this.leadingZeros(date.min, 2) + ' 分 '
  13. const sec = this.leadingZeros(date.sec, 2) + ' 秒 '
  14. this.setData({
  15. c1: years + days + hours + min + sec,
  16. })
  17. },
  18. })
  19. this.c3 = new $wuxCountDown({
  20. date: +(new Date) + 60000 * 20,
  21. render(date) {
  22. const min = this.leadingZeros(date.min, 2) + ' 分 '
  23. const sec = this.leadingZeros(date.sec, 2) + ' 秒 '
  24. this.setData({
  25. c3: min + sec,
  26. })
  27. },
  28. })
  29. },
  30. vcode() {
  31. if (this.c2 && this.c2.interval) return !1
  32. this.c2 = new $wuxCountDown({
  33. date: +(new Date) + 60000,
  34. onEnd() {
  35. this.setData({
  36. c2: '重新获取验证码',
  37. })
  38. },
  39. render(date) {
  40. const sec = this.leadingZeros(date.sec, 2) + ' 秒 '
  41. date.sec !== 0 && this.setData({
  42. c2: sec,
  43. })
  44. },
  45. })
  46. },
  47. stop() {
  48. this.c3.stop()
  49. },
  50. start() {
  51. this.c3.start()
  52. },
  53. update() {
  54. this.c3.update(+(new Date) + 60000 * 30)
  55. },
  56. })