根据二级路由 优化控制状态界面
This commit is contained in:
@@ -53,7 +53,7 @@ const logs = [
|
||||
{ time: '10:05:22', device: 'RBT-01', type: '事件', desc: '电量较低,建议回充', level: '低电量' },
|
||||
];
|
||||
|
||||
export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceSelect }) {
|
||||
export default function DeviceOverviewPage() {
|
||||
const { userInfo } = useSelector((state: RootState) => state.user);
|
||||
const { stationId } = useSelector((state: RootState) => state.station);
|
||||
|
||||
@@ -68,6 +68,7 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
|
||||
const [devicesAll, setDevicesAll] = useState([]);
|
||||
const [taskStats, setTaskStats] = useState({ completed: 12, total: 15 });
|
||||
const [deviceStatistics, setDeviceStatistics] = useState(null);
|
||||
const [currentSelectedRobot, setCurrentSelectedRobot] = useState(null);
|
||||
|
||||
// 编辑机器人弹窗相关
|
||||
const [editRobotModalOpen, setEditRobotModalOpen] = useState(false);
|
||||
@@ -115,6 +116,7 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
|
||||
console.error('数据请求失败', err);
|
||||
}
|
||||
};
|
||||
const onViewStatus = (sn) => { }
|
||||
|
||||
|
||||
// 打开编辑弹窗
|
||||
@@ -233,9 +235,9 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
|
||||
|
||||
// 当前选中设备(切换时才变)
|
||||
const selectedDevice = useMemo(() => {
|
||||
const sn = selectedSn || (devicesAll?.[0]?.device_sn || devicesAll?.[0]?.serialNumber);
|
||||
const sn = currentSelectedRobot || (devicesAll?.[0]?.device_sn || devicesAll?.[0]?.serialNumber);
|
||||
return devicesAll?.find(item => (item.device_sn || item.serialNumber) === sn) || null;
|
||||
}, [devicesAll, selectedSn]);
|
||||
}, [devicesAll, currentSelectedRobot]);
|
||||
|
||||
const isUAV = !!selectedDevice?.gateway_sn;
|
||||
useEffect(() => {
|
||||
@@ -510,7 +512,7 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
|
||||
const getVal = (val) => val == "no_rain" ? "无" : (val || '-');
|
||||
|
||||
const handleDeviceChange = (id) => {
|
||||
if (onDeviceSelect) onDeviceSelect(id);
|
||||
setCurrentSelectedRobot(id);
|
||||
};
|
||||
|
||||
// 获取无人机状态
|
||||
@@ -646,18 +648,19 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 80,
|
||||
width: 120,
|
||||
//fixed: 'right',
|
||||
render: (_, record) => (
|
||||
<Space size={4}>
|
||||
{/* 编辑按钮绑定弹窗 */}
|
||||
|
||||
<Button
|
||||
size="small"
|
||||
type="text"
|
||||
icon={<EditOutlined />}
|
||||
onClick={() => openEditRobotModal(record)}
|
||||
title="编辑"
|
||||
/>
|
||||
<Button size="small" type="text" icon={<SettingOutlined />} />
|
||||
<Button size="small" type="text" icon={<SettingOutlined />} title="设置" />
|
||||
</Space>
|
||||
)
|
||||
}]}
|
||||
@@ -718,7 +721,7 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS
|
||||
<Button
|
||||
type="primary" size="small" ghost icon={<InfoCircleOutlined />}
|
||||
style={{ borderRadius: 4, fontSize: 11, marginLeft: 'auto' }}
|
||||
onClick={() => onViewStatus && onViewStatus(selectedDevice.device_sn || selectedDevice.serialNumber)}
|
||||
onClick={() => onViewStatus(selectedDevice.device_sn || selectedDevice.serialNumber)}
|
||||
>详情</Button>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -63,10 +63,7 @@ const { RangePicker } = DatePicker;
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
export default function DeviceStatusPage({
|
||||
serialNumber,
|
||||
onDeviceChange,
|
||||
}) {
|
||||
export default function DeviceStatusPage() {
|
||||
const { userInfo } = useSelector((state: RootState) => state.user);
|
||||
const { stationId } = useSelector((state: RootState) => state.station);
|
||||
const [persistentDroneData, setPersistentDroneData] = useState(null); // 持久化无人机数据
|
||||
@@ -175,24 +172,44 @@ export default function DeviceStatusPage({
|
||||
fetchAllData();
|
||||
}, [userInfo, stationId]);
|
||||
|
||||
// 当前选中的设备SN
|
||||
const [selectedSn, setSelectedSn] = useState('');
|
||||
|
||||
|
||||
|
||||
// 当设备列表加载后,如果没有选中的设备,默认选中第一个
|
||||
useEffect(() => {
|
||||
if (devicesAll?.length > 0) {
|
||||
const firstDevice = devicesAll[0];
|
||||
setSelectedSn(firstDevice.device_sn || firstDevice.serialNumber);
|
||||
}
|
||||
}, [devicesAll]);
|
||||
|
||||
// 获取当前选中的无人机设备
|
||||
const device = useMemo(() => {
|
||||
const sn =
|
||||
serialNumber ||
|
||||
devicesAll?.[0]?.device_sn ||
|
||||
devicesAll?.[0]?.serialNumber;
|
||||
const sn = selectedSn;
|
||||
|
||||
if (!sn) return null;
|
||||
|
||||
return devicesAll?.find(
|
||||
(d) => (d.device_sn || d.serialNumber) === sn,
|
||||
(d) => (d.device_sn || d.serialNumber) == sn,
|
||||
);
|
||||
}, [devicesAll, serialNumber]);
|
||||
}, [devicesAll, selectedSn]);
|
||||
|
||||
const isUAV = useMemo(() => {
|
||||
return !!device?.device_sn;
|
||||
// 设备有 drone_callsign 或 gateway_sn 则是无人机
|
||||
return !!(device?.drone_callsign || device?.gateway_sn);
|
||||
}, [device]);
|
||||
|
||||
// 设备选择变化时,调用回调并更新内部状态
|
||||
const handleDeviceSelectChange = (val) => {
|
||||
setSelectedSn(val);
|
||||
// 切换设备时清空之前的标记点等
|
||||
setMarkedPoints([]);
|
||||
setCompleteFlag(false);
|
||||
setSavePath(null);
|
||||
};
|
||||
|
||||
// 当MQTT数据更新时,更新持久化数据(只在有新数据时更新)
|
||||
const handleMqttMessage = (topic, message) => {
|
||||
|
||||
@@ -357,8 +374,8 @@ export default function DeviceStatusPage({
|
||||
}, [device, wsDeviceInfo, isUAV]);
|
||||
|
||||
const { video: robotVideo, error, ready } = useWebRTCPlayer(
|
||||
!isUAV ? serialNumber : '',
|
||||
`webrtc://1.95.137.212/live/livestream/${serialNumber}`,
|
||||
!isUAV ? device?.serialNumber : '',
|
||||
`webrtc://1.95.137.212/live/livestream/${device?.serialNumber}`,
|
||||
);
|
||||
const getVal = (val) => val === "no_rain" ? "无" : (val || '-');
|
||||
|
||||
@@ -850,40 +867,47 @@ export default function DeviceStatusPage({
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: 12,
|
||||
flexWrap: 'wrap',
|
||||
}}
|
||||
>
|
||||
<Text strong>选择设备:</Text>
|
||||
|
||||
<Select
|
||||
style={{ width: 380 }}
|
||||
value={device?.device_sn || device?.serialNumber}
|
||||
onChange={(val) => onDeviceChange?.(val)}
|
||||
style={{ width: 380, minWidth: 280 }}
|
||||
value={selectedSn}
|
||||
onChange={handleDeviceSelectChange}
|
||||
showSearch
|
||||
optionFilterProp="label"
|
||||
placeholder="请选择设备"
|
||||
allowClear={false}
|
||||
loading={devicesAll.length === 0}
|
||||
options={[
|
||||
{
|
||||
label: <span>机器人</span>,
|
||||
title: 'manager',
|
||||
options: devicesAll.filter(item => item.serialNumber).map(item => ({
|
||||
label: '机器人',
|
||||
title: 'robot',
|
||||
options: devicesAll.filter(item => !item.gateway_sn && !item.drone_callsign && item.serialNumber).map(item => ({
|
||||
value: item.device_sn || item.serialNumber,
|
||||
label: item.deviceAlias || item.deviceName || '未知设备'
|
||||
label: `${item.deviceAlias || item.deviceName || '未知设备'} `,
|
||||
})),
|
||||
},
|
||||
{
|
||||
label: <span>无人机</span>,
|
||||
title: 'engineer',
|
||||
options: devicesAll.filter(item => item.gateway_sn).map(item => ({
|
||||
label: '无人机',
|
||||
title: 'uav',
|
||||
options: devicesAll.filter(item => item.gateway_sn || item.drone_callsign).map(item => ({
|
||||
value: item.device_sn,
|
||||
label: item.drone_callsign || item.callsign || '未知设备'
|
||||
label: `${item.drone_callsign || item.callsign || '未知无人机'}`,
|
||||
})),
|
||||
},
|
||||
]}
|
||||
].filter(group => group.options.length > 0)}
|
||||
/>
|
||||
|
||||
<Tag color="blue">
|
||||
<Tag color={isUAV ? 'cyan' : 'blue'}>
|
||||
{isUAV ? '无人机' : '机器人'}
|
||||
</Tag>
|
||||
|
||||
<Tag color={device?.onlineStatus == 1 ? 'green' : 'default'}>
|
||||
{device?.onlineStatus === 1 ? '在线' : '离线'}
|
||||
</Tag>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -1085,7 +1109,7 @@ export default function DeviceStatusPage({
|
||||
{robotVideo ? (
|
||||
mowerView === 'all' ? (
|
||||
<MowerAllView
|
||||
serialNumber={serialNumber}
|
||||
serialNumber={device?.serialNumber}
|
||||
robotVideo={robotVideo}
|
||||
error={error}
|
||||
ready={ready}
|
||||
@@ -1093,7 +1117,7 @@ export default function DeviceStatusPage({
|
||||
) : (
|
||||
<div style={{ position: 'relative', width: '100%', height: '100%' }}>
|
||||
<VideoPlayer
|
||||
deviceId={serialNumber}
|
||||
deviceId={device?.serialNumber}
|
||||
idx={
|
||||
mowerView === 'front' ? 1
|
||||
: mowerView === 'back' ? 2
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ const ProtectedRoute = lazy(() => import('../components/ProtectedRoute'));
|
||||
const Login = lazy(() => import('../pages/Login'));
|
||||
|
||||
const Home = lazy(() => import('../pages/Home'));
|
||||
const Devices = lazy(() => import('../pages/Devices'));
|
||||
|
||||
const Video = lazy(() => import('../pages/Video'));
|
||||
const Alerts = lazy(() => import('../pages/Alerts'));
|
||||
const Downloads = lazy(() => import('../pages/Downloads'));
|
||||
@@ -32,6 +32,7 @@ const Profile = lazy(() => import('../pages/Profile'));
|
||||
const DeviceStatus = lazy(() => import('../components/devices/DeviceStatusPage'));
|
||||
const WayLineTask = lazy(() => import('../components/devices/WayLinePage'));
|
||||
const RobotTask = lazy(() => import('../components/devices/RobotTaskPage'));
|
||||
const DevicesOverview = lazy(() => import('../components/devices/DeviceOverviewPage'));
|
||||
|
||||
|
||||
const BasicSettings = lazy(() => import('../components/SystemSetting/BasicSettings'));
|
||||
@@ -123,7 +124,7 @@ const routes: RouteObject[] = [
|
||||
path: 'devices/overview',
|
||||
element: (
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<Devices />
|
||||
<DevicesOverview />
|
||||
</Suspense>
|
||||
)
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user