修复一些bug
This commit is contained in:
@@ -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 %}
|
||||
Reference in New Issue
Block a user