feat: 1:地图仪表盘 2:获取设备消息
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
// 横向设备列表容器
|
||||
.deviceListHorizontal {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 12px;
|
||||
overflow-x: auto;
|
||||
padding: 8px 0;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
height: 6px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: #d9d9d9;
|
||||
border-radius: 3px;
|
||||
|
||||
&:hover {
|
||||
background: #bfbfbf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 横向设备卡片
|
||||
.deviceCardHorizontal {
|
||||
min-width: 200px;
|
||||
padding: 16px;
|
||||
border: 2px solid #d9d9d9;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
transition: all 0.3s ease;
|
||||
background: #fff;
|
||||
|
||||
&:hover {
|
||||
border-color: #1890ff;
|
||||
box-shadow: 0 2px 8px rgba(24, 144, 255, 0.2);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
&.selected {
|
||||
border-color: #1890ff;
|
||||
background: linear-gradient(135deg, #e6f7ff 0%, #f0f9ff 100%);
|
||||
box-shadow: 0 4px 12px rgba(24, 144, 255, 0.3);
|
||||
}
|
||||
|
||||
.deviceIcon {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 50%;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #fff;
|
||||
font-size: 24px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.deviceContent {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
.deviceName {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #262626;
|
||||
margin-bottom: 8px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.deviceStatus {
|
||||
font-size: 12px;
|
||||
color: #8c8c8c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 视频播放器占位
|
||||
.videoPlaceholder {
|
||||
height: 300px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #f5f5f5;
|
||||
border-radius: 4px;
|
||||
|
||||
p {
|
||||
margin-top: 16px;
|
||||
color: #999;
|
||||
}
|
||||
}
|
||||
|
||||
// 控制面板占位
|
||||
.controlPlaceholder {
|
||||
height: 300px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
// 在线状态脉冲动画(绿色 - 机库在线)
|
||||
@keyframes pulse {
|
||||
0% {
|
||||
box-shadow: 0 0 0 0 rgba(82, 196, 26, 0.6);
|
||||
}
|
||||
50% {
|
||||
box-shadow: 0 0 20px 4px rgba(82, 196, 26, 0.3);
|
||||
}
|
||||
100% {
|
||||
box-shadow: 0 0 0 0 rgba(82, 196, 26, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// 无人机开机状态脉冲动画(橙色)
|
||||
@keyframes pulse-orange {
|
||||
0% {
|
||||
box-shadow: 0 0 0 0 rgba(250, 173, 20, 0.6);
|
||||
}
|
||||
50% {
|
||||
box-shadow: 0 0 20px 4px rgba(250, 173, 20, 0.3);
|
||||
}
|
||||
100% {
|
||||
box-shadow: 0 0 0 0 rgba(250, 173, 20, 0);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
+177
@@ -0,0 +1,177 @@
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
import { message } from 'antd';
|
||||
|
||||
// 扩展Window类型,添加AMap全局变量
|
||||
declare global {
|
||||
interface Window {
|
||||
AMap: any;
|
||||
}
|
||||
}
|
||||
|
||||
interface AmapContainerProps {
|
||||
tourismList: any[];
|
||||
onTourismClick: (tourism: any) => void;
|
||||
}
|
||||
|
||||
const AmapContainer: React.FC<AmapContainerProps> = (props) => {
|
||||
const { tourismList, onTourismClick } = props;
|
||||
const mapRef = useRef<HTMLDivElement>(null);
|
||||
const mapInstanceRef = useRef<any>(null);
|
||||
const markersRef = useRef<Map<string, any>>(new Map());
|
||||
|
||||
// 初始化地图
|
||||
useEffect(() => {
|
||||
const initMap = () => {
|
||||
if (!window.AMap) {
|
||||
console.error('window.AMap 未定义');
|
||||
message.error('地图SDK未加载');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mapRef.current) {
|
||||
console.error('地图容器未找到');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
console.log('开始初始化高德地图...');
|
||||
mapInstanceRef.current = new window.AMap.Map(mapRef.current, {
|
||||
zoom: 5, // 缩放级别5可以看到整个中国
|
||||
center: [104.195397, 35.86166], // 中国地理中心
|
||||
mapStyle: 'amap://styles/normal',
|
||||
viewMode: '2D',
|
||||
features: ['bg', 'road', 'building'],
|
||||
resizeEnable: true,
|
||||
});
|
||||
|
||||
console.log('地图初始化成功,开始加载控件插件...');
|
||||
// 添加地图控件 - 使用 AMap.plugin 异步加载
|
||||
window.AMap.plugin(['AMap.Scale', 'AMap.ToolBar'], () => {
|
||||
if (mapInstanceRef.current) {
|
||||
try {
|
||||
const scale = new window.AMap.Scale();
|
||||
const toolBar = new window.AMap.ToolBar();
|
||||
mapInstanceRef.current.addControl(scale);
|
||||
mapInstanceRef.current.addControl(toolBar);
|
||||
console.log('地图控件加载成功');
|
||||
} catch (err: any) {
|
||||
console.error('地图控件加载失败:', err);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error('地图初始化失败:', error);
|
||||
message.error('地图初始化失败: ' + error.message);
|
||||
}
|
||||
};
|
||||
|
||||
// 加载高德地图SDK
|
||||
if (!window.AMap) {
|
||||
const apiKey = process.env.REACT_APP_AMAP_KEY || 'YOUR_AMAP_KEY';
|
||||
console.log('开始加载高德地图SDK, API Key:', apiKey);
|
||||
|
||||
const script = document.createElement('script');
|
||||
script.type = 'text/javascript';
|
||||
script.src = `https://webapi.amap.com/maps?v=1.4.15&key=${apiKey}`;
|
||||
script.async = true;
|
||||
script.crossOrigin = 'anonymous';
|
||||
|
||||
script.onload = () => {
|
||||
console.log('高德地图SDK加载成功');
|
||||
initMap();
|
||||
};
|
||||
|
||||
script.onerror = (error) => {
|
||||
console.error('高德地图SDK加载失败:', error);
|
||||
message.error('地图SDK加载失败,请检查网络连接和API Key');
|
||||
};
|
||||
|
||||
document.head.appendChild(script);
|
||||
} else {
|
||||
console.log('高德地图SDK已存在,直接初始化');
|
||||
initMap();
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (mapInstanceRef.current) {
|
||||
try {
|
||||
mapInstanceRef.current.destroy();
|
||||
} catch (error) {
|
||||
console.error('地图销毁失败:', error);
|
||||
}
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
// 更新景区标记
|
||||
useEffect(() => {
|
||||
if (!mapInstanceRef.current || !tourismList.length) return;
|
||||
|
||||
// 清除旧标记
|
||||
markersRef.current.forEach((marker, key) => {
|
||||
if (key.startsWith('tourism_')) {
|
||||
marker.setMap(null);
|
||||
markersRef.current.delete(key);
|
||||
}
|
||||
});
|
||||
|
||||
// 验证并过滤有效的景区坐标(只显示有经纬度的景区)
|
||||
const validTourisms = tourismList.filter((tourism) => {
|
||||
const lat = parseFloat(tourism.latitude);
|
||||
const lng = parseFloat(tourism.longitude);
|
||||
return !isNaN(lat) && !isNaN(lng) && lat !== 0 && lng !== 0;
|
||||
});
|
||||
|
||||
// 如果没有有效景区,不进行后续操作
|
||||
if (validTourisms.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 添加景区标记
|
||||
validTourisms.forEach((tourism) => {
|
||||
const lng = parseFloat(tourism.longitude);
|
||||
const lat = parseFloat(tourism.latitude);
|
||||
|
||||
// 根据 status 状态设置颜色:1=绿色(启用),0=红色(禁用)
|
||||
const fillColor = tourism.status === 1 ? '#52c41a' : '#ff4d4f';
|
||||
|
||||
const marker = new window.AMap.CircleMarker({
|
||||
center: [lng, lat],
|
||||
radius: 15,
|
||||
fillColor: fillColor,
|
||||
fillOpacity: 0.8,
|
||||
strokeColor: '#fff',
|
||||
strokeWeight: 3,
|
||||
zIndex: 10,
|
||||
cursor: 'pointer',
|
||||
});
|
||||
|
||||
// 添加点击事件
|
||||
marker.on('click', () => onTourismClick(tourism));
|
||||
|
||||
// 添加信息窗体
|
||||
const infoWindow = new window.AMap.InfoWindow({
|
||||
content: `<div style="padding: 8px;">
|
||||
<h4 style="margin: 0 0 8px 0;">${tourism.tourismName || '景区'}</h4>
|
||||
<p style="margin: 0; color: #666;">${tourism.tourismAddress || ''}</p>
|
||||
</div>`,
|
||||
offset: new window.AMap.Pixel(0, -30),
|
||||
});
|
||||
|
||||
marker.on('mouseover', () => {
|
||||
infoWindow.open(mapInstanceRef.current, marker.getCenter());
|
||||
});
|
||||
|
||||
marker.on('mouseout', () => {
|
||||
infoWindow.close();
|
||||
});
|
||||
|
||||
marker.setMap(mapInstanceRef.current);
|
||||
markersRef.current.set(`tourism_${tourism.id}`, marker);
|
||||
});
|
||||
}, [tourismList, onTourismClick]);
|
||||
|
||||
return <div ref={mapRef} style={{ width: '100%', height: '100%' }} />;
|
||||
};
|
||||
|
||||
export default AmapContainer;
|
||||
+250
@@ -0,0 +1,250 @@
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import { message } from 'antd';
|
||||
|
||||
// 动态导入Cesium
|
||||
let Cesium: any = null;
|
||||
|
||||
interface CesiumContainerProps {
|
||||
tourismList: any[];
|
||||
onTourismClick: (tourism: any) => void;
|
||||
}
|
||||
|
||||
const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
const { tourismList, onTourismClick } = props;
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const viewerRef = useRef<any>(null);
|
||||
const entitiesRef = useRef<Map<string, any>>(new Map());
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
// 初始化Cesium
|
||||
useEffect(() => {
|
||||
const initCesium = async () => {
|
||||
try {
|
||||
// 动态导入Cesium
|
||||
if (!Cesium) {
|
||||
const cesiumModule = await import('cesium');
|
||||
Cesium = cesiumModule;
|
||||
|
||||
// 动态加载Cesium样式(使用CDN,稳定可靠)
|
||||
if (!document.querySelector('link[href*="cesium"]')) {
|
||||
const link = document.createElement('link');
|
||||
link.rel = 'stylesheet';
|
||||
link.href = 'https://unpkg.com/cesium@1.110.0/Build/Cesium/Widgets/widgets.css';
|
||||
document.head.appendChild(link);
|
||||
}
|
||||
}
|
||||
|
||||
if (!containerRef.current) return;
|
||||
|
||||
// 配置Cesium Ion Token(使用默认的,或配置自己的)
|
||||
// Cesium.Ion.defaultAccessToken = process.env.REACT_APP_CESIUM_TOKEN || '';
|
||||
|
||||
// 创建Viewer
|
||||
viewerRef.current = new Cesium.Viewer(containerRef.current, {
|
||||
// 使用天地图或高德作为底图(国内访问)
|
||||
imageryProvider: new Cesium.UrlTemplateImageryProvider({
|
||||
url: 'https://webst02.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}',
|
||||
minimumLevel: 3,
|
||||
maximumLevel: 18,
|
||||
}),
|
||||
|
||||
// 地形设置 - 使用默认地形(平坦)
|
||||
terrainProvider: new Cesium.EllipsoidTerrainProvider(),
|
||||
|
||||
// UI组件配置
|
||||
animation: false, // 不显示动画控件
|
||||
timeline: false, // 不显示时间轴
|
||||
fullscreenButton: false, // 不显示全屏按钮
|
||||
geocoder: false, // 不显示地理位置搜索
|
||||
homeButton: true, // 显示主页按钮
|
||||
sceneModePicker: true, // 显示2D/3D切换
|
||||
baseLayerPicker: false, // 不显示底图选择器
|
||||
navigationHelpButton: false,// 不显示帮助按钮
|
||||
|
||||
// 性能优化
|
||||
requestRenderMode: true, // 请求渲染模式
|
||||
maximumRenderTimeChange: Infinity,
|
||||
});
|
||||
|
||||
// 设置初始视角(中国中心,可以看到全国范围)
|
||||
viewerRef.current.camera.setView({
|
||||
destination: Cesium.Cartesian3.fromDegrees(104.195397, 35.86166, 5000000), // 提高高度到5000km
|
||||
orientation: {
|
||||
heading: Cesium.Math.toRadians(0),
|
||||
pitch: Cesium.Math.toRadians(-60), // 俯视角度
|
||||
roll: 0.0,
|
||||
},
|
||||
});
|
||||
|
||||
// 移除Cesium Logo和版权信息的点击事件
|
||||
const creditContainer = viewerRef.current.cesiumWidget.creditContainer;
|
||||
if (creditContainer) {
|
||||
creditContainer.style.display = 'none';
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
message.success('3D地图加载完成');
|
||||
} catch (error) {
|
||||
console.error('Cesium初始化失败:', error);
|
||||
message.error('3D地图加载失败');
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
initCesium();
|
||||
|
||||
return () => {
|
||||
// 清理
|
||||
if (viewerRef.current && !viewerRef.current.isDestroyed()) {
|
||||
viewerRef.current.destroy();
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
// 更新景区标记
|
||||
useEffect(() => {
|
||||
if (!viewerRef.current || !Cesium || !tourismList.length) return;
|
||||
|
||||
const viewer = viewerRef.current;
|
||||
|
||||
// 清除旧标记
|
||||
entitiesRef.current.forEach((entity, key) => {
|
||||
if (key.startsWith('tourism_')) {
|
||||
viewer.entities.remove(entity);
|
||||
entitiesRef.current.delete(key);
|
||||
}
|
||||
});
|
||||
|
||||
// 验证并过滤有效的景区坐标(只显示有经纬度的景区)
|
||||
const validTourisms = tourismList.filter((tourism) => {
|
||||
const lat = parseFloat(tourism.latitude);
|
||||
const lng = parseFloat(tourism.longitude);
|
||||
return !isNaN(lat) && !isNaN(lng) && lat !== 0 && lng !== 0;
|
||||
});
|
||||
|
||||
// 如果没有有效景区,不进行后续操作
|
||||
if (validTourisms.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 添加景区标记
|
||||
const positions: any[] = [];
|
||||
|
||||
validTourisms.forEach((tourism) => {
|
||||
const lon = parseFloat(tourism.longitude);
|
||||
const lat = parseFloat(tourism.latitude);
|
||||
|
||||
// 根据 status 状态设置颜色:1=绿色(启用),0=红色(禁用)
|
||||
const pointColor = tourism.status === 1 ? '#52c41a' : '#ff4d4f';
|
||||
|
||||
positions.push(Cesium.Cartesian3.fromDegrees(lon, lat));
|
||||
|
||||
// 创建实体标记
|
||||
const entity = viewer.entities.add({
|
||||
id: `tourism_${tourism.id}`,
|
||||
position: Cesium.Cartesian3.fromDegrees(lon, lat, 0),
|
||||
|
||||
// 点标记
|
||||
point: {
|
||||
pixelSize: 20,
|
||||
color: Cesium.Color.fromCssColorString(pointColor),
|
||||
outlineColor: Cesium.Color.WHITE,
|
||||
outlineWidth: 3,
|
||||
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
|
||||
},
|
||||
|
||||
// 标签
|
||||
label: {
|
||||
text: tourism.tourismName || '景区',
|
||||
font: '14px sans-serif',
|
||||
fillColor: Cesium.Color.WHITE,
|
||||
outlineColor: Cesium.Color.BLACK,
|
||||
outlineWidth: 2,
|
||||
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
|
||||
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
||||
pixelOffset: new Cesium.Cartesian2(0, -25),
|
||||
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
|
||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||
},
|
||||
|
||||
// 存储景区数据
|
||||
properties: {
|
||||
tourismData: tourism,
|
||||
},
|
||||
});
|
||||
|
||||
entitiesRef.current.set(`tourism_${tourism.id}`, entity);
|
||||
});
|
||||
}, [tourismList]);
|
||||
|
||||
// 点击事件
|
||||
useEffect(() => {
|
||||
if (!viewerRef.current || !Cesium) return;
|
||||
|
||||
const viewer = viewerRef.current;
|
||||
const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
|
||||
|
||||
// 左键点击
|
||||
handler.setInputAction((movement: any) => {
|
||||
const pickedObject = viewer.scene.pick(movement.position);
|
||||
|
||||
if (Cesium.defined(pickedObject) && pickedObject.id) {
|
||||
const entity = pickedObject.id;
|
||||
const tourismData = entity.properties?.tourismData?.getValue();
|
||||
|
||||
if (tourismData) {
|
||||
onTourismClick(tourismData);
|
||||
}
|
||||
}
|
||||
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
|
||||
// 鼠标移动悬停效果
|
||||
handler.setInputAction((movement: any) => {
|
||||
const pickedObject = viewer.scene.pick(movement.endPosition);
|
||||
|
||||
if (Cesium.defined(pickedObject) && pickedObject.id && pickedObject.id.point) {
|
||||
// 鼠标悬停时放大点
|
||||
pickedObject.id.point.pixelSize = 25;
|
||||
document.body.style.cursor = 'pointer';
|
||||
} else {
|
||||
// 恢复所有点的大小
|
||||
entitiesRef.current.forEach((entity) => {
|
||||
if (entity.point) {
|
||||
entity.point.pixelSize = 20;
|
||||
}
|
||||
});
|
||||
document.body.style.cursor = 'default';
|
||||
}
|
||||
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
||||
|
||||
return () => {
|
||||
handler.destroy();
|
||||
document.body.style.cursor = 'default';
|
||||
};
|
||||
}, [onTourismClick]);
|
||||
|
||||
return (
|
||||
<div style={{ width: '100%', height: '100%', position: 'relative' }}>
|
||||
<div ref={containerRef} style={{ width: '100%', height: '100%' }} />
|
||||
{loading && (
|
||||
<div
|
||||
style={{
|
||||
position: 'absolute',
|
||||
top: '50%',
|
||||
left: '50%',
|
||||
transform: 'translate(-50%, -50%)',
|
||||
color: '#fff',
|
||||
fontSize: 16,
|
||||
background: 'rgba(0,0,0,0.5)',
|
||||
padding: '10px 20px',
|
||||
borderRadius: 4,
|
||||
}}
|
||||
>
|
||||
加载3D地图中...
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default CesiumContainer;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
.mapContainer {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
import React from 'react';
|
||||
import AmapContainer from './AmapContainer';
|
||||
import CesiumContainer from './CesiumContainer';
|
||||
import styles from './index.less';
|
||||
|
||||
interface MapContainerProps {
|
||||
mode: '2d' | '3d';
|
||||
tourismList: any[];
|
||||
onTourismClick: (tourism: any) => void;
|
||||
}
|
||||
|
||||
const MapContainer: React.FC<MapContainerProps> = (props) => {
|
||||
const { mode, ...otherProps } = props;
|
||||
|
||||
return (
|
||||
<div className={styles.mapContainer}>
|
||||
{/* 2D地图 - 高德 */}
|
||||
{mode === '2d' && <AmapContainer {...otherProps} />}
|
||||
|
||||
{/* 3D地图 - Cesium */}
|
||||
{mode === '3d' && <CesiumContainer {...otherProps} />}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default MapContainer;
|
||||
@@ -0,0 +1,42 @@
|
||||
.mapDashboard {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
background: #000;
|
||||
|
||||
.toolbar {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 64px;
|
||||
background: rgba(255, 255, 255, 0.95);
|
||||
backdrop-filter: blur(10px);
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0 24px;
|
||||
z-index: 1000;
|
||||
|
||||
.left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.title {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: #000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.mapWrapper {
|
||||
position: absolute;
|
||||
top: 64px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Button, Space, Badge, message, Radio } from 'antd';
|
||||
import {
|
||||
ReloadOutlined,
|
||||
FullscreenOutlined,
|
||||
FullscreenExitOutlined,
|
||||
GlobalOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { history } from 'umi';
|
||||
import MapContainer from './components/MapContainer';
|
||||
import { ordersApi } from '@/services/orders';
|
||||
import { tenantApi } from '@/services/tenant';
|
||||
import styles from './index.less';
|
||||
|
||||
type MapMode = '2d' | '3d';
|
||||
|
||||
const MapDashboard: React.FC = () => {
|
||||
const [tourismList, setTourismList] = useState<any[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [mapMode, setMapMode] = useState<MapMode>('2d');
|
||||
const [isFullscreen, setIsFullscreen] = useState(false);
|
||||
const [params, setParams] = useState<{ tenantId?: string; includeChildren?: boolean }>({});
|
||||
|
||||
// 首次进入时,默认按"当前租户 + 包含下级租户"查询
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
try {
|
||||
let tenantId: string | undefined;
|
||||
const cur: any = await tenantApi.getCurrentTenant();
|
||||
tenantId = cur?.data?.tenantId ?? cur?.tenantId;
|
||||
if (!tenantId) {
|
||||
const stats: any = await tenantApi.getScopeStats();
|
||||
tenantId = stats?.data?.currentTenantId ?? stats?.currentTenantId;
|
||||
}
|
||||
if (tenantId) {
|
||||
setParams({ tenantId, includeChildren: true });
|
||||
}
|
||||
} catch {
|
||||
// 忽略错误
|
||||
}
|
||||
})();
|
||||
}, []);
|
||||
|
||||
// 获取景区列表
|
||||
const fetchTourismList = async () => {
|
||||
if (!params.tenantId) {
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await ordersApi.tourism({
|
||||
current: 1,
|
||||
pageSize: 1000,
|
||||
...params,
|
||||
});
|
||||
setTourismList(response.data || []);
|
||||
} catch (error) {
|
||||
message.error('获取景区列表失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 景区点击事件 - 跳转到景区设备详情页面
|
||||
const handleTourismClick = (tourism: any) => {
|
||||
history.push(`/device/mapDashboard/tourismDeviceDetail/${tourism.id}`, {
|
||||
tourismName: tourism.tourismName,
|
||||
tourism: tourism,
|
||||
});
|
||||
};
|
||||
|
||||
// 地图模式切换
|
||||
const handleMapModeChange = (mode: MapMode) => {
|
||||
setMapMode(mode);
|
||||
message.success(`已切换到${mode === '2d' ? '二维' : '三维'}地图`);
|
||||
};
|
||||
|
||||
// 全屏切换
|
||||
const toggleFullscreen = () => {
|
||||
if (!document.fullscreenElement) {
|
||||
document.documentElement.requestFullscreen();
|
||||
setIsFullscreen(true);
|
||||
} else {
|
||||
document.exitFullscreen();
|
||||
setIsFullscreen(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 租户ID获取后,加载景区列表
|
||||
useEffect(() => {
|
||||
if (params.tenantId) {
|
||||
fetchTourismList();
|
||||
}
|
||||
}, [params.tenantId]);
|
||||
|
||||
return (
|
||||
<div className={styles.mapDashboard}>
|
||||
{/* 顶部工具栏 */}
|
||||
<div className={styles.toolbar}>
|
||||
<div className={styles.left}>
|
||||
<span className={styles.title}>景区地图仪表盘</span>
|
||||
<Badge
|
||||
status="success"
|
||||
text={`共${tourismList.length}个景区`}
|
||||
style={{ marginLeft: 16 }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Space size="middle">
|
||||
{/* 地图模式切换 */}
|
||||
<Radio.Group
|
||||
value={mapMode}
|
||||
onChange={(e) => handleMapModeChange(e.target.value)}
|
||||
buttonStyle="solid"
|
||||
>
|
||||
<Radio.Button value="2d">
|
||||
<GlobalOutlined /> 高德2D
|
||||
</Radio.Button>
|
||||
<Radio.Button value="3d">
|
||||
<GlobalOutlined /> Cesium 3D
|
||||
</Radio.Button>
|
||||
</Radio.Group>
|
||||
|
||||
<Button
|
||||
icon={<ReloadOutlined />}
|
||||
onClick={fetchTourismList}
|
||||
loading={loading}
|
||||
>
|
||||
刷新
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
icon={isFullscreen ? <FullscreenExitOutlined /> : <FullscreenOutlined />}
|
||||
onClick={toggleFullscreen}
|
||||
>
|
||||
{isFullscreen ? '退出全屏' : '全屏'}
|
||||
</Button>
|
||||
</Space>
|
||||
</div>
|
||||
|
||||
{/* 全屏地图 */}
|
||||
<div className={styles.mapWrapper}>
|
||||
<MapContainer
|
||||
mode={mapMode}
|
||||
tourismList={tourismList}
|
||||
onTourismClick={handleTourismClick}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default MapDashboard;
|
||||
@@ -109,6 +109,11 @@ export const ordersApi = {
|
||||
const res = await request('/api-order/tourism', { method: 'DELETE', data: { id } });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
// 根据景区ID获取设备SN列表
|
||||
getDeviceSnsByTourismId: async (tourismId: number) => {
|
||||
const res = await request(`/api-order/tourism/${tourismId}/device-sns`, { method: 'GET' });
|
||||
return (res as any).data || [];
|
||||
},
|
||||
|
||||
// 首页轮播
|
||||
homeCarousel: async (params: { current?: number; pageSize?: number; [k: string]: any }) => {
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// 全局类型声明
|
||||
|
||||
// CSS模块声明
|
||||
declare module '*.css' {
|
||||
const content: any;
|
||||
export default content;
|
||||
}
|
||||
|
||||
declare module '*.less' {
|
||||
const content: any;
|
||||
export default content;
|
||||
}
|
||||
|
||||
// Cesium相关声明
|
||||
declare module 'cesium' {
|
||||
const content: any;
|
||||
export = content;
|
||||
}
|
||||
|
||||
declare module 'cesium/Build/Cesium/Widgets/widgets.css';
|
||||
|
||||
// 扩展Window类型
|
||||
interface Window {
|
||||
AMap: any;
|
||||
}
|
||||
Reference in New Issue
Block a user