feat(storefront): 首页改版与筛选体系
- 首页收敛为市场工具条 + 门户行(快捷入口 / 轮播 / 账户面板) - 筛选按基础 10 项与高级筛选重排,接入皮肤组、段位、地区等参数 - 新增专区、排序、列表/宫格切换,并同步移动端筛选 - 精简导航并统一当前页下划线高亮
This commit is contained in:
@@ -1,24 +1,89 @@
|
||||
import { useState } from 'react'
|
||||
import { Button, Empty, ErrorBlock, PullToRefresh, SearchBar, Skeleton, Tag } from 'antd-mobile'
|
||||
import { RightOutline, SearchOutline } from 'antd-mobile-icons'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { Button, Empty, ErrorBlock, Popup, PullToRefresh, SearchBar, Skeleton, Tag } from 'antd-mobile'
|
||||
import { DownOutline, RightOutline, SearchOutline } from 'antd-mobile-icons'
|
||||
import { Link } from 'react-router-dom'
|
||||
|
||||
import { BrandLogo } from '@/components/BrandLogo'
|
||||
import { useListings } from '@/features/listings/api'
|
||||
import {
|
||||
coinRanges,
|
||||
emptyListingFilters,
|
||||
priceRanges,
|
||||
ratioRanges,
|
||||
type ListingFilterState,
|
||||
} from '@/features/listings/ListingFilterPanel'
|
||||
import { fetchListingPublishOptions } from '@/features/seller/options'
|
||||
import type { Listing } from '@/shared/api/types'
|
||||
|
||||
const quickFilters = [
|
||||
{ label: '全部', keyword: '' },
|
||||
{ label: '国服', keyword: '国服' },
|
||||
{ label: '高资产', keyword: '高资产' },
|
||||
{ label: '可租', keyword: '' },
|
||||
const zoneTabs = [
|
||||
{ key: 'all', label: '全部' },
|
||||
{ key: 'sale', label: '特惠' },
|
||||
{ key: 'gift', label: '赠送' },
|
||||
{ key: 'night', label: '夜间' },
|
||||
{ key: 'password', label: '账密' },
|
||||
{ key: 'highCoin', label: '高币' },
|
||||
]
|
||||
|
||||
const sortOptions = [
|
||||
{ value: '', label: '综合推荐' },
|
||||
{ value: 'published', label: '最新发布' },
|
||||
{ value: 'ratio', label: '比例优先' },
|
||||
{ value: 'coinDesc', label: '哈夫币从高到低' },
|
||||
{ value: 'priceAsc', label: '价格从低到高' },
|
||||
]
|
||||
|
||||
const insuranceOptions = ['2*1', '2*2', '2*3', '3*3']
|
||||
const levelOptions = ['4级', '5级', '6级', '7级']
|
||||
const loginOptions = ['扫码', '账号密码']
|
||||
|
||||
function money(cents: number) {
|
||||
return `¥${(cents / 100).toFixed(2)}`
|
||||
}
|
||||
|
||||
function assetText(item: Listing, key: string) {
|
||||
const value = item.asset_summary?.[key]
|
||||
if (value == null || value === '' || typeof value === 'object') return ''
|
||||
return String(value)
|
||||
}
|
||||
|
||||
function MobileChipGroup({
|
||||
label,
|
||||
options,
|
||||
selected,
|
||||
onToggle,
|
||||
}: {
|
||||
label: string
|
||||
options: string[]
|
||||
selected: string[]
|
||||
onToggle: (option: string) => void
|
||||
}) {
|
||||
return (
|
||||
<div className="mobile-filter-group">
|
||||
<span className="mobile-filter-group__label">{label}</span>
|
||||
<div className="mobile-filter-chips">
|
||||
{options.map(option => (
|
||||
<button
|
||||
key={option}
|
||||
type="button"
|
||||
className={`mobile-filter-chip${selected.includes(option) ? ' is-active' : ''}`}
|
||||
onClick={() => onToggle(option)}
|
||||
>
|
||||
{option}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function MobileListingCard({ item }: { item: Listing }) {
|
||||
const specs = [
|
||||
assetText(item, 'season_insurance') ? `保险 ${assetText(item, 'season_insurance')}` : '',
|
||||
assetText(item, 'stamina_level') ? `体力 ${assetText(item, 'stamina_level')}` : '',
|
||||
assetText(item, 'load_level') ? `负重 ${assetText(item, 'load_level')}` : '',
|
||||
].filter(Boolean)
|
||||
|
||||
return (
|
||||
<Link to={`/m/listings/${item.id}`} className="mobile-listing-card">
|
||||
<div className="mobile-listing-card__cover">
|
||||
@@ -40,6 +105,9 @@ function MobileListingCard({ item }: { item: Listing }) {
|
||||
<span>{item.server_region || '区服待定'}</span>
|
||||
<span>{item.rank_level || '段位待定'}</span>
|
||||
<span>哈夫币 {item.haf_coin_amount.toLocaleString()}</span>
|
||||
{specs.map(spec => (
|
||||
<span key={spec}>{spec}</span>
|
||||
))}
|
||||
</div>
|
||||
<div className="mobile-listing-card__bottom">
|
||||
<div>
|
||||
@@ -58,17 +126,79 @@ function MobileListingCard({ item }: { item: Listing }) {
|
||||
export function MobileHomePage() {
|
||||
const [keyword, setKeyword] = useState('')
|
||||
const [searchValue, setSearchValue] = useState('')
|
||||
const [zone, setZone] = useState('all')
|
||||
const [sort, setSort] = useState('')
|
||||
const [filters, setFilters] = useState<ListingFilterState>(emptyListingFilters)
|
||||
const [draft, setDraft] = useState<ListingFilterState>(emptyListingFilters)
|
||||
const [filterOpen, setFilterOpen] = useState(false)
|
||||
const [sortOpen, setSortOpen] = useState(false)
|
||||
|
||||
const publishOptions = useQuery({
|
||||
queryKey: ['listing-publish-options'],
|
||||
queryFn: fetchListingPublishOptions,
|
||||
staleTime: 300_000,
|
||||
})
|
||||
const quickSkinGroups = (publishOptions.data?.skin_groups ?? []).filter(group =>
|
||||
['melee', 'operatorRed'].includes(group.key)
|
||||
)
|
||||
|
||||
const coin = coinRanges.find(range => range.key === filters.coinKey)
|
||||
const price = priceRanges.find(range => range.key === filters.priceKey)
|
||||
const ratio = ratioRanges.find(range => range.key === filters.ratioKey)
|
||||
|
||||
const { data, isPending, isError, refetch } = useListings({
|
||||
page: 1,
|
||||
page_size: 20,
|
||||
keyword,
|
||||
zone: zone === 'all' ? '' : zone,
|
||||
sort,
|
||||
min_coin: coin?.min,
|
||||
max_coin: coin?.max,
|
||||
min_price: price?.min,
|
||||
max_price: price?.max,
|
||||
min_ratio: ratio?.min,
|
||||
max_ratio: ratio?.max,
|
||||
insurance: filters.insurance.join(','),
|
||||
stamina: filters.stamina.join(','),
|
||||
load: filters.load.join(','),
|
||||
login_method: filters.loginMethod.join(','),
|
||||
skin_name: filters.skinNames.join(','),
|
||||
})
|
||||
|
||||
const applyFilter = (value: string) => {
|
||||
setKeyword(value)
|
||||
setSearchValue(value)
|
||||
const applyFilter = () => {
|
||||
setFilters(draft)
|
||||
setFilterOpen(false)
|
||||
}
|
||||
|
||||
const resetDraft = () => setDraft(emptyListingFilters)
|
||||
|
||||
const toggleDraft = (
|
||||
key: 'insurance' | 'stamina' | 'load' | 'loginMethod' | 'skinNames',
|
||||
option: string
|
||||
) => {
|
||||
const current = draft[key]
|
||||
setDraft({
|
||||
...draft,
|
||||
[key]: current.includes(option)
|
||||
? current.filter(item => item !== option)
|
||||
: [...current, option],
|
||||
})
|
||||
}
|
||||
|
||||
const toggleRange = (key: 'coinKey' | 'priceKey' | 'ratioKey', nextKey: string) => {
|
||||
setDraft({ ...draft, [key]: draft[key] === nextKey ? undefined : nextKey })
|
||||
}
|
||||
|
||||
const activeCount =
|
||||
filters.insurance.length +
|
||||
filters.stamina.length +
|
||||
filters.load.length +
|
||||
filters.loginMethod.length +
|
||||
filters.skinNames.length +
|
||||
[filters.coinKey, filters.priceKey, filters.ratioKey].filter(Boolean).length
|
||||
|
||||
const sortLabel = sortOptions.find(option => option.value === sort)?.label ?? '综合推荐'
|
||||
|
||||
return (
|
||||
<div className="mobile-home">
|
||||
<section className="mobile-hero">
|
||||
@@ -87,18 +217,6 @@ export function MobileHomePage() {
|
||||
placeholder="搜索区服、段位、装备或商品号"
|
||||
searchIcon={<SearchOutline />}
|
||||
/>
|
||||
<div className="mobile-chips">
|
||||
{quickFilters.map(item => (
|
||||
<button
|
||||
type="button"
|
||||
key={item.label}
|
||||
className={keyword === item.keyword && item.label !== '全部' ? 'is-active' : ''}
|
||||
onClick={() => applyFilter(item.keyword)}
|
||||
>
|
||||
{item.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="mobile-trust">
|
||||
@@ -116,6 +234,34 @@ export function MobileHomePage() {
|
||||
<span className="mobile-count">共 {data?.total ?? 0} 件</span>
|
||||
</div>
|
||||
|
||||
<div className="mobile-zone-tabs">
|
||||
{zoneTabs.map(tab => (
|
||||
<button
|
||||
key={tab.key}
|
||||
type="button"
|
||||
className={zone === tab.key ? 'is-active' : ''}
|
||||
onClick={() => setZone(tab.key)}
|
||||
>
|
||||
{tab.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mobile-list-toolbar">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setDraft(filters)
|
||||
setFilterOpen(true)
|
||||
}}
|
||||
>
|
||||
筛选{activeCount > 0 ? ` (${activeCount})` : ''}
|
||||
</button>
|
||||
<button type="button" onClick={() => setSortOpen(true)}>
|
||||
{sortLabel} <DownOutline />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{isError ? (
|
||||
<div className="mobile-error">
|
||||
<ErrorBlock
|
||||
@@ -148,7 +294,17 @@ export function MobileHomePage() {
|
||||
) : (
|
||||
<div className="mobile-empty">
|
||||
<Empty description="还没有符合条件的商品" />
|
||||
<Button size="small" color="primary" onClick={() => applyFilter('')}>
|
||||
<Button
|
||||
size="small"
|
||||
color="primary"
|
||||
onClick={() => {
|
||||
setKeyword('')
|
||||
setSearchValue('')
|
||||
setFilters(emptyListingFilters)
|
||||
setZone('all')
|
||||
setSort('')
|
||||
}}
|
||||
>
|
||||
查看全部
|
||||
</Button>
|
||||
</div>
|
||||
@@ -161,6 +317,135 @@ export function MobileHomePage() {
|
||||
<h2>先把规则说明白</h2>
|
||||
<p>押金、租金、额外消耗和退款规则都会在订单里逐项列出。结账备注不参与系统结算。</p>
|
||||
</section>
|
||||
|
||||
<Popup
|
||||
visible={filterOpen}
|
||||
onMaskClick={() => setFilterOpen(false)}
|
||||
bodyStyle={{ height: '72vh', overflowY: 'auto', borderTopLeftRadius: 16, borderTopRightRadius: 16 }}
|
||||
>
|
||||
<div className="mobile-filter-sheet">
|
||||
<div className="mobile-filter-sheet__head">
|
||||
<strong>筛选条件</strong>
|
||||
<button type="button" onClick={resetDraft}>
|
||||
重置
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="mobile-filter-group">
|
||||
<span className="mobile-filter-group__label">哈夫币</span>
|
||||
<div className="mobile-filter-chips">
|
||||
{coinRanges.map(option => (
|
||||
<button
|
||||
key={option.key}
|
||||
type="button"
|
||||
className={`mobile-filter-chip${draft.coinKey === option.key ? ' is-active' : ''}`}
|
||||
onClick={() => toggleRange('coinKey', option.key)}
|
||||
>
|
||||
{option.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mobile-filter-group">
|
||||
<span className="mobile-filter-group__label">租金</span>
|
||||
<div className="mobile-filter-chips">
|
||||
{priceRanges.map(option => (
|
||||
<button
|
||||
key={option.key}
|
||||
type="button"
|
||||
className={`mobile-filter-chip${draft.priceKey === option.key ? ' is-active' : ''}`}
|
||||
onClick={() => toggleRange('priceKey', option.key)}
|
||||
>
|
||||
{option.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mobile-filter-group">
|
||||
<span className="mobile-filter-group__label">比例</span>
|
||||
<div className="mobile-filter-chips">
|
||||
{ratioRanges.map(option => (
|
||||
<button
|
||||
key={option.key}
|
||||
type="button"
|
||||
className={`mobile-filter-chip${draft.ratioKey === option.key ? ' is-active' : ''}`}
|
||||
onClick={() => toggleRange('ratioKey', option.key)}
|
||||
>
|
||||
{option.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MobileChipGroup
|
||||
label="保险"
|
||||
options={insuranceOptions}
|
||||
selected={draft.insurance}
|
||||
onToggle={option => toggleDraft('insurance', option)}
|
||||
/>
|
||||
<MobileChipGroup
|
||||
label="体力"
|
||||
options={levelOptions}
|
||||
selected={draft.stamina}
|
||||
onToggle={option => toggleDraft('stamina', option)}
|
||||
/>
|
||||
<MobileChipGroup
|
||||
label="负重"
|
||||
options={levelOptions}
|
||||
selected={draft.load}
|
||||
onToggle={option => toggleDraft('load', option)}
|
||||
/>
|
||||
<MobileChipGroup
|
||||
label="登录"
|
||||
options={loginOptions}
|
||||
selected={draft.loginMethod}
|
||||
onToggle={option => toggleDraft('loginMethod', option)}
|
||||
/>
|
||||
{quickSkinGroups.map(group => (
|
||||
<MobileChipGroup
|
||||
key={group.key}
|
||||
label={group.title}
|
||||
options={group.options}
|
||||
selected={draft.skinNames}
|
||||
onToggle={option => toggleDraft('skinNames', option)}
|
||||
/>
|
||||
))}
|
||||
|
||||
<div className="mobile-filter-sheet__actions">
|
||||
<Button block onClick={() => setFilterOpen(false)}>
|
||||
取消
|
||||
</Button>
|
||||
<Button block color="primary" onClick={applyFilter}>
|
||||
确定
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Popup>
|
||||
|
||||
<Popup
|
||||
visible={sortOpen}
|
||||
onMaskClick={() => setSortOpen(false)}
|
||||
bodyStyle={{ borderTopLeftRadius: 16, borderTopRightRadius: 16 }}
|
||||
>
|
||||
<div className="mobile-sort-sheet">
|
||||
<strong>排序方式</strong>
|
||||
{sortOptions.map(option => (
|
||||
<button
|
||||
key={option.value}
|
||||
type="button"
|
||||
className={sort === option.value ? 'is-active' : ''}
|
||||
onClick={() => {
|
||||
setSort(option.value)
|
||||
setSortOpen(false)
|
||||
}}
|
||||
>
|
||||
{option.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</Popup>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user