设备状态界面
This commit is contained in:
@@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react';
|
||||
import { Layout, Typography, Menu } from 'antd';
|
||||
import { AimOutlined, AppstoreOutlined, SettingOutlined } from '@ant-design/icons';
|
||||
import DeviceOverviewPage from '../components/devices/DeviceOverviewPage';
|
||||
import DeviceStatusPage from '../components/devices/DeviceStatusPage';
|
||||
import { getDeviceListApi, getPlaneDeviceList } from '../api/device';
|
||||
import { useSelector } from 'react-redux';
|
||||
import { RootState } from '../store';
|
||||
@@ -10,14 +11,17 @@ import WayLinePage from '../components/devices/WayLinePage';
|
||||
const { Header, Content } = Layout;
|
||||
const { Text } = Typography;
|
||||
|
||||
const DeviceStatusSettingPage = () => (
|
||||
const DeviceStatusSettingPage = ({ serialNumber }) => (
|
||||
<div style={{ padding: 20 }}>
|
||||
<h2>设置状态页面(/devices/status)</h2>
|
||||
<h2>设置状态页面</h2>
|
||||
<p>当前查看设备序列号: <span style={{ fontWeight: 'bold', color: '#1890ff' }}>{serialNumber || '未选择设备'}</span></p>
|
||||
{/* 这里后续可以根据 serialNumber 加载具体的设备状态详情 */}
|
||||
</div>
|
||||
);
|
||||
|
||||
export default function DeviceIndexPage() {
|
||||
const [activeTab, setActiveTab] = useState('overview');
|
||||
const [selectedSn, setSelectedSn] = useState(null);
|
||||
const { userInfo } = useSelector((state: RootState) => state.user);
|
||||
const [devices, setDevices] = useState([]);
|
||||
const [planedevices, setPlaneDevices] = useState([]);
|
||||
@@ -25,7 +29,7 @@ export default function DeviceIndexPage() {
|
||||
|
||||
const tabs = [
|
||||
{ key: 'overview', label: '装备总览', icon: <AppstoreOutlined /> },
|
||||
{ key: 'status', label: '设置状态', icon: <SettingOutlined /> },
|
||||
{ key: 'status', label: '设备状态', icon: <SettingOutlined /> },
|
||||
{ key: 'wayLineTask', label: '航线任务', icon: <AimOutlined /> },
|
||||
];
|
||||
|
||||
@@ -44,11 +48,9 @@ export default function DeviceIndexPage() {
|
||||
const devData = deviceRes?.code === 200 ? (deviceRes.data || []) : [];
|
||||
const planeData = planeRes?.code === 200 ? (planeRes.data?.detail || []) : [];
|
||||
|
||||
// 3. 分别保存
|
||||
setDevices(devData);
|
||||
setPlaneDevices(planeData);
|
||||
|
||||
// 4. 最终合并(只执行一次!)
|
||||
setDevicesAll([...devData, ...planeData]);
|
||||
|
||||
} catch (err) {
|
||||
@@ -60,15 +62,27 @@ export default function DeviceIndexPage() {
|
||||
fetchAllData();
|
||||
}, [userInfo]);
|
||||
|
||||
const handleViewStatus = (sn) => {
|
||||
setSelectedSn(sn);
|
||||
setActiveTab('status');
|
||||
};
|
||||
|
||||
const renderContent = () => {
|
||||
if (activeTab === 'overview') {
|
||||
return <DeviceOverviewPage
|
||||
devices={devices}
|
||||
planedevices={planedevices}
|
||||
devicesAll={devicesAll}
|
||||
onViewStatus={handleViewStatus}
|
||||
/>;
|
||||
}
|
||||
if (activeTab === 'status') {
|
||||
return <DeviceStatusPage
|
||||
devicesAll={devicesAll}
|
||||
serialNumber={selectedSn}
|
||||
onDeviceChange={(sn) => setSelectedSn(sn)}
|
||||
/>;
|
||||
}
|
||||
if (activeTab === 'status') return <DeviceStatusSettingPage />;
|
||||
if (activeTab === 'wayLineTask') return <WayLinePage />;
|
||||
return null;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user