countDown.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. function t(obj, attr, newAttr) {
  2. return attr in obj ? Object.defineProperty(obj, attr, {
  3. value: newAttr,
  4. enumerable: true,
  5. configurable: true,
  6. writable: true
  7. }) : obj[attr] = newAttr, obj;
  8. }
  9. var timeFormat = require("timeFormat"),
  10. app = getApp();
  11. exports.default = {
  12. initCountDown: function (e) {
  13. var that = this,
  14. r = {
  15. day: "0",
  16. second: "00",
  17. minute: "00",
  18. hour: "00"
  19. };
  20. if (e - new Date().getTime() <= 0) {
  21. var i;
  22. this.setData((i = {}, t(i, "countDownMap." + e, r), t(i, "actEndMap." + e, !0), i));
  23. } else {
  24. this.$data.timer[e] = app.globalData.timer.add(function () {
  25. that.interval(e);
  26. });
  27. }
  28. },
  29. interval: function (t) {
  30. var n = {}, r = t - new Date().getTime();
  31. if (r <= 0) {
  32. return app.globalData.timer.remove(this.$data.timer[t]),
  33. this.$data.actEndMap[t] || (n["actEndMap." + t] = true),
  34. n["countDownMap." + t] = {
  35. day: "0",
  36. second: "00",
  37. minute: "00",
  38. hour: "00"
  39. },
  40. void this.setData(n);
  41. }
  42. var i = Math.ceil(r / 1000),
  43. o = parseInt(i / 86400),
  44. u = i % 86400,
  45. s = (0, timeFormat.formatNumber)(parseInt(u / 3600));
  46. u %= 3600;
  47. var d = {
  48. day: o,
  49. hour: s,
  50. minute: (0, timeFormat.formatNumber)(parseInt(u / 60)),
  51. second: (0, timeFormat.formatNumber)(u % 60)
  52. };
  53. this.$data.actEndMap[t] && (n["actEndMap." + t] = !1), n["countDownMap." + t] = d, this.setData(n);
  54. }
  55. };