task.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // pages/task/task.js
  2. const app = getApp();
  3. const url = require('../../utils/url.js');
  4. const net = require('../../utils/net.js');
  5. const util = require('../../utils/util.js');
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. file: url.file,
  12. playId: 0,
  13. task: {}
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function(options) {
  19. wx.showShareMenu({
  20. withShareTicket: false
  21. });
  22. this.setData({
  23. task: options
  24. });
  25. if (this.data.task.playRefer == 2) {
  26. net.login({
  27. success: res => {
  28. this.begin();
  29. }
  30. });
  31. this.autoIntoTarget();
  32. }
  33. },
  34. /**
  35. * 生命周期函数--监听页面初次渲染完成
  36. */
  37. onReady: function() {
  38. },
  39. /**
  40. * 生命周期函数--监听页面显示
  41. */
  42. onShow: function() {
  43. if (this.data.playId != 0) {
  44. this.end();
  45. }
  46. },
  47. /**
  48. * 生命周期函数--监听页面隐藏
  49. */
  50. onHide: function() {
  51. },
  52. /**
  53. * 生命周期函数--监听页面卸载
  54. */
  55. onUnload: function() {
  56. },
  57. /**
  58. * 页面相关事件处理函数--监听用户下拉动作
  59. */
  60. onPullDownRefresh: function() {
  61. },
  62. /**
  63. * 页面上拉触底事件的处理函数
  64. */
  65. onReachBottom: function() {
  66. },
  67. /**
  68. * 用户点击右上角分享
  69. */
  70. onShareAppMessage: function() {
  71. const tast = this.data.task;
  72. tast.playRefer = 2;
  73. const param = util.parseUrlParamByJson(tast);
  74. return {
  75. title: tast.title,
  76. path: '/pages/task/task?' + param,
  77. imageUrl: this.data.task.card == '' ? '' : this.data.file + this.data.task.card,
  78. }
  79. },
  80. begin: function() {
  81. net.request({
  82. url: url.begin,
  83. method: 'POST',
  84. data: {
  85. programId: this.data.task.programId,
  86. gtaskId: this.data.task.gtaskId,
  87. playRefer: this.data.task.playRefer
  88. },
  89. success: res => {
  90. this.data.playId = res.data;
  91. }
  92. });
  93. },
  94. end: function() {
  95. net.request({
  96. url: url.end,
  97. method: 'POST',
  98. data: {
  99. playId: this.data.playId
  100. },
  101. success: res => {
  102. this.data.playId = 0;
  103. }
  104. });
  105. },
  106. autoIntoTarget: function() {
  107. var path = decodeURIComponent(this.data.task.jumpPath);
  108. wx.navigateToMiniProgram({
  109. appId: this.data.task.appId,
  110. path: path,
  111. success: res => {
  112. }
  113. });
  114. },
  115. toTarget: function() {
  116. var path = decodeURIComponent(this.data.task.jumpPath);
  117. app.log(path);
  118. wx.navigateToMiniProgram({
  119. appId: this.data.task.appId,
  120. path: path,
  121. success: res => {
  122. this.begin();
  123. }
  124. });
  125. }
  126. })