feat(mobile): 新增解忧商行移动端首页、详情与个人中心

This commit is contained in:
yml2213
2026-10-30 12:26:31 +08:00
parent 97167fa482
commit ef01486e53
14 changed files with 1499 additions and 10 deletions
@@ -0,0 +1,166 @@
import { useState } from 'react'
import { Button, Empty, ErrorBlock, PullToRefresh, SearchBar, Skeleton, Tag } from 'antd-mobile'
import { RightOutline, SearchOutline } from 'antd-mobile-icons'
import { Link } from 'react-router-dom'
import { BrandLogo } from '@/components/BrandLogo'
import { useListings } from '@/features/listings/api'
import type { Listing } from '@/shared/api/types'
const quickFilters = [
{ label: '全部', keyword: '' },
{ label: '国服', keyword: '国服' },
{ label: '高资产', keyword: '高资产' },
{ label: '可租', keyword: '' },
]
function money(cents: number) {
return `¥${(cents / 100).toFixed(2)}`
}
function MobileListingCard({ item }: { item: Listing }) {
return (
<Link to={`/m/listings/${item.id}`} className="mobile-listing-card">
<div className="mobile-listing-card__cover">
{item.cover_url ? (
<img src={item.cover_url} alt={item.title} loading="lazy" />
) : (
<BrandLogo height={38} variant="seal" />
)}
</div>
<div className="mobile-listing-card__body">
<div className="mobile-listing-card__top">
<span className="mobile-listing-card__no">{item.listing_no}</span>
<Tag color={item.in_transaction ? 'default' : 'success'} fill="outline">
{item.in_transaction ? '租赁中' : '可租'}
</Tag>
</div>
<h3>{item.title}</h3>
<div className="mobile-listing-card__tags">
<span>{item.server_region || '区服待定'}</span>
<span>{item.rank_level || '段位待定'}</span>
<span>哈夫币 {item.haf_coin_amount.toLocaleString()}</span>
</div>
<div className="mobile-listing-card__bottom">
<div>
<strong>{money(item.price_cent)}</strong>
<small>押金 {money(item.deposit_amount_cent)}</small>
</div>
<span className="mobile-listing-card__more">
查看 <RightOutline />
</span>
</div>
</div>
</Link>
)
}
export function MobileHomePage() {
const [keyword, setKeyword] = useState('')
const [searchValue, setSearchValue] = useState('')
const { data, isPending, isError, refetch } = useListings({
page: 1,
page_size: 20,
keyword,
})
const applyFilter = (value: string) => {
setKeyword(value)
setSearchValue(value)
}
return (
<div className="mobile-home">
<section className="mobile-hero">
<div className="mobile-hero__eyebrow">JIEYOU TRADING HOUSE</div>
<h1>
租得明白,
<br />
还得安心。
</h1>
<p>实名审核 · 流程留痕 · 账单逐项列明</p>
<SearchBar
className="mobile-search"
value={searchValue}
onChange={setSearchValue}
onSearch={value => setKeyword(value.trim())}
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">
<span>实名审核</span>
<span>交接留痕</span>
<span>争议可申诉</span>
</section>
<section className="mobile-list-section">
<div className="mobile-section-head">
<div>
<span className="mobile-eyebrow">CURATED ACCOUNTS</span>
<h2>本周柜选</h2>
</div>
<span className="mobile-count">共 {data?.total ?? 0} 件</span>
</div>
{isError ? (
<div className="mobile-error">
<ErrorBlock
status="disconnected"
title="商品没有加载出来"
description="后端服务可能暂时不可用,你的账号和订单不受影响。"
/>
<Button color="primary" size="small" onClick={() => void refetch()}>
重试
</Button>
</div>
) : null}
<PullToRefresh onRefresh={() => refetch().then(() => undefined)}>
{isPending ? (
<div className="mobile-skeleton-list">
{Array.from({ length: 3 }).map((_, index) => (
<div className="mobile-skeleton-card" key={index}>
<Skeleton animated className="mobile-skeleton-cover" />
<Skeleton.Paragraph lineCount={3} animated />
</div>
))}
</div>
) : data?.items.length ? (
<div className="mobile-listing-list">
{data.items.map(item => (
<MobileListingCard item={item} key={item.id} />
))}
</div>
) : (
<div className="mobile-empty">
<Empty description="还没有符合条件的商品" />
<Button size="small" color="primary" onClick={() => applyFilter('')}>
查看全部
</Button>
</div>
)}
</PullToRefresh>
</section>
<section className="mobile-rules">
<span className="mobile-eyebrow">RULES, IN PLAIN WORDS</span>
<h2>先把规则说明白</h2>
<p>押金、租金、额外消耗和退款规则都会在订单里逐项列出。结账备注不参与系统结算。</p>
</section>
</div>
)
}