v1.0.3 - 添加批量添加比赛功能
This commit is contained in:
@@ -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 = '添加比赛';
|
||||
|
||||
Reference in New Issue
Block a user