fix: 修复文件夹过滤时分页总数计算错误

This commit is contained in:
2026-04-22 11:18:51 +08:00
parent bf63610510
commit c8aecaeb03
2 changed files with 12 additions and 2 deletions

View File

@@ -55,7 +55,8 @@ def list_items():
status=request.args.get('status'), status=request.args.get('status'),
tag=request.args.get('tag'), tag=request.args.get('tag'),
keyword=request.args.get('keyword'), keyword=request.args.get('keyword'),
starred=starred starred=starred,
folder_id=folder_id
) )
return jsonify({'success': True, 'data': items, 'total': total}) return jsonify({'success': True, 'data': items, 'total': total})

View File

@@ -326,7 +326,7 @@ class Database:
return items return items
def count_items(self, type: str = None, status: str = None, tag: str = None, def count_items(self, type: str = None, status: str = None, tag: str = None,
keyword: str = None, starred: bool = None) -> int: keyword: str = None, starred: bool = None, folder_id: int = None) -> int:
"""计算符合条件的条目总数""" """计算符合条件的条目总数"""
with self.get_conn() as conn: with self.get_conn() as conn:
cursor = conn.cursor() cursor = conn.cursor()
@@ -358,6 +358,15 @@ class Database:
keyword_pattern = f"%{keyword}%" keyword_pattern = f"%{keyword}%"
params.extend([keyword_pattern, keyword_pattern, keyword_pattern]) params.extend([keyword_pattern, keyword_pattern, keyword_pattern])
# 文件夹过滤
if folder_id is not None:
if folder_id == -1:
# 未分类folder_id为NULL
conditions.append("i.folder_id IS NULL")
else:
conditions.append("i.folder_id = ?")
params.append(folder_id)
if conditions: if conditions:
query += " WHERE " + " AND ".join(conditions) query += " WHERE " + " AND ".join(conditions)