index.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // components/mine/index.js
  2. import { bootCoin } from "../../api/mine"
  3. import { getNotifications } from "../../api/api"
  4. import { formatTime } from "../../utils/util"
  5. Component({
  6. /**
  7. * 组件的属性列表
  8. */
  9. properties: {
  10. },
  11. /**
  12. * 组件的初始数据
  13. */
  14. data: {
  15. symbol: "BTC",
  16. icon: "/images/one.png",
  17. btnTxt: "开始挖矿",
  18. history: [{
  19. "symbol": "doge",
  20. "icon": "/images/one.png",
  21. "amount": 12.00034,
  22. "ts": "2021/05/10 15:50:03",
  23. "from": "abcde034345dd",
  24. "to": "aabde2343df34",
  25. "out": 0,
  26. },{
  27. "symbol": "doge",
  28. "icon": "/images/one.png",
  29. "amount": 12.00034,
  30. "ts": "2021/05/10 17:12:42",
  31. "from": "abcde034345dd",
  32. "to": "aabde2343df34",
  33. "out": -1,
  34. }],
  35. totals: 9999.9999,
  36. progress: 99.999,
  37. timer: null,
  38. coinTimer: null
  39. },
  40. /**
  41. * 组件的方法列表
  42. */
  43. methods: {
  44. tabIn: function() {
  45. this.getNotification();
  46. this.starTimer();
  47. console.log(formatTime(new Date(1620633003000)));
  48. this.setData({history: []});
  49. },
  50. tabOut: function() {
  51. clearInterval(this.data.timer);
  52. clearTimeout(this.data.coinTimer);
  53. },
  54. getNotification: function() {
  55. var that = this;
  56. getNotifications().then(res=>{
  57. console.log(res);
  58. that.setData({
  59. });
  60. }, err=>{
  61. console.log(err);
  62. that.setData({
  63. totals: 0,
  64. progress: 0
  65. });
  66. });
  67. that.data.coinTimer = setTimeout(()=>{
  68. that.getNotification();
  69. }, 30000);
  70. },
  71. starTimer: function() {
  72. var that = this;
  73. that.data.timer = setInterval(function(){
  74. var current = parseFloat(that.data.progress);
  75. that.setData({
  76. progress: (current + parseFloat(Math.random() * 0.001)).toFixed(4)
  77. });
  78. }, 1000);
  79. },
  80. drawClick: function() {
  81. let that = this;
  82. that.setData({
  83. btnTxt: "挖矿中"
  84. });
  85. },
  86. goRule: function() {
  87. wx.navigateTo({
  88. url: '/pages/mine_rule/index',
  89. })
  90. },
  91. dateTime: function(time) {
  92. console.log(time);
  93. return formatTime(new Date(parseInt(time)));
  94. }
  95. }
  96. })