feat(mobile): 新增解忧商行移动端首页、详情与个人中心
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import 'antd-mobile/es/global'
|
||||
|
||||
import { TabBar } from 'antd-mobile'
|
||||
import { AppOutline, MessageOutline, UnorderedListOutline, UserOutline } from 'antd-mobile-icons'
|
||||
import { Link, Outlet, useLocation, useNavigate } from 'react-router-dom'
|
||||
|
||||
import { BrandLogo } from '@/components/BrandLogo'
|
||||
import { useSessionStore } from '@/stores/session'
|
||||
|
||||
const tabs = [
|
||||
{ key: '/m', title: '首页', icon: <AppOutline /> },
|
||||
{ key: '/m/orders', title: '订单', icon: <UnorderedListOutline /> },
|
||||
{ key: '/m/messages', title: '消息', icon: <MessageOutline /> },
|
||||
{ key: '/m/profile', title: '我的', icon: <UserOutline /> },
|
||||
]
|
||||
|
||||
function activeTab(pathname: string) {
|
||||
if (pathname.startsWith('/m/orders') || pathname.startsWith('/m/chats')) return '/m/orders'
|
||||
if (pathname.startsWith('/m/messages')) return '/m/messages'
|
||||
if (pathname.startsWith('/m/profile')) return '/m/profile'
|
||||
return '/m'
|
||||
}
|
||||
|
||||
export function MobileLayout() {
|
||||
const location = useLocation()
|
||||
const navigate = useNavigate()
|
||||
const user = useSessionStore(state => state.user)
|
||||
const hideTabbar = /^\/m\/listings\/[^/]+$/.test(location.pathname)
|
||||
|
||||
return (
|
||||
<div className="mobile-shell">
|
||||
<header className="mobile-header">
|
||||
<Link to="/m" className="mobile-header__brand" aria-label="解忧商行移动端首页">
|
||||
<BrandLogo height={30} />
|
||||
</Link>
|
||||
<div className="mobile-header__right">
|
||||
{user ? (
|
||||
<Link to="/m/profile" className="mobile-header__user">
|
||||
{user.nickname || '我的'}
|
||||
</Link>
|
||||
) : (
|
||||
<Link to="/m/login" className="mobile-header__login">
|
||||
登录
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main className="mobile-content">
|
||||
<Outlet />
|
||||
</main>
|
||||
|
||||
<div className="mobile-tabbar" hidden={hideTabbar}>
|
||||
<TabBar
|
||||
activeKey={activeTab(location.pathname)}
|
||||
onChange={key => navigate(key)}
|
||||
safeArea
|
||||
>
|
||||
{tabs.map(tab => (
|
||||
<TabBar.Item key={tab.key} icon={tab.icon} title={tab.title} />
|
||||
))}
|
||||
</TabBar>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user