修复内容库分页:返回总数而非当前页数量
- 新增 get_articles_count 函数获取总数 - 列表API返回总数用于分页计算
This commit is contained in:
@@ -198,6 +198,14 @@ class Database:
|
|||||||
cursor.execute('DELETE FROM articles WHERE id = ?', (article_id,))
|
cursor.execute('DELETE FROM articles WHERE id = ?', (article_id,))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
return cursor.rowcount > 0
|
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'):
|
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)
|
offset = request.args.get('offset', 0, type=int)
|
||||||
|
|
||||||
articles = db.get_all_articles(limit=limit, offset=offset)
|
articles = db.get_all_articles(limit=limit, offset=offset)
|
||||||
|
total_count = db.get_articles_count() # 获取总数
|
||||||
|
|
||||||
# 解析JSON字段
|
# 解析JSON字段
|
||||||
for article in articles:
|
for article in articles:
|
||||||
@@ -23,7 +24,7 @@ def list_articles():
|
|||||||
return jsonify({
|
return jsonify({
|
||||||
'success': True,
|
'success': True,
|
||||||
'articles': articles,
|
'articles': articles,
|
||||||
'count': len(articles)
|
'count': total_count # 返回总数
|
||||||
})
|
})
|
||||||
|
|
||||||
@bp.route('/search', methods=['GET'])
|
@bp.route('/search', methods=['GET'])
|
||||||
|
|||||||
Reference in New Issue
Block a user