index.js 2.1 KB

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