Skip to content

Commit 93ae988

Browse files
author
CzNd
committed
美化ui
1 parent 8499074 commit 93ae988

6 files changed

Lines changed: 259 additions & 255 deletions

File tree

frontend/src/components/Common/Sidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const Sidebar = () => {
8282
position="sticky"
8383
bg="bg.subtle"
8484
top={0}
85-
minW="xs"
85+
minW="60"
8686
h="100vh"
8787
p={4}
8888
>

frontend/src/components/Common/SidebarItems.tsx

Lines changed: 78 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { Box, Flex, Icon, Text } from "@chakra-ui/react"
22
import { useQueryClient } from "@tanstack/react-query"
3-
import { Link as RouterLink } from "@tanstack/react-router"
4-
import { FiBriefcase, FiHome, FiSettings, FiUsers } from "react-icons/fi"
3+
import { Link as RouterLink, useRouter } from "@tanstack/react-router"
4+
import { FiBriefcase, FiHome, FiSettings, FiUsers, FiChevronDown, FiChevronRight } from "react-icons/fi"
55
import type { IconType } from "react-icons/lib"
6+
import React, { useState } from "react"
67

78
import type { UserPublic } from "@/client"
89

@@ -25,31 +26,89 @@ interface Item {
2526
path: string
2627
}
2728

29+
const trafficAnalysisSubItems = [
30+
{ title: "上客点密度分析", tab: "pickup-density" },
31+
{ title: "车辆轨迹可视化", tab: "vehicle-trajectory" },
32+
{ title: "统计数据", tab: "statistics" },
33+
]
34+
2835
const SidebarItems = ({ onClose }: SidebarItemsProps) => {
2936
const queryClient = useQueryClient()
3037
const currentUser = queryClient.getQueryData<UserPublic>(["currentUser"])
38+
const router = useRouter()
39+
const currentPath = router.state.location.pathname
40+
const currentTab = router.state.location.search?.tab
41+
const [expandedMenu, setExpandedMenu] = useState<string | null>(null)
3142

3243
const finalItems: Item[] = currentUser?.is_superuser
3344
? [...items, { icon: FiUsers, title: "Admin", path: "/admin" }]
3445
: items
3546

36-
const listItems = finalItems.map(({ icon, title, path }) => (
37-
<RouterLink key={title} to={path} onClick={onClose}>
38-
<Flex
39-
gap={4}
40-
px={4}
41-
py={2}
42-
_hover={{
43-
background: "gray.subtle",
44-
}}
45-
alignItems="center"
46-
fontSize="sm"
47-
>
48-
<Icon as={icon} alignSelf="center" />
49-
<Text ml={2}>{title}</Text>
50-
</Flex>
51-
</RouterLink>
52-
))
47+
const handleExpand = (title: string) => {
48+
setExpandedMenu(prev => (prev === title ? null : title))
49+
}
50+
51+
const listItems = finalItems.map(({ icon, title, path }) => {
52+
if (title === "交通数据分析") {
53+
return (
54+
<Box key={title}>
55+
<Flex
56+
gap={4}
57+
px={4}
58+
py={2}
59+
alignItems="center"
60+
fontSize="sm"
61+
cursor="pointer"
62+
_hover={{ background: "gray.subtle" }}
63+
onClick={() => handleExpand(title)}
64+
>
65+
<Icon as={icon} alignSelf="center" />
66+
<Text ml={2} userSelect="none">{title}</Text>
67+
<Icon as={expandedMenu === title ? FiChevronDown : FiChevronRight} ml="auto" />
68+
</Flex>
69+
{expandedMenu === title && (
70+
<Box pl={12} mt={1}>
71+
{trafficAnalysisSubItems.map((sub, idx) => (
72+
<RouterLink
73+
key={sub.tab}
74+
to={`/traffic-analysis?tab=${sub.tab}`}
75+
onClick={onClose}
76+
style={{ display: "block" }}
77+
>
78+
<Text
79+
py={1}
80+
mb={idx !== trafficAnalysisSubItems.length - 1 ? 2 : 0}
81+
color={currentTab === sub.tab ? "blue.500" : "gray.700"}
82+
fontWeight={currentTab === sub.tab ? "bold" : "normal"}
83+
fontSize="sm"
84+
_hover={{ color: "blue.600" }}
85+
userSelect="none"
86+
>
87+
{sub.title}
88+
</Text>
89+
</RouterLink>
90+
))}
91+
</Box>
92+
)}
93+
</Box>
94+
)
95+
}
96+
return (
97+
<RouterLink key={title} to={path} onClick={onClose}>
98+
<Flex
99+
gap={4}
100+
px={4}
101+
py={2}
102+
_hover={{ background: "gray.subtle" }}
103+
alignItems="center"
104+
fontSize="sm"
105+
>
106+
<Icon as={icon} alignSelf="center" />
107+
<Text ml={2}>{title}</Text>
108+
</Flex>
109+
</RouterLink>
110+
)
111+
})
53112

54113
return (
55114
<>

frontend/src/components/Traffic_analysis/PassengerCountChart.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import React, { useEffect, useState } from "react"
22
import ReactECharts from 'echarts-for-react'
3-
import { Text, Flex } from "@chakra-ui/react"
3+
import { Text, Flex, Input } from "@chakra-ui/react"
44
import { Field } from '../ui/field'
5-
import { RadioGroup } from '../ui/radio'
5+
import { RadioGroup, Radio } from '../ui/radio'
6+
import { Button } from '../ui/button'
67

78
function formatDate(date: Date) {
89
const y = date.getFullYear()
@@ -57,21 +58,21 @@ export default function PassengerCountChart() {
5758
<>
5859
<Flex align="center" gap={4} mb={2}>
5960
<Field label="选择日期">
60-
<input
61+
<Input
6162
type="date"
6263
value={date}
6364
onChange={e => setDate(e.target.value)}
64-
style={{ height: 32, borderRadius: 4, border: '1px solid #ccc', padding: '0 8px' }}
65+
height={8}
66+
borderRadius={4}
67+
border="1px solid #ccc"
68+
px={2}
69+
w={40}
6570
/>
6671
</Field>
6772
<Field label="时间间隔">
68-
<RadioGroup value={interval}>
69-
<label style={{marginRight: 12}}>
70-
<input type="radio" value="15min" checked={interval === '15min'} onChange={() => setInterval('15min')} /> 15分钟
71-
</label>
72-
<label>
73-
<input type="radio" value="1h" checked={interval === '1h'} onChange={() => setInterval('1h')} /> 1小时
74-
</label>
73+
<RadioGroup value={interval} onValueChange={e => setInterval(e.value as '15min' | '1h')} direction="row">
74+
<Radio value="15min">15分钟</Radio>
75+
<Radio value="1h">1小时</Radio>
7576
</RadioGroup>
7677
</Field>
7778
</Flex>

0 commit comments

Comments
 (0)