修复空文件夹数据的异常显示问题

- 修复空文件夹显示 "undefined 项" 而非 "0 项" 的问题
- 修复空文件夹分页显示 "1-0 项" 而非 "0-0 项" 的问题
- 在后端 API 中添加 include_items 字段的数据验证和处理
This commit is contained in:
x1ao4 2025-08-06 12:37:20 +08:00
parent b85db9631b
commit 5a4afbe737
2 changed files with 61 additions and 2 deletions

View File

@ -863,6 +863,20 @@ def get_share_detail():
share_detail["paths"] = paths
share_detail["stoken"] = stoken
# 处理文件夹的include_items字段确保空文件夹显示为0项而不是undefined
if "list" in share_detail and isinstance(share_detail["list"], list):
for file_item in share_detail["list"]:
if file_item.get("dir", False):
# 如果是文件夹确保include_items字段存在且为数字
if "include_items" not in file_item or file_item["include_items"] is None:
file_item["include_items"] = 0
elif not isinstance(file_item["include_items"], (int, float)):
# 如果include_items不是数字类型尝试转换为整数失败则设为0
try:
file_item["include_items"] = int(file_item["include_items"])
except (ValueError, TypeError):
file_item["include_items"] = 0
# 如果是GET请求或者不需要预览正则直接返回分享详情
if request.method == "GET" or not request.json.get("regex"):
return jsonify({"success": True, "data": share_detail})
@ -1028,6 +1042,20 @@ def get_share_detail():
share_detail = preview_regex(share_detail)
# 再次处理文件夹的include_items字段确保预览后的数据也正确
if "list" in share_detail and isinstance(share_detail["list"], list):
for file_item in share_detail["list"]:
if file_item.get("dir", False):
# 如果是文件夹确保include_items字段存在且为数字
if "include_items" not in file_item or file_item["include_items"] is None:
file_item["include_items"] = 0
elif not isinstance(file_item["include_items"], (int, float)):
# 如果include_items不是数字类型尝试转换为整数失败则设为0
try:
file_item["include_items"] = int(file_item["include_items"])
except (ValueError, TypeError):
file_item["include_items"] = 0
return jsonify({"success": True, "data": share_detail})
@ -1067,8 +1095,26 @@ def get_savepath_detail():
return jsonify({"success": False, "data": {"error": "获取fid失败"}})
else:
fid = request.args.get("fid", "0")
# 获取文件列表
files = account.ls_dir(fid)
# 处理文件夹的include_items字段确保空文件夹显示为0项而不是undefined
if isinstance(files, list):
for file_item in files:
if file_item.get("dir", False):
# 如果是文件夹确保include_items字段存在且为数字
if "include_items" not in file_item or file_item["include_items"] is None:
file_item["include_items"] = 0
elif not isinstance(file_item["include_items"], (int, float)):
# 如果include_items不是数字类型尝试转换为整数失败则设为0
try:
file_item["include_items"] = int(file_item["include_items"])
except (ValueError, TypeError):
file_item["include_items"] = 0
file_list = {
"list": account.ls_dir(fid),
"list": files,
"paths": paths,
}
return jsonify({"success": True, "data": file_list})
@ -1921,6 +1967,19 @@ def get_file_list():
else:
return jsonify({"success": False, "message": f"获取文件列表失败: {error_msg}"})
# 处理文件夹的include_items字段确保空文件夹显示为0项而不是undefined
for file_item in files:
if file_item.get("dir", False):
# 如果是文件夹确保include_items字段存在且为数字
if "include_items" not in file_item or file_item["include_items"] is None:
file_item["include_items"] = 0
elif not isinstance(file_item["include_items"], (int, float)):
# 如果include_items不是数字类型尝试转换为整数失败则设为0
try:
file_item["include_items"] = int(file_item["include_items"])
except (ValueError, TypeError):
file_item["include_items"] = 0
# 计算总数
total = len(files)

View File

@ -1484,7 +1484,7 @@
<!-- 分页区域 -->
<div class="pagination-container d-flex justify-content-between align-items-center mt-3">
<div class="page-info text-secondary">
显示 {{ fileManager.currentPage > 0 ? ((fileManager.currentPage - 1) * fileManager.pageSize + 1) + '-' + Math.min(fileManager.currentPage * fileManager.pageSize, fileManager.total) : '0' }} 项,共 {{ fileManager.total }} 个项目{{ fileManager.selectedFiles.length > 0 ? ',已选中 ' + fileManager.selectedFiles.length + ' 项' : '' }}
显示 {{ fileManager.total > 0 ? ((fileManager.currentPage - 1) * fileManager.pageSize + 1) + '-' + Math.min(fileManager.currentPage * fileManager.pageSize, fileManager.total) : '0-0' }} 项,共 {{ fileManager.total }} 个项目{{ fileManager.selectedFiles.length > 0 ? ',已选中 ' + fileManager.selectedFiles.length + ' 项' : '' }}
</div>
<div class="pagination-controls d-flex align-items-center">
<button type="button" class="btn btn-outline-secondary btn-sm mx-1" :class="{ disabled: fileManager.currentPage <= 1 }" @click="changeFolderPage(fileManager.currentPage - 1)" :disabled="fileManager.currentPage <= 1">