将移动端首页图标分类区域修改为水平滚动、固定2行显示的布局,提升小屏设备的图标展示效率。
当前图标分类使用网格布局(grid grid-cols-3 gap-3)实现,代码位于src/client/mobile/pages/NewHomePage.tsx第392行:
<div className="grid grid-cols-3 gap-3">
{categories.map((category, index) => (
<button
key={index}
onClick={() => navigate(category.path || '/')}
className="flex flex-col items-center p-4 rounded-xl transition-all duration-300 hover:shadow-lg backdrop-blur-sm"
style={{
backgroundColor: 'rgba(255,255,255,0.7)',
border: `1px solid ${COLORS.ink.medium}`,
color: COLORS.text.primary
}}
>
{/* 图标和文字内容 */}
</button>
))}
</div>
将网格布局容器修改为水平滚动容器,保留按钮元素结构不变:
<div className="relative">
{/* 水平滚动容器 */}
<div className="flex space-x-3 overflow-x-auto pb-4 snap-x snap-mandatory hide-scrollbar">
{categories.map((category, index) => (
<button
key={index}
onClick={() => navigate(category.path || '/')}
className="flex-shrink-0 w-24 flex flex-col items-center p-4 rounded-xl transition-all duration-300 hover:shadow-lg backdrop-blur-sm snap-start"
style={{
backgroundColor: 'rgba(255,255,255,0.7)',
border: `1px solid ${COLORS.ink.medium}`,
color: COLORS.text.primary
}}
>
{/* 原有图标内容 */}
<div
className="w-14 h-14 rounded-full flex items-center justify-center shadow-sm"
style={{ backgroundColor: COLORS.accent.blue, color: 'white' }}
>
<img
src={category.image || '/images/placeholder.jpg'}
alt={category.name}
className="w-8 h-8 object-cover rounded-full"
onError={(e) => {
(e.target as HTMLImageElement).style.display = 'none';
(e.target as HTMLImageElement).parentElement!.innerHTML = '📱';
}}
/>
</div>
<span className={`${FONT_STYLES.caption} mt-2 line-clamp-1`}>{category.name}</span>
</button>
))}
</div>
{/* 可选:添加渐变遮罩指示可滚动 */}
<div className="absolute right-0 top-0 bottom-0 w-8 bg-gradient-to-l from-ink-light to-transparent pointer-events-none"></div>
</div>
需要添加以下CSS样式实现固定2行布局和水平滚动:
/* 隐藏滚动条但保留滚动功能 */
.hide-scrollbar::-webkit-scrollbar {
display: none;
}
.hide-scrollbar {
-ms-overflow-style: none;
scrollbar-width: none;
}
/* 固定两行高度计算 */
.fixed-two-rows {
height: calc( (按钮高度) * 2 + (间距) );
}
/* 按钮样式调整 */
.category-button {
/* 确保按钮宽度一致 */
width: 24vw;
max-width: 120px;
}
容器修改:
grid grid-cols-3改为flex space-x-3 overflow-x-autopb-4提供底部内边距避免裁剪snap-x和snap-mandatory增强滚动体验按钮样式调整:
flex-shrink-0防止按钮被压缩24vw(约4个按钮/屏)snap-start确保滚动对齐两行高度控制:
(按钮高度 + 间距) * 2120px(含内边距)80pxhover:shadow-lg效果src/client/mobile/pages/NewHomePage.tsx第392行的容器 className