Files
hfb_jysh/frontend/src/features/home/HomePortalRow.tsx
T
yml2213 cfafc21014 feat(storefront): 首页改版与筛选体系
- 首页收敛为市场工具条 + 门户行(快捷入口 / 轮播 / 账户面板)
- 筛选按基础 10 项与高级筛选重排,接入皮肤组、段位、地区等参数
- 新增专区、排序、列表/宫格切换,并同步移动端筛选
- 精简导航并统一当前页下划线高亮
2026-10-31 11:52:11 +08:00

191 lines
6.9 KiB
TypeScript

import { useQuery } from '@tanstack/react-query'
import { App, Button, Carousel, Typography } from 'antd'
import { ArrowRightOutlined } from '@ant-design/icons'
import { Link, useNavigate } from 'react-router-dom'
import {
fallbackBanners,
useHomeConfig,
type HomeBannerItem,
type HomeEntryConfig,
} from '@/features/home/api'
import { fetchWalletBalance } from '@/features/wallet/api'
import { useSessionStore } from '@/stores/session'
import { formatMoney } from '@/shared/utils/format'
export function HomePortalRow() {
const navigate = useNavigate()
const { modal, message } = App.useApp()
const user = useSessionStore(state => state.user)
const token = useSessionStore(state => state.token)
const home = useHomeConfig()
const wallet = useQuery({
queryKey: ['wallet-balance', 'home'],
queryFn: fetchWalletBalance,
enabled: Boolean(token),
})
const banners = (home.data?.banners ?? []).filter(item => item.enabled !== false)
const slides = banners.length > 0 ? banners : fallbackBanners
const aw = home.data?.aw_recycle
const co = home.data?.cooperation_feedback
const entriesEnabled = home.data?.home_entries_enabled ?? true
const openEntry = (entry: HomeEntryConfig) => {
if (entry.image_url) {
modal.info({
title: entry.title,
width: 520,
content: <img src={entry.image_url} alt={entry.title} style={{ width: '100%' }} />,
})
return
}
message.info(entry.subtitle || '暂无更多说明')
}
const openSlide = (item: HomeBannerItem) => {
const action = item.pc?.action
if (!action || action.type === 'none' || !action.target) return
if (action.type === 'route') {
navigate(action.target)
return
}
if (action.type === 'link') {
window.open(action.target, action.open_new_tab ? '_blank' : '_self')
return
}
if (action.type === 'preview') {
modal.info({
title: item.title || item.eyebrow || '轮播图',
width: 720,
content: <img src={action.target} alt={item.title || ''} style={{ width: '100%' }} />,
})
}
}
return (
<section className="home-portal">
<div className="home-portal__inner">
<nav className="home-portal__menu" aria-label="快捷入口">
<Link to="/crash" className="home-portal__menu-item">
<div>
<strong>撞车</strong>
<span>撞车装备与现货</span>
</div>
<ArrowRightOutlined />
</Link>
{entriesEnabled && aw?.enabled ? (
<button type="button" className="home-portal__menu-item" onClick={() => openEntry(aw)}>
<div>
<strong>{aw.title}</strong>
<span>{aw.subtitle}</span>
</div>
<ArrowRightOutlined />
</button>
) : null}
{entriesEnabled && co?.enabled ? (
<button type="button" className="home-portal__menu-item" onClick={() => openEntry(co)}>
<div>
<strong>{co.title}</strong>
<span>{co.subtitle}</span>
</div>
<ArrowRightOutlined />
</button>
) : null}
<Link to="/announcements" className="home-portal__menu-item">
<div>
<strong>公告中心</strong>
<span>平台规则与活动</span>
</div>
<ArrowRightOutlined />
</Link>
<Link to="/messages" className="home-portal__menu-item">
<div>
<strong>联系客服</strong>
<span>问题留痕,处理更快</span>
</div>
<ArrowRightOutlined />
</Link>
</nav>
<div className="home-portal__banner">
<Carousel autoplay autoplaySpeed={5200} dots>
{slides.map((item, index) => (
<div
className="home-slide"
key={`${item.title ?? 'slide'}-${index}`}
data-tone={item.tone || 'green'}
onClick={() => openSlide(item)}
>
{item.pc?.image_url || item.image_url ? (
<img
src={item.pc?.image_url || item.image_url}
alt={item.pc?.alt || item.title || ''}
/>
) : (
<div className="home-slide__body">
{item.badge ? <em className="home-slide__badge">{item.badge}</em> : null}
{item.eyebrow ? <span className="home-slide__eyebrow">{item.eyebrow}</span> : null}
<strong>{item.title}</strong>
{item.pill ? <span className="home-slide__pill">{item.pill}</span> : null}
</div>
)}
</div>
))}
</Carousel>
</div>
<aside className="home-portal__account">
{user ? (
<>
<div className="home-account__head">
<span className="home-account__avatar">
{(user.nickname || user.phone || '客').slice(0, 1)}
</span>
<div>
<strong>欢迎回来</strong>
<span>{user.nickname || user.phone}</span>
</div>
</div>
<div className="home-account__balance">
<span>可用余额</span>
<strong>{wallet.data ? formatMoney(wallet.data.available_balance_cent) : '—'}</strong>
<Link to="/wallet">
查看钱包 <ArrowRightOutlined />
</Link>
</div>
<div className="home-account__grid">
<Link to="/orders">我的订单</Link>
<Link to="/listings/collections">我的足迹</Link>
<Link to="/profile">个人中心</Link>
<Link to="/seller/listings">卖家中心</Link>
</div>
<div className="home-account__actions">
<Button type="primary" onClick={() => document.querySelector('#listings')?.scrollIntoView()}>
我要租号
</Button>
<Button onClick={() => navigate('/seller/listings/new')}>我要出租</Button>
</div>
</>
) : (
<>
<Typography.Title level={4} className="home-account__title">
欢迎来到解忧商行
</Typography.Title>
<Typography.Paragraph type="secondary" className="home-account__lead">
登录后可查看订单、钱包与足迹,未登录也能先逛柜选。
</Typography.Paragraph>
<Button type="primary" block onClick={() => navigate('/login')}>
登录 / 注册
</Button>
<Button block onClick={() => navigate('/listings/collections')}>
我的足迹
</Button>
</>
)}
</aside>
</div>
</section>
)
}