修改一下

This commit is contained in:
mmc
2026-04-21 08:51:57 +08:00
parent 6122e884fe
commit 713322659c
9 changed files with 1170 additions and 577 deletions

BIN
src/assets/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

View File

@@ -1,150 +1,151 @@
import React, { useState, useEffect } from 'react';
import { Outlet, useNavigate, useLocation } from 'react-router-dom';
import {
Layout,
Menu,
Button,
Avatar,
Space,
ConfigProvider,
theme,
Breadcrumb,
Badge
import {
Layout,
Menu,
Button,
Avatar,
Space,
ConfigProvider,
theme,
Breadcrumb,
Badge
} from 'antd';
import {
DashboardOutlined,
ExperimentOutlined,
VideoCameraOutlined,
BellOutlined,
DownloadOutlined,
UserOutlined,
LogoutOutlined,
MenuUnfoldOutlined,
MenuFoldOutlined,
GlobalOutlined,
TeamOutlined
import {
DashboardOutlined,
ExperimentOutlined,
VideoCameraOutlined,
BellOutlined,
DownloadOutlined,
UserOutlined,
LogoutOutlined,
MenuUnfoldOutlined,
MenuFoldOutlined,
GlobalOutlined,
TeamOutlined
} from '@ant-design/icons';
import { MOCK_USER } from '../constants';
import logo from '../assets/logo.png';
const { Header, Sider, Content } = Layout;
export default function AppLayout() {
const [collapsed, setCollapsed] = useState(false);
const [time, setTime] = useState(new Date().toLocaleString());
const navigate = useNavigate();
const location = useLocation();
const [collapsed, setCollapsed] = useState(false);
const [time, setTime] = useState(new Date().toLocaleString());
const navigate = useNavigate();
const location = useLocation();
// 从 localStorage 获取真实用户信息
const userJson = localStorage.getItem('user');
const user = userJson ? JSON.parse(userJson) : MOCK_USER;
// 从 localStorage 获取真实用户信息
const userJson = localStorage.getItem('user');
const user = userJson ? JSON.parse(userJson) : MOCK_USER;
useEffect(() => {
const timer = setInterval(() => setTime(new Date().toLocaleString()), 1000);
return () => clearInterval(timer);
}, []);
useEffect(() => {
const timer = setInterval(() => setTime(new Date().toLocaleString()), 1000);
return () => clearInterval(timer);
}, []);
const handleLogout = () => {
localStorage.removeItem('isAuthenticated');
localStorage.removeItem('user');
localStorage.removeItem('token');
navigate('/login');
};
const handleLogout = () => {
localStorage.removeItem('isAuthenticated');
localStorage.removeItem('user');
localStorage.removeItem('token');
navigate('/login');
};
const menuItems = [
{ key: '/', icon: <DashboardOutlined />, label: '概览控制台', roles: ['admin', 'operator', 'viewer'] },
{ key: '/devices', icon: <ExperimentOutlined />, label: '设备管理', roles: ['admin', 'operator'] },
{ key: '/video', icon: <VideoCameraOutlined />, label: '在线视频', roles: ['admin', 'operator', 'viewer'] },
{ key: '/alerts', icon: <BellOutlined />, label: '警报中心', roles: ['admin', 'operator'] },
{ key: '/downloads', icon: <DownloadOutlined />, label: '视频下载', roles: ['admin', 'operator'] },
{ key: '/users', icon: <TeamOutlined />, label: '用户管理', roles: ['admin'] },
{ key: '/roles', icon: <UserOutlined />, label: '角色权限', roles: ['admin'] },
];
const menuItems = [
{ key: '/', icon: <DashboardOutlined />, label: '概览控制台', roles: ['admin', 'operator', 'viewer'] },
{ key: '/devices', icon: <ExperimentOutlined />, label: '设备管理', roles: ['admin', 'operator'] },
{ key: '/video', icon: <VideoCameraOutlined />, label: '在线视频', roles: ['admin', 'operator', 'viewer'] },
{ key: '/alerts', icon: <BellOutlined />, label: '警报中心', roles: ['admin', 'operator'] },
{ key: '/downloads', icon: <DownloadOutlined />, label: '视频下载', roles: ['admin', 'operator'] },
{ key: '/users', icon: <TeamOutlined />, label: '用户管理', roles: ['admin'] },
{ key: '/roles', icon: <UserOutlined />, label: '角色权限', roles: ['admin'] },
{ key: '/serialNumGenerate', icon: <UserOutlined />, label: '序列号生成', roles: ['admin'] },
];
const filteredMenu = menuItems.filter(item => item.roles.includes(user.role));
const filteredMenu = menuItems.filter(item => item.roles.includes(user.role));
const currentPathLabel = menuItems.find(i => i.key === location.pathname)?.label || '概览控制台';
const currentPathLabel = menuItems.find(i => i.key === location.pathname)?.label || '概览控制台';
return (
<ConfigProvider
theme={{
algorithm: theme.defaultAlgorithm,
token: {
colorPrimary: '#1890ff',
borderRadius: 2,
},
components: {
Layout: {
headerBg: '#fff',
siderBg: '#001529',
},
Menu: {
darkItemBg: '#001529',
darkItemSelectedBg: '#1890ff',
}
}
}}
>
<Layout style={{ minHeight: '100vh' }}>
<Sider trigger={null} collapsible collapsed={collapsed} width={200} theme="dark">
<div className="h-16 flex items-center justify-center border-b border-white/10 overflow-hidden">
<Space size="small" className="px-2">
<GlobalOutlined style={{ fontSize: 24, color: '#1890ff' }} />
{!collapsed && <span className="text-white font-bold text-lg whitespace-nowrap">RobotMaster AI</span>}
</Space>
</div>
<Menu
theme="dark"
mode="inline"
selectedKeys={[location.pathname]}
items={filteredMenu}
onClick={({ key }) => navigate(key)}
/>
{!collapsed && (
<div className="absolute bottom-4 left-4 right-4 p-2 bg-white/5 rounded text-[12px] text-gray-400">
当前权限: <span className="text-white font-bold">{user.role === 'admin' ? '系统管理员' : user.role === 'operator' ? '操作员' : '观察员'}</span>
</div>
)}
</Sider>
<Layout>
<Header className="px-6 flex items-center justify-between shadow-sm border-b border-gray-100 h-16 bg-white shrink-0 z-10">
<div className="flex items-center gap-4">
<Button
type="text"
icon={collapsed ? <MenuUnfoldOutlined /> : <MenuFoldOutlined />}
onClick={() => setCollapsed(!collapsed)}
style={{ fontSize: '16px', width: 40, height: 40 }}
/>
<Breadcrumb
items={[
{ title: '系统首页' },
{ title: currentPathLabel }
]}
/>
</div>
return (
<ConfigProvider
theme={{
algorithm: theme.defaultAlgorithm,
token: {
colorPrimary: '#1890ff',
borderRadius: 2,
},
components: {
Layout: {
headerBg: '#fff',
siderBg: '#001529',
},
Menu: {
darkItemBg: '#001529',
darkItemSelectedBg: '#1890ff',
}
}
}}
>
<Layout style={{ minHeight: '100vh' }}>
<Sider trigger={null} collapsible collapsed={collapsed} width={220} theme="dark">
<div className="h-16 flex items-center justify-center border-b border-white/10 overflow-hidden">
<Space size="small" className="px-2">
<img src={logo} alt="Logo" style={{ width: "24px", height: "24px" }} />
{!collapsed && <span className="text-white font-bold text-lg whitespace-nowrap">机器人智慧服务系统</span>}
</Space>
</div>
<Menu
theme="dark"
mode="inline"
selectedKeys={[location.pathname]}
items={filteredMenu}
onClick={({ key }) => navigate(key)}
/>
{!collapsed && (
<div className="absolute bottom-4 left-4 right-4 p-2 bg-white/5 rounded text-[12px] text-gray-400">
当前权限: <span className="text-white font-bold">{user.role === 'admin' ? '系统管理员' : user.role === 'operator' ? '操作员' : '观察员'}</span>
</div>
)}
</Sider>
<Layout>
<Header className="px-6 flex items-center justify-between shadow-sm border-b border-gray-100 h-16 bg-white shrink-0 z-10">
<div className="flex items-center gap-4">
<Button
type="text"
icon={collapsed ? <MenuUnfoldOutlined /> : <MenuFoldOutlined />}
onClick={() => setCollapsed(!collapsed)}
style={{ fontSize: '16px', width: 40, height: 40 }}
/>
<Breadcrumb
items={[
{ title: '系统首页' },
{ title: currentPathLabel }
]}
/>
</div>
<div className="flex items-center gap-6">
<div className="flex items-center gap-3 pr-6 border-r border-gray-100">
<span className="text-gray-400 font-mono text-[13px]">{time}</span>
<Badge status="success" />
<span className="text-gray-800 font-medium">{user.name}</span>
<Avatar src={user.avatar} size="small" icon={<UserOutlined />} />
</div>
<Button
type="text"
danger
icon={<LogoutOutlined />}
onClick={handleLogout}
className="font-bold text-[12px] uppercase"
>
退出登录
</Button>
</div>
</Header>
<Content className="p-4 overflow-y-auto bg-[#f4f7f9] min-h-0">
<Outlet />
</Content>
</Layout>
</Layout>
</ConfigProvider>
);
<div className="flex items-center gap-6">
<div className="flex items-center gap-3 pr-6 border-r border-gray-100">
<span className="text-gray-400 font-mono text-[13px]">{time}</span>
<Badge status="success" />
<span className="text-gray-800 font-medium">{user.name}</span>
<Avatar src={user.avatar} size="small" icon={<UserOutlined />} />
</div>
<Button
type="text"
danger
icon={<LogoutOutlined />}
onClick={handleLogout}
className="font-bold text-[12px] uppercase"
>
退出登录
</Button>
</div>
</Header>
<Content className="p-4 overflow-y-auto bg-[#f4f7f9] min-h-0">
<Outlet />
</Content>
</Layout>
</Layout>
</ConfigProvider>
);
}

View File

@@ -1,32 +1,32 @@
import React, { useState } from 'react';
import {
Table,
Input,
Button,
Tag,
Progress,
Space,
Typography,
Row,
Col,
Statistic,
Descriptions,
Tabs,
Card
import {
Table,
Input,
Button,
Tag,
Progress,
Space,
Typography,
Row,
Col,
Statistic,
Descriptions,
Tabs,
Card
} from 'antd';
import {
SearchOutlined,
PlusOutlined,
SettingOutlined,
PoweroffOutlined,
ClusterOutlined,
ArrowRightOutlined,
CloseOutlined,
DashboardOutlined,
HeatMapOutlined,
InfoCircleOutlined,
LineChartOutlined,
ThunderboltOutlined
import {
SearchOutlined,
PlusOutlined,
SettingOutlined,
PoweroffOutlined,
ClusterOutlined,
ArrowRightOutlined,
CloseOutlined,
DashboardOutlined,
HeatMapOutlined,
InfoCircleOutlined,
LineChartOutlined,
ThunderboltOutlined
} from '@ant-design/icons';
import { DEVICES } from '../constants';
import { motion, AnimatePresence } from 'motion/react';
@@ -34,239 +34,256 @@ import { motion, AnimatePresence } from 'motion/react';
const { Text, Title } = Typography;
export default function Devices() {
const [selectedDeviceId, setSelectedDeviceId] = useState<string | null>(null);
const selectedDevice = DEVICES.find(d => d.id === selectedDeviceId);
const [selectedDeviceId, setSelectedDeviceId] = useState<string | null>(null);
const selectedDevice = DEVICES.find(d => d.id === selectedDeviceId);
const columns = [
{
title: '节点身份',
dataIndex: 'name',
key: 'name',
render: (text: string, record: any) => (
<Space direction="vertical" size={0}>
<Text strong style={{ fontSize: 13 }}>{text}</Text>
<Text type="secondary" style={{ fontSize: 10, fontFamily: 'monospace' }}>{record.id} | {record.type}</Text>
</Space>
),
},
{
title: '负载/状态',
key: 'status',
render: (record: any) => (
<Space direction="vertical" size={0}>
<Text
strong
italic
style={{
fontSize: 10,
color: record.status === 'online' ? '#52c41a' : record.status === 'alert' ? '#f5222d' : '#bfbfbf'
}}
>
{record.status.toUpperCase()}
</Text>
<Space size="small">
<ClusterOutlined style={{ fontSize: 10, color: 'rgba(0,0,0,0.25)' }} />
<Text type="secondary" style={{ fontSize: 11, fontFamily: 'monospace' }}>{record.cpu}%</Text>
</Space>
</Space>
),
},
{
title: '能量效率',
dataIndex: 'battery',
key: 'battery',
render: (percent: number) => (
<Space size="middle">
<Progress
percent={percent}
size={[60, 4]}
showInfo={false}
status={percent < 20 ? 'exception' : 'active'}
strokeColor={percent < 20 ? '#f5222d' : percent < 50 ? '#faad14' : '#52c41a'}
/>
<Text style={{ fontSize: 11, fontFamily: 'monospace' }}>{percent}%</Text>
</Space>
),
},
{
title: '管理',
key: 'action',
align: 'right' as const,
render: () => (
<Space>
<Button type="text" size="small" icon={<SettingOutlined />} />
<Button type="text" size="small" danger icon={<PoweroffOutlined />} />
</Space>
),
},
];
const columns = [
{
title: '节点身份',
dataIndex: 'name',
key: 'name',
render: (text: string, record: any) => (
<Space direction="vertical" size={0}>
<Text strong style={{ fontSize: 13 }}>{text}</Text>
<Text type="secondary" style={{ fontSize: 10, fontFamily: 'monospace' }}>{record.id} | {record.type}</Text>
</Space>
),
},
{
title: '负载/状态',
key: 'status',
render: (record: any) => (
<Space direction="vertical" size={0}>
<Text
strong
italic
style={{
fontSize: 10,
color: record.status === 'online' ? '#52c41a' : record.status === 'alert' ? '#f5222d' : '#bfbfbf'
}}
>
{record.status.toUpperCase()}
</Text>
<Space size="small">
<ClusterOutlined style={{ fontSize: 10, color: 'rgba(0,0,0,0.25)' }} />
<Text type="secondary" style={{ fontSize: 11, fontFamily: 'monospace' }}>{record.cpu}%</Text>
</Space>
</Space>
),
},
{
title: '能量效率',
dataIndex: 'battery',
key: 'battery',
render: (percent: number) => (
<Space size="middle">
<Progress
percent={percent}
size={[60, 4]}
showInfo={false}
status={percent < 20 ? 'exception' : 'active'}
strokeColor={percent < 20 ? '#f5222d' : percent < 50 ? '#faad14' : '#52c41a'}
/>
<Text style={{ fontSize: 11, fontFamily: 'monospace' }}>{percent}%</Text>
</Space>
),
},
{
title: '类型',
dataIndex: 'battery',
key: 'battery',
render: (percent: number) => (
<Space size="middle">
<Progress
percent={percent}
size={[60, 4]}
showInfo={false}
status={percent < 20 ? 'exception' : 'active'}
strokeColor={percent < 20 ? '#f5222d' : percent < 50 ? '#faad14' : '#52c41a'}
/>
<Text style={{ fontSize: 11, fontFamily: 'monospace' }}>{percent}%</Text>
</Space>
),
},
{
title: '管理',
key: 'action',
align: 'right' as const,
render: () => (
<Space>
<Button type="text" size="small" icon={<SettingOutlined />} />
<Button type="text" size="small" danger icon={<PoweroffOutlined />} />
</Space>
),
},
];
return (
<div className="flex flex-col h-full gap-4">
<div className="flex items-center justify-between">
<Title level={5} style={{ margin: 0 }}>核心资产管理系统</Title>
<Space>
<Input
prefix={<SearchOutlined style={{ color: 'rgba(0,0,0,0.25)' }} />}
placeholder="搜索节点、ID或类型..."
style={{ width: 250, borderRadius: 2 }}
/>
<Button type="primary" icon={<PlusOutlined />} style={{ borderRadius: 2 }}>
接入新节点
</Button>
</Space>
</div>
return (
<div className="flex flex-col h-full gap-4">
<div className="flex items-center justify-between">
<Title level={5} style={{ margin: 0 }}>核心资产管理系统</Title>
<Space>
<Input
prefix={<SearchOutlined style={{ color: 'rgba(0,0,0,0.25)' }} />}
placeholder="搜索节点、ID或类型..."
style={{ width: 250, borderRadius: 2 }}
/>
<Button type="primary" icon={<PlusOutlined />} style={{ borderRadius: 2 }}>
接入新节点
</Button>
</Space>
</div>
<Row gutter={16} className="flex-1 overflow-hidden" style={{ minHeight: 0 }}>
<Col flex="auto" className="h-full overflow-hidden">
<Card styles={{ body: { padding: 0 } }} className="h-full overflow-hidden flex flex-col">
<Table
size="small"
columns={columns}
dataSource={DEVICES.map(d => ({ ...d, key: d.id }))}
pagination={false}
sticky
scroll={{ y: 'calc(100vh - 250px)' }}
onRow={(record) => ({
onClick: () => setSelectedDeviceId(record.id),
className: selectedDeviceId === record.id ? 'bg-blue-50' : '',
style: { cursor: 'pointer' }
})}
/>
</Card>
</Col>
<Row gutter={16} className="flex-1 " style={{ minHeight: 0, flexWrap: 'nowrap', }}>
<Col flex="auto" className="h-full overflow-hidden">
<Card styles={{ body: { padding: 0 } }} className="h-full overflow-hidden flex flex-col">
<Table
size="small"
columns={columns}
dataSource={DEVICES.map(d => ({ ...d, key: d.id }))}
pagination={false}
sticky
scroll={{ y: 'calc(100vh - 250px)' }}
onRow={(record) => ({
onClick: () => setSelectedDeviceId(record.id),
className: selectedDeviceId === record.id ? 'bg-blue-50' : '',
style: { cursor: 'pointer' }
})}
/>
</Card>
</Col>
<AnimatePresence>
{selectedDevice && (
<Col flex="0 0 340px" className="h-full">
<motion.div
initial={{ x: 340, opacity: 0 }}
animate={{ x: 0, opacity: 1 }}
exit={{ x: 340, opacity: 0 }}
className="h-full"
>
<Card
className="h-full overflow-hidden"
styles={{ body: { padding: 0, height: '100%', display: 'flex', flexDirection: 'column' } }}
>
<div className="p-4 border-b border-gray-100 flex justify-between items-start bg-gray-50">
<div>
<Text type="secondary" style={{ fontSize: 10, letterSpacing: 2, textTransform: 'uppercase', display: 'block' }}>
Asset Intelligence / v4.0
</Text>
<Title level={4} style={{ margin: '4px 0' }}>{selectedDevice.name}</Title>
<Space>
<Tag color="blue" bordered={false} style={{ fontSize: 10, fontWeight: 'bold' }}>{selectedDevice.type}</Tag>
<Text type="secondary" style={{ fontSize: 11, fontFamily: 'monospace' }}>ID: {selectedDevice.id}</Text>
</Space>
</div>
<Button
type="text"
icon={<CloseOutlined />}
onClick={() => setSelectedDeviceId(null)}
/>
</div>
<AnimatePresence>
{selectedDevice && (
<Col flex="0 0 340px" className="h-full">
<motion.div
initial={{ x: 340, opacity: 0 }}
animate={{ x: 0, opacity: 1 }}
exit={{ x: 340, opacity: 0 }}
className="h-full"
>
<Card
className="h-full overflow-hidden"
styles={{ body: { padding: 0, height: '100%', display: 'flex', flexDirection: 'column' } }}
>
<div className="p-4 border-b border-gray-100 flex justify-between items-start bg-gray-50">
<div>
<Text type="secondary" style={{ fontSize: 10, letterSpacing: 2, textTransform: 'uppercase', display: 'block' }}>
Asset Intelligence / v4.0
</Text>
<Title level={4} style={{ margin: '4px 0' }}>{selectedDevice.name}</Title>
<Space>
<Tag color="blue" bordered={false} style={{ fontSize: 10, fontWeight: 'bold' }}>{selectedDevice.type}</Tag>
<Text type="secondary" style={{ fontSize: 11, fontFamily: 'monospace' }}>ID: {selectedDevice.id}</Text>
</Space>
</div>
<Button
type="text"
icon={<CloseOutlined />}
onClick={() => setSelectedDeviceId(null)}
/>
</div>
<div className="flex-1 overflow-y-auto">
<Tabs
defaultActiveKey="1"
className="px-4"
items={[
{
key: '1',
label: '基本信息',
children: (
<div className="space-y-6 pt-4 pb-4">
<Descriptions column={1} size="small" bordered>
<Descriptions.Item label="设备名称">{selectedDevice.name}</Descriptions.Item>
<Descriptions.Item label="设备 ID">{selectedDevice.id}</Descriptions.Item>
<Descriptions.Item label="设备类型">{selectedDevice.type}</Descriptions.Item>
<Descriptions.Item label="最后心跳">{selectedDevice.lastUpdate}</Descriptions.Item>
<Descriptions.Item label="固件版本">FW_2.5.4_REL</Descriptions.Item>
<Descriptions.Item label="接入协议">MQTT_SSL</Descriptions.Item>
</Descriptions>
<div className="flex-1 overflow-y-auto">
<Tabs
defaultActiveKey="1"
className="px-4"
items={[
{
key: '1',
label: '基本信息',
children: (
<div className="space-y-6 pt-4 pb-4">
<Descriptions column={1} size="small" bordered>
<Descriptions.Item label="设备名称">{selectedDevice.name}</Descriptions.Item>
<Descriptions.Item label="设备 ID">{selectedDevice.id}</Descriptions.Item>
<Descriptions.Item label="设备类型">{selectedDevice.type}</Descriptions.Item>
<Descriptions.Item label="最后心跳">{selectedDevice.lastUpdate}</Descriptions.Item>
<Descriptions.Item label="固件版本">FW_2.5.4_REL</Descriptions.Item>
<Descriptions.Item label="接入协议">MQTT_SSL</Descriptions.Item>
</Descriptions>
<div className="p-3 bg-blue-50 border border-blue-100 rounded">
<Space size="small" align="start">
<InfoCircleOutlined style={{ color: '#1890ff', marginTop: 3 }} />
<Text type="secondary" style={{ fontSize: 11 }}>
该设备目前运行正常,已通过节点身份验证,正在进行全量数据透传。
</Text>
</Space>
</div>
</div>
)
},
{
key: '2',
label: '运行状态',
children: (
<div className="space-y-6 pt-4 pb-4">
<Row gutter={[12, 12]}>
<Col span={12}>
<Card size="small" bordered styles={{ body: { padding: 12 } }} style={{ backgroundColor: '#fafafa' }}>
<Statistic title={<Space><ClusterOutlined />负载率</Space>} value={selectedDevice.cpu} suffix="%" valueStyle={{ fontSize: 16, fontFamily: 'monospace' }} />
</Card>
</Col>
<Col span={12}>
<Card size="small" bordered styles={{ body: { padding: 12 } }} style={{ backgroundColor: '#fafafa' }}>
<Statistic title={<Space><HeatMapOutlined />核心温度</Space>} value={selectedDevice.temp} suffix="°C" valueStyle={{ fontSize: 16, fontFamily: 'monospace', color: '#f5222d' }} />
</Card>
</Col>
<Col span={12}>
<Card size="small" bordered styles={{ body: { padding: 12 } }} style={{ backgroundColor: '#fafafa' }}>
<Statistic title={<Space><ThunderboltOutlined />剩余能量</Space>} value={selectedDevice.battery} suffix="%" valueStyle={{ fontSize: 16, fontFamily: 'monospace', color: '#52c41a' }} />
</Card>
</Col>
<Col span={12}>
<Card size="small" bordered styles={{ body: { padding: 12 } }} style={{ backgroundColor: '#fafafa' }}>
<Statistic title={<Space><DashboardOutlined />系统健康</Space>} value={98.2} suffix="%" valueStyle={{ fontSize: 16, fontFamily: 'monospace' }} />
</Card>
</Col>
</Row>
<div className="p-3 bg-blue-50 border border-blue-100 rounded">
<Space size="small" align="start">
<InfoCircleOutlined style={{ color: '#1890ff', marginTop: 3 }} />
<Text type="secondary" style={{ fontSize: 11 }}>
该设备目前运行正常,已通过节点身份验证,正在进行全量数据透传。
</Text>
</Space>
</div>
</div>
)
},
{
key: '2',
label: '运行状态',
children: (
<div className="space-y-6 pt-4 pb-4">
<Row gutter={[12, 12]}>
<Col span={12}>
<Card size="small" bordered styles={{ body: { padding: 12 } }} style={{ backgroundColor: '#fafafa' }}>
<Statistic title={<Space><ClusterOutlined />负载率</Space>} value={selectedDevice.cpu} suffix="%" valueStyle={{ fontSize: 16, fontFamily: 'monospace' }} />
</Card>
</Col>
<Col span={12}>
<Card size="small" bordered styles={{ body: { padding: 12 } }} style={{ backgroundColor: '#fafafa' }}>
<Statistic title={<Space><HeatMapOutlined />核心温度</Space>} value={selectedDevice.temp} suffix="°C" valueStyle={{ fontSize: 16, fontFamily: 'monospace', color: '#f5222d' }} />
</Card>
</Col>
<Col span={12}>
<Card size="small" bordered styles={{ body: { padding: 12 } }} style={{ backgroundColor: '#fafafa' }}>
<Statistic title={<Space><ThunderboltOutlined />剩余能量</Space>} value={selectedDevice.battery} suffix="%" valueStyle={{ fontSize: 16, fontFamily: 'monospace', color: '#52c41a' }} />
</Card>
</Col>
<Col span={12}>
<Card size="small" bordered styles={{ body: { padding: 12 } }} style={{ backgroundColor: '#fafafa' }}>
<Statistic title={<Space><DashboardOutlined />系统健康</Space>} value={98.2} suffix="%" valueStyle={{ fontSize: 16, fontFamily: 'monospace' }} />
</Card>
</Col>
</Row>
<div className="pt-2 border-t border-gray-100">
<Text strong type="secondary" style={{ fontSize: 11, textTransform: 'uppercase', display: 'block', marginBottom: 12 }}>
实时动态 (SIGNAL)
</Text>
<Space direction="vertical" className="w-full" size="small">
<div className="flex justify-between items-center bg-gray-50 p-2 rounded">
<Text type="secondary" style={{ fontSize: 11 }}>上行链路速率</Text>
<Text style={{ fontFamily: 'monospace', fontSize: 11 }}>1.2 Mbps</Text>
</div>
<div className="flex justify-between items-center bg-gray-50 p-2 rounded">
<Text type="secondary" style={{ fontSize: 11 }}>下行链路速率</Text>
<Text style={{ fontFamily: 'monospace', fontSize: 11 }}>0.4 Mbps</Text>
</div>
<div className="flex justify-between items-center bg-gray-50 p-2 rounded">
<Text type="secondary" style={{ fontSize: 11 }}>当前信号强度</Text>
<Tag color="success" style={{ margin: 0, fontSize: 10 }}>EXCELLENT</Tag>
</div>
</Space>
</div>
</div>
)
}
]}
/>
</div>
<div className="pt-2 border-t border-gray-100">
<Text strong type="secondary" style={{ fontSize: 11, textTransform: 'uppercase', display: 'block', marginBottom: 12 }}>
实时动态 (SIGNAL)
</Text>
<Space direction="vertical" className="w-full" size="small">
<div className="flex justify-between items-center bg-gray-50 p-2 rounded">
<Text type="secondary" style={{ fontSize: 11 }}>上行链路速率</Text>
<Text style={{ fontFamily: 'monospace', fontSize: 11 }}>1.2 Mbps</Text>
</div>
<div className="flex justify-between items-center bg-gray-50 p-2 rounded">
<Text type="secondary" style={{ fontSize: 11 }}>下行链路速率</Text>
<Text style={{ fontFamily: 'monospace', fontSize: 11 }}>0.4 Mbps</Text>
</div>
<div className="flex justify-between items-center bg-gray-50 p-2 rounded">
<Text type="secondary" style={{ fontSize: 11 }}>当前信号强度</Text>
<Tag color="success" style={{ margin: 0, fontSize: 10 }}>EXCELLENT</Tag>
</div>
</Space>
</div>
</div>
)
}
]}
/>
</div>
<div className="p-4 border-t border-gray-100 bg-gray-50">
<Space direction="vertical" className="w-full" size="small">
<Button type="primary" block icon={<ArrowRightOutlined />} style={{ borderRadius: 2 }}>
发起远程诊断
</Button>
<Button block icon={<LineChartOutlined />} style={{ borderRadius: 2 }}>
同步设备策略
</Button>
</Space>
</div>
</Card>
</motion.div>
</Col>
)}
</AnimatePresence>
</Row>
</div>
);
<div className="p-4 border-t border-gray-100 bg-gray-50">
<Space direction="vertical" className="w-full" size="small">
<Button type="primary" block icon={<ArrowRightOutlined />} style={{ borderRadius: 2 }}>
发起远程诊断
</Button>
<Button block icon={<LineChartOutlined />} style={{ borderRadius: 2 }}>
同步设备策略
</Button>
</Space>
</div>
</Card>
</motion.div>
</Col>
)}
</AnimatePresence>
</Row>
</div>
);
}

View File

@@ -1,150 +1,150 @@
import React from 'react';
import { useNavigate } from 'react-router-dom';
import {
Form,
Input,
Button,
Checkbox,
Typography,
Space,
Card,
message
import {
Form,
Input,
Button,
Checkbox,
Typography,
Space,
Card,
message
} from 'antd';
import {
UserOutlined,
LockOutlined,
RocketOutlined,
SafetyCertificateOutlined,
ArrowRightOutlined
import {
UserOutlined,
LockOutlined,
RocketOutlined,
SafetyCertificateOutlined,
ArrowRightOutlined
} from '@ant-design/icons';
import { motion } from 'motion/react';
const { Text, Title } = Typography;
export default function Login() {
const navigate = useNavigate();
const navigate = useNavigate();
const onFinish = (values: any) => {
// 模拟登录逻辑
console.log('Login attempt:', values);
// 根据用户名模拟不同的角色用于演示
let role = 'viewer';
let name = '观察员';
if (values.username === 'admin') {
role = 'admin';
name = '系统管理员';
} else if (values.username === 'operator') {
role = 'operator';
name = '操作员';
}
const onFinish = (values: any) => {
// 模拟登录逻辑
console.log('Login attempt:', values);
// 存储用户信息
const userInfo = {
username: values.username,
name: name,
role: role,
avatar: `https://api.dicebear.com/7.x/avataaars/svg?seed=${values.username}`
};
// 根据用户名模拟不同的角色用于演示
let role = 'viewer';
let name = '观察员';
localStorage.setItem('isAuthenticated', 'true');
localStorage.setItem('token', 'mock_token_' + Date.now()); // 模拟 Token
localStorage.setItem('user', JSON.stringify(userInfo));
if (values.username === 'admin') {
role = 'admin';
name = '系统管理员';
} else if (values.username === 'operator') {
role = 'operator';
name = '操作员';
}
message.success(`欢迎回来, ${name}`);
navigate('/');
};
// 存储用户信息
const userInfo = {
username: values.username,
name: name,
role: role,
avatar: `https://api.dicebear.com/7.x/avataaars/svg?seed=${values.username}`
};
return (
<div className="min-h-screen bg-[#001529] flex items-center justify-center p-4 relative overflow-hidden">
{/* Background Decor */}
<div className="absolute inset-0 overflow-hidden pointer-events-none opacity-20">
<div className="absolute top-0 left-0 w-full h-full bg-[radial-gradient(circle_at_50%_50%,#1890ff_0%,transparent_50%)] opacity-20" />
</div>
localStorage.setItem('isAuthenticated', 'true');
localStorage.setItem('token', 'mock_token_' + Date.now()); // 模拟 Token
localStorage.setItem('user', JSON.stringify(userInfo));
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
style={{ width: '100%', maxWidth: 400 }}
>
<Card
bordered={false}
className="shadow-2xl overflow-hidden"
styles={{ body: { padding: 0 } }}
>
{/* Header */}
<div className="bg-[#001529] p-8 text-center border-b border-white/10">
<div className="inline-flex items-center justify-center w-12 h-12 rounded bg-blue-500/10 text-[#1890ff] mb-4 border border-blue-500/20">
<RocketOutlined style={{ fontSize: 24 }} />
</div>
<Title level={4} style={{ color: '#fff', margin: 0, letterSpacing: 1 }}>RobotMaster AI</Title>
<Text style={{ color: 'rgba(255,255,255,0.45)', fontSize: 10, marginTop: 4, display: 'block', letterSpacing: 2 }}>机器人智慧服务系统</Text>
</div>
message.success(`欢迎回来, ${name}`);
navigate('/');
};
{/* Form */}
<div className="p-8">
<Form
name="login"
layout="vertical"
onFinish={onFinish}
autoComplete="off"
size="large"
>
<Form.Item
label={<Text strong type="secondary" style={{ fontSize: 11, textTransform: 'uppercase' }}><UserOutlined style={{ color: '#1890ff', marginRight: 8 }} />账号名称</Text>}
name="username"
rules={[{ required: true, message: '请输入管理员账号' }]}
>
<Input placeholder="请输入管理员账号" style={{ borderRadius: 2 }} />
</Form.Item>
return (
<div className="min-h-screen bg-[#001529] flex items-center justify-center p-4 relative overflow-hidden">
{/* Background Decor */}
<div className="absolute inset-0 overflow-hidden pointer-events-none opacity-20">
<div className="absolute top-0 left-0 w-full h-full bg-[radial-gradient(circle_at_50%_50%,#1890ff_0%,transparent_50%)] opacity-20" />
</div>
<Form.Item
label={<Text strong type="secondary" style={{ fontSize: 11, textTransform: 'uppercase' }}><LockOutlined style={{ color: '#1890ff', marginRight: 8 }} />访问令牌 / 密码</Text>}
name="password"
rules={[{ required: true, message: '请输入密码' }]}
>
<Input.Password placeholder="••••••••" style={{ borderRadius: 2 }} />
</Form.Item>
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
style={{ width: '100%', maxWidth: 400 }}
>
<Card
bordered={false}
className="shadow-2xl overflow-hidden"
styles={{ body: { padding: 0 } }}
>
{/* Header */}
<div className="bg-[#001529] p-8 text-center border-b border-white/10">
<div className="inline-flex items-center justify-center w-12 h-12 rounded bg-blue-500/10 text-[#1890ff] mb-4 border border-blue-500/20">
<RocketOutlined style={{ fontSize: 24 }} />
</div>
<Title level={4} style={{ color: '#fff', margin: 0, letterSpacing: 1 }}>机器人智慧服务系统</Title>
<Text style={{ color: 'rgba(255,255,255,0.45)', fontSize: 10, marginTop: 4, display: 'block', letterSpacing: 2 }}>机器人智慧服务系统</Text>
</div>
<div className="flex items-center justify-between mb-6">
<Form.Item name="remember" valuePropName="checked" noStyle>
<Checkbox><Text type="secondary" style={{ fontSize: 12 }}>记住会话</Text></Checkbox>
</Form.Item>
<Button type="link" size="small" style={{ fontSize: 12 }}>找回凭据?</Button>
</div>
{/* Form */}
<div className="p-8">
<Form
name="login"
layout="vertical"
onFinish={onFinish}
autoComplete="off"
size="large"
>
<Form.Item
label={<Text strong type="secondary" style={{ fontSize: 11, textTransform: 'uppercase' }}><UserOutlined style={{ color: '#1890ff', marginRight: 8 }} />账号名称</Text>}
name="username"
rules={[{ required: true, message: '请输入管理员账号' }]}
>
<Input placeholder="请输入管理员账号" style={{ borderRadius: 2 }} />
</Form.Item>
<Form.Item>
<Button
type="primary"
htmlType="submit"
block
icon={<SafetyCertificateOutlined />}
style={{ borderRadius: 2, height: 44, fontWeight: 'bold', fontSize: 14 }}
>
核验并进入系统 <ArrowRightOutlined />
</Button>
</Form.Item>
</Form>
</div>
<Form.Item
label={<Text strong type="secondary" style={{ fontSize: 11, textTransform: 'uppercase' }}><LockOutlined style={{ color: '#1890ff', marginRight: 8 }} />访问令牌 / 密码</Text>}
name="password"
rules={[{ required: true, message: '请输入密码' }]}
>
<Input.Password placeholder="••••••••" style={{ borderRadius: 2 }} />
</Form.Item>
{/* Footer */}
<div className="px-8 py-4 bg-gray-50 border-t border-gray-100 flex justify-between items-center">
<Text type="secondary" style={{ fontSize: 10, fontFamily: 'monospace' }}>System Version: v4.2.1-stable</Text>
<Space size={4}>
<div className="w-1.5 h-1.5 rounded-full bg-green-500 animate-pulse" />
<Text strong type="secondary" style={{ fontSize: 10, textTransform: 'uppercase' }}>Server Online</Text>
</Space>
</div>
</Card>
</motion.div>
<div className="flex items-center justify-between mb-6">
<Form.Item name="remember" valuePropName="checked" noStyle>
<Checkbox><Text type="secondary" style={{ fontSize: 12 }}>记住会话</Text></Checkbox>
</Form.Item>
<Button type="link" size="small" style={{ fontSize: 12 }}>找回凭据?</Button>
</div>
{/* Security Notice */}
<div className="absolute bottom-8 text-center w-full px-4">
<Text strong style={{ color: 'rgba(255,255,255,0.2)', fontSize: 10, letterSpacing: 4 }}>
AUTHORIZED PERSONNEL ONLY | ENCRYPTED LINK | TRACE ENABLED
</Text>
</div>
</div>
);
<Form.Item>
<Button
type="primary"
htmlType="submit"
block
icon={<SafetyCertificateOutlined />}
style={{ borderRadius: 2, height: 44, fontWeight: 'bold', fontSize: 14 }}
>
核验并进入系统 <ArrowRightOutlined />
</Button>
</Form.Item>
</Form>
</div>
{/* Footer */}
<div className="px-8 py-4 bg-gray-50 border-t border-gray-100 flex justify-between items-center">
<Text type="secondary" style={{ fontSize: 10, fontFamily: 'monospace' }}>System Version: v4.2.1-stable</Text>
<Space size={4}>
<div className="w-1.5 h-1.5 rounded-full bg-green-500 animate-pulse" />
<Text strong type="secondary" style={{ fontSize: 10, textTransform: 'uppercase' }}>Server Online</Text>
</Space>
</div>
</Card>
</motion.div>
{/* Security Notice */}
<div className="absolute bottom-8 text-center w-full px-4">
<Text strong style={{ color: 'rgba(255,255,255,0.2)', fontSize: 10, letterSpacing: 4 }}>
AUTHORIZED PERSONNEL ONLY | ENCRYPTED LINK | TRACE ENABLED
</Text>
</div>
</div>
);
}

View File

@@ -0,0 +1,260 @@
import React, { useState, useRef } from 'react';
import { Form, Select, Input, Button, Space, message, Card, Typography, Row, Col } from 'antd';
import QRCode from 'qrcode';
import axios from 'axios';
const { Text } = Typography;
const SerialNumGenerate = () => {
const [form] = Form.useForm();
const [qrUrl, setQrUrl] = useState('');
const [qrText, setQrText] = useState('');
const [loading, setLoading] = useState(false);
const qrRef = useRef(null);
// 查询状态
const [queryCode, setQueryCode] = useState('');
const [queryLoading, setQueryLoading] = useState(false);
const initialValues = {
model: 'MC700',
config: 'AIR',
country: '中国',
province: '江苏',
code: '',
type: 'mower',
};
// 生成二维码(纯字符串+显示明文)
const generateQRCode = async () => {
try {
const values = await form.validateFields();
const timestamp = new Date().getTime();
const qrContent = `${values.model}-${values.config}-${values.type}-${values.country}-${values.province}-${values.code}-${timestamp}`;
const url = await QRCode.toDataURL(qrContent);
setQrUrl(url);
setQrText(qrContent);
message.success('二维码生成成功!');
} catch (error) {
message.error('请完善信息');
console.error(error);
}
};
// 保存到数据库
const saveToDatabase = async () => {
if (!qrUrl) {
message.warning('先生成二维码');
return;
}
setLoading(true);
try {
const values = await form.validateFields();
const timestamp = new Date().getTime();
const data = { ...values, timestamp, qrCode: qrUrl, qrText: qrText };
await axios.post('/api/save-qrcode', data);
message.success('已保存到数据库!');
} catch (err) {
message.error('保存失败');
} finally {
setLoading(false);
}
};
// 查询二维码
const handleQueryQRCode = async () => {
if (!queryCode) {
message.warning('请输入编号');
return;
}
setQueryLoading(true);
try {
const res = await axios.get('/api/query-qrcode', { params: { code: queryCode } });
if (res.data?.qrCode) {
setQrUrl(res.data.qrCode);
setQrText(res.data.qrText || '');
message.success('查询成功!');
} else {
message.warning('未找到该编号的二维码');
}
} catch (err) {
message.error('查询失败');
} finally {
setQueryLoading(false);
}
};
return (
<div style={{ padding: '40px 20px', background: '#f0f2f5', minHeight: '100vh' }}>
<Card
title="序列号二维码生成器"
style={{
maxWidth: 900,
margin: '0 auto',
borderRadius: 12,
boxShadow: '0 4px 20px rgba(0,0,0,0.08)',
padding: '20px',
}}
headStyle={{
fontSize: '20px',
fontWeight: 600,
textAlign: 'center',
borderBottom: '1px solid #f0f0f0',
paddingBottom: 16,
}}
>
{/* 核心:Row+Col 左右分栏布局 */}
<Row gutter={[32, 24]}>
{/* 左侧:表单区域 */}
<Col xs={24} md={14}>
<Form
form={form}
initialValues={initialValues}
labelCol={{ md: 5 }}
wrapperCol={{ md: 19 }}
size="large"
>
<Form.Item name="model" label="型号" rules={[{ required: true, message: '请选择型号' }]}>
<Select placeholder="选择型号">
<Select.Option value="MC700">MC700</Select.Option>
<Select.Option value="MC800">MC800</Select.Option>
<Select.Option value="MC900">MC900</Select.Option>
</Select>
</Form.Item>
<Form.Item name="config" label="配置" rules={[{ required: true, message: '请选择配置' }]}>
<Select placeholder="选择配置">
<Select.Option value="AIR">AIR</Select.Option>
<Select.Option value="PRO">PRO</Select.Option>
<Select.Option value="MAX">MAX</Select.Option>
</Select>
</Form.Item>
<Form.Item name="type" label="类型" rules={[{ required: true, message: '请选择类型' }]}>
<Select placeholder="选择类型">
<Select.Option value="mower">割草机</Select.Option>
<Select.Option value="vacuum">巡检机</Select.Option>
</Select>
</Form.Item>
<Form.Item name="country" label="国家" rules={[{ required: true, message: '请选择国家' }]}>
<Select placeholder="选择国家">
<Select.Option value="中国">中国</Select.Option>
<Select.Option value="美国">美国</Select.Option>
<Select.Option value="日本">日本</Select.Option>
</Select>
</Form.Item>
<Form.Item name="province" label="省份" rules={[{ required: true, message: '请选择省份' }]}>
<Select placeholder="选择省份">
<Select.Option value="江苏">江苏</Select.Option>
<Select.Option value="浙江">浙江</Select.Option>
<Select.Option value="广东">广东</Select.Option>
</Select>
</Form.Item>
<Form.Item name="code" label="编号" rules={[{ required: true, message: '请输入编号' }]}>
<Input placeholder="请输入唯一编号" />
</Form.Item>
<Form.Item wrapperCol={{ offset: 5 }} style={{ marginTop: 10 }}>
<Button type="primary" onClick={generateQRCode} block>
生成二维码(带时间戳)
</Button>
</Form.Item>
</Form>
{/* 查询区域(放在左侧底部) */}
<div style={{
marginTop: 20,
padding: '16px',
background: '#f9fbfc',
borderRadius: 8,
border: '1px solid #e8e8e8'
}}>
<div style={{ marginBottom: 10, fontWeight: 500, color: '#1677ff' }}>
🔍 查询历史二维码
</div>
<Space.Compact style={{ width: '100%' }}>
<Input
placeholder="输入编号查询"
value={queryCode}
onChange={(e) => setQueryCode(e.target.value)}
/>
<Button type="primary" loading={queryLoading} onClick={handleQueryQRCode}>
查询二维码
</Button>
</Space.Compact>
</div>
</Col>
{/* 右侧:二维码内容+图片区域(固定在右侧,不拉长页面) */}
<Col xs={24} md={10}>
<div style={{
height: '100%',
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
padding: '20px',
background: '#fafafa',
borderRadius: 12,
border: '1px dashed #d9d9d9',
minHeight: 480,
}}>
{/* 二维码内容文字(右侧顶部) */}
{qrText && (
<div style={{
padding: '12px 16px',
background: '#e6f7ff',
borderRadius: 8,
marginBottom: 20,
width: '100%',
textAlign: 'center',
}}>
<Text strong style={{ fontSize: 14, color: '#0050b3', wordBreak: 'break-all' }}>
二维码内容:{qrText}
</Text>
</div>
)}
{/* 二维码图片(右侧中间) */}
{qrUrl ? (
<div style={{ textAlign: 'center' }}>
<img
ref={qrRef}
src={qrUrl}
alt="二维码"
style={{
width: 240,
height: 240,
borderRadius: 8,
boxShadow: '0 2px 12px rgba(0,0,0,0.1)',
}}
/>
</div>
) : (
<div style={{ color: '#999', textAlign: 'center', padding: '60px 0' }}>
请先生成二维码
</div>
)}
{/* 操作按钮(右侧底部) */}
<Space size="middle" style={{ marginTop: 24 }}>
<Button onClick={() => qrRef.current && window.open(qrRef.current.src)}>
下载二维码
</Button>
<Button type="primary" loading={loading} onClick={saveToDatabase}>
保存到数据库
</Button>
</Space>
</div>
</Col>
</Row>
</Card>
</div>
);
};
export default SerialNumGenerate;

View File

@@ -10,53 +10,58 @@ import Alerts from '../pages/Alerts';
import Downloads from '../pages/Downloads';
import Roles from '../pages/Roles';
import Users from '../pages/Users';
import SerialNumGenerate from '../pages/SerialNumGenerate';
export const router = createBrowserRouter([
{
path: '/login',
element: <Login />,
},
{
element: <ProtectedRoute />,
children: [
{
path: '/',
element: <Layout />,
children: [
{
index: true,
element: <Home />,
},
{
path: 'devices',
element: <Devices />,
},
{
path: 'video',
element: <VideoControl />,
},
{
path: 'alerts',
element: <Alerts />,
},
{
path: 'downloads',
element: <Downloads />,
},
{
path: 'roles',
element: <Roles />,
},
{
path: 'users',
element: <Users />,
},
{
path: '*',
element: <div className="p-10 text-center font-bold text-gray-400">模块开发中...</div>,
},
],
},
],
},
{
path: '/login',
element: <Login />,
},
{
element: <ProtectedRoute />,
children: [
{
path: '/',
element: <Layout />,
children: [
{
index: true,
element: <Home />,
},
{
path: 'devices',
element: <Devices />,
},
{
path: 'video',
element: <VideoControl />,
},
{
path: 'alerts',
element: <Alerts />,
},
{
path: 'downloads',
element: <Downloads />,
},
{
path: 'roles',
element: <Roles />,
},
{
path: 'users',
element: <Users />,
},
{
path: 'serialNumGenerate',
element: <SerialNumGenerate />,
},
{
path: '*',
element: <div className="p-10 text-center font-bold text-gray-400">模块开发中...</div>,
},
],
},
],
},
]);