2026-05-11 10:47:51 +08:00
|
|
|
import React, { useState, useEffect } from 'react';
|
2026-05-15 15:39:28 +08:00
|
|
|
import { Layout, Typography, Menu, Tabs } from 'antd';
|
2026-05-11 15:48:14 +08:00
|
|
|
import { AimOutlined, AppstoreOutlined, SettingOutlined } from '@ant-design/icons';
|
2026-05-11 10:47:51 +08:00
|
|
|
import DeviceOverviewPage from '../components/devices/DeviceOverviewPage';
|
2026-05-11 16:34:44 +08:00
|
|
|
import DeviceStatusPage from '../components/devices/DeviceStatusPage';
|
2026-05-11 10:47:51 +08:00
|
|
|
import { getDeviceListApi, getPlaneDeviceList } from '../api/device';
|
|
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
|
import { RootState } from '../store';
|
2026-05-11 15:48:14 +08:00
|
|
|
import WayLinePage from '../components/devices/WayLinePage';
|
2026-05-11 10:47:51 +08:00
|
|
|
|
|
|
|
|
const { Header, Content } = Layout;
|
|
|
|
|
const { Text } = Typography;
|
|
|
|
|
|
2026-05-11 16:34:44 +08:00
|
|
|
const DeviceStatusSettingPage = ({ serialNumber }) => (
|
2026-05-11 10:47:51 +08:00
|
|
|
<div style={{ padding: 20 }}>
|
2026-05-11 16:34:44 +08:00
|
|
|
<h2>设置状态页面</h2>
|
|
|
|
|
<p>当前查看设备序列号: <span style={{ fontWeight: 'bold', color: '#1890ff' }}>{serialNumber || '未选择设备'}</span></p>
|
|
|
|
|
{/* 这里后续可以根据 serialNumber 加载具体的设备状态详情 */}
|
2026-05-11 10:47:51 +08:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export default function DeviceIndexPage() {
|
|
|
|
|
const [activeTab, setActiveTab] = useState('overview');
|
2026-05-11 16:34:44 +08:00
|
|
|
const [selectedSn, setSelectedSn] = useState(null);
|
2026-05-11 10:47:51 +08:00
|
|
|
const { userInfo } = useSelector((state: RootState) => state.user);
|
|
|
|
|
const [devices, setDevices] = useState([]);
|
|
|
|
|
const [planedevices, setPlaneDevices] = useState([]);
|
|
|
|
|
const [devicesAll, setDevicesAll] = useState([]);
|
|
|
|
|
|
|
|
|
|
const tabs = [
|
2026-05-11 14:59:36 +08:00
|
|
|
{ key: 'overview', label: '装备总览', icon: <AppstoreOutlined /> },
|
2026-05-11 16:34:44 +08:00
|
|
|
{ key: 'status', label: '设备状态', icon: <SettingOutlined /> },
|
2026-05-11 15:48:14 +08:00
|
|
|
{ key: 'wayLineTask', label: '航线任务', icon: <AimOutlined /> },
|
2026-04-21 08:51:57 +08:00
|
|
|
];
|
2026-04-17 17:20:41 +08:00
|
|
|
|
2026-05-11 14:59:36 +08:00
|
|
|
// 👇 核心修复:同时请求 + 同时合并
|
|
|
|
|
const fetchAllData = async () => {
|
|
|
|
|
if (!userInfo?.username) return;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// 1. 同时发请求
|
|
|
|
|
const [deviceRes, planeRes] = await Promise.all([
|
|
|
|
|
getDeviceListApi({ tenantName: userInfo.username, deptId: 1 }),
|
|
|
|
|
getPlaneDeviceList(),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// 2. 处理设备数据
|
|
|
|
|
const devData = deviceRes?.code === 200 ? (deviceRes.data || []) : [];
|
|
|
|
|
const planeData = planeRes?.code === 200 ? (planeRes.data?.detail || []) : [];
|
2026-05-11 10:47:51 +08:00
|
|
|
|
2026-05-11 14:59:36 +08:00
|
|
|
setDevices(devData);
|
|
|
|
|
setPlaneDevices(planeData);
|
|
|
|
|
|
2026-05-12 08:34:13 +08:00
|
|
|
const all = [...devData, ...planeData];
|
|
|
|
|
setDevicesAll(all);
|
|
|
|
|
|
|
|
|
|
// 如果当前没选中,默认选第一个
|
|
|
|
|
if (!selectedSn && all.length > 0) {
|
|
|
|
|
setSelectedSn(all[0].device_sn || all[0].serialNumber);
|
|
|
|
|
}
|
2026-05-11 14:59:36 +08:00
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error('数据请求失败', err);
|
|
|
|
|
}
|
2026-05-11 10:47:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-05-11 14:59:36 +08:00
|
|
|
fetchAllData();
|
|
|
|
|
}, [userInfo]);
|
2026-04-17 17:20:41 +08:00
|
|
|
|
2026-05-11 16:34:44 +08:00
|
|
|
const handleViewStatus = (sn) => {
|
|
|
|
|
setSelectedSn(sn);
|
|
|
|
|
setActiveTab('status');
|
|
|
|
|
};
|
|
|
|
|
|
2026-05-11 14:59:36 +08:00
|
|
|
const renderContent = () => {
|
|
|
|
|
if (activeTab === 'overview') {
|
|
|
|
|
return <DeviceOverviewPage
|
|
|
|
|
devices={devices}
|
|
|
|
|
planedevices={planedevices}
|
|
|
|
|
devicesAll={devicesAll}
|
2026-05-11 16:34:44 +08:00
|
|
|
onViewStatus={handleViewStatus}
|
2026-05-12 08:34:13 +08:00
|
|
|
selectedSn={selectedSn}
|
|
|
|
|
onDeviceSelect={(sn) => setSelectedSn(sn)}
|
2026-05-11 16:34:44 +08:00
|
|
|
/>;
|
|
|
|
|
}
|
|
|
|
|
if (activeTab === 'status') {
|
|
|
|
|
return <DeviceStatusPage
|
|
|
|
|
devicesAll={devicesAll}
|
|
|
|
|
serialNumber={selectedSn}
|
|
|
|
|
onDeviceChange={(sn) => setSelectedSn(sn)}
|
2026-05-11 14:59:36 +08:00
|
|
|
/>;
|
|
|
|
|
}
|
2026-05-21 15:39:46 +08:00
|
|
|
if (activeTab === 'wayLineTask') return <WayLinePage planedevices={planedevices} />;
|
2026-05-11 14:59:36 +08:00
|
|
|
return null;
|
|
|
|
|
};
|
2026-04-17 17:20:41 +08:00
|
|
|
|
2026-05-11 10:47:51 +08:00
|
|
|
return (
|
2026-05-15 15:39:28 +08:00
|
|
|
<Layout style={{ minHeight: '100vh', overflow: 'hidden', scrollbarWidth: "thin", scrollbarColor: '#ccc transparent' }}>
|
2026-05-14 17:23:12 +08:00
|
|
|
<div style={{ display: 'flex', paddingBottom: "4px" }}>
|
|
|
|
|
<div style={{ padding: '8px 12px 0', flexShrink: 0 }}>
|
|
|
|
|
<Typography.Title level={4} style={{ margin: 0, fontSize: 'clamp(14px, 1.2vw, 18px)' }}>装备控制</Typography.Title>
|
2026-05-15 15:39:28 +08:00
|
|
|
{/*<Text type="secondary" style={{ fontSize: '12px' }}>装备总览、状态监控与参数配置</Text>*/}
|
2026-05-09 16:44:39 +08:00
|
|
|
</div>
|
|
|
|
|
|
2026-05-15 15:39:28 +08:00
|
|
|
<Header style={{
|
|
|
|
|
flex: 1, padding: 0, background: 'transparent',
|
|
|
|
|
backgroundColor: 'transparent', borderBottom: '1px solid #f0f0f0', height: 40, lineHeight: '40px'
|
|
|
|
|
}}>
|
|
|
|
|
|
2026-05-11 10:47:51 +08:00
|
|
|
<Menu
|
|
|
|
|
mode="horizontal"
|
|
|
|
|
selectedKeys={[activeTab]}
|
|
|
|
|
onClick={({ key }) => setActiveTab(key)}
|
|
|
|
|
items={tabs}
|
2026-05-15 15:39:28 +08:00
|
|
|
style={{
|
|
|
|
|
border: '0',
|
|
|
|
|
height: 40,
|
|
|
|
|
lineHeight: '40px',
|
|
|
|
|
background: 'transparent', // 这里直接写,不需要 !important
|
|
|
|
|
backgroundColor: 'transparent' // 兼容更好
|
|
|
|
|
}} />
|
2026-05-11 10:47:51 +08:00
|
|
|
</Header>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<Content style={{
|
2026-05-14 17:23:12 +08:00
|
|
|
maxHeight: 'calc(100vh - 40px)',
|
2026-05-11 10:47:51 +08:00
|
|
|
overflowY: 'auto',
|
|
|
|
|
background: '#f5f7fa',
|
2026-05-15 15:39:28 +08:00
|
|
|
padding: '8px 0px',
|
2026-05-11 14:59:36 +08:00
|
|
|
scrollbarWidth: "thin"
|
2026-05-11 10:47:51 +08:00
|
|
|
}}>
|
|
|
|
|
{renderContent()}
|
2026-05-09 16:44:39 +08:00
|
|
|
</Content>
|
|
|
|
|
</Layout>
|
2026-04-21 08:51:57 +08:00
|
|
|
);
|
2026-04-17 17:20:41 +08:00
|
|
|
}
|