From 981b3c9c5c9a90441ea00232803267f1ccf5875e Mon Sep 17 00:00:00 2001 From: hz4th_coder Date: Tue, 14 Jul 2026 00:50:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=86=85=E5=AE=B9=E5=BA=93?= =?UTF-8?q?=E5=88=86=E9=A1=B5=EF=BC=9A=E8=BF=94=E5=9B=9E=E6=80=BB=E6=95=B0?= =?UTF-8?q?=E8=80=8C=E9=9D=9E=E5=BD=93=E5=89=8D=E9=A1=B5=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 get_articles_count 函数获取总数 - 列表API返回总数用于分页计算 --- models/database.py | 8 ++++++++ routes/articles.py | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/models/database.py b/models/database.py index 1c770da..23640a7 100644 --- a/models/database.py +++ b/models/database.py @@ -198,6 +198,14 @@ class Database: cursor.execute('DELETE FROM articles WHERE id = ?', (article_id,)) conn.commit() return cursor.rowcount > 0 + + def get_articles_count(self): + """获取文章总数""" + with self.get_connection() as conn: + cursor = conn.cursor() + cursor.execute('SELECT COUNT(*) as count FROM articles') + row = cursor.fetchone() + return row['count'] if row else 0 # ========== 待处理产品操作 ========== def add_pending_product(self, product_name, category=None, subcategory=None, priority=0, source='manual'): diff --git a/routes/articles.py b/routes/articles.py index a135d92..6a708ee 100644 --- a/routes/articles.py +++ b/routes/articles.py @@ -14,6 +14,7 @@ def list_articles(): offset = request.args.get('offset', 0, type=int) articles = db.get_all_articles(limit=limit, offset=offset) + total_count = db.get_articles_count() # 获取总数 # 解析JSON字段 for article in articles: @@ -23,7 +24,7 @@ def list_articles(): return jsonify({ 'success': True, 'articles': articles, - 'count': len(articles) + 'count': total_count # 返回总数 }) @bp.route('/search', methods=['GET'])