更改总计逻辑

This commit is contained in:
2026-07-21 15:21:29 +08:00
parent 0c73c40e8a
commit cff1074474
10 changed files with 620 additions and 50 deletions

View File

@@ -25,10 +25,50 @@ async function batchDownloadHistory() {
const ids = Array.from(checkboxes).map(cb => parseInt(cb.value));
// 逐个下载
ids.forEach(id => {
window.open(`/api/download?id=${id}`, '_blank');
});
// 检查是否有生成失败的记录
const failedCount = Array.from(checkboxes).filter(cb => cb.dataset.status !== '1').length;
const successCount = checkboxes.length - failedCount;
if (successCount === 0) {
alert('选中的记录都是生成失败的,无法下载');
return;
}
if (failedCount > 0) {
if (!confirm(`选中的 ${checkboxes.length} 条记录中有 ${failedCount} 条是生成失败的,无法下载。\n是否打包下载成功的 ${successCount} 条?`)) {
return;
}
}
try {
const response = await fetch('/api/download/batch', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ ids: ids })
});
if (response.ok) {
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
const timestamp = new Date().toISOString().slice(0, 19).replace(/[-T:]/g, '');
a.download = `批量下载_${timestamp}.zip`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
} else {
try {
const result = await response.json();
alert('下载失败: ' + (result.message || '未知错误'));
} catch (e) {
alert('下载失败: 服务器返回错误');
}
}
} catch (error) {
alert('下载失败: ' + error.message);
}
}
// 按日期查询
@@ -159,7 +199,7 @@ function renderHistory(list) {
return `
<tr>
<td><input type="checkbox" class="history-checkbox" value="${item.id}"></td>
<td><input type="checkbox" class="history-checkbox" value="${item.id}" data-status="${item.status}" data-name="${configName}"></td>
<td>${reportDate}</td>
<td>${timeRange}</td>
<td>${configName}</td>