From 48bb1b3c1265721961f92c27bed60e6ffea89770 Mon Sep 17 00:00:00 2001 From: Viajero <2737079298@qq.com> Date: Tue, 14 Oct 2025 19:14:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E2=80=9C=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/app.py b/app.py index e386623..4258d7d 100644 --- a/app.py +++ b/app.py @@ -656,6 +656,43 @@ def delete_entry(doc_id): return "删除失败", 500 +# 批量删除数据路由 +@app.route('/batch_delete', methods=['POST']) +@admin_required +def batch_delete(): + """ + 批量删除选中的数据(仅管理员可访问) + + 返回: + 重定向到所有数据页面或错误信息 + """ + try: + # 获取选中的文档ID列表 + doc_ids = request.form.getlist('doc_ids') + + if not doc_ids: + flash('请选择要删除的记录', 'error') + return redirect(url_for('show_all')) + + # 批量删除选中的文档 + success_count = 0 + for doc_id in doc_ids: + if delete_by_id(doc_id): + success_count += 1 + + if success_count > 0: + flash(f'成功删除 {success_count} 条记录', 'success') + else: + flash('删除失败,请重试', 'error') + + return redirect(url_for('show_all')) + + except Exception as e: + print(f"批量删除失败: {str(e)}") + flash('批量删除失败,请重试', 'error') + return redirect(url_for('show_all')) + + @app.route('/edit/', methods=['GET', 'POST']) @login_required def edit_entry(doc_id):