路由懒加载 还要取消暂停路径规划接口 接入

This commit is contained in:
mmc
2026-06-02 17:32:29 +08:00
parent 69a8a47d0d
commit 1a87d659f4
4 changed files with 203 additions and 35 deletions

View File

@@ -289,4 +289,24 @@ export function excuetRoute(data) {
})
}
//取消任务
export function cancelRoute(data) {
return request({
url: `/iot/deviceTask/cancelTask`,
method: 'post',
data
})
}
export function pauseRoute(data) {
return request({
url: `/iot/deviceTask/pauseTask`,
method: 'post',
data
})
}

View File

@@ -367,7 +367,9 @@ export default function DeviceStatusPage({
controllerRef.current = controller;
return () => {
controller.destroy();
controller?.destroy();
controllerRef.current?.destroy();
controllerRef.current = null;
};
}, [userInfo, messageApi]);
@@ -376,11 +378,7 @@ export default function DeviceStatusPage({
if (!device || !controllerRef.current || !device?.serialNumber || isUAV) return;
controllerRef.current.connectDevice(device);
return () => {
controllerRef.current.destroy();
controllerRef.current = null;
}
}, [device?.serialNumber]);
// 定时获取无人机状态

View File

@@ -62,7 +62,7 @@ export default function RobotTaskPage() {
const controller = new DeviceController(userInfo, messageApi);
controllerRef.current = controller;
return () => {
controllerRef.current.destroy();
controllerRef.current?.destroy();
controllerRef.current = null;
}

View File

@@ -1,13 +1,15 @@
import React, { lazy, Suspense } from 'react';
import { createBrowserRouter } from 'react-router-dom';
import type { RouteObject } from 'react-router-dom';
import VideoMonitorPage from '../pages/VideoMonitorPage';
import AIDiagnosisPage from '../pages/AIAnalysis';
import CleanOptimizationPage from '../pages/CleanOptimization';
import WorkOrderPage from '../pages/WorkOrder';
import ReportCenterPage from '../pages/ReportCenter';
import RealTimeMonitorPage from '../pages/RealTimeMonitor';
import Agri from '../pages/Agri';
// 🔥 所有组件全部改为懒加载
const VideoMonitorPage = lazy(() => import('../pages/VideoMonitorPage'));
const AIDiagnosisPage = lazy(() => import('../pages/AIAnalysis'));
const CleanOptimizationPage = lazy(() => import('../pages/CleanOptimization'));
const WorkOrderPage = lazy(() => import('../pages/WorkOrder'));
const ReportCenterPage = lazy(() => import('../pages/ReportCenter'));
const RealTimeMonitorPage = lazy(() => import('../pages/RealTimeMonitor'));
const Agri = lazy(() => import('../pages/Agri'));
const Layout = lazy(() => import('../components/Layout'));
const ProtectedRoute = lazy(() => import('../components/ProtectedRoute'));
@@ -26,6 +28,7 @@ const StationManage = lazy(() => import('../components/SystemSetting/StationMana
const SystemSetting = lazy(() => import('../pages/SystemSetting'));
const Profile = lazy(() => import('../pages/Profile'));
// 加载中动画
function PageFallback() {
return (
<div className="flex items-center justify-center h-full min-h-[200px]">
@@ -60,6 +63,7 @@ export const routeMeta: Record<string, {
'/profile': { title: '个人中心', roles: ['admin', 'operator', 'viewer'], requiresAuth: true },
};
// ====================== 全部懒加载的路由配置 ======================
const routes: RouteObject[] = [
{
path: '/login',
@@ -83,28 +87,174 @@ const routes: RouteObject[] = [
</Suspense>
),
children: [
{ index: true, element: <Home /> },
{ path: 'overview', element: <Home /> },
{ path: 'devices', element: <Devices /> },
{ path: 'video', element: <Video /> },
{ path: 'RealtimeMonitor', element: <RealTimeMonitorPage /> },
{ path: 'monitor', element: <VideoMonitorPage /> },
{ path: 'agri', element: <Agri /> },
{ path: 'alerts', element: <Alerts /> },
{ path: 'AIanalysis', element: <AIDiagnosisPage /> },
{ path: 'clean', element: <CleanOptimizationPage /> },
{ path: 'task', element: <WorkOrderPage /> },
{ path: 'table', element: <ReportCenterPage /> },
{ path: 'systemSetting', element: <SystemSetting /> },
{ path: 'downloads', element: <Downloads /> },
{ path: 'manage/users', element: <Users /> },
{ path: 'manage/roles', element: <Roles /> },
{ path: 'manage/menuList', element: <MenuList /> },
{ path: 'organization', element: <Organization /> },
{ path: 'station', element: <StationManage /> },
{ path: 'system', element: <SystemSetting /> },
{ path: 'profile', element: <Profile /> },
{
index: true,
element: (
<Suspense fallback={<PageFallback />}>
<Home />
</Suspense>
)
},
{
path: 'overview',
element: (
<Suspense fallback={<PageFallback />}>
<Home />
</Suspense>
)
},
{
path: 'devices',
element: (
<Suspense fallback={<PageFallback />}>
<Devices />
</Suspense>
)
},
{
path: 'video',
element: (
<Suspense fallback={<PageFallback />}>
<Video />
</Suspense>
)
},
{
path: 'RealtimeMonitor',
element: (
<Suspense fallback={<PageFallback />}>
<RealTimeMonitorPage />
</Suspense>
)
},
{
path: 'monitor',
element: (
<Suspense fallback={<PageFallback />}>
<VideoMonitorPage />
</Suspense>
)
},
{
path: 'agri',
element: (
<Suspense fallback={<PageFallback />}>
<Agri />
</Suspense>
)
},
{
path: 'alerts',
element: (
<Suspense fallback={<PageFallback />}>
<Alerts />
</Suspense>
)
},
{
path: 'AIanalysis',
element: (
<Suspense fallback={<PageFallback />}>
<AIDiagnosisPage />
</Suspense>
)
},
{
path: 'clean',
element: (
<Suspense fallback={<PageFallback />}>
<CleanOptimizationPage />
</Suspense>
)
},
{
path: 'task',
element: (
<Suspense fallback={<PageFallback />}>
<WorkOrderPage />
</Suspense>
)
},
{
path: 'table',
element: (
<Suspense fallback={<PageFallback />}>
<ReportCenterPage />
</Suspense>
)
},
{
path: 'systemSetting',
element: (
<Suspense fallback={<PageFallback />}>
<SystemSetting />
</Suspense>
)
},
{
path: 'downloads',
element: (
<Suspense fallback={<PageFallback />}>
<Downloads />
</Suspense>
)
},
{
path: 'manage/users',
element: (
<Suspense fallback={<PageFallback />}>
<Users />
</Suspense>
)
},
{
path: 'manage/roles',
element: (
<Suspense fallback={<PageFallback />}>
<Roles />
</Suspense>
)
},
{
path: 'manage/menuList',
element: (
<Suspense fallback={<PageFallback />}>
<MenuList />
</Suspense>
)
},
{
path: 'organization',
element: (
<Suspense fallback={<PageFallback />}>
<Organization />
</Suspense>
)
},
{
path: 'station',
element: (
<Suspense fallback={<PageFallback />}>
<StationManage />
</Suspense>
)
},
{
path: 'system',
element: (
<Suspense fallback={<PageFallback />}>
<SystemSetting />
</Suspense>
)
},
{
path: 'profile',
element: (
<Suspense fallback={<PageFallback />}>
<Profile />
</Suspense>
)
},
{
path: '*',
element: (