diff --git a/frontend/admin.html b/frontend/admin.html index 43ccd13..48e5ceb 100644 --- a/frontend/admin.html +++ b/frontend/admin.html @@ -72,7 +72,10 @@ ⚽ 比赛管理 - + 添加比赛 + + 批量添加 + + 添加比赛 + @@ -154,6 +157,35 @@ + + + + × + 批量添加比赛 + + 比赛数据(每行一条,用逗号分隔) + + + + 轮次(可选,批量设置) + + -- 使用数据中的轮次 -- + 小组赛 + 16强 + 8强 + 半决赛 + 季军赛 + 决赛 + + + 批量添加 + + + diff --git a/frontend/js/admin.js b/frontend/js/admin.js index 9898801..0f01707 100644 --- a/frontend/js/admin.js +++ b/frontend/js/admin.js @@ -409,6 +409,81 @@ async function deleteAlgorithm(id) { } } +// 显示批量添加比赛弹窗 +function showBatchAddMatchModal() { + document.getElementById('batch-match-data').value = ''; + document.getElementById('batch-match-round').value = ''; + document.getElementById('batch-match-modal').style.display = 'block'; +} + +// 批量添加比赛 +async function batchAddMatches() { + const dataText = document.getElementById('batch-match-data').value.trim(); + const defaultRound = document.getElementById('batch-match-round').value; + + if (!dataText) { + alert('请输入比赛数据'); + return; + } + + const lines = dataText.split('\n').filter(line => line.trim()); + let successCount = 0; + let failCount = 0; + let errors = [];\n + for (const line of lines) { + const parts = line.split(',').map(p => p.trim()); + + if (parts.length < 3) { + failCount++; + errors.push(`格式错误: ${line}`);n continue; + } + + const matchData = { + match_code: parts[0], + home_team: parts[1], + away_team: parts[2], + match_time: parts[3] || null, + round_name: parts[4] || defaultRound || '小组赛', + status: 'upcoming' + }; + + try { + const response = await fetch(`${API_BASE}/api/matches`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(matchData) + }); + + const result = await response.json(); + + if (result.success) { + successCount++; + } else { + failCount++; + errors.push(`${matchData.match_code}: ${result.message}`); + } + } catch (error) { + failCount++; + errors.push(`${matchData.match_code}: 网络错误`); + } + } + + let message = `批量添加完成\n成功: ${successCount} 条\n失败: ${failCount} 条`; + if (errors.length > 0 && errors.length <= 5) { + message += '\n\n失败详情:\n' + errors.join('\n'); + } else if (errors.length > 5) { + message += '\n\n失败详情(前5条):\n' + errors.slice(0, 5).join('\n') + '\n...'; + } + + alert(message); + + if (successCount > 0) { + closeModal('batch-match-modal'); + loadMatches(); + loadPredictions(); + } +} + // 显示添加比赛弹窗 function showAddMatchModal() { document.getElementById('match-modal-title').textContent = '添加比赛';