mobile
This commit is contained in:
+107
-34
@@ -1,15 +1,18 @@
|
||||
import { useState } from 'react'
|
||||
import {
|
||||
ApartmentOutlined,
|
||||
BarChartOutlined,
|
||||
CameraOutlined,
|
||||
LogoutOutlined,
|
||||
MenuOutlined,
|
||||
OrderedListOutlined,
|
||||
UserOutlined,
|
||||
} from '@ant-design/icons'
|
||||
import { Avatar, Button, Layout, Menu, Result, Space, Tag, Typography } from 'antd'
|
||||
import { Avatar, Button, Drawer, Layout, Menu, Result, Space, Tag, Typography } from 'antd'
|
||||
import { Outlet, useLocation, useNavigate } from 'react-router-dom'
|
||||
import { ROLE_MANAGE_AREA, ROLE_MANAGE_ATTRACTION } from '@/auth/roles'
|
||||
import { useAuth } from '@/auth/AuthContext'
|
||||
import { useIsMobile } from '@/hooks/useIsMobile'
|
||||
|
||||
const { Header, Sider, Content } = Layout
|
||||
|
||||
@@ -22,10 +25,20 @@ export function AdminLayout() {
|
||||
const { email, roles, logout } = useAuth()
|
||||
const location = useLocation()
|
||||
const navigate = useNavigate()
|
||||
const isMobile = useIsMobile()
|
||||
const [menuOpen, setMenuOpen] = useState(false)
|
||||
|
||||
const hasManageArea = roles.includes(ROLE_MANAGE_AREA)
|
||||
const hasManageAttraction = roles.includes(ROLE_MANAGE_ATTRACTION)
|
||||
|
||||
// При переходе десктоп↔мобильный открытый Drawer теряет смысл — сбрасываем
|
||||
// во время рендера (паттерн «adjust state when props change» из доков React).
|
||||
const [wasMobile, setWasMobile] = useState(isMobile)
|
||||
if (wasMobile !== isMobile) {
|
||||
setWasMobile(isMobile)
|
||||
setMenuOpen(false)
|
||||
}
|
||||
|
||||
if (!hasManageArea && !hasManageAttraction) {
|
||||
return (
|
||||
<Result
|
||||
@@ -58,6 +71,31 @@ export function AdminLayout() {
|
||||
|
||||
const selectedKey = '/' + (location.pathname.split('/')[1] ?? '')
|
||||
|
||||
const menu = (
|
||||
<Menu
|
||||
mode="inline"
|
||||
selectedKeys={[selectedKey]}
|
||||
items={menuItems}
|
||||
onClick={({ key }) => {
|
||||
navigate(key)
|
||||
setMenuOpen(false)
|
||||
}}
|
||||
style={{ borderRight: 0, paddingTop: 8 }}
|
||||
/>
|
||||
)
|
||||
|
||||
const roleTags = (
|
||||
<Space size={4} wrap>
|
||||
{roles
|
||||
.filter((role) => ROLE_LABELS[role])
|
||||
.map((role) => (
|
||||
<Tag key={role} color="gold">
|
||||
{ROLE_LABELS[role]}
|
||||
</Tag>
|
||||
))}
|
||||
</Space>
|
||||
)
|
||||
|
||||
return (
|
||||
<Layout style={{ minHeight: '100vh' }}>
|
||||
<Header
|
||||
@@ -66,48 +104,83 @@ export function AdminLayout() {
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
gap: 16,
|
||||
paddingInline: isMobile ? 12 : undefined,
|
||||
}}
|
||||
>
|
||||
<Space size="middle">
|
||||
<Typography.Title level={4} style={{ color: '#fff', margin: 0 }}>
|
||||
Городар · Админ-панель
|
||||
</Typography.Title>
|
||||
</Space>
|
||||
<Space size="middle">
|
||||
<Space size={4} wrap>
|
||||
{roles
|
||||
.filter((role) => ROLE_LABELS[role])
|
||||
.map((role) => (
|
||||
<Tag key={role} color="gold">
|
||||
{ROLE_LABELS[role]}
|
||||
</Tag>
|
||||
))}
|
||||
</Space>
|
||||
<Space size={8}>
|
||||
<Avatar size="small" icon={<UserOutlined />} />
|
||||
<Typography.Text style={{ color: 'rgba(255,255,255,0.85)' }}>{email}</Typography.Text>
|
||||
{isMobile ? (
|
||||
<>
|
||||
<Space size={4}>
|
||||
<Button
|
||||
type="text"
|
||||
icon={<MenuOutlined />}
|
||||
aria-label="Меню"
|
||||
onClick={() => setMenuOpen(true)}
|
||||
style={{ color: '#fff' }}
|
||||
/>
|
||||
<Typography.Title level={4} style={{ color: '#fff', margin: 0 }}>
|
||||
Городар
|
||||
</Typography.Title>
|
||||
</Space>
|
||||
<Button
|
||||
type="text"
|
||||
aria-label="Выйти"
|
||||
icon={<LogoutOutlined />}
|
||||
onClick={logout}
|
||||
style={{ color: 'rgba(255,255,255,0.85)' }}
|
||||
>
|
||||
Выйти
|
||||
</Button>
|
||||
</Space>
|
||||
</Space>
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Space size="middle">
|
||||
<Typography.Title level={4} style={{ color: '#fff', margin: 0 }}>
|
||||
Городар · Админ-панель
|
||||
</Typography.Title>
|
||||
</Space>
|
||||
<Space size="middle">
|
||||
{roleTags}
|
||||
<Space size={8}>
|
||||
<Avatar size="small" icon={<UserOutlined />} />
|
||||
<Typography.Text style={{ color: 'rgba(255,255,255,0.85)' }}>{email}</Typography.Text>
|
||||
<Button
|
||||
type="text"
|
||||
icon={<LogoutOutlined />}
|
||||
onClick={logout}
|
||||
style={{ color: 'rgba(255,255,255,0.85)' }}
|
||||
>
|
||||
Выйти
|
||||
</Button>
|
||||
</Space>
|
||||
</Space>
|
||||
</>
|
||||
)}
|
||||
</Header>
|
||||
<Layout>
|
||||
<Sider theme="light" width={220}>
|
||||
<Menu
|
||||
mode="inline"
|
||||
selectedKeys={[selectedKey]}
|
||||
items={menuItems}
|
||||
onClick={({ key }) => navigate(key)}
|
||||
style={{ height: '100%', borderRight: 0, paddingTop: 8 }}
|
||||
/>
|
||||
</Sider>
|
||||
<Content style={{ padding: 24 }}>
|
||||
{isMobile ? (
|
||||
<Drawer
|
||||
title="Меню"
|
||||
placement="left"
|
||||
width={288}
|
||||
open={menuOpen}
|
||||
onClose={() => setMenuOpen(false)}
|
||||
styles={{ body: { padding: 0 } }}
|
||||
>
|
||||
<div style={{ padding: '8px 24px' }}>
|
||||
<Space size={8}>
|
||||
<Avatar size="small" icon={<UserOutlined />} />
|
||||
<Typography.Text style={{ maxWidth: 180 }} ellipsis>
|
||||
{email}
|
||||
</Typography.Text>
|
||||
</Space>
|
||||
<div style={{ marginTop: 8 }}>{roleTags}</div>
|
||||
</div>
|
||||
{menu}
|
||||
</Drawer>
|
||||
) : (
|
||||
<Sider theme="light" width={220}>
|
||||
{menu}
|
||||
</Sider>
|
||||
)}
|
||||
<Content style={{ padding: isMobile ? 16 : 24 }}>
|
||||
<Outlet />
|
||||
</Content>
|
||||
</Layout>
|
||||
|
||||
Reference in New Issue
Block a user