bug
Codex Assistant
2025-11-05 3714621173c606c4c58439ed8941100ce9ddea14
wx/pages/index/index.js
@@ -21,19 +21,20 @@
    // 筛选条件
    filterStatus: 'all', // all, upcoming, ongoing, ended
    // 轮播图当前索引
    currentBannerIndex: 0
    currentBannerIndex: 0,
    // 分享相关数据
    shareActivityId: null,
    shareActivityName: null
  },
  onLoad(options) {
    console.log('首页加载')
    this.loadBanners()
    this.loadActivities()
  },
  onShow() {
    console.log('首页显示')
    // 统一系统导航栏标题
    try { wx.setNavigationBarTitle({ title: '蓉易创' }) } catch (e) {}
    try { wx.setNavigationBarTitle({ title: '蓉e创' }) } catch (e) {}
    // 检查登录状态
    if (!app.globalData.token) {
      app.login()
@@ -42,6 +43,9 @@
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().init();
    }
    // 加载数据
    this.loadBanners()
    this.loadActivities()
  },
  onPullDownRefresh() {
@@ -175,9 +179,9 @@
    if (filterStatus !== 'all') {
      // 根据filterStatus映射到对应的state值
      const stateMapping = {
        'upcoming': 1,    // 即将开始
        'ongoing': 2,     // 进行中
        'ended': 3        // 已结束
        'upcoming': 1,    // 即将开始 -> 发布状态
        'ongoing': 1,     // 进行中 -> 发布状态
        'ended': 2        // 已结束 -> 关闭状态
      }
      stateFilter = stateMapping[filterStatus]
    }
@@ -214,7 +218,7 @@
      page: currentPage,
      size: pageSize,
      name: nameFilter,
      state: stateFilter
      state: 1
    }).then(data => {
      if (data.activities) {
        let newActivities = data.activities.content
@@ -434,5 +438,164 @@
    return now <= signupDeadline && 
           activity.state === 'SIGNUP' &&
           activity.playerCount < activity.playerMax
  },
  // 分享单个比赛
  onShareActivity(e) {
    const { id, name } = e.currentTarget.dataset
    // 显示分享选项
    wx.showActionSheet({
      itemList: ['分享给朋友', '生成分享海报'],
      success: (res) => {
        if (res.tapIndex === 0) {
          // 分享给朋友
          this.shareToFriend(id, name)
        } else if (res.tapIndex === 1) {
          // 生成分享海报
          this.generateSharePoster(id, name)
        }
      },
      fail: (res) => {
        console.log('用户取消分享')
      }
    })
  },
  // 分享给朋友
  shareToFriend(activityId, activityName) {
    wx.showShareMenu({
      withShareTicket: true,
      menus: ['shareAppMessage', 'shareTimeline']
    })
    // 设置当前要分享的活动信息
    this.setData({
      shareActivityId: activityId,
      shareActivityName: activityName
    })
    // 触发分享
    wx.updateShareMenu({
      withShareTicket: true,
      isUpdatableMessage: true,
      activityId: 'share_activity_' + activityId,
      templateInfo: {
        parameterList: [{
          name: 'activity_name',
          value: activityName
        }]
      }
    })
    wx.showToast({
      title: '请点击右上角分享',
      icon: 'none',
      duration: 2000
    })
  },
  // 生成分享海报
  generateSharePoster(activityId, activityName) {
    wx.showLoading({
      title: '生成海报中...'
    })
    // 这里可以调用后端API生成分享海报
    // 或者使用canvas在前端生成
    setTimeout(() => {
      wx.hideLoading()
      wx.showToast({
        title: '海报生成功能开发中',
        icon: 'none',
        duration: 2000
      })
    }, 1500)
  },
  // 页面分享功能 - 分享给朋友
  onShareAppMessage(res) {
    console.log('分享给朋友', res)
    // 如果是从比赛卡片分享
    if (this.data.shareActivityId && this.data.shareActivityName) {
      const shareData = {
        title: `${this.data.shareActivityName} - 蓉e创比赛平台`,
        path: `/pages/activity/detail?id=${this.data.shareActivityId}`,
        imageUrl: '', // 可以设置分享图片
        success: (res) => {
          console.log('分享成功', res)
          wx.showToast({
            title: '分享成功',
            icon: 'success',
            duration: 2000
          })
          // 清除分享状态
          this.setData({
            shareActivityId: null,
            shareActivityName: null
          })
        },
        fail: (res) => {
          console.log('分享失败', res)
          wx.showToast({
            title: '分享失败',
            icon: 'none',
            duration: 2000
          })
        }
      }
      return shareData
    }
    // 默认分享整个首页
    return {
      title: '蓉e创比赛平台 - 发现精彩比赛',
      path: '/pages/index/index',
      imageUrl: '', // 可以设置默认分享图片
      success: (res) => {
        console.log('分享成功', res)
        wx.showToast({
          title: '分享成功',
          icon: 'success',
          duration: 2000
        })
      },
      fail: (res) => {
        console.log('分享失败', res)
        wx.showToast({
          title: '分享失败',
          icon: 'none',
          duration: 2000
        })
      }
    }
  },
  // 分享到朋友圈
  onShareTimeline() {
    console.log('分享到朋友圈')
    return {
      title: '蓉e创比赛平台 - 发现精彩比赛',
      query: '',
      imageUrl: '', // 可以设置分享图片
      success: (res) => {
        console.log('分享到朋友圈成功', res)
        wx.showToast({
          title: '分享成功',
          icon: 'success',
          duration: 2000
        })
      },
      fail: (res) => {
        console.log('分享到朋友圈失败', res)
        wx.showToast({
          title: '分享失败',
          icon: 'none',
          duration: 2000
        })
      }
    }
  }
})