修复一些bug
This commit is contained in:
2
app.py
2
app.py
@@ -650,8 +650,6 @@ def delete_entry(doc_id):
|
|||||||
|
|
||||||
if success:
|
if success:
|
||||||
return redirect(url_for(redirect_url))
|
return redirect(url_for(redirect_url))
|
||||||
if delete_by_id(doc_id):
|
|
||||||
return redirect(url_for('show_all'))
|
|
||||||
else:
|
else:
|
||||||
return "删除失败", 500
|
return "删除失败", 500
|
||||||
|
|
||||||
|
|||||||
@@ -224,6 +224,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="card-actions">
|
<div class="card-actions">
|
||||||
<a href="{{ url_for('edit_entry', doc_id=item._id) }}" class="action-button edit-btn">编辑</a>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -342,12 +343,72 @@ function batchDelete() {
|
|||||||
|
|
||||||
document.body.appendChild(form);
|
document.body.appendChild(form);
|
||||||
form.submit();
|
form.submit();
|
||||||
|
|
||||||
|
// 提交后自动刷新页面
|
||||||
|
form.addEventListener('submit', function() {
|
||||||
|
setTimeout(function() {
|
||||||
|
window.location.reload();
|
||||||
|
}, 1000); // 1秒后刷新页面,给服务器处理时间
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 页面加载时初始化
|
// 页面加载时初始化
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
updateSelectedCount();
|
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>
|
</script>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -99,7 +99,7 @@
|
|||||||
<p>您确定要删除这条数据吗?此操作不可撤销。</p>
|
<p>您确定要删除这条数据吗?此操作不可撤销。</p>
|
||||||
<div class="modal-actions">
|
<div class="modal-actions">
|
||||||
<button onclick="closeDeleteModal()" class="btn btn-secondary">取消</button>
|
<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>
|
<button type="submit" class="btn btn-danger">确认删除</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
@@ -470,6 +470,23 @@ function closeDeleteModal() {
|
|||||||
document.getElementById('deleteModal').style.display = 'none';
|
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) {
|
window.onclick = function(event) {
|
||||||
const imageModal = document.getElementById('imageModal');
|
const imageModal = document.getElementById('imageModal');
|
||||||
|
|||||||
Reference in New Issue
Block a user