fix: 优化总分显示逻辑,使用后端返回的 scoringComplete 字段

1. 总分显示条件改为使用 player.scoringComplete
2. 等待状态显示已评分/应评裁判数量
3. 移除前端计算逻辑,统一由后端控制

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
DevOps
2025-12-23 23:10:03 +08:00
parent 53c865a076
commit f9efd8baa8

View File

@@ -62,10 +62,15 @@
<text class="tag-label">我的评分</text> <text class="tag-label">我的评分</text>
<text class="tag-value">{{ player.myScore }}</text> <text class="tag-value">{{ player.myScore }}</text>
</view> </view>
<view class="score-tag"> <!-- 总分只有所有裁判都评分完成后才显示 -->
<view class="score-tag" v-if="player.scoringComplete">
<text class="tag-label">总分</text> <text class="tag-label">总分</text>
<text class="tag-value">{{ formatScore(player.totalScore) }}</text> <text class="tag-value">{{ formatScore(player.totalScore) }}</text>
</view> </view>
<view class="score-tag waiting" v-else>
<text class="tag-label">总分</text>
<text class="tag-value">评分中({{ player.scoredJudgeCount || 0 }}/{{ player.requiredJudgeCount || "?" }})</text>
</view>
</view> </view>
</view> </view>
</template> </template>
@@ -242,6 +247,86 @@ export default {
return score return score
}, },
/**
* 计算选手总分
* 规则:所有裁判评分完成后,去掉一个最高分和一个最低分,取剩余分数的平均值
* @param {Object} player - 选手对象
* @returns {Number|null} 计算后的总分,如果未完成评分返回 null
*/
calculateTotalScore(player) {
// 检查是否有裁判评分数据
if (!player.judgeScores || !Array.isArray(player.judgeScores)) {
return null
}
// 检查是否所有裁判都已评分
const totalJudges = player.totalJudges || 0
const scoredCount = player.judgeScores.length
if (totalJudges === 0 || scoredCount < totalJudges) {
return null
}
// 提取所有分数
const scores = player.judgeScores.map(j => parseFloat(j.score)).filter(s => !isNaN(s))
if (scores.length < 3) {
// 少于3个评分无法去掉最高最低直接取平均
if (scores.length === 0) return null
const sum = scores.reduce((a, b) => a + b, 0)
return sum / scores.length
}
// 排序
scores.sort((a, b) => a - b)
// 去掉最高分和最低分
const trimmedScores = scores.slice(1, -1)
// 计算平均分
const sum = trimmedScores.reduce((a, b) => a + b, 0)
const average = sum / trimmedScores.length
return average
},
/**
* 检查选手是否所有裁判都已评分
* @param {Object} player - 选手对象
* @returns {Boolean}
*/
isAllJudgesScored(player) {
if (!player.judgeScores || !Array.isArray(player.judgeScores)) {
return false
}
const totalJudges = player.totalJudges || 0
return totalJudges > 0 && player.judgeScores.length >= totalJudges
},
/**
* 获取选手的显示总分
* @param {Object} player - 选手对象
* @returns {String} 格式化后的总分或 '--'
*/
getDisplayTotalScore(player) {
const score = this.calculateTotalScore(player)
if (score === null) {
return '--'
}
return score.toFixed(3)
},
/**
* 获取裁判评分进度
* @param {Object} player - 选手对象
* @returns {String} 进度字符串,如 "3/6"
*/
getJudgeProgress(player) {
const scored = player.judgeScores ? player.judgeScores.length : 0
const total = player.totalJudges || '?'
return scored + '/' + total
},
async handleRefresh() { async handleRefresh() {
if (this.isLoading) return if (this.isLoading) return
uni.showToast({ title: '刷新中...', icon: 'loading', duration: 1000 }) uni.showToast({ title: '刷新中...', icon: 'loading', duration: 1000 })
@@ -514,6 +599,7 @@ export default {
.score-tags { .score-tags {
display: flex; display: flex;
gap: 16rpx; gap: 16rpx;
flex-wrap: wrap;
} }
.score-tag { .score-tag {
@@ -536,6 +622,17 @@ export default {
font-weight: 500; font-weight: 500;
} }
/* ==================== 等待中状态 ==================== */
.score-tag.waiting {
background-color: #FFF7E6;
border-color: #FFD591;
}
.score-tag.waiting .tag-value {
color: #FA8C16;
font-size: 24rpx;
}
/* ==================== 未评分操作 ==================== */ /* ==================== 未评分操作 ==================== */
.action-row { .action-row {
display: flex; display: flex;