修复一些bug

This commit is contained in:
2025-11-09 20:28:17 +08:00
parent 48bb1b3c12
commit e650a087ca
3 changed files with 79 additions and 3 deletions

2
app.py
View File

@@ -650,8 +650,6 @@ def delete_entry(doc_id):
if success:
return redirect(url_for(redirect_url))
if delete_by_id(doc_id):
return redirect(url_for('show_all'))
else:
return "删除失败", 500

View File

@@ -224,6 +224,7 @@
</div>
<div class="card-actions">
<a href="{{ url_for('edit_entry', doc_id=item._id) }}" class="action-button edit-btn">编辑</a>
<button type="button" class="action-button delete-btn" onclick="deleteRecord('{{ item._id }}')">删除</button>
</div>
</div>
@@ -342,12 +343,72 @@ function batchDelete() {
document.body.appendChild(form);
form.submit();
// 提交后自动刷新页面
form.addEventListener('submit', function() {
setTimeout(function() {
window.location.reload();
}, 1000); // 1秒后刷新页面给服务器处理时间
});
}
// 页面加载时初始化
document.addEventListener('DOMContentLoaded', function() {
updateSelectedCount();
});
// 单个删除功能
function deleteRecord(docId) {
// 显示删除确认模态框
showDeleteModal(docId);
}
// 显示删除确认模态框
function showDeleteModal(docId) {
// 创建模态框HTML
const modalHtml = `
<div id="deleteModal" class="modal" style="display: block;">
<div class="modal-content modal-small">
<h3>确认删除</h3>
<p>您确定要删除这条数据吗?此操作不可撤销。</p>
<div class="modal-actions">
<button onclick="closeDeleteModal()" class="btn btn-secondary">取消</button>
<button onclick="confirmDeleteRecord('${docId}')" class="btn btn-danger">确认删除</button>
</div>
</div>
</div>
`;
// 添加模态框到页面
document.body.insertAdjacentHTML('beforeend', modalHtml);
}
// 关闭删除确认模态框
function closeDeleteModal() {
const modal = document.getElementById('deleteModal');
if (modal) {
modal.remove();
}
}
// 确认删除记录
function confirmDeleteRecord(docId) {
// 关闭模态框
closeDeleteModal();
// 创建表单并提交
const form = document.createElement('form');
form.method = 'POST';
form.action = '/delete/' + docId;
document.body.appendChild(form);
form.submit();
// 提交后自动刷新页面
setTimeout(function() {
window.location.reload();
}, 1000); // 1秒后刷新页面给服务器处理时间
}
</script>
{% endblock %}

View File

@@ -99,7 +99,7 @@
<p>您确定要删除这条数据吗?此操作不可撤销。</p>
<div class="modal-actions">
<button onclick="closeDeleteModal()" class="btn btn-secondary">取消</button>
<form id="deleteForm" method="POST" style="display: inline;">
<form id="deleteForm" method="POST" style="display: inline;" onsubmit="handleDeleteSubmit(event)">
<button type="submit" class="btn btn-danger">确认删除</button>
</form>
</div>
@@ -470,6 +470,23 @@ function closeDeleteModal() {
document.getElementById('deleteModal').style.display = 'none';
}
// 处理删除表单提交
function handleDeleteSubmit(event) {
// 关闭模态框
closeDeleteModal();
// 显示删除中的提示
const submitButton = event.target.querySelector('button[type="submit"]');
const originalText = submitButton.textContent;
submitButton.textContent = '删除中...';
submitButton.disabled = true;
// 提交表单后自动刷新页面
setTimeout(function() {
window.location.reload();
}, 1000); // 1秒后刷新页面给服务器处理时间
}
// 点击模态框外部关闭
window.onclick = function(event) {
const imageModal = document.getElementById('imageModal');