index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. var t = require("../../utils/timeFormat"),
  2. e = getApp();
  3. Component({
  4. properties: {
  5. target: {
  6. type: String
  7. },
  8. showDay: Boolean,
  9. beginTime: String,
  10. callback: String,
  11. format: Array,
  12. clearTimer: Boolean
  13. },
  14. externalClasses: ["countdown-class", "item-class"],
  15. data: {
  16. time: {
  17. day: "0",
  18. second: "00",
  19. minute: "00",
  20. hour: "00"
  21. },
  22. resultFormat: [],
  23. changeFormat: !1,
  24. timeStamp: 0,
  25. timer: null
  26. },
  27. ready: function() {
  28. this.init(this.data.target);
  29. },
  30. methods: {
  31. init: function(t) {
  32. var a = this,
  33. i = {
  34. day: "0",
  35. second: "00",
  36. minute: "00",
  37. hour: "00"
  38. };
  39. if (t - new Date().getTime() <= 0) return this.setData({
  40. time: i
  41. }), void this.triggerEvent("callback");
  42. this.data.timer = e.globalData.timer.add(function() {
  43. a.interval(t);
  44. });
  45. },
  46. interval: function(a) {
  47. var i = a - new Date().getTime();
  48. if (i <= 0) return e.globalData.timer.remove(this.data.timer), this.triggerEvent("callback"),
  49. void this.setData({
  50. time: {
  51. day: "0",
  52. second: "00",
  53. minute: "00",
  54. hour: "00"
  55. }
  56. });
  57. var r = Math.ceil(i / 1e3),
  58. n = parseInt(r / 86400),
  59. o = r % 86400,
  60. m = (0, t.formatNumber)(parseInt(o / 3600));
  61. o %= 3600;
  62. var s = {
  63. day: n,
  64. hour: m,
  65. minute: (0, t.formatNumber)(parseInt(o / 60)),
  66. second: (0, t.formatNumber)(o % 60)
  67. };
  68. this.setData({
  69. time: s
  70. });
  71. }
  72. },
  73. detached: function() {
  74. e.globalData.timer.remove(this.data.timer);
  75. }
  76. });