feat(mobile): 重构移动端首页与个人中心
This commit is contained in:
@@ -1,7 +1,29 @@
|
||||
import { Button, List, Tag } from 'antd-mobile'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import type { ReactNode } from 'react'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { Button, Dialog, Tag } from 'antd-mobile'
|
||||
import {
|
||||
AddCircleOutline,
|
||||
BillOutline,
|
||||
CheckCircleOutline,
|
||||
ClockCircleOutline,
|
||||
GiftOutline,
|
||||
GlobalOutline,
|
||||
MessageOutline,
|
||||
PayCircleOutline,
|
||||
RightOutline,
|
||||
SetOutline,
|
||||
ShopbagOutline,
|
||||
StarOutline,
|
||||
TruckOutline,
|
||||
UserCircleOutline,
|
||||
UserContactOutline,
|
||||
VideoOutline,
|
||||
} from 'antd-mobile-icons'
|
||||
import { Link, useNavigate } from 'react-router-dom'
|
||||
|
||||
import { BrandLogo } from '@/components/BrandLogo'
|
||||
import { fetchWalletBalance } from '@/features/wallet/api'
|
||||
import { formatMoney } from '@/shared/utils/format'
|
||||
import { useSessionStore } from '@/stores/session'
|
||||
|
||||
const realnameLabel: Record<string, string> = {
|
||||
@@ -10,61 +32,200 @@ const realnameLabel: Record<string, string> = {
|
||||
rejected: '未通过',
|
||||
}
|
||||
|
||||
interface ServiceItem {
|
||||
label: string
|
||||
icon: ReactNode
|
||||
to: string
|
||||
}
|
||||
|
||||
const buyerServices: ServiceItem[] = [
|
||||
{ label: '全部订单', icon: <BillOutline />, to: '/m/orders' },
|
||||
{ label: '待支付', icon: <ClockCircleOutline />, to: '/m/orders?tab=pending_payment' },
|
||||
{ label: '待交接', icon: <TruckOutline />, to: '/m/orders?tab=pending_handoff' },
|
||||
{ label: '使用中', icon: <VideoOutline />, to: '/m/orders?tab=renting' },
|
||||
{ label: '已完成', icon: <CheckCircleOutline />, to: '/m/orders?tab=completed' },
|
||||
{ label: '我的足迹', icon: <StarOutline />, to: '/m/listings/collections' },
|
||||
]
|
||||
|
||||
const sellerServices: ServiceItem[] = [
|
||||
{ label: '发布商品', icon: <AddCircleOutline />, to: '/m/seller/listings/new' },
|
||||
{ label: '我的商品', icon: <ShopbagOutline />, to: '/m/seller/listings' },
|
||||
{ label: '提现', icon: <PayCircleOutline />, to: '/m/wallet/withdrawal' },
|
||||
{ label: '撞车商城', icon: <GiftOutline />, to: '/m/crash' },
|
||||
]
|
||||
|
||||
const publicServices: ServiceItem[] = [
|
||||
{ label: '消息中心', icon: <MessageOutline />, to: '/m/messages' },
|
||||
{ label: '邀请好友', icon: <GiftOutline />, to: '/m/invitations' },
|
||||
{ label: '公告中心', icon: <GlobalOutline />, to: '/m/announcements' },
|
||||
{ label: '实名认证', icon: <UserContactOutline />, to: '/m/realname' },
|
||||
]
|
||||
|
||||
function ServiceGrid({ items }: { items: ServiceItem[] }) {
|
||||
return (
|
||||
<div className="mobile-service-grid">
|
||||
{items.map(item => (
|
||||
<Link to={item.to} className="mobile-service-item" key={item.label}>
|
||||
<span>{item.icon}</span>
|
||||
<strong>{item.label}</strong>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export function MobileProfilePage() {
|
||||
const navigate = useNavigate()
|
||||
const user = useSessionStore(state => state.user)
|
||||
const token = useSessionStore(state => state.token)
|
||||
const logout = useSessionStore(state => state.logout)
|
||||
const wallet = useQuery({
|
||||
queryKey: ['wallet-balance', 'mobile-profile'],
|
||||
queryFn: fetchWalletBalance,
|
||||
enabled: Boolean(token),
|
||||
})
|
||||
const realnameStatus = user?.realname_status || 'unverified'
|
||||
const realnameTone =
|
||||
realnameStatus === 'verified' ? 'success' : realnameStatus === 'rejected' ? 'danger' : 'default'
|
||||
const qualityOwner = user?.quality_owner_status === 'active'
|
||||
|
||||
const handleLogout = async () => {
|
||||
const confirmed = await Dialog.confirm({
|
||||
content: '确定退出当前账号吗?',
|
||||
confirmText: '退出',
|
||||
cancelText: '取消',
|
||||
})
|
||||
if (!confirmed) return
|
||||
await logout()
|
||||
navigate('/m')
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mobile-profile">
|
||||
<section className="mobile-profile__head">
|
||||
<BrandLogo height={42} variant="seal" />
|
||||
<div>
|
||||
<h1>{user ? user.nickname || '我的商行' : '还没登录'}</h1>
|
||||
<p>{user ? user.phone : '登录后查看订单、钱包与实名状态'}</p>
|
||||
<section className={`mobile-profile-hero${user ? '' : ' is-guest'}`}>
|
||||
<div className="mobile-profile-hero__top">
|
||||
<div className="mobile-profile-avatar">
|
||||
{user ? user.nickname?.slice(0, 1) || user.phone.slice(-1) : <UserCircleOutline />}
|
||||
</div>
|
||||
<div className="mobile-profile-identity">
|
||||
<div>
|
||||
<h1>{user ? user.nickname || `用户${user.phone.slice(-6)}` : '立即登录'}</h1>
|
||||
{user ? (
|
||||
<Tag color={realnameStatus === 'verified' ? 'success' : 'default'} fill="outline">
|
||||
{realnameLabel[realnameStatus] || '未实名'}
|
||||
</Tag>
|
||||
) : null}
|
||||
{qualityOwner ? <Tag color="warning">优质号主</Tag> : null}
|
||||
</div>
|
||||
<p>
|
||||
{user
|
||||
? `ID: ${user.id} · ${user.phone.slice(0, 3)}****${user.phone.slice(-4)}`
|
||||
: '登录后查看订单、余额与账号收益'}
|
||||
</p>
|
||||
</div>
|
||||
{user ? (
|
||||
<button
|
||||
type="button"
|
||||
className="mobile-profile-settings"
|
||||
onClick={() => void handleLogout()}
|
||||
>
|
||||
<SetOutline />
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<List className="mobile-profile__list">
|
||||
<List.Item extra={user ? '已登录' : '未登录'}>账号状态</List.Item>
|
||||
<List.Item
|
||||
clickable
|
||||
onClick={() => navigate(user ? '/m/realname' : '/m/login?redirect=/m/realname')}
|
||||
extra={<Tag color={realnameTone}>{realnameLabel[realnameStatus] ?? '未实名'}</Tag>}
|
||||
>
|
||||
实名认证
|
||||
</List.Item>
|
||||
<List.Item onClick={() => navigate('/m/orders')}>我的订单</List.Item>
|
||||
<List.Item onClick={() => navigate('/m/messages')}>消息中心</List.Item>
|
||||
<List.Item
|
||||
onClick={() =>
|
||||
navigate(user ? '/m/seller/listings' : '/m/login?redirect=/m/seller/listings')
|
||||
}
|
||||
>
|
||||
卖家中心
|
||||
</List.Item>
|
||||
</List>
|
||||
|
||||
<div className="mobile-profile__actions">
|
||||
{user ? (
|
||||
<Button
|
||||
block
|
||||
onClick={async () => {
|
||||
await logout()
|
||||
navigate('/m')
|
||||
}}
|
||||
>
|
||||
退出登录
|
||||
</Button>
|
||||
<div className="mobile-profile-assets">
|
||||
<div>
|
||||
<span>账户余额</span>
|
||||
<strong>
|
||||
{wallet.data ? formatMoney(wallet.data.available_balance_cent) : '加载中'}
|
||||
</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span>可用积分</span>
|
||||
<strong>{user.points_available ?? 0}</strong>
|
||||
</div>
|
||||
<button type="button" onClick={() => navigate('/m/wallet/withdrawal')}>
|
||||
提现
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<Button block color="primary" onClick={() => navigate('/m/login')}>
|
||||
登录 / 注册
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="mobile-primary-actions">
|
||||
<Link to="/m" className="mobile-primary-action is-rent">
|
||||
<span>
|
||||
<ShopbagOutline />
|
||||
</span>
|
||||
<div>
|
||||
<strong>我要租号</strong>
|
||||
<small>海量账号任你挑选</small>
|
||||
</div>
|
||||
<RightOutline />
|
||||
</Link>
|
||||
<Link to="/m/seller/listings/new" className="mobile-primary-action is-sell">
|
||||
<span>
|
||||
<AddCircleOutline />
|
||||
</span>
|
||||
<div>
|
||||
<strong>我要出号</strong>
|
||||
<small>闲置账号快速出租</small>
|
||||
</div>
|
||||
<RightOutline />
|
||||
</Link>
|
||||
</section>
|
||||
|
||||
<section className="mobile-profile-section">
|
||||
<div className="mobile-profile-section__head">
|
||||
<div>
|
||||
<span>买家中心</span>
|
||||
<strong>我的租用</strong>
|
||||
</div>
|
||||
<Link to="/m/orders">
|
||||
全部订单 <RightOutline />
|
||||
</Link>
|
||||
</div>
|
||||
<ServiceGrid items={buyerServices} />
|
||||
</section>
|
||||
|
||||
<section className="mobile-profile-section">
|
||||
<div className="mobile-profile-section__head">
|
||||
<div>
|
||||
<span>卖家中心</span>
|
||||
<strong>账号出租</strong>
|
||||
</div>
|
||||
<Link to="/m/seller/listings">
|
||||
商品管理 <RightOutline />
|
||||
</Link>
|
||||
</div>
|
||||
<ServiceGrid items={sellerServices} />
|
||||
</section>
|
||||
|
||||
<section className="mobile-profile-section">
|
||||
<div className="mobile-profile-section__head">
|
||||
<div>
|
||||
<span>公共服务</span>
|
||||
<strong>账户与服务</strong>
|
||||
</div>
|
||||
</div>
|
||||
<ServiceGrid items={publicServices} />
|
||||
</section>
|
||||
|
||||
{user ? (
|
||||
<section className="mobile-profile-account">
|
||||
<BrandLogo height={28} />
|
||||
<div>
|
||||
<strong>{user.nickname || '解忧商行用户'}</strong>
|
||||
<span>成长等级:{user.renter_growth_level_name || '普通用户'}</span>
|
||||
</div>
|
||||
<Button size="small" fill="none" onClick={() => void handleLogout()}>
|
||||
退出
|
||||
</Button>
|
||||
</section>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user