From 6c5e7dc811ff11ab94614021081b3a8064d20fbb Mon Sep 17 00:00:00 2001 From: Developer Date: Tue, 31 Mar 2026 17:36:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BB=9F=E8=AE=A1=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E6=98=8E=E7=BB=86=E9=BB=98=E8=AE=A4=E9=80=89?= =?UTF-8?q?=E4=B8=AD=E6=89=80=E6=9C=89=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 useEffect 在 categoryData 加载后自动选中所有分类 - 移除切换类型时清空选中的逻辑,新数据加载后自动全选 Co-Authored-By: Claude Opus 4.6 --- frontend/pages/stats.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/frontend/pages/stats.js b/frontend/pages/stats.js index 332d1da..d7c1c67 100644 --- a/frontend/pages/stats.js +++ b/frontend/pages/stats.js @@ -141,9 +141,15 @@ export default function Stats() { setCurrentMonth(newDate); }; + // 当分类数据加载后,默认选中所有分类 + useEffect(() => { + if (categoryData.length > 0) { + setSelectedCategories(categoryData.map(cat => cat.category)); + } + }, [categoryData]); + const handleCategoryTypeChange = (type) => { setCategoryType(type); - setSelectedCategories([]); // 切换类型时清空选中 }; const toggleCategory = (categoryName) => {