修复内容库分页:返回总数而非当前页数量
- 新增 get_articles_count 函数获取总数 - 列表API返回总数用于分页计算
This commit is contained in:
@@ -199,6 +199,14 @@ class Database:
|
||||
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'):
|
||||
"""添加待处理产品"""
|
||||
|
||||
+2
-1
@@ -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'])
|
||||
|
||||
Reference in New Issue
Block a user