装备 完善
This commit is contained in:
@@ -9,7 +9,6 @@ import { RootState } from '../store';
|
||||
const { Header, Content } = Layout;
|
||||
const { Text } = Typography;
|
||||
|
||||
// 设置状态页面(你后续自己填内容)
|
||||
const DeviceStatusSettingPage = () => (
|
||||
<div style={{ padding: 20 }}>
|
||||
<h2>设置状态页面(/devices/status)</h2>
|
||||
@@ -24,50 +23,62 @@ export default function DeviceIndexPage() {
|
||||
const [devicesAll, setDevicesAll] = useState([]);
|
||||
|
||||
const tabs = [
|
||||
{ key: 'overview', label: '装备总览', icon: <AppstoreOutlined />, path: '/devices/overview' },
|
||||
{ key: 'status', label: '设置状态', icon: <SettingOutlined />, path: '/devices/status' },
|
||||
{ key: 'overview', label: '装备总览', icon: <AppstoreOutlined /> },
|
||||
{ key: 'status', label: '设置状态', icon: <SettingOutlined /> },
|
||||
];
|
||||
|
||||
const renderContent = () => {
|
||||
if (activeTab === 'overview') return <DeviceOverviewPage devices={devices} planedevices={planedevices} devicesAll={devicesAll} />;
|
||||
if (activeTab === 'status') return <DeviceStatusSettingPage />;
|
||||
return null;
|
||||
};
|
||||
const getPlaneList = () => {
|
||||
getPlaneDeviceList().then(res => {
|
||||
if (res?.code == 200) {
|
||||
const drones = res?.data?.detail;
|
||||
setPlaneDevices(drones);
|
||||
setDevicesAll([...devices, ...drones]);
|
||||
}
|
||||
});
|
||||
};
|
||||
// 👇 核心修复:同时请求 + 同时合并
|
||||
const fetchAllData = async () => {
|
||||
if (!userInfo?.username) return;
|
||||
|
||||
const getDevice = () => {
|
||||
const data = { tenantName: userInfo.username, deptId: 1 };
|
||||
getDeviceListApi(data).then(res => {
|
||||
if (res?.code == 200 && res?.data?.length) {
|
||||
setDevices(res.data);
|
||||
setDevicesAll([...planedevices, ...res.data.data]);
|
||||
}
|
||||
});
|
||||
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 || []) : [];
|
||||
|
||||
// 3. 分别保存
|
||||
setDevices(devData);
|
||||
setPlaneDevices(planeData);
|
||||
|
||||
// 4. 最终合并(只执行一次!)
|
||||
setDevicesAll([...devData, ...planeData]);
|
||||
|
||||
} catch (err) {
|
||||
console.error('数据请求失败', err);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getDevice();
|
||||
getPlaneList();
|
||||
}, []);
|
||||
fetchAllData();
|
||||
}, [userInfo]);
|
||||
|
||||
const renderContent = () => {
|
||||
if (activeTab === 'overview') {
|
||||
return <DeviceOverviewPage
|
||||
devices={devices}
|
||||
planedevices={planedevices}
|
||||
devicesAll={devicesAll}
|
||||
/>;
|
||||
}
|
||||
if (activeTab === 'status') return <DeviceStatusSettingPage />;
|
||||
return null;
|
||||
};
|
||||
|
||||
return (
|
||||
<Layout style={{ minHeight: '100vh', background: '#fff', overflow: 'hidden' }}>
|
||||
<div style={{ display: 'flex', paddingBottom: "12px" }}>
|
||||
<div style={{ padding: '20px 24px 0' }}>
|
||||
<div style={{ padding: '20px 24px 0', flexShrink: 0 }}>
|
||||
<Typography.Title level={4} style={{ margin: 0 }}>装备控制</Typography.Title>
|
||||
<Text type="secondary"> 装备总览、状态监控与参数配置</Text>
|
||||
</div>
|
||||
|
||||
<Header style={{ background: '#fff', padding: 0, borderBottom: '1px solid #f0f0f0', position: 'sticky', top: 0, zIndex: 10 }}>
|
||||
<Header style={{ flex: 1, background: '#fff', padding: 0, borderBottom: '1px solid #f0f0f0' }}>
|
||||
<Menu
|
||||
mode="horizontal"
|
||||
selectedKeys={[activeTab]}
|
||||
@@ -78,13 +89,12 @@ export default function DeviceIndexPage() {
|
||||
</Header>
|
||||
</div>
|
||||
|
||||
|
||||
<Content style={{
|
||||
maxHeight: 'calc(100vh - 64px)',
|
||||
overflowY: 'auto',
|
||||
background: '#f5f7fa',
|
||||
padding: '20px',
|
||||
scrollbarWidth: "none"
|
||||
scrollbarWidth: "thin"
|
||||
}}>
|
||||
{renderContent()}
|
||||
</Content>
|
||||
|
||||
Reference in New Issue
Block a user