This commit is contained in:
2026-08-06 12:30:14 +08:00
parent 770e6f47d2
commit a884b28fef
+43 -40
View File
@@ -1,28 +1,29 @@
import { Settings } from "./Setting.tsx"; // 保留导入,不修改
import { Leaflet_Map } from "./Map/Leaflet_Map.tsx"
import { Aircraft_List } from "./Map/Aircraft_List.tsx";
import {Settings} from "./Setting.tsx"; // 保留导入,不修改
import {Leaflet_Map} from "./Map/Leaflet_Map.tsx"
import {Aircraft_List} from "./Map/Aircraft_List.tsx";
import enhance from './core/enhance.tsx';
import { useEffect, useState } from 'react';
import {useEffect, useState} from 'react';
// @ts-ignore
import { AppstoreOutlined, MailOutlined, SettingOutlined } from '@ant-design/icons';
import { Flex, Menu, MenuProps, Switch, message } from 'antd';
import {AppstoreOutlined, MailOutlined, SettingOutlined} from '@ant-design/icons';
import {Flex, Menu, MenuProps, Switch, message} from 'antd';
import { Routes, Route, Link, useNavigate, NavigateFunction, useLocation } from 'react-router-dom';
import {Routes, Route, Link, useNavigate, NavigateFunction, useLocation} from 'react-router-dom';
import React from 'react';
import ReactDOM, { Root } from 'react-dom/client';
import ReactDOM, {Root} from 'react-dom/client';
import { BrowserRouter } from 'react-router-dom';
import {BrowserRouter} from 'react-router-dom';
import FileList from "./FileList.tsx";
import { DSP } from "./DSP/DSP.tsx";
import { Navigate, Router } from "react-router";
import {DSP} from "./DSP/DSP.tsx";
import {Navigate, Router} from "react-router";
import axios from "axios";
import { baseURL } from "./Global.tsx";
import {baseURL} from "./Global.tsx";
import {is_cesium_webgl_available, webgl_unavailable_message} from "./Map/WebGL_Support.ts";
import L from 'leaflet';
const Cesium_Map_View = React.lazy(() => import("./Map/Cesium_Map.tsx"));
delete (L.Icon.Default.prototype as any)._getIconUrl;
@@ -61,23 +62,23 @@ class App extends enhance.Base {
this.menuItems = [
{
label: '2D地图',
icon: <SettingOutlined />,
icon: <SettingOutlined/>,
key: '/map',
},
{
label: this.webgl_supported ? '3D地图' : '3D地图(WebGL不可用)',
icon: <SettingOutlined />,
icon: <SettingOutlined/>,
key: '/map3d',
disabled: !this.webgl_supported,
},
{
label: '设置',
icon: <SettingOutlined />,
icon: <SettingOutlined/>,
key: '/settings',
},
{
label: '飞机列表',
icon: <SettingOutlined />,
icon: <SettingOutlined/>,
key: '/aircraftlist',
},
// {
@@ -105,13 +106,13 @@ class App extends enhance.Base {
this.leaflet_map = new Leaflet_Map();
this.aircraft_list = new Aircraft_List();
this.dsp = new DSP();
// 延迟初始化Settings,避免“初始化前访问”错误
setTimeout(() => {
this.setting = new Settings();
this.flush();
this.setting = new Settings();
this.flush();
}, 0);
};
};
use_hook() {
this.navigate = useNavigate();
@@ -174,7 +175,7 @@ class App extends enhance.Base {
render(props: any) {
// ************************ 优化:渲染前校验子组件是否初始化完成,避免报错 ************************
if (!this.leaflet_map || !this.setting || !this.aircraft_list || !this.dsp) {
return <div style={{ textAlign: 'center', padding: '20px' }}>...</div>;
return <div style={{textAlign: 'center', padding: '20px'}}>...</div>;
}
return (
@@ -216,56 +217,56 @@ class App extends enhance.Base {
fontWeight: 'bold',
padding: '0 20px 0 8px'
}}>
{`开机时间:${this.formatTimestamp(this.start_device_time)} 版本:${this.version}`}
{`服务开启时间:${this.formatTimestamp(this.start_device_time)} 版本:${this.version}`}
</div>
</div>
<Routes>
<Route
path="/map"
element={(
<div style={{ width: '100%', height: '100%', position: 'relative'}}>
<this.leaflet_map.x />
<div style={{width: '100%', height: '100%', position: 'relative'}}>
<this.leaflet_map.x/>
</div>
)}
/>
<Route
path="/ui/map"
element={(
<div style={{ width: '100%', height: '100%', position: 'relative'}}>
<this.leaflet_map.x />
<div style={{width: '100%', height: '100%', position: 'relative'}}>
<this.leaflet_map.x/>
</div>
)}
/>
<Route
path="/settings"
element={(
<this.setting.x />
<this.setting.x/>
)}
/>
<Route
path="/ui/settings"
element={(
<this.setting.x />
<this.setting.x/>
)}
/>
<Route
path="/map3d"
element={(
this.webgl_supported ? <div style={{ width: '100%', height: '100%', position: 'relative'}}>
this.webgl_supported ? <div style={{width: '100%', height: '100%', position: 'relative'}}>
<React.Suspense fallback={<div style={{padding: 20}}>3D地图加载中...</div>}>
<Cesium_Map_View initialSceneMode="3d" />
<Cesium_Map_View initialSceneMode="3d"/>
</React.Suspense>
</div> : <Navigate to="/map" replace />
</div> : <Navigate to="/map" replace/>
)}
/>
<Route
path="/ui/map3d"
element={(
this.webgl_supported ? <div style={{ width: '100%', height: '100%', position: 'relative'}}>
this.webgl_supported ? <div style={{width: '100%', height: '100%', position: 'relative'}}>
<React.Suspense fallback={<div style={{padding: 20}}>3D地图加载中...</div>}>
<Cesium_Map_View initialSceneMode="3d" />
<Cesium_Map_View initialSceneMode="3d"/>
</React.Suspense>
</div> : <Navigate to="/ui/map" replace />
</div> : <Navigate to="/ui/map" replace/>
)}
/>
<Route
@@ -274,7 +275,7 @@ class App extends enhance.Base {
<div style={{
flex: 1,
}}>
<this.aircraft_list.x />
<this.aircraft_list.x/>
</div>
)}
/>
@@ -290,7 +291,7 @@ class App extends enhance.Base {
{/* </div>*/}
{/* )}*/}
{/*/>*/}
<Route path="*" element={<Navigate to="/map" />} />
<Route path="*" element={<Navigate to="/map"/>}/>
</Routes>
</div>
@@ -302,8 +303,10 @@ class App extends enhance.Base {
export let app = new App();
const container = document.getElementById('root');
if (container) {
// 清空容器现有内容(避免热更新重复绑定)
container.innerHTML = '';
const root = ReactDOM.createRoot(container);
root.render(<BrowserRouter><app.x/></BrowserRouter>);
// 清空容器现有内容(避免热更新重复绑定)
container.innerHTML = '';
const root = ReactDOM.createRoot(container);
root.render(<BrowserRouter>
<app.x/>
</BrowserRouter>);
}