實現完整的後台得獎資訊
This commit is contained in:
@@ -60,33 +60,95 @@ export function AwardDetailDialog({ open, onOpenChange, award }: AwardDetailDial
|
||||
const [currentPhotoIndex, setCurrentPhotoIndex] = useState(0)
|
||||
const [competitionJudges, setCompetitionJudges] = useState<any[]>([])
|
||||
|
||||
// 添加調試資訊
|
||||
console.log('🏆 AwardDetailDialog 渲染:', {
|
||||
open,
|
||||
award: award ? {
|
||||
id: award.id,
|
||||
competitionId: award.competitionId,
|
||||
awardName: award.awardName,
|
||||
hasCompetitionId: !!award.competitionId
|
||||
} : null
|
||||
});
|
||||
|
||||
const competition = competitions.find((c) => c.id === award.competitionId)
|
||||
const judgeScores = getJudgeScores(award.id)
|
||||
const appData = getAppData(award.id)
|
||||
|
||||
// 載入競賽評審團資訊
|
||||
useEffect(() => {
|
||||
console.log('🔍 useEffect 觸發:', { open, competitionId: award.competitionId, awardId: award.id });
|
||||
|
||||
if (open && award.competitionId) {
|
||||
const loadCompetitionJudges = async () => {
|
||||
const loadCompetitionJudges = async (retryCount = 0) => {
|
||||
try {
|
||||
console.log('🔍 載入競賽評審團:', award.competitionId);
|
||||
const response = await fetch(`/api/competitions/${award.competitionId}/judges`);
|
||||
console.log('🔍 載入競賽評審團:', award.competitionId, '重試次數:', retryCount);
|
||||
console.log('🏆 獎項資料:', award);
|
||||
|
||||
// 添加時間戳防止快取,並設置快取控制標頭
|
||||
const timestamp = Date.now();
|
||||
const apiUrl = `/api/competitions/${award.competitionId}/judges?t=${timestamp}`;
|
||||
console.log('🌐 API URL:', apiUrl);
|
||||
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
||||
'Pragma': 'no-cache',
|
||||
'Expires': '0'
|
||||
}
|
||||
});
|
||||
|
||||
console.log('📡 API 回應狀態:', response.status);
|
||||
console.log('📡 API 回應標頭:', Object.fromEntries(response.headers.entries()));
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
console.error('❌ API 錯誤回應:', errorText);
|
||||
throw new Error(`HTTP error! status: ${response.status}, message: ${errorText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
console.log('📄 API 回應資料:', JSON.stringify(data, null, 2));
|
||||
|
||||
if (data.success && data.data && data.data.judges) {
|
||||
console.log('✅ 獲取到評審團:', data.data.judges.length, '位');
|
||||
console.log('👥 評審團詳細資料:', data.data.judges);
|
||||
setCompetitionJudges(data.data.judges);
|
||||
} else {
|
||||
console.error('❌ 獲取評審團失敗:', data.message);
|
||||
setCompetitionJudges([]);
|
||||
console.error('❌ 獲取評審團失敗:', data.message || '未知錯誤');
|
||||
console.error('❌ 完整錯誤資料:', data);
|
||||
|
||||
// 如果沒有評審資料且是第一次嘗試,重試一次
|
||||
if (retryCount === 0) {
|
||||
console.log('🔄 重試載入評審團...');
|
||||
setTimeout(() => loadCompetitionJudges(1), 1000);
|
||||
} else {
|
||||
setCompetitionJudges([]);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ 載入評審團失敗:', error);
|
||||
setCompetitionJudges([]);
|
||||
|
||||
// 如果是網路錯誤且是第一次嘗試,重試一次
|
||||
if (retryCount === 0) {
|
||||
console.log('🔄 網路錯誤,重試載入評審團...');
|
||||
setTimeout(() => loadCompetitionJudges(1), 2000);
|
||||
} else {
|
||||
setCompetitionJudges([]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 清空之前的評審資料,確保重新載入
|
||||
setCompetitionJudges([]);
|
||||
loadCompetitionJudges();
|
||||
} else {
|
||||
console.log('❌ useEffect 條件不滿足:', {
|
||||
open,
|
||||
competitionId: award.competitionId,
|
||||
hasCompetitionId: !!award.competitionId
|
||||
});
|
||||
}
|
||||
}, [open, award.competitionId]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user