index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // pages/match/details/index.js
  2. const app = getApp();
  3. let wxParse = require("../../../wxParse/wxParse.js");
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. appAssetsUrl2: app.appAssetsUrl2,
  10. matchDetail: {}
  11. },
  12. /**
  13. * 分享赛事按钮点击事件
  14. */
  15. onShareTap() {
  16. },
  17. /**
  18. * 加载赛事详情数据
  19. */
  20. loadMatchDetail(matchId) {
  21. wx.showLoading({
  22. title: '加载中...'
  23. });
  24. // TODO: 调用API获取赛事详情
  25. app._get(`news/info/${matchId}`, {}, (res) => {
  26. if (res.code === 0) {
  27. wxParse.wxParse('content', 'html', res.data.content, this, 0);
  28. this.setData({
  29. matchDetail: res.data
  30. });
  31. }
  32. wx.hideLoading();
  33. });
  34. },
  35. /**
  36. * 生命周期函数--监听页面加载
  37. */
  38. onLoad(options) {
  39. const { id } = options;
  40. if (id) {
  41. this.setData({
  42. 'matchDetail.id': id
  43. });
  44. this.loadMatchDetail(id);
  45. }
  46. },
  47. /**
  48. * 生命周期函数--监听页面初次渲染完成
  49. */
  50. onReady() {
  51. // 设置分享菜单
  52. wx.showShareMenu({
  53. withShareTicket: true,
  54. menus: ['shareAppMessage', 'shareTimeline']
  55. });
  56. },
  57. /**
  58. * 生命周期函数--监听页面显示
  59. */
  60. onShow() {
  61. // 页面显示时的操作
  62. },
  63. /**
  64. * 生命周期函数--监听页面隐藏
  65. */
  66. onHide() {
  67. // 页面隐藏时的操作
  68. },
  69. /**
  70. * 生命周期函数--监听页面卸载
  71. */
  72. onUnload() {
  73. // 页面卸载时的清理工作
  74. },
  75. /**
  76. * 页面相关事件处理函数--监听用户下拉动作
  77. */
  78. onPullDownRefresh() {
  79. // 下拉刷新重新加载数据
  80. const { matchDetail } = this.data;
  81. if (matchDetail.id) {
  82. this.loadMatchDetail(matchDetail.id);
  83. }
  84. wx.stopPullDownRefresh();
  85. },
  86. /**
  87. * 页面上拉触底事件的处理函数
  88. */
  89. onReachBottom() {
  90. // 详情页面不需要上拉加载
  91. },
  92. /**
  93. * 用户点击右上角分享
  94. */
  95. onShareAppMessage() {
  96. const { matchDetail } = this.data;
  97. return {
  98. title: matchDetail.title || '青云慧 - 创业赛事详情',
  99. path: `/pages/match/details/index?id=${matchDetail.id}`,
  100. imageUrl: matchDetail.bannerImage || '/assets/images/share/match-detail-share.jpg'
  101. };
  102. },
  103. /**
  104. * 用户点击右上角分享到朋友圈
  105. */
  106. onShareTimeline() {
  107. const { matchDetail } = this.data;
  108. return {
  109. title: matchDetail.title || '青云慧 - 创业赛事详情',
  110. query: `id=${matchDetail.id}`,
  111. imageUrl: matchDetail.bannerImage || '/assets/images/share/match-detail-share.jpg'
  112. };
  113. }
  114. });