优化项目整合内容
This commit is contained in:
112
static/js/app.js
112
static/js/app.js
@@ -2425,15 +2425,36 @@ async function showQueryHistoryDialog() {
|
||||
if (result.data.length === 0) {
|
||||
historyList = '<p class="text-muted text-center">暂无查询历史记录</p>';
|
||||
} else {
|
||||
// 添加批量操作控制栏
|
||||
historyList += `
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" id="selectAllQueryHistory" onchange="toggleAllQueryHistorySelection()">
|
||||
<label class="form-check-label" for="selectAllQueryHistory">
|
||||
全选
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<button class="btn btn-danger btn-sm" id="batchDeleteQueryHistoryBtn" onclick="batchDeleteQueryHistory()" disabled>
|
||||
<i class="fas fa-trash"></i> 批量删除 (<span id="selectedQueryHistoryCount">0</span>)
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
result.data.forEach(history => {
|
||||
const createdDate = new Date(history.created_at).toLocaleString();
|
||||
const consistencyRate = history.total_keys > 0 ?
|
||||
Math.round((history.identical_count / history.total_keys) * 100) : 0;
|
||||
const safeName = (history.name || '').replace(/'/g, "\\'");
|
||||
|
||||
historyList += `
|
||||
<div class="card mb-3">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between align-items-start">
|
||||
<div class="form-check me-3 mt-1">
|
||||
<input class="form-check-input query-history-checkbox" type="checkbox" value="${history.id}" onchange="updateQueryHistorySelectionCount()">
|
||||
</div>
|
||||
<div class="flex-grow-1">
|
||||
<h6 class="card-title mb-1">
|
||||
${history.name}
|
||||
@@ -2467,7 +2488,7 @@ async function showQueryHistoryDialog() {
|
||||
<button class="btn btn-sm btn-success me-1" onclick="loadHistoryResults(${history.id})" title="查看结果">
|
||||
<i class="fas fa-chart-bar"></i>
|
||||
</button>
|
||||
<button class="btn btn-sm btn-danger" onclick="deleteHistoryRecord(${history.id}, '${history.name}')" title="删除">
|
||||
<button class="btn btn-sm btn-danger" onclick="deleteHistoryRecord(${history.id}, '${safeName}')" title="删除">
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
@@ -2484,7 +2505,7 @@ async function showQueryHistoryDialog() {
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">
|
||||
<i class="fas fa-history"></i> 查询历史记录
|
||||
<i class="fas fa-history"></i> 查询历史记录管理
|
||||
</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
@@ -4158,4 +4179,91 @@ function formatCompositeKey(key) {
|
||||
// 单主键或其他情况:使用JSON格式
|
||||
return JSON.stringify(key);
|
||||
}
|
||||
}
|
||||
|
||||
// 切换全选Cassandra查询历史记录
|
||||
function toggleAllQueryHistorySelection() {
|
||||
const selectAllCheckbox = document.getElementById('selectAllQueryHistory');
|
||||
const historyCheckboxes = document.querySelectorAll('.query-history-checkbox');
|
||||
|
||||
historyCheckboxes.forEach(checkbox => {
|
||||
checkbox.checked = selectAllCheckbox.checked;
|
||||
});
|
||||
|
||||
updateQueryHistorySelectionCount();
|
||||
}
|
||||
|
||||
// 更新Cassandra查询历史记录选择数量
|
||||
function updateQueryHistorySelectionCount() {
|
||||
const selectedCheckboxes = document.querySelectorAll('.query-history-checkbox:checked');
|
||||
const count = selectedCheckboxes.length;
|
||||
const totalCheckboxes = document.querySelectorAll('.query-history-checkbox');
|
||||
|
||||
// 更新显示计数
|
||||
const countSpan = document.getElementById('selectedQueryHistoryCount');
|
||||
if (countSpan) {
|
||||
countSpan.textContent = count;
|
||||
}
|
||||
|
||||
// 更新批量删除按钮状态
|
||||
const batchDeleteBtn = document.getElementById('batchDeleteQueryHistoryBtn');
|
||||
if (batchDeleteBtn) {
|
||||
batchDeleteBtn.disabled = count === 0;
|
||||
}
|
||||
|
||||
// 更新全选复选框状态
|
||||
const selectAllCheckbox = document.getElementById('selectAllQueryHistory');
|
||||
if (selectAllCheckbox) {
|
||||
if (count === 0) {
|
||||
selectAllCheckbox.indeterminate = false;
|
||||
selectAllCheckbox.checked = false;
|
||||
} else if (count === totalCheckboxes.length) {
|
||||
selectAllCheckbox.indeterminate = false;
|
||||
selectAllCheckbox.checked = true;
|
||||
} else {
|
||||
selectAllCheckbox.indeterminate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 批量删除Cassandra查询历史记录
|
||||
async function batchDeleteQueryHistory() {
|
||||
const selectedCheckboxes = document.querySelectorAll('.query-history-checkbox:checked');
|
||||
const selectedIds = Array.from(selectedCheckboxes).map(cb => parseInt(cb.value));
|
||||
|
||||
if (selectedIds.length === 0) {
|
||||
showAlert('warning', '请选择要删除的历史记录');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!confirm(`确定要删除选中的 ${selectedIds.length} 条历史记录吗?此操作不可恢复。`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/query-history/batch-delete', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
history_ids: selectedIds
|
||||
})
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
showAlert('success', `成功删除 ${result.deleted_count} 条历史记录`);
|
||||
// 重新显示历史记录列表
|
||||
setTimeout(() => {
|
||||
showQueryHistoryDialog();
|
||||
}, 500);
|
||||
} else {
|
||||
showAlert('danger', result.error || '批量删除失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('批量删除Cassandra查询历史记录失败:', error);
|
||||
showAlert('danger', `批量删除失败: ${error.message}`);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user