// pages/match/details/index.js const app = getApp(); let wxParse = require("../../../wxParse/wxParse.js"); Page({ /** * 页面的初始数据 */ data: { appAssetsUrl2: app.appAssetsUrl2, matchDetail: {} }, /** * 分享赛事按钮点击事件 */ onShareTap() { }, /** * 加载赛事详情数据 */ loadMatchDetail(matchId) { wx.showLoading({ title: '加载中...' }); // TODO: 调用API获取赛事详情 app._get(`news/info/${matchId}`, {}, (res) => { if (res.code === 0) { wxParse.wxParse('content', 'html', res.data.content, this, 0); this.setData({ matchDetail: res.data }); } wx.hideLoading(); }); }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { const { id } = options; if (id) { this.setData({ 'matchDetail.id': id }); this.loadMatchDetail(id); } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { // 设置分享菜单 wx.showShareMenu({ withShareTicket: true, menus: ['shareAppMessage', 'shareTimeline'] }); }, /** * 生命周期函数--监听页面显示 */ onShow() { // 页面显示时的操作 }, /** * 生命周期函数--监听页面隐藏 */ onHide() { // 页面隐藏时的操作 }, /** * 生命周期函数--监听页面卸载 */ onUnload() { // 页面卸载时的清理工作 }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { // 下拉刷新重新加载数据 const { matchDetail } = this.data; if (matchDetail.id) { this.loadMatchDetail(matchDetail.id); } wx.stopPullDownRefresh(); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { // 详情页面不需要上拉加载 }, /** * 用户点击右上角分享 */ onShareAppMessage() { const { matchDetail } = this.data; return { title: matchDetail.title || '青云慧 - 创业赛事详情', path: `/pages/match/details/index?id=${matchDetail.id}`, imageUrl: matchDetail.bannerImage || '/assets/images/share/match-detail-share.jpg' }; }, /** * 用户点击右上角分享到朋友圈 */ onShareTimeline() { const { matchDetail } = this.data; return { title: matchDetail.title || '青云慧 - 创业赛事详情', query: `id=${matchDetail.id}`, imageUrl: matchDetail.bannerImage || '/assets/images/share/match-detail-share.jpg' }; } });