From 73fd24597c21d96e849b20ca41d0757a4d721e73 Mon Sep 17 00:00:00 2001 From: meetqy Date: Thu, 2 Nov 2023 10:03:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=80=BB=E6=95=B0=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/Setting/FolderTree.tsx | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/themes/gallery/src/components/Setting/FolderTree.tsx b/themes/gallery/src/components/Setting/FolderTree.tsx index 4788fd2e..9aee99ca 100644 --- a/themes/gallery/src/components/Setting/FolderTree.tsx +++ b/themes/gallery/src/components/Setting/FolderTree.tsx @@ -19,6 +19,18 @@ interface FileTreeProps { data: Folder[]; } +// 递归计算文件夹总数 +function countFolder(data: Folder[]): number { + let count = 0; + data.forEach((item) => { + count += item._count.images; + if (item.children?.length) { + count += countFolder(item.children); + } + }); + return count; +} + function FolderTree({ data }: FileTreeProps) { const [setting, setSetting] = useRecoilState(settingSelector); const router = useRouter(); @@ -56,12 +68,15 @@ function FolderTree({ data }: FileTreeProps) { // 父级文件夹 const FolderRoot = ({ data }: { data: Folder }) => { - const allCount = data.children?.reduce((a, b) => a + b._count.images, 0); + const childCount = countFolder(data.children ?? []); + const allCount = data._count.images + (childCount ?? 0); + + const open = openFolderIds.includes(data.id); return (