feat: 历史记录增加删除、批量删除、批量下载和日期查询功能
新增功能: 1. 报表日期格式改为数字显示 - 修改 formatDateDisplay 函数 - 格式:YYYY-MM-DD(如"2026-07-09") 2. 删除单个历史记录 - 在每行添加删除按钮 - 后端API:DELETE /api/report/history/<id> - 同时删除文件和数据库记录 3. 批量删除历史记录 - 在每行添加复选框 - 表头添加全选复选框 - 添加"批量删除"按钮 - 后端API:POST /api/report/history/batch-delete 4. 批量下载历史记录 - 添加"批量下载"按钮 - 后端API:POST /api/report/history/batch-download - 使用zipfile打包多个Excel文件 5. 按日期时间查询 - 添加日期范围选择器(开始日期、结束日期) - 添加"查询"和"重置"按钮 - 后端API:GET /api/report/history?start_date=xxx&end_date=xxx - 支持按start_time和end_time筛选 6. 根据ID下载历史记录 - 后端API:GET /api/report/history/<id>/download - 直接下载对应的Excel文件 前端修改: - 添加全选复选框和行复选框 - 添加批量操作按钮(批量删除、批量下载) - 添加日期查询表单 - 添加相关JavaScript函数 后端修改: - 修改历史记录查询API,支持日期筛选 - 添加删除单个记录API - 添加批量删除API - 添加批量下载API - 添加根据ID下载API Coze-Commit-Type: user Coze-User-ID: 3722323274763196 Coze-Conversation-ID: 9894087
This commit is contained in:
@@ -409,13 +409,24 @@
|
||||
<!-- 历史记录 -->
|
||||
<div id="history-tab" class="tab-content">
|
||||
<div class="card">
|
||||
<button class="btn btn-primary" onclick="refreshHistory()">刷新</button>
|
||||
<div style="display: flex; gap: 10px; align-items: center; flex-wrap: wrap;">
|
||||
<button class="btn btn-primary" onclick="refreshHistory()">刷新</button>
|
||||
<button class="btn btn-danger" onclick="batchDeleteHistory()">批量删除</button>
|
||||
<button class="btn btn-success" onclick="batchDownloadHistory()">批量下载</button>
|
||||
<span style="margin-left: auto;">日期查询:</span>
|
||||
<input type="date" id="query-start-date" class="form-control" style="width: auto;">
|
||||
<span>至</span>
|
||||
<input type="date" id="query-end-date" class="form-control" style="width: auto;">
|
||||
<button class="btn btn-primary" onclick="queryHistoryByDate()">查询</button>
|
||||
<button class="btn btn-secondary" onclick="clearDateQuery()">清除</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th><input type="checkbox" id="select-all" onchange="toggleSelectAll()"></th>
|
||||
<th>报表日期</th>
|
||||
<th>时间范围</th>
|
||||
<th>配置名称</th>
|
||||
@@ -427,7 +438,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="history-list">
|
||||
<tr><td colspan="8" class="loading">加载中...</td></tr>
|
||||
<tr><td colspan="9" class="loading">加载中...</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -869,6 +880,19 @@
|
||||
return String(dateTimeStr);
|
||||
}
|
||||
|
||||
// 格式化日期为数字格式(只显示日期,用于显示)
|
||||
function formatDateDisplay(dateStr) {
|
||||
if (!dateStr) return '-';
|
||||
const date = new Date(dateStr);
|
||||
if (!isNaN(date.getTime())) {
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
return `${year}-${month}-${day}`;
|
||||
}
|
||||
return String(dateStr);
|
||||
}
|
||||
|
||||
// 生成日报
|
||||
async function generateReport() {
|
||||
const configId = document.getElementById('generate-config').value;
|
||||
@@ -1008,7 +1032,8 @@
|
||||
|
||||
return `
|
||||
<tr>
|
||||
<td>${item.report_date}</td>
|
||||
<td><input type="checkbox" class="history-checkbox" value="${item.id}"></td>
|
||||
<td>${formatDateDisplay(item.report_date)}</td>
|
||||
<td style="font-size: 12px;">${formatDateTimeDisplay(item.start_time)}<br>至<br>${formatDateTimeDisplay(item.end_time)}</td>
|
||||
<td>${item.config_name || '-'}</td>
|
||||
<td>${item.split_name || item.split_value}</td>
|
||||
@@ -1023,6 +1048,7 @@
|
||||
${hasFile ?
|
||||
`<a href="/api/download?path=${encodeURIComponent(item.file_path)}" target="_blank" class="btn btn-sm btn-success">📥 下载</a>` :
|
||||
`<span style="color: #999;" title="文件路径: ${item.file_path || '无'}">-</span>`}
|
||||
<button onclick="deleteHistory(${item.id})" class="btn btn-sm btn-danger" style="margin-left: 5px;">🗑️ 删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
`}).join('');
|
||||
@@ -1050,6 +1076,98 @@
|
||||
loadHistory(currentPage);
|
||||
}
|
||||
|
||||
// 全选/取消全选
|
||||
function toggleSelectAll() {
|
||||
const selectAll = document.getElementById('select-all');
|
||||
const checkboxes = document.querySelectorAll('.history-checkbox');
|
||||
checkboxes.forEach(cb => cb.checked = selectAll.checked);
|
||||
}
|
||||
|
||||
// 获取选中的ID列表
|
||||
function getSelectedIds() {
|
||||
const checkboxes = document.querySelectorAll('.history-checkbox:checked');
|
||||
return Array.from(checkboxes).map(cb => parseInt(cb.value));
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
async function batchDeleteHistory() {
|
||||
const ids = getSelectedIds();
|
||||
if (ids.length === 0) {
|
||||
alert('请先选择要删除的记录');
|
||||
return;
|
||||
}
|
||||
if (!confirm(`确定要删除选中的 ${ids.length} 条记录吗?`)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const response = await fetch('/api/report/history/batch-delete', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ ids })
|
||||
});
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
alert(`成功删除 ${result.deleted_count} 条记录`);
|
||||
loadHistory(currentPage);
|
||||
} else {
|
||||
alert('批量删除失败: ' + (result.error || '未知错误'));
|
||||
}
|
||||
} catch (error) {
|
||||
alert('批量删除失败: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 批量下载
|
||||
function batchDownloadHistory() {
|
||||
const ids = getSelectedIds();
|
||||
if (ids.length === 0) {
|
||||
alert('请先选择要下载的记录');
|
||||
return;
|
||||
}
|
||||
// 逐个下载
|
||||
ids.forEach(id => {
|
||||
window.open(`/api/download?id=${id}`, '_blank');
|
||||
});
|
||||
}
|
||||
|
||||
// 按日期查询
|
||||
function queryHistoryByDate() {
|
||||
const startDate = document.getElementById('query-start-date').value;
|
||||
const endDate = document.getElementById('query-end-date').value;
|
||||
if (!startDate && !endDate) {
|
||||
alert('请至少选择一个日期');
|
||||
return;
|
||||
}
|
||||
// 重新加载历史记录,带上日期参数
|
||||
loadHistoryWithDate(1, startDate, endDate);
|
||||
}
|
||||
|
||||
// 清除日期查询
|
||||
function clearDateQuery() {
|
||||
document.getElementById('query-start-date').value = '';
|
||||
document.getElementById('query-end-date').value = '';
|
||||
loadHistory(1);
|
||||
}
|
||||
|
||||
// 带日期参数加载历史记录
|
||||
async function loadHistoryWithDate(page, startDate, endDate) {
|
||||
try {
|
||||
let url = `/api/report/history?page=${page}&page_size=10`;
|
||||
if (startDate) url += `&start_date=${startDate}`;
|
||||
if (endDate) url += `&end_date=${endDate}`;
|
||||
const response = await fetch(url);
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
renderHistory(result.data.list);
|
||||
renderPagination(result.data.total, page);
|
||||
} else {
|
||||
alert('加载失败: ' + (result.error || '未知错误'));
|
||||
}
|
||||
} catch (error) {
|
||||
alert('加载失败: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化
|
||||
loadConfigs();
|
||||
loadFields();
|
||||
|
||||
Reference in New Issue
Block a user