232 lines
7.4 KiB
TypeScript
232 lines
7.4 KiB
TypeScript
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> = {
|
|
verified: '已实名',
|
|
pending: '审核中',
|
|
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 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-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>
|
|
|
|
{user ? (
|
|
<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>
|
|
)}
|
|
</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>
|
|
)
|
|
}
|