Codex Assistant
14 小时以前 0a48616045ddce1562584543a0e89e5144051fde
wx/pages/review/index.js
@@ -2,6 +2,14 @@
const app = getApp()
const { graphqlRequest, formatDate } = require('../../lib/utils')
const GET_RATING_STATS_QUERY = `
  query GetRatingStats($activityPlayerId: ID!) {
    judgeRatingsForPlayer(activityPlayerId: $activityPlayerId) {
      hasRated
    }
  }
`
Page({
  data: {
    loading: false,
@@ -55,7 +63,7 @@
  // 切换选项卡
  switchTab(e) {
    const index = e.currentTarget.dataset.index
    const index = parseInt(e.currentTarget.dataset.index) || 0
    if (index === this.data.currentTab) return
    
    this.setData({
@@ -110,10 +118,29 @@
      ])
    } catch (error) {
      console.error('加载数据失败:', error)
      wx.showToast({
        title: '加载失败',
        icon: 'none'
      })
      // 检查是否是认证相关错误
      if (error.message && (
        error.message.includes('没有权限访问') ||
        error.message.includes('请先登录') ||
        error.message.includes('重新登录')
      )) {
        wx.showToast({
          title: '正在重新登录...',
          icon: 'loading',
          duration: 2000
        })
        // 等待一段时间后重试
        setTimeout(() => {
          this.loadData()
        }, 2000)
      } else {
        wx.showToast({
          title: '加载失败,请重试',
          icon: 'none'
        })
      }
    } finally {
      this.setData({ loading: false })
      wx.stopPullDownRefresh()
@@ -223,13 +250,13 @@
        const projects = data.items.map(item => ({
          ...item,
          submitTime: item.submitTime ? formatDate(item.submitTime) : '',
          reviewTime: item.reviewTime ? formatDate(item.reviewTime) : '',
          statusText: this.getStatusText(item.status),
          statusType: this.getStatusType(item.status)
          reviewTime: item.reviewTime ? formatDate(item.reviewTime) : ''
        }))
        const projectsWithRatingCount = await this.enrichProjectsWithRatingCounts(projects)
        this.setData({
          projectList: isLoadMore ? [...this.data.projectList, ...projects] : projects,
          projectList: isLoadMore ? [...this.data.projectList, ...projectsWithRatingCount] : projectsWithRatingCount,
          hasMore: data.hasMore || false,
          currentPage: variables.page
        })
@@ -274,26 +301,39 @@
    }
  },
  // 获取状态文本
  getStatusText(status) {
    const statusMap = {
      'SUBMITTED': '已提交',
      'UNDER_REVIEW': '评审中',
      'REVIEWED': '已评审',
      'REJECTED': '已拒绝'
  async enrichProjectsWithRatingCounts(projects) {
    if (!Array.isArray(projects) || projects.length === 0) {
      return projects || []
    }
    return statusMap[status] || status
    try {
      const counts = await Promise.all(projects.map(project => this.getProjectRatingCount(project.id)))
      return projects.map((project, index) => ({
        ...project,
        ratingCount: counts[index]
      }))
    } catch (error) {
      console.error('批量获取评审次数失败:', error)
      return projects.map(project => ({
        ...project,
        ratingCount: typeof project.ratingCount === 'number' ? project.ratingCount : 0
      }))
    }
  },
  // 获取状态类型
  getStatusType(status) {
    const typeMap = {
      'SUBMITTED': 'info',
      'UNDER_REVIEW': 'warning',
      'REVIEWED': 'success',
      'REJECTED': 'danger'
  async getProjectRatingCount(activityPlayerId) {
    if (!activityPlayerId) {
      return 0
    }
    return typeMap[status] || 'info'
    try {
      const result = await graphqlRequest(GET_RATING_STATS_QUERY, { activityPlayerId })
      const ratings = result?.judgeRatingsForPlayer || []
      return ratings.filter(item => item?.hasRated).length
    } catch (error) {
      console.error(`获取项目 ${activityPlayerId} 的评审次数失败:`, error)
      return 0
    }
  },
  // 获取空状态文本
@@ -323,4 +363,4 @@
    ]
    return emptyDescs[currentTab] || ''
  }
})
})