Skip to content

Commit c63d038

Browse files
committed
fix(square): 解决分类菜单在无数据时的渲染问题
- 添加了分类数据为空时的条件渲染逻辑 - 修复了页面加载时分类状态的初始化问题 - 优化了无分类数据时的用户体验
1 parent 694aab9 commit c63d038

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

himarket-web/himarket-frontend/src/components/square/CategoryMenu.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ interface CategoryMenuProps {
1414
}
1515

1616
export function CategoryMenu({ categories, activeCategory, onSelectCategory, loading = false }: CategoryMenuProps) {
17+
// 没有分类数据时不渲染任何内容
18+
if (!loading && categories.length === 0) {
19+
return null;
20+
}
21+
1722
return (
1823
<div className="overflow-hidden">
1924
{loading ? (

himarket-web/himarket-frontend/src/pages/Square.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,13 @@ function Square(props: { activeType: string }) {
6262
{ id: "all", name: "全部", count: 0 },
6363
...categoryList
6464
]);
65+
// 重置选中的分类为"全部"
66+
setActiveCategory("all");
6567
} else {
6668
setCategories([])
69+
// 没有分类时,不选中任何分类
70+
setActiveCategory("");
6771
}
68-
69-
// 重置选中的分类为"全部"
70-
setActiveCategory("all");
7172
}
7273
} catch (error) {
7374
console.error("Failed to fetch categories:", error);

0 commit comments

Comments
 (0)