历史记录中,增加按配置名称搜索
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
let historyStartDate = '';
|
||||
let historyEndDate = '';
|
||||
let historyStatus = '';
|
||||
let historyConfigName = '';
|
||||
let historyPageSize = 10;
|
||||
|
||||
// 每页显示条数变化
|
||||
@@ -75,8 +76,10 @@ async function batchDownloadHistory() {
|
||||
function queryHistoryByDate() {
|
||||
const startDate = document.getElementById('history-start-date').value;
|
||||
const endDate = document.getElementById('history-end-date').value;
|
||||
const configNameInput = document.getElementById('history-config-name');
|
||||
historyStartDate = startDate;
|
||||
historyEndDate = endDate;
|
||||
historyConfigName = configNameInput ? configNameInput.value.trim() : '';
|
||||
loadHistoryWithDate(1);
|
||||
}
|
||||
|
||||
@@ -85,9 +88,12 @@ function clearHistoryFilter() {
|
||||
document.getElementById('history-status-filter').value = '';
|
||||
document.getElementById('history-start-date').value = '';
|
||||
document.getElementById('history-end-date').value = '';
|
||||
const configNameInput = document.getElementById('history-config-name');
|
||||
if (configNameInput) configNameInput.value = '';
|
||||
historyStatus = '';
|
||||
historyStartDate = '';
|
||||
historyEndDate = '';
|
||||
historyConfigName = '';
|
||||
loadHistory(1);
|
||||
}
|
||||
|
||||
@@ -281,10 +287,16 @@ async function loadHistory(page = 1) {
|
||||
|
||||
async function loadHistoryWithDate(page) {
|
||||
try {
|
||||
// 同步配置名称搜索框的值(翻页时保留筛选条件)
|
||||
const configNameInput = document.getElementById('history-config-name');
|
||||
if (configNameInput) {
|
||||
historyConfigName = configNameInput.value.trim();
|
||||
}
|
||||
let url = `/api/report/history?page=${page}&page_size=${historyPageSize}`;
|
||||
if (historyStatus) url += `&status=${historyStatus}`;
|
||||
if (historyStartDate) url += `&start_date=${historyStartDate}`;
|
||||
if (historyEndDate) url += `&end_date=${historyEndDate}`;
|
||||
if (historyConfigName) url += `&config_name=${encodeURIComponent(historyConfigName)}`;
|
||||
const response = await fetch(url);
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
@@ -362,3 +374,70 @@ async function batchDeleteHistory() {
|
||||
alert('删除失败: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 批量导出当前筛选条件下的所有记录(与搜索条件同步)
|
||||
async function batchDownloadFilteredHistory() {
|
||||
// 同步当前筛选条件
|
||||
const configNameInput = document.getElementById('history-config-name');
|
||||
if (configNameInput) {
|
||||
historyConfigName = configNameInput.value.trim();
|
||||
}
|
||||
historyStatus = document.getElementById('history-status-filter').value;
|
||||
historyStartDate = document.getElementById('history-start-date').value;
|
||||
historyEndDate = document.getElementById('history-end-date').value;
|
||||
|
||||
// 构建筛选条件描述
|
||||
const filterDescParts = [];
|
||||
if (historyStatus) {
|
||||
filterDescParts.push(historyStatus === '1' ? '成功' : '失败');
|
||||
}
|
||||
if (historyConfigName) {
|
||||
filterDescParts.push(`配置名称含"${historyConfigName}"`);
|
||||
}
|
||||
if (historyStartDate) {
|
||||
filterDescParts.push(`开始日期 ${historyStartDate}`);
|
||||
}
|
||||
if (historyEndDate) {
|
||||
filterDescParts.push(`结束日期 ${historyEndDate}`);
|
||||
}
|
||||
const filterDesc = filterDescParts.length > 0 ? filterDescParts.join(',') : '全部记录';
|
||||
|
||||
if (!confirm(`将导出符合当前筛选条件的所有成功记录(${filterDesc})。\n注意:仅导出生成成功的报表。\n是否继续?`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/download/batch-filter', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
config_name: historyConfigName,
|
||||
start_date: historyStartDate,
|
||||
end_date: historyEndDate,
|
||||
status: historyStatus
|
||||
})
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user