根据二级路由 优化控制状态界面
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Layout, Typography, Menu } from 'antd';
|
||||
import { Layout, Typography, Menu, Sider } from 'antd';
|
||||
import { AimOutlined, AppstoreOutlined, SettingOutlined, BranchesOutlined } from '@ant-design/icons';
|
||||
import DeviceOverviewPage from '../components/devices/DeviceOverviewPage';
|
||||
import DeviceStatusPage from '../components/devices/DeviceStatusPage';
|
||||
@@ -9,7 +9,7 @@ import { RootState } from '../store';
|
||||
import WayLinePage from '../components/devices/WayLinePage';
|
||||
import RobotTaskPage from '../components/devices/RobotTaskPage';
|
||||
|
||||
const { Header, Content } = Layout;
|
||||
const { Content } = Layout;
|
||||
const { Text } = Typography;
|
||||
|
||||
|
||||
@@ -17,59 +17,33 @@ export default function DeviceIndexPage() {
|
||||
const [activeTab, setActiveTab] = useState('overview');
|
||||
const [selectedSn, setSelectedSn] = useState(null);
|
||||
const { stationId } = useSelector((state: RootState) => state.station);
|
||||
const [devices, setDevices] = useState([]);
|
||||
const [planedevices, setPlaneDevices] = useState([]);
|
||||
|
||||
const [devicesAll, setDevicesAll] = useState([]);
|
||||
const { userInfo } = useSelector((state: RootState) => state.user);
|
||||
|
||||
|
||||
const menuItems = [
|
||||
{ key: 'overview', label: '装备总览', icon: <AppstoreOutlined /> },
|
||||
{ key: 'status', label: '设备状态', icon: <SettingOutlined /> },
|
||||
{ key: 'wayLineTask', label: '航线任务', icon: <AimOutlined /> },
|
||||
{ key: 'robotTask', label: '机器人任务', icon: <BranchesOutlined /> },
|
||||
];
|
||||
|
||||
// 获取设备列表(用于默认选择第一个)
|
||||
const fetchAllData = async () => {
|
||||
if (!stationId) return;
|
||||
|
||||
try {
|
||||
const [deviceRes, planeRes] = await Promise.all([
|
||||
getSiteDevice({ siteId: stationId, pageSize: 9999, pageNum: 1, orgId: userInfo.orgId }),
|
||||
getSiteUAVList(stationId),
|
||||
]);
|
||||
|
||||
const devData = deviceRes?.code === 200 ? (deviceRes.rows || []) : [];
|
||||
let planeData = planeRes?.code === 200 ? (planeRes?.rows || []) : [];
|
||||
|
||||
planeData = planeData.map(item => ({
|
||||
...item,
|
||||
type: 'plane',
|
||||
lastRunningStatus: {
|
||||
longitude: item.longitude || 0,
|
||||
latitude: item.latitude || 0,
|
||||
},
|
||||
deviceAlias: item.drone_callsign || item.device_sn || '无人机',
|
||||
}));
|
||||
|
||||
setDevices(devData);
|
||||
setPlaneDevices(planeData);
|
||||
const all = [...devData, ...planeData];
|
||||
setDevicesAll(all);
|
||||
|
||||
// 默认选中第一个设备
|
||||
if (!selectedSn && all.length > 0) {
|
||||
setSelectedSn(all[0].device_sn || all[0].serialNumber);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('数据请求失败', err);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchAllData();
|
||||
}, [stationId]);
|
||||
|
||||
const handleViewStatus = (sn) => {
|
||||
setSelectedSn(sn);
|
||||
setActiveTab('status');
|
||||
};
|
||||
|
||||
// 切换菜单时,如果是航线任务或机器人任务,确保选择的是第一个设备
|
||||
const handleMenuClick = ({ key }) => {
|
||||
setActiveTab(key);
|
||||
console.log('切换到', key, '当前选中设备SN', selectedSn);
|
||||
// 如果没有选择设备,自动选择第一个
|
||||
if ((key === 'wayLineTask' || key === 'robotTask') && devicesAll.length > 0) {
|
||||
setSelectedSn(devicesAll[0].device_sn || devicesAll[0].serialNumber);
|
||||
}
|
||||
};
|
||||
|
||||
const renderContent = () => {
|
||||
if (activeTab === 'overview') {
|
||||
@@ -79,24 +53,58 @@ export default function DeviceIndexPage() {
|
||||
onDeviceSelect={(sn) => setSelectedSn(sn)}
|
||||
/>;
|
||||
}
|
||||
|
||||
|
||||
if (activeTab === 'status') {
|
||||
return <DeviceStatusPage
|
||||
serialNumber={selectedSn}
|
||||
onDeviceChange={(sn) => setSelectedSn(sn)}
|
||||
/>;
|
||||
}
|
||||
if (activeTab === 'wayLineTask') return <WayLinePage />;
|
||||
if (activeTab === 'robotTask') return <RobotTaskPage />;
|
||||
return null;
|
||||
};
|
||||
|
||||
return (
|
||||
<Layout style={{ minHeight: '100vh', overflow: 'hidden', scrollbarWidth: "thin", scrollbarColor: '#ccc transparent' }}>
|
||||
<div style={{ padding: '12px 16px 8px', borderBottom: '1px solid #f0f0f0', background: '#fff' }}>
|
||||
<Typography.Title level={4} style={{ margin: 0, fontSize: 'clamp(14px, 1.2vw, 18px)' }}>装备控制</Typography.Title>
|
||||
</div>
|
||||
<Layout>
|
||||
<Sider
|
||||
width={180}
|
||||
style={{
|
||||
background: '#fff',
|
||||
borderRight: '1px solid #f0f0f0',
|
||||
overflow: 'auto',
|
||||
height: 'calc(100vh - 52px)',
|
||||
left: 0,
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
}}
|
||||
theme="light"
|
||||
>
|
||||
<Menu
|
||||
mode="inline"
|
||||
selectedKeys={[activeTab]}
|
||||
onClick={handleMenuClick}
|
||||
items={menuItems}
|
||||
style={{
|
||||
border: '0',
|
||||
paddingTop: 8,
|
||||
}}
|
||||
/>
|
||||
</Sider>
|
||||
|
||||
|
||||
<Content style={{
|
||||
maxHeight: 'calc(100vh - 40px)',
|
||||
overflowY: 'auto',
|
||||
background: '#f5f7fa',
|
||||
padding: '8px 0px',
|
||||
scrollbarWidth: "thin"
|
||||
}}>
|
||||
{renderContent()}
|
||||
</Content>
|
||||
<Content style={{
|
||||
maxHeight: 'calc(100vh - 52px)',
|
||||
overflowY: 'auto',
|
||||
background: '#f5f7fa',
|
||||
padding: '8px 12px',
|
||||
scrollbarWidth: "thin"
|
||||
}}>
|
||||
{renderContent()}
|
||||
</Content>
|
||||
</Layout>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user