fix: 修复文件夹过滤时分页总数计算错误
This commit is contained in:
@@ -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})
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user