This commit is contained in:
a.ilin
2026-10-06 10:23:46 +03:00
parent 9654c2d9ef
commit f6fd6d79a0
9 changed files with 194 additions and 57 deletions
+2 -1
View File
@@ -57,9 +57,10 @@ export function LoginScreen() {
alignItems: 'center',
justifyContent: 'center',
background: '#f0f2f5',
padding: 16,
}}
>
<Card style={{ width: 400 }}>
<Card style={{ width: 400, maxWidth: '100%' }}>
<Typography.Title level={3} style={{ textAlign: 'center', marginTop: 0 }}>
Городар · Админ-панель
</Typography.Title>
+7
View File
@@ -0,0 +1,7 @@
import { Grid } from 'antd'
/** true на экранах уже md (768px) — телефонная вёрстка. */
export function useIsMobile(): boolean {
const screens = Grid.useBreakpoint()
return !screens.md
}
+97 -24
View File
@@ -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,22 +71,20 @@ export function AdminLayout() {
const selectedKey = '/' + (location.pathname.split('/')[1] ?? '')
return (
<Layout style={{ minHeight: '100vh' }}>
<Header
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
gap: 16,
const menu = (
<Menu
mode="inline"
selectedKeys={[selectedKey]}
items={menuItems}
onClick={({ key }) => {
navigate(key)
setMenuOpen(false)
}}
>
<Space size="middle">
<Typography.Title level={4} style={{ color: '#fff', margin: 0 }}>
Городар · Админ-панель
</Typography.Title>
</Space>
<Space size="middle">
style={{ borderRight: 0, paddingTop: 8 }}
/>
)
const roleTags = (
<Space size={4} wrap>
{roles
.filter((role) => ROLE_LABELS[role])
@@ -83,6 +94,50 @@ export function AdminLayout() {
</Tag>
))}
</Space>
)
return (
<Layout style={{ minHeight: '100vh' }}>
<Header
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
gap: 16,
paddingInline: isMobile ? 12 : undefined,
}}
>
{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)' }}
/>
</>
) : (
<>
<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>
@@ -96,18 +151,36 @@ export function AdminLayout() {
</Button>
</Space>
</Space>
</>
)}
</Header>
<Layout>
{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
mode="inline"
selectedKeys={[selectedKey]}
items={menuItems}
onClick={({ key }) => navigate(key)}
style={{ height: '100%', borderRight: 0, paddingTop: 8 }}
/>
{menu}
</Sider>
<Content style={{ padding: 24 }}>
)}
<Content style={{ padding: isMobile ? 16 : 24 }}>
<Outlet />
</Content>
</Layout>
+4
View File
@@ -6,6 +6,7 @@ import { createArea, fetchAreas, updateArea } from '@/api/areas'
import { notifyApiError, notifySuccess } from '@/api/errors'
import type { Area } from '@/api/types'
import { AreaTreeSelect } from '@/components/AreaTreeSelect'
import { useIsMobile } from '@/hooks/useIsMobile'
interface TrailItem {
id: string
@@ -26,6 +27,7 @@ const PAGE_SIZE = 20
export function AreaListPage() {
const queryClient = useQueryClient()
const isMobile = useIsMobile()
const [parentId, setParentId] = useState<string | null>(null)
const [trail, setTrail] = useState<TrailItem[]>([])
const [page, setPage] = useState(0)
@@ -167,6 +169,7 @@ export function AreaListPage() {
columns={columns}
dataSource={data?.content ?? []}
loading={areasQuery.isLoading}
scroll={{ x: 'max-content' }}
locale={{
emptyText: <Empty description="В этой зоне нет вложенных зон" />,
}}
@@ -175,6 +178,7 @@ export function AreaListPage() {
pageSize: data?.size ?? PAGE_SIZE,
total: data?.totalElements ?? 0,
showSizeChanger: false,
simple: isMobile,
onChange: (p) => setPage(p - 1),
}}
/>
@@ -148,7 +148,7 @@ export function AttractionDetailPage() {
<>
<Space direction="vertical" size="middle" style={{ width: '100%' }}>
<div className="page-header-flex">
<Space>
<Space wrap>
<Link to={`/attractions?area=${attraction.areaId}`}>
<Button icon={<ArrowLeftOutlined />}>К списку</Button>
</Link>
@@ -162,7 +162,7 @@ export function AttractionDetailPage() {
</div>
<Card title="Карточка">
<Descriptions column={2} bordered size="small">
<Descriptions column={{ xs: 1, md: 2 }} bordered size="small">
<Descriptions.Item label="Название">{attraction.name}</Descriptions.Item>
<Descriptions.Item label="CV-профиль">
<Tag color={cvProfileMeta[attraction.cvProfile].color}>
@@ -196,7 +196,7 @@ export function AttractionDetailPage() {
</Card>
<Card title="Иконка">
<Space size="large" align="start">
<Space size="large" align="start" wrap>
{iconUrl ? (
<Image src={iconUrl} width={96} height={96} style={{ objectFit: 'cover' }} />
) : (
+18 -7
View File
@@ -2,6 +2,7 @@ import type { FormInstance } from 'antd'
import { Button, Form, Input, InputNumber, Select, Space } from 'antd'
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'
import type { CreateAttractionRequest, CvProfile, UpdateAttractionRequest } from '@/api/types'
import { useIsMobile } from '@/hooks/useIsMobile'
import { cvProfileOptions } from '@/utils/format'
export interface AttractionFormValues {
@@ -74,6 +75,8 @@ export function AttractionForm({
form: FormInstance<AttractionFormValues>
initialValues?: AttractionFormInitialValues
}) {
const isMobile = useIsMobile()
return (
<Form
form={form}
@@ -111,11 +114,16 @@ export function AttractionForm({
<Form.Item name="address" label="Адрес">
<Input maxLength={255} />
</Form.Item>
<Space size="large" style={{ display: 'flex' }} align="start">
<Space
size="large"
style={{ display: 'flex' }}
align="start"
direction={isMobile ? 'vertical' : 'horizontal'}
>
<Form.Item
name="latitude"
label="Широта"
style={{ width: 220 }}
style={{ width: isMobile ? '100%' : 220 }}
rules={[
{
validator: (_, value: number | null | undefined) =>
@@ -130,7 +138,7 @@ export function AttractionForm({
<Form.Item
name="longitude"
label="Долгота"
style={{ width: 220 }}
style={{ width: isMobile ? '100%' : 220 }}
rules={[
{
validator: (_, value: number | null | undefined) =>
@@ -148,22 +156,25 @@ export function AttractionForm({
{(fields, { add, remove }) => (
<>
{fields.map((field) => (
<Space key={field.key} align="baseline" style={{ display: 'flex', marginBottom: 4 }}>
<div
key={field.key}
style={{ display: 'flex', alignItems: 'baseline', gap: 8, marginBottom: 4 }}
>
<Form.Item
name={field.name}
rules={[{ required: true, message: 'Пустой факт — удалите строку' }]}
noStyle
>
<Input placeholder="Текст факта" maxLength={500} style={{ width: 440 }} />
<Input placeholder="Текст факта" maxLength={500} style={{ flex: 1, minWidth: 0 }} />
</Form.Item>
<MinusCircleOutlined onClick={() => remove(field.name)} />
</Space>
</div>
))}
<Button
type="dashed"
icon={<PlusOutlined />}
onClick={() => add()}
style={{ width: 472 }}
style={{ width: '100%', maxWidth: 472 }}
>
Добавить факт
</Button>
+16 -2
View File
@@ -7,6 +7,7 @@ import { createAttraction, fetchAttractions } from '@/api/attractions'
import { notifyApiError, notifySuccess } from '@/api/errors'
import type { Attraction } from '@/api/types'
import { AreaTreeSelect } from '@/components/AreaTreeSelect'
import { useIsMobile } from '@/hooks/useIsMobile'
import { cvProfileMeta } from '@/utils/format'
import {
AttractionForm,
@@ -18,6 +19,7 @@ const PAGE_SIZE = 20
export function AttractionListPage() {
const navigate = useNavigate()
const isMobile = useIsMobile()
const [searchParams, setSearchParams] = useSearchParams()
const [areaId, setAreaId] = useState<string | null>(searchParams.get('area'))
const [page, setPage] = useState(0)
@@ -109,14 +111,24 @@ export function AttractionListPage() {
<Typography.Title level={3} className="page-title">
Достопримечательности
</Typography.Title>
<Space>
<Space
size="middle"
direction={isMobile ? 'vertical' : 'horizontal'}
style={isMobile ? { width: '100%' } : undefined}
>
<AreaTreeSelect
value={areaId}
onChange={changeArea}
placeholder="Зона (обязательно)"
allowClear
style={isMobile ? { width: '100%' } : undefined}
/>
<Button type="primary" disabled={!areaId} onClick={() => setCreateOpen(true)}>
<Button
type="primary"
block={isMobile}
disabled={!areaId}
onClick={() => setCreateOpen(true)}
>
Создать
</Button>
</Space>
@@ -130,12 +142,14 @@ export function AttractionListPage() {
columns={columns}
dataSource={data?.content ?? []}
loading={attractionsQuery.isLoading}
scroll={{ x: 'max-content' }}
locale={{ emptyText: <Empty description="В зоне пока нет достопримечательностей" /> }}
pagination={{
current: (data?.number ?? 0) + 1,
pageSize: data?.size ?? PAGE_SIZE,
total: data?.totalElements ?? 0,
showSizeChanger: false,
simple: isMobile,
onChange: (p) => setPage(p - 1),
}}
/>
+15 -2
View File
@@ -18,6 +18,7 @@ import { notifyApiError, notifySuccess } from '@/api/errors'
import { activateSet, archiveSet, createSet, fetchSets, renameSet } from '@/api/sets'
import type { AttractionSet } from '@/api/types'
import { AreaTreeSelect } from '@/components/AreaTreeSelect'
import { useIsMobile } from '@/hooks/useIsMobile'
import { setStatusMeta } from '@/utils/format'
import { SetItemsModal } from '@/pages/sets/SetItemsModal'
@@ -27,6 +28,7 @@ interface NameFormValues {
export function SetListPage() {
const queryClient = useQueryClient()
const isMobile = useIsMobile()
const [searchParams, setSearchParams] = useSearchParams()
const [areaId, setAreaId] = useState<string | null>(searchParams.get('area'))
const [createOpen, setCreateOpen] = useState(false)
@@ -165,14 +167,24 @@ export function SetListPage() {
<Typography.Title level={3} className="page-title">
Наборы
</Typography.Title>
<Space>
<Space
size="middle"
direction={isMobile ? 'vertical' : 'horizontal'}
style={isMobile ? { width: '100%' } : undefined}
>
<AreaTreeSelect
value={areaId}
onChange={changeArea}
placeholder="Зона (обязательно)"
allowClear
style={isMobile ? { width: '100%' } : undefined}
/>
<Button type="primary" disabled={!areaId} onClick={() => setCreateOpen(true)}>
<Button
type="primary"
block={isMobile}
disabled={!areaId}
onClick={() => setCreateOpen(true)}
>
Создать набор
</Button>
</Space>
@@ -186,6 +198,7 @@ export function SetListPage() {
columns={columns}
dataSource={sets}
loading={setsQuery.isLoading}
scroll={{ x: 'max-content' }}
pagination={false}
locale={{ emptyText: <Empty description="В зоне пока нет наборов" /> }}
/>
+22 -8
View File
@@ -1,4 +1,4 @@
import { useState } from 'react'
import { useState, type CSSProperties } from 'react'
import { keepPreviousData, useQuery } from '@tanstack/react-query'
import { Button, Card, DatePicker, Form, Input, Select, Space, Table, Tag, Typography } from 'antd'
import type { ColumnsType } from 'antd/es/table'
@@ -9,6 +9,7 @@ import { fetchAttractions } from '@/api/attractions'
import { fetchVisits } from '@/api/visits'
import type { Visit, VisitFilter } from '@/api/types'
import { AreaTreeSelect } from '@/components/AreaTreeSelect'
import { useIsMobile } from '@/hooks/useIsMobile'
import { formatConfidence, formatUtc, verdictMeta } from '@/utils/format'
const PAGE_SIZE = 20
@@ -23,6 +24,7 @@ interface FilterFormValues {
export function VisitListPage() {
const [form] = Form.useForm<FilterFormValues>()
const isMobile = useIsMobile()
const watchedAreaId = Form.useWatch('areaId', form)
const [applied, setApplied] = useState<VisitFilter>({})
const [page, setPage] = useState(0)
@@ -99,6 +101,11 @@ export function VisitListPage() {
const data = visitsQuery.data
// На мобиле поля фильтра занимают всю ширину, на десктопе — фиксированные.
const itemStyle: CSSProperties = isMobile ? { width: '100%' } : { marginRight: 12 }
const controlStyle = (desktopWidth: number): CSSProperties =>
isMobile ? { width: '100%' } : { width: desktopWidth }
return (
<>
<Typography.Title level={3} className="page-title" style={{ marginBottom: 16 }}>
@@ -112,14 +119,15 @@ export function VisitListPage() {
onFinish={applyFilters}
style={{ rowGap: 12, flexWrap: 'wrap', alignItems: 'center' }}
>
<Form.Item name="areaId" style={{ marginRight: 12 }}>
<Form.Item name="areaId" style={itemStyle}>
<AreaTreeSelect
placeholder="Зона"
allowClear
onChange={() => form.setFieldValue('attractionId', undefined)}
style={isMobile ? { width: '100%' } : undefined}
/>
</Form.Item>
<Form.Item name="attractionId" style={{ marginRight: 12 }}>
<Form.Item name="attractionId" style={itemStyle}>
<Select
placeholder={watchedAreaId ? 'Достопримечательность' : 'Сначала выберите зону'}
disabled={watchedAreaId == null}
@@ -131,14 +139,18 @@ export function VisitListPage() {
allowClear
showSearch
optionFilterProp="label"
style={{ width: 280 }}
style={controlStyle(280)}
/>
</Form.Item>
<Form.Item name="userId" style={{ marginRight: 12 }}>
<Input placeholder="ID пользователя" allowClear style={{ width: 240 }} />
<Form.Item name="userId" style={itemStyle}>
<Input placeholder="ID пользователя" allowClear style={controlStyle(240)} />
</Form.Item>
<Form.Item name="range" style={{ marginRight: 12 }}>
<DatePicker.RangePicker placeholder={['С даты', 'По дату']} allowEmpty={[true, true]} />
<Form.Item name="range" style={itemStyle}>
<DatePicker.RangePicker
placeholder={['С даты', 'По дату']}
allowEmpty={[true, true]}
style={isMobile ? { width: '100%' } : undefined}
/>
</Form.Item>
<Form.Item style={{ marginRight: 0 }}>
<Space>
@@ -165,11 +177,13 @@ export function VisitListPage() {
dataSource={data?.content ?? []}
loading={visitsQuery.isLoading}
onChange={handleTableChange}
scroll={{ x: 'max-content' }}
pagination={{
current: (data?.number ?? 0) + 1,
pageSize: data?.size ?? PAGE_SIZE,
total: data?.totalElements ?? 0,
showSizeChanger: false,
simple: isMobile,
showTotal: (total) => `Всего: ${total}`,
}}
/>