新增得獎更新、刪除的功能
This commit is contained in:
@@ -82,20 +82,14 @@ export function ScoringManagement() {
|
||||
const [isLoadingRules, setIsLoadingRules] = useState(false)
|
||||
|
||||
|
||||
// 調試:檢查競賽數據
|
||||
console.log('📋 競賽數據:', competitions)
|
||||
console.log('👨⚖️ 評審數據:', judges)
|
||||
console.log('📊 競賽數量:', competitions?.length || 0)
|
||||
|
||||
// 檢查初始載入狀態
|
||||
useEffect(() => {
|
||||
if (competitions && competitions.length > 0) {
|
||||
console.log('✅ 競賽數據已載入,關閉初始載入狀態')
|
||||
setIsInitialLoading(false)
|
||||
|
||||
// 自動選擇第一個競賽(如果沒有選中的話)
|
||||
if (!selectedCompetition) {
|
||||
console.log('🎯 自動選擇第一個競賽:', competitions[0].name)
|
||||
setSelectedCompetition(competitions[0])
|
||||
}
|
||||
}
|
||||
@@ -176,7 +170,6 @@ export function ScoringManagement() {
|
||||
setError('載入評分數據失敗')
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('載入評分數據失敗:', err)
|
||||
setError('載入評分數據失敗')
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
@@ -376,7 +369,6 @@ export function ScoringManagement() {
|
||||
|
||||
// 根據參賽者類型確定participantType
|
||||
const selectedParticipant = competitionParticipants.find(p => p.id === manualScoring.participantId)
|
||||
console.log('🔍 選中的參賽者:', selectedParticipant);
|
||||
|
||||
// 由於所有參賽者都是團隊的 app,所以 participantType 應該是 'app'
|
||||
const participantType = 'app'
|
||||
@@ -392,7 +384,6 @@ export function ScoringManagement() {
|
||||
recordId: selectedRecord?.id // 編輯時的記錄ID
|
||||
}
|
||||
|
||||
console.log('🔍 提交評分請求數據:', requestData);
|
||||
|
||||
const response = await fetch('/api/admin/scoring', {
|
||||
method: 'POST',
|
||||
@@ -403,7 +394,6 @@ export function ScoringManagement() {
|
||||
})
|
||||
|
||||
const data = await response.json()
|
||||
console.log('🔍 API 回應:', data);
|
||||
|
||||
if (data.success) {
|
||||
setSuccess(showEditScoring ? "評分更新成功!" : "評分提交成功!")
|
||||
@@ -444,7 +434,6 @@ export function ScoringManagement() {
|
||||
setError(data.message || "評分提交失敗")
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('評分提交失敗:', err)
|
||||
setError("評分提交失敗,請重試")
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
@@ -479,7 +468,6 @@ export function ScoringManagement() {
|
||||
setScoringStats(data.data)
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('載入評分統計失敗:', err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -496,32 +484,23 @@ export function ScoringManagement() {
|
||||
const loadCompetitionData = async () => {
|
||||
if (!selectedCompetition) return
|
||||
|
||||
console.log('🔍 開始載入競賽數據,競賽ID:', selectedCompetition.id)
|
||||
setIsLoadingData(true)
|
||||
setError("")
|
||||
|
||||
try {
|
||||
// 載入競賽評審
|
||||
console.log('📋 載入競賽評審...')
|
||||
const judgesResponse = await fetch(`/api/competitions/${selectedCompetition.id}/judges`)
|
||||
const judgesData = await judgesResponse.json()
|
||||
|
||||
console.log('評審API回應:', judgesData)
|
||||
|
||||
if (judgesData.success && judgesData.data && judgesData.data.judges) {
|
||||
setCompetitionJudges(judgesData.data.judges)
|
||||
console.log('✅ 評審數據載入成功:', judgesData.data.judges.length, '個評審')
|
||||
} else {
|
||||
console.error('❌ 評審數據載入失敗:', judgesData.message || 'API回應格式錯誤')
|
||||
setCompetitionJudges([])
|
||||
}
|
||||
|
||||
// 使用統一的評分進度API來獲取準確的參賽者數量
|
||||
console.log('📱 載入競賽參賽者(使用統一計算邏輯)...')
|
||||
const scoringProgressResponse = await fetch(`/api/competitions/scoring-progress?competitionId=${selectedCompetition.id}`)
|
||||
const scoringProgressData = await scoringProgressResponse.json()
|
||||
|
||||
console.log('評分進度API回應:', scoringProgressData)
|
||||
|
||||
let participants = []
|
||||
|
||||
@@ -533,7 +512,6 @@ export function ScoringManagement() {
|
||||
const appsResponse = await fetch(`/api/competitions/${selectedCompetition.id}/apps`)
|
||||
const appsData = await appsResponse.json()
|
||||
|
||||
console.log('應用API回應:', appsData)
|
||||
|
||||
if (appsData.success && appsData.data && appsData.data.apps) {
|
||||
// 直接使用API返回的APP數據,確保數量與評分進度一致
|
||||
@@ -546,38 +524,26 @@ export function ScoringManagement() {
|
||||
creator: app.creator || '未知作者',
|
||||
teamId: app.teamId || null
|
||||
}))
|
||||
console.log(`✅ ${selectedCompetition.type === 'team' ? '團隊' : '個人'}競賽APP數據載入成功:`, participants.length, '個APP')
|
||||
} else {
|
||||
console.error('❌ 應用數據載入失敗:', appsData.message || 'API回應格式錯誤')
|
||||
}
|
||||
} else {
|
||||
console.error('❌ 評分進度數據載入失敗:', scoringProgressData.message || 'API回應格式錯誤')
|
||||
}
|
||||
|
||||
setCompetitionParticipants(participants)
|
||||
console.log('✅ 參賽者數據載入完成:', participants.length, '個參賽者')
|
||||
console.log('🔍 參賽者詳細數據:', participants)
|
||||
|
||||
// 載入競賽規則
|
||||
console.log('📋 載入競賽規則...')
|
||||
const rulesResponse = await fetch(`/api/competitions/${selectedCompetition.id}/rules`)
|
||||
const rulesData = await rulesResponse.json()
|
||||
|
||||
if (rulesData.success && rulesData.data) {
|
||||
setCompetitionRules(rulesData.data)
|
||||
console.log('✅ 競賽規則載入成功:', rulesData.data.length, '個規則')
|
||||
} else {
|
||||
console.error('❌ 競賽規則載入失敗:', rulesData.message || 'API回應格式錯誤')
|
||||
setCompetitionRules([])
|
||||
}
|
||||
|
||||
// 如果沒有載入到任何數據,顯示警告
|
||||
if (participants.length === 0) {
|
||||
console.warn('⚠️ 沒有載入到任何參賽者數據')
|
||||
setError('該競賽暫無參賽者數據,請檢查競賽設置')
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('❌ 載入競賽數據失敗:', err)
|
||||
setError('載入競賽數據失敗: ' + (err instanceof Error ? err.message : '未知錯誤'))
|
||||
|
||||
// 設置空數組以避免undefined錯誤
|
||||
@@ -599,13 +565,10 @@ export function ScoringManagement() {
|
||||
|
||||
if (data.success) {
|
||||
setScoringSummary(data.data)
|
||||
console.log('✅ 評分完成度匯總載入成功:', data.data)
|
||||
} else {
|
||||
console.log('❌ 評分完成度匯總載入失敗:', data)
|
||||
setScoringSummary(null)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('載入評分完成度匯總失敗:', error)
|
||||
setScoringSummary(null)
|
||||
} finally {
|
||||
setIsLoadingSummary(false)
|
||||
@@ -634,11 +597,9 @@ export function ScoringManagement() {
|
||||
scoredJudges: data.data?.length || 0
|
||||
})
|
||||
} else {
|
||||
console.error('載入APP評分詳情失敗:', data.message)
|
||||
setError(data.message || '載入APP評分詳情失敗')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('載入APP評分詳情失敗:', error)
|
||||
setError('載入APP評分詳情失敗')
|
||||
} finally {
|
||||
setIsLoadingAppDetails(false)
|
||||
@@ -713,9 +674,7 @@ export function ScoringManagement() {
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Select value={selectedCompetition?.id || ""} onValueChange={(value) => {
|
||||
console.log('🎯 選擇競賽:', value)
|
||||
const competition = competitions.find(c => c.id === value)
|
||||
console.log('🏆 找到競賽:', competition)
|
||||
setSelectedCompetition(competition)
|
||||
}}>
|
||||
<SelectTrigger className="w-full">
|
||||
|
Reference in New Issue
Block a user