feat: 物联网卡管理

This commit is contained in:
2026-03-27 18:31:21 +08:00
parent e6361ac72b
commit 982e4364d5
50 changed files with 3571 additions and 354 deletions
@@ -53,26 +53,49 @@
.routeActions {
position: absolute;
bottom: 20px;
bottom: 24px;
left: 50%;
transform: translateX(-50%);
background: rgba(10, 18, 32, 0.92);
padding: 10px 20px;
border-radius: 8px;
z-index: 800;
background: linear-gradient(135deg, rgba(8, 22, 36, 0.94) 0%, rgba(15, 35, 58, 0.9) 100%);
padding: 12px 18px;
border-radius: 16px;
z-index: 830;
display: flex;
align-items: center;
gap: 12px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
border: 1px solid rgba(0, 212, 255, 0.3);
box-shadow:
0 16px 34px rgba(0, 0, 0, 0.35),
inset 0 1px 0 rgba(255, 255, 255, 0.08),
inset 0 0 0 1px rgba(73, 174, 255, 0.1);
border: 1px solid rgba(79, 188, 255, 0.28);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
.routeActionsTitle {
color: #00d4ff;
font-size: 13px;
font-weight: 500;
max-width: 150px;
color: #dff3ff;
font-size: 14px;
font-weight: 700;
max-width: 180px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
letter-spacing: 0.4px;
}
@media (max-width: 960px) {
.routeActions {
left: 12px;
right: 12px;
bottom: 12px;
transform: none;
justify-content: space-between;
flex-wrap: wrap;
gap: 10px;
}
.routeActionsTitle {
max-width: 100%;
width: 100%;
}
}
@@ -18,9 +18,13 @@ interface CenterViewProps {
selectedRouteId: string | null;
boatData: BoatTelemetryData | null;
onModelCenter?: (lon: number, lat: number) => void;
isSailing?: boolean;
previewStopSignal?: number;
onStartSailing?: (routeId: string) => void;
onPreviewChange?: (previewing: boolean) => void;
}
const CenterView: React.FC<CenterViewProps> = ({ deviceSn, routes, selectedRouteId, boatData, onModelCenter }) => {
const CenterView: React.FC<CenterViewProps> = ({ deviceSn, routes, selectedRouteId, boatData, onModelCenter, isSailing, previewStopSignal, onStartSailing, onPreviewChange }) => {
const containerRef = useRef<HTMLDivElement>(null);
const viewerRef = useRef<any>(null);
const [viewerReady, setViewerReady] = useState(false);
@@ -32,6 +36,24 @@ const CenterView: React.FC<CenterViewProps> = ({ deviceSn, routes, selectedRoute
const { loadTileset, unloadAllTilesets } = useTilesetLoader();
const { isPreviewing, startPreview, stopPreview } = useRoutePreview({ viewerRef });
// 预览状态变化时通知父组件
useEffect(() => {
onPreviewChange?.(isPreviewing);
}, [isPreviewing, onPreviewChange]);
const lastPreviewStopSignalRef = useRef(previewStopSignal);
// 外部停止通道:例如 HUD 点击“结束预览”时由父组件递增信号
useEffect(() => {
if (previewStopSignal == null) return;
if (lastPreviewStopSignalRef.current === previewStopSignal) return;
lastPreviewStopSignalRef.current = previewStopSignal;
if (isPreviewing) {
stopPreview();
}
}, [previewStopSignal, isPreviewing, stopPreview]);
// 航线渲染数据(含航点)
const [routeRenderItems, setRouteRenderItems] = useState<any[]>([]);
// 缓存已加载的航线详情
@@ -384,10 +406,12 @@ const CenterView: React.FC<CenterViewProps> = ({ deviceSn, routes, selectedRoute
await startPreview(waypoints, 2);
}, [selectedRouteId, startPreview]);
// 执行航线(暂未实现)
// 执行航线
const handleExecuteRoute = useCallback(() => {
message.info('航行功能开发中...');
}, []);
if (selectedRouteId && onStartSailing) {
onStartSailing(selectedRouteId);
}
}, [selectedRouteId, onStartSailing]);
// 获取选中航线名称
const selectedRouteName = useMemo(() => {
@@ -407,8 +431,8 @@ const CenterView: React.FC<CenterViewProps> = ({ deviceSn, routes, selectedRoute
</div>
)}
{/* 选中线路时显示操作按钮 */}
{selectedRouteId && !isPreviewing && (
{/* 选中线路时显示操作按钮(非航行模式) */}
{selectedRouteId && !isPreviewing && !isSailing && (
<div className={styles.routeActions}>
<div className={styles.routeActionsTitle}>{selectedRouteName}</div>
<Space>
@@ -432,20 +456,7 @@ const CenterView: React.FC<CenterViewProps> = ({ deviceSn, routes, selectedRoute
</div>
)}
{/* 预览中显示停止按钮 */}
{isPreviewing && (
<div className={styles.routeActions}>
<Button
danger
type="primary"
icon={<StopOutlined />}
onClick={stopPreview}
size="small"
>
停止预览 (ESC)
</Button>
</div>
)}
{/* 预览停止操作已收敛至 NavigationHUD,此处不再重复渲染 */}
</div>
);
};
@@ -0,0 +1,80 @@
.emergencyBtn {
position: absolute;
top: 22px;
right: 22px;
z-index: 930;
width: 142px;
height: 54px;
border-radius: 999px;
background: linear-gradient(135deg, rgba(255, 111, 85, 0.96) 0%, rgba(206, 51, 53, 0.94) 100%);
border: 1px solid rgba(255, 181, 152, 0.36);
color: #fff;
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
cursor: pointer;
outline: none;
box-shadow:
0 16px 34px rgba(94, 16, 18, 0.34),
0 0 0 1px rgba(255, 110, 92, 0.22),
inset 0 1px 0 rgba(255, 255, 255, 0.18);
transition: all 0.2s ease;
animation: dangerPulse 2s infinite;
font-family: 'Rajdhani', 'Orbitron', 'DIN', 'Avenir Next', 'PingFang SC', sans-serif;
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
&:hover {
background: linear-gradient(135deg, rgba(255, 133, 110, 0.98) 0%, rgba(230, 61, 63, 0.96) 100%);
box-shadow:
0 18px 38px rgba(112, 19, 23, 0.42),
0 0 22px rgba(255, 107, 88, 0.32),
inset 0 1px 0 rgba(255, 255, 255, 0.24);
animation: dangerPulseHover 1s infinite;
}
&:active {
transform: scale(0.97);
box-shadow:
0 8px 16px rgba(82, 17, 18, 0.35),
inset 0 4px 10px rgba(0, 0, 0, 0.16);
animation: none;
}
}
.icon {
font-size: 18px;
margin-top: -1px;
}
.text {
font-size: 15px;
font-weight: 700;
letter-spacing: 0.8px;
}
@keyframes dangerPulse {
0% { box-shadow: 0 0 0 0 rgba(255, 77, 79, 0.6); }
70% { box-shadow: 0 0 0 12px rgba(255, 77, 79, 0); }
100% { box-shadow: 0 0 0 0 rgba(255, 77, 79, 0); }
}
@keyframes dangerPulseHover {
0% { box-shadow: 0 0 0 0 rgba(255, 77, 79, 0.8); }
70% { box-shadow: 0 0 0 16px rgba(255, 77, 79, 0); }
100% { box-shadow: 0 0 0 0 rgba(255, 77, 79, 0); }
}
@media (max-width: 960px) {
.emergencyBtn {
top: 14px;
right: 14px;
width: 132px;
height: 50px;
}
.text {
font-size: 14px;
}
}
@@ -0,0 +1,34 @@
import React from 'react';
import { Modal } from 'antd';
import { WarningOutlined, ExclamationCircleOutlined } from '@ant-design/icons';
import styles from './index.less';
export interface EmergencyButtonProps {
onEmergencyStop: () => void;
deviceSn: string;
}
const EmergencyButton: React.FC<EmergencyButtonProps> = ({ onEmergencyStop, deviceSn }) => {
const handleClick = () => {
Modal.confirm({
title: '确认紧急停靠',
icon: <ExclamationCircleOutlined style={{ color: '#ff4d4f' }} />,
content: `您确定要立即停止设备 ${deviceSn} 的所有动作吗?这可能会造成不可逆的后果。`,
okText: '确认停靠',
okType: 'danger',
cancelText: '取消',
onOk: () => {
onEmergencyStop();
},
});
};
return (
<button className={styles.emergencyBtn} onClick={handleClick}>
<WarningOutlined className={styles.icon} />
<span className={styles.text}>紧急停靠</span>
</button>
);
};
export default EmergencyButton;
@@ -1,3 +1,17 @@
/* ========== 玻璃拟态变量 ========== */
@glass-border: rgba(65, 170, 255, 0.28);
@glass-border-light: rgba(92, 211, 255, 0.18);
@accent-cyan: #00d4ff;
@accent-blue: #0096ff;
@text-primary: #eaf6ff;
@text-secondary: rgba(255, 255, 255, 0.55);
@text-dim: rgba(255, 255, 255, 0.35);
@card-bg: linear-gradient(145deg, rgba(10, 24, 48, 0.7), rgba(8, 18, 38, 0.5));
@card-bg-active: linear-gradient(145deg, rgba(0, 80, 160, 0.2), rgba(0, 120, 200, 0.1));
@card-shadow: 0 2px 12px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.06);
@card-shadow-active: 0 2px 20px rgba(0, 112, 212, 0.2), inset 0 1px 0 rgba(0, 180, 255, 0.12);
@transition-fast: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
.panel {
height: 100%;
display: flex;
@@ -6,54 +20,74 @@
/* ========== 头部 ========== */
.header {
padding: 18px 16px;
border-bottom: 1px solid rgba(0, 212, 255, 0.12);
padding: 20px 16px 16px;
border-bottom: 1px solid @glass-border-light;
display: flex;
align-items: center;
gap: 10px;
gap: 12px;
position: relative;
// 底部渐变高光
&::after {
content: '';
position: absolute;
bottom: -1px;
left: 16px;
right: 16px;
height: 1px;
background: linear-gradient(90deg, transparent, rgba(0, 212, 255, 0.2), transparent);
}
}
.headerIcon {
width: 36px;
height: 36px;
width: 38px;
height: 38px;
border-radius: 10px;
background: linear-gradient(135deg, rgba(0, 112, 212, 0.3), rgba(0, 180, 255, 0.15));
background: linear-gradient(135deg, rgba(0, 100, 200, 0.35), rgba(0, 180, 255, 0.15));
backdrop-filter: blur(8px);
border: 1px solid rgba(0, 150, 255, 0.25);
display: flex;
align-items: center;
justify-content: center;
color: #00d4ff;
color: @accent-cyan;
font-size: 16px;
flex-shrink: 0;
box-shadow: 0 2px 8px rgba(0, 100, 200, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.headerTitle {
font-size: 15px;
font-weight: 600;
color: #fff;
color: @text-primary;
line-height: 1.3;
letter-spacing: 0.5px;
}
.headerSub {
font-size: 11px;
color: rgba(255, 255, 255, 0.35);
color: @text-dim;
letter-spacing: 0.3px;
}
.count {
margin-left: auto;
background: rgba(0, 112, 212, 0.2);
color: #00b4ff;
background: linear-gradient(135deg, rgba(0, 100, 200, 0.25), rgba(0, 150, 255, 0.15));
border: 1px solid rgba(0, 150, 255, 0.2);
color: @accent-cyan;
font-size: 12px;
font-weight: 600;
padding: 2px 10px;
font-weight: 700;
font-family: 'Rajdhani', 'DIN', monospace;
padding: 2px 12px;
border-radius: 10px;
flex-shrink: 0;
letter-spacing: 0.5px;
}
/* ========== 列表 ========== */
.list {
flex: 1;
overflow-y: auto;
padding: 10px;
padding: 12px 10px;
}
.center {
@@ -65,27 +99,58 @@
/* ========== 线路卡片 ========== */
.routeCard {
padding: 14px;
padding: 14px 16px;
margin-bottom: 8px;
border-radius: 10px;
cursor: pointer;
transition: all 0.25s;
border: 1px solid rgba(255, 255, 255, 0.06);
background: rgba(255, 255, 255, 0.03);
transition: @transition-fast;
border: 1px solid rgba(255, 255, 255, 0.05);
background: @card-bg;
backdrop-filter: blur(6px);
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
position: relative;
overflow: hidden;
// 左侧指示条
&::before {
content: '';
position: absolute;
left: 0;
top: 20%;
bottom: 20%;
width: 2px;
background: transparent;
border-radius: 1px;
transition: @transition-fast;
}
&:hover {
background: rgba(0, 150, 220, 0.08);
border-color: rgba(0, 180, 255, 0.2);
background: linear-gradient(145deg, rgba(0, 80, 160, 0.12), rgba(0, 120, 200, 0.06));
border-color: rgba(0, 150, 255, 0.25);
box-shadow: @card-shadow;
transform: translateX(2px);
&::before {
background: rgba(0, 180, 255, 0.4);
}
}
}
.routeCardActive {
background: rgba(0, 112, 212, 0.12);
background: @card-bg-active;
border-color: rgba(0, 150, 255, 0.4);
box-shadow: 0 0 16px rgba(0, 112, 212, 0.12);
box-shadow: @card-shadow-active;
&::before {
background: linear-gradient(180deg, @accent-cyan, @accent-blue);
width: 3px;
top: 12%;
bottom: 12%;
}
.routeName {
color: #00d4ff;
color: @accent-cyan;
text-shadow: 0 0 12px rgba(0, 212, 255, 0.3);
}
}
@@ -94,7 +159,8 @@
font-weight: 600;
color: rgba(255, 255, 255, 0.92);
margin-bottom: 8px;
transition: color 0.2s;
transition: @transition-fast;
letter-spacing: 0.3px;
}
/* ========== 标签行 ========== */
@@ -110,15 +176,18 @@
align-items: center;
gap: 4px;
font-size: 11px;
color: rgba(255, 255, 255, 0.5);
background: rgba(255, 255, 255, 0.06);
color: @text-secondary;
background: rgba(0, 100, 180, 0.1);
border: 1px solid rgba(0, 150, 255, 0.1);
padding: 2px 8px;
border-radius: 4px;
font-family: 'Rajdhani', 'DIN', sans-serif;
letter-spacing: 0.3px;
}
.tagIcon {
font-size: 10px;
color: rgba(0, 180, 255, 0.6);
color: rgba(0, 180, 255, 0.65);
}
/* ========== 航点路径 ========== */
@@ -126,42 +195,53 @@
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 4px;
gap: 5px;
padding: 10px 0 4px;
border-top: 1px dashed rgba(255, 255, 255, 0.08);
border-top: 1px solid rgba(65, 170, 255, 0.1);
}
.waypointDot {
width: 6px;
height: 6px;
border-radius: 50%;
background: rgba(0, 180, 255, 0.6);
background: @accent-cyan;
box-shadow: 0 0 4px rgba(0, 212, 255, 0.4);
flex-shrink: 0;
}
.waypointName {
font-size: 12px;
color: rgba(255, 255, 255, 0.7);
letter-spacing: 0.2px;
}
.waypointArrow {
font-size: 11px;
color: rgba(0, 180, 255, 0.5);
color: rgba(0, 180, 255, 0.45);
margin: 0 1px;
}
/* ========== 开始航行按钮 ========== */
.startBtn {
margin-top: 12px;
height: 36px;
height: 38px;
border-radius: 8px;
font-weight: 600;
font-size: 14px;
letter-spacing: 1px;
letter-spacing: 1.5px;
background: linear-gradient(135deg, #0070d4, #0096ff);
border: none;
border: 1px solid rgba(0, 150, 255, 0.3);
box-shadow: 0 2px 12px rgba(0, 112, 212, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.1);
transition: @transition-fast;
&:hover {
background: linear-gradient(135deg, #0080e8, #00a8ff);
box-shadow: 0 4px 20px rgba(0, 112, 212, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.12);
transform: translateY(-1px);
}
&:active {
transform: translateY(0);
box-shadow: 0 1px 6px rgba(0, 112, 212, 0.3);
}
}
@@ -0,0 +1,467 @@
.hudContainer {
position: absolute;
left: 50%;
bottom: 26px;
transform: translateX(-50%);
width: calc(100% - 48px);
max-width: 1360px;
z-index: 920;
display: grid;
grid-template-columns: 168px 1fr 216px 168px;
gap: 16px;
align-items: stretch;
border-radius: 20px;
padding: 14px 16px;
background:
linear-gradient(120deg, rgba(7, 20, 34, 0.95) 0%, rgba(11, 36, 60, 0.9) 58%, rgba(18, 29, 50, 0.94) 100%);
border: 1px solid rgba(65, 170, 255, 0.28);
box-shadow:
0 16px 40px rgba(2, 11, 24, 0.5),
inset 0 1px 0 rgba(255, 255, 255, 0.08),
inset 0 0 0 1px rgba(33, 145, 240, 0.14);
color: #eaf6ff;
font-family: 'Rajdhani', 'DIN', 'Avenir Next', 'PingFang SC', sans-serif;
font-variant-numeric: tabular-nums;
overflow: hidden;
}
.hudContainer::before {
content: '';
position: absolute;
top: 0;
left: 16px;
right: 16px;
height: 1px;
background: linear-gradient(90deg, transparent 0%, rgba(133, 206, 255, 0.7) 45%, transparent 100%);
}
.hudContainer::after {
content: '';
position: absolute;
top: -120px;
right: -120px;
width: 280px;
height: 280px;
background: radial-gradient(circle, rgba(70, 156, 255, 0.22) 0%, rgba(70, 156, 255, 0) 72%);
pointer-events: none;
}
.previewMode {
border-color: rgba(72, 190, 255, 0.42);
}
.sailingMode {
border-color: rgba(255, 158, 94, 0.38);
}
.primaryCluster,
.centerCluster,
.statusCluster,
.actionCluster {
position: relative;
z-index: 1;
}
.primaryCluster {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 8px;
}
.speedDial {
width: 116px;
height: 116px;
position: relative;
}
.speedSvg {
width: 100%;
height: 100%;
}
.speedTrack,
.speedRing {
fill: none;
stroke-width: 8;
transform-origin: 60px 60px;
transform: rotate(-90deg);
}
.speedTrack {
stroke: rgba(208, 231, 255, 0.16);
}
.speedRing {
stroke: #4fcbff;
stroke-linecap: round;
transition: stroke-dashoffset 0.35s ease;
filter: drop-shadow(0 0 8px rgba(79, 203, 255, 0.7));
}
.speedCenter {
position: absolute;
inset: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.speedValue {
font-size: 34px;
line-height: 1;
font-weight: 700;
color: #f5fbff;
}
.speedUnit {
margin-top: 4px;
font-size: 12px;
letter-spacing: 1px;
color: rgba(166, 223, 255, 0.86);
}
.modeChip {
padding: 2px 12px;
border-radius: 100px;
font-size: 12px;
font-weight: 600;
color: #d8eeff;
border: 1px solid rgba(156, 213, 255, 0.35);
background: rgba(20, 48, 75, 0.7);
}
.centerCluster {
display: flex;
flex-direction: column;
justify-content: center;
gap: 10px;
}
.routeHeader {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
}
.routeTitle {
font-size: 20px;
font-weight: 700;
color: #f1f9ff;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.routeProgress {
font-size: 14px;
font-weight: 700;
color: #7fd9ff;
}
.routeProgressTrack {
width: 100%;
height: 6px;
border-radius: 999px;
overflow: hidden;
background: rgba(201, 226, 255, 0.2);
}
.routeProgressFill {
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #2e9dff 0%, #3ff0ff 55%, #7effcc 100%);
transition: width 0.3s ease;
box-shadow: 0 0 8px rgba(76, 202, 255, 0.6);
}
.waypointCard {
border-radius: 12px;
padding: 10px 12px;
background: linear-gradient(140deg, rgba(22, 47, 78, 0.78) 0%, rgba(11, 26, 43, 0.84) 100%);
border: 1px solid rgba(110, 186, 255, 0.22);
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
}
.waypointMain {
display: flex;
align-items: center;
gap: 10px;
min-width: 0;
}
.navArrow {
font-size: 20px;
color: #59cbff;
filter: drop-shadow(0 0 6px rgba(89, 203, 255, 0.7));
}
.infoLabel {
font-size: 11px;
letter-spacing: 0.6px;
color: rgba(195, 226, 255, 0.7);
}
.waypointName {
font-size: 16px;
font-weight: 700;
color: #f7fcff;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 220px;
}
.waypointStats {
display: flex;
gap: 20px;
}
.infoValue {
margin-top: 2px;
font-size: 17px;
color: #8de5ff;
font-weight: 700;
}
.emptyWaypoint {
width: 100%;
text-align: center;
color: rgba(204, 229, 255, 0.72);
font-size: 13px;
}
.summaryRow {
display: flex;
gap: 28px;
}
.summaryItem {
min-width: 92px;
}
.summaryValue {
margin-top: 2px;
font-size: 15px;
font-weight: 700;
color: #e6f5ff;
}
.statusCluster {
display: flex;
flex-direction: column;
justify-content: center;
gap: 10px;
}
.compassCard,
.powerCard {
border-radius: 12px;
padding: 8px 10px;
background: rgba(12, 29, 48, 0.78);
border: 1px solid rgba(106, 176, 238, 0.22);
}
.cardTitle {
font-size: 12px;
color: #b7deff;
display: flex;
align-items: center;
gap: 6px;
}
.compassDial {
margin: 6px auto;
width: 72px;
height: 72px;
border-radius: 50%;
border: 1px solid rgba(141, 208, 255, 0.3);
background: radial-gradient(circle at center, rgba(68, 157, 226, 0.25) 0%, rgba(8, 23, 38, 0.8) 70%);
position: relative;
}
.compassRotor {
position: absolute;
inset: 0;
transition: transform 0.28s ease;
}
.compassTick {
position: absolute;
left: 50%;
top: 5px;
width: 2px;
height: 7px;
margin-left: -1px;
background: rgba(174, 219, 255, 0.75);
transform-origin: 50% 31px;
}
.compassNeedle {
position: absolute;
left: 50%;
top: 8px;
margin-left: -3px;
width: 0;
height: 0;
border-left: 3px solid transparent;
border-right: 3px solid transparent;
border-bottom: 14px solid #ff8f66;
filter: drop-shadow(0 0 5px rgba(255, 143, 102, 0.8));
}
.compassValue {
text-align: center;
font-size: 13px;
font-weight: 700;
color: #ecf8ff;
}
.powerCard {
display: flex;
flex-direction: column;
gap: 6px;
}
.powerRow {
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
}
.powerValue {
font-size: 13px;
font-weight: 700;
color: #f7fbff;
}
.powerTrack {
height: 6px;
border-radius: 999px;
overflow: hidden;
background: rgba(196, 223, 250, 0.2);
}
.powerFill,
.signalFill {
height: 100%;
border-radius: inherit;
transition: width 0.25s ease;
}
.powerFill {
background: linear-gradient(90deg, #fa7d57 0%, #ffcf77 100%);
}
.signalFill {
background: linear-gradient(90deg, #2ea4ff 0%, #63f4ff 100%);
}
.actionCluster {
display: flex;
flex-direction: column;
justify-content: center;
gap: 10px;
}
.actionBtn {
height: 40px;
border-radius: 12px;
border: 1px solid transparent;
background: rgba(255, 255, 255, 0.07);
color: #f2faff;
font-size: 14px;
font-weight: 700;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
cursor: pointer;
transition: all 0.2s ease;
}
.actionBtn:active {
transform: scale(0.97);
}
.actionPrimary {
border-color: rgba(95, 210, 255, 0.5);
background: linear-gradient(120deg, rgba(43, 147, 232, 0.34) 0%, rgba(51, 190, 235, 0.5) 100%);
box-shadow: inset 0 0 0 1px rgba(144, 220, 255, 0.2);
}
.actionPrimary:hover {
filter: brightness(1.08);
}
.actionDanger {
border-color: rgba(255, 151, 108, 0.62);
background: linear-gradient(120deg, rgba(219, 95, 46, 0.55) 0%, rgba(255, 140, 90, 0.52) 100%);
}
.actionDanger:hover {
filter: brightness(1.06);
}
@media (max-width: 1240px) {
.hudContainer {
grid-template-columns: 154px 1fr 200px 154px;
gap: 12px;
}
.routeTitle {
font-size: 18px;
}
.waypointName {
max-width: 150px;
}
.waypointStats {
gap: 14px;
}
}
@media (max-width: 960px) {
.hudContainer {
left: 12px;
right: 12px;
bottom: 10px;
transform: none;
width: auto;
grid-template-columns: 1fr;
max-height: 46vh;
overflow-y: auto;
}
.primaryCluster,
.statusCluster,
.actionCluster {
flex-direction: row;
align-items: center;
justify-content: space-between;
}
.centerCluster {
order: -1;
}
.summaryRow {
justify-content: space-between;
}
.actionCluster {
gap: 8px;
}
.actionBtn {
flex: 1;
}
}
@@ -0,0 +1,216 @@
import React, { useMemo } from 'react';
import {
PauseCircleOutlined,
PlayCircleOutlined,
StopOutlined,
SendOutlined,
ThunderboltOutlined,
WifiOutlined,
CompassOutlined,
} from '@ant-design/icons';
import styles from './index.less';
type NavigationMode = 'preview' | 'sailing';
export interface NavigationHUDProps {
mode: NavigationMode;
routeName: string;
speed: number;
heading: number;
battery: number;
signalStrength?: number;
nextWaypoint?: {
name: string;
distance: number;
estimatedTime: number;
};
remainingDistance: number;
estimatedRemainingTime: number;
progress: number;
isPaused: boolean;
onPause: () => void;
onResume: () => void;
onStop: () => void;
}
/** 格式化距离 */
const formatDist = (m: number) => (m >= 1000 ? `${(m / 1000).toFixed(1)}km` : `${Math.round(m)}m`);
/** 格式化时间 */
const formatTime = (s: number) => {
const mins = Math.floor(s / 60);
const secs = Math.floor(s % 60);
if (mins >= 60) {
const h = Math.floor(mins / 60);
const m = mins % 60;
return `${h}时${m}分`;
}
return mins > 0 ? `${mins}分${secs}秒` : `${secs}秒`;
};
const directionText = (heading: number) => {
const normalized = ((heading % 360) + 360) % 360;
if (normalized < 22.5 || normalized >= 337.5) return '北';
if (normalized < 67.5) return '东北';
if (normalized < 112.5) return '东';
if (normalized < 157.5) return '东南';
if (normalized < 202.5) return '南';
if (normalized < 247.5) return '西南';
if (normalized < 292.5) return '西';
return '西北';
};
const NavigationHUD: React.FC<NavigationHUDProps> = ({
mode,
routeName,
speed,
heading,
battery,
signalStrength,
nextWaypoint,
remainingDistance,
estimatedRemainingTime,
progress,
isPaused,
onPause,
onResume,
onStop,
}) => {
const maxSpeed = 12;
const clampedSpeed = Math.max(0, Math.min(speed, maxSpeed));
const speedPercent = clampedSpeed / maxSpeed;
const ringLength = 2 * Math.PI * 44;
const ringOffset = ringLength * (1 - speedPercent);
const normalizedProgress = Math.max(0, Math.min(100, progress));
const normalizedBattery = Math.max(0, Math.min(100, battery));
const normalizedSignal = Math.max(0, Math.min(100, signalStrength ?? 0));
const compassTicks = useMemo(() => {
const marks = [];
for (let i = 0; i < 12; i += 1) {
marks.push(<span key={i} className={styles.compassTick} style={{ transform: `rotate(${i * 30}deg)` }} />);
}
return marks;
}, []);
const previewing = mode === 'preview';
const actionText = previewing ? '结束预览' : isPaused ? '继续航行' : '暂停航行';
const actionIcon = previewing ? <StopOutlined /> : isPaused ? <PlayCircleOutlined /> : <PauseCircleOutlined />;
const actionHandler = previewing ? onStop : isPaused ? onResume : onPause;
return (
<div className={`${styles.hudContainer} ${previewing ? styles.previewMode : styles.sailingMode}`}>
<div className={styles.primaryCluster}>
<div className={styles.speedDial}>
<svg viewBox="0 0 120 120" className={styles.speedSvg}>
<circle cx="60" cy="60" r="44" className={styles.speedTrack} />
<circle
cx="60"
cy="60"
r="44"
className={styles.speedRing}
style={{ strokeDasharray: ringLength, strokeDashoffset: ringOffset }}
/>
</svg>
<div className={styles.speedCenter}>
<div className={styles.speedValue}>{speed.toFixed(1)}</div>
<div className={styles.speedUnit}>m/s</div>
</div>
</div>
<div className={styles.modeChip}>{previewing ? '预览模式' : '航行模式'}</div>
</div>
<div className={styles.centerCluster}>
<div className={styles.routeHeader}>
<span className={styles.routeTitle}>{routeName || '未选择线路'}</span>
<span className={styles.routeProgress}>{normalizedProgress}%</span>
</div>
<div className={styles.routeProgressTrack}>
<div className={styles.routeProgressFill} style={{ width: `${normalizedProgress}%` }} />
</div>
<div className={styles.waypointCard}>
{nextWaypoint ? (
<>
<div className={styles.waypointMain}>
<SendOutlined className={styles.navArrow} />
<div>
<div className={styles.infoLabel}>下一航点</div>
<div className={styles.waypointName}>{nextWaypoint.name}</div>
</div>
</div>
<div className={styles.waypointStats}>
<div>
<div className={styles.infoLabel}>到点距离</div>
<div className={styles.infoValue}>{formatDist(nextWaypoint.distance)}</div>
</div>
<div>
<div className={styles.infoLabel}>到点时间</div>
<div className={styles.infoValue}>{formatTime(nextWaypoint.estimatedTime)}</div>
</div>
</div>
</>
) : (
<div className={styles.emptyWaypoint}>
暂无航点数据
</div>
)}
</div>
<div className={styles.summaryRow}>
<div className={styles.summaryItem}>
<div className={styles.infoLabel}>剩余里程</div>
<div className={styles.summaryValue}>{formatDist(remainingDistance)}</div>
</div>
<div className={styles.summaryItem}>
<div className={styles.infoLabel}>预计剩余</div>
<div className={styles.summaryValue}>{formatTime(estimatedRemainingTime)}</div>
</div>
</div>
</div>
<div className={styles.statusCluster}>
<div className={styles.compassCard}>
<div className={styles.cardTitle}><CompassOutlined /> 航向</div>
<div className={styles.compassDial}>
<div className={styles.compassRotor} style={{ transform: `rotate(${heading}deg)` }}>
{compassTicks}
</div>
<div className={styles.compassNeedle} />
</div>
<div className={styles.compassValue}>{Math.round(heading)}° · {directionText(heading)}</div>
</div>
<div className={styles.powerCard}>
<div className={styles.powerRow}>
<span className={styles.infoLabel}><ThunderboltOutlined /> 电量</span>
<span className={styles.powerValue}>{Math.round(normalizedBattery)}%</span>
</div>
<div className={styles.powerTrack}>
<div className={styles.powerFill} style={{ width: `${normalizedBattery}%` }} />
</div>
<div className={styles.powerRow}>
<span className={styles.infoLabel}><WifiOutlined /> 信号</span>
<span className={styles.powerValue}>{signalStrength == null ? '--' : `${Math.round(normalizedSignal)}%`}</span>
</div>
<div className={styles.powerTrack}>
<div className={styles.signalFill} style={{ width: `${signalStrength == null ? 0 : normalizedSignal}%` }} />
</div>
</div>
</div>
<div className={styles.actionCluster}>
<button className={`${styles.actionBtn} ${styles.actionPrimary}`} onClick={actionHandler}>
{actionIcon}
<span>{actionText}</span>
</button>
{!previewing && (
<button className={`${styles.actionBtn} ${styles.actionDanger}`} onClick={onStop}>
<StopOutlined />
<span>结束航行</span>
</button>
)}
</div>
</div>
);
};
export default NavigationHUD;
@@ -0,0 +1,369 @@
.overlay {
position: absolute;
top: 20px;
left: 20px;
z-index: 910;
width: 340px;
border-radius: 20px;
padding: 14px;
background:
linear-gradient(145deg, rgba(8, 21, 36, 0.94) 0%, rgba(13, 35, 58, 0.9) 58%, rgba(18, 28, 46, 0.95) 100%);
border: 1px solid rgba(92, 180, 255, 0.28);
box-shadow:
0 18px 42px rgba(3, 10, 24, 0.42),
inset 0 1px 0 rgba(255, 255, 255, 0.08),
inset 0 0 0 1px rgba(41, 129, 210, 0.12);
color: #eef7ff;
overflow: hidden;
font-family: 'Rajdhani', 'DIN', 'Avenir Next', 'PingFang SC', sans-serif;
}
.overlay::before {
content: '';
position: absolute;
top: 0;
left: 14px;
right: 14px;
height: 1px;
background: linear-gradient(90deg, transparent 0%, rgba(134, 211, 255, 0.75) 50%, transparent 100%);
}
.previewMode {
border-color: rgba(74, 196, 255, 0.42);
}
.sailingMode {
border-color: rgba(255, 152, 108, 0.34);
}
.header,
.progressCard,
.waypointList,
.footer {
position: relative;
z-index: 1;
}
.header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.routeBlock {
min-width: 0;
display: flex;
flex-direction: column;
gap: 4px;
}
.caption {
font-size: 11px;
letter-spacing: 1px;
text-transform: uppercase;
color: rgba(186, 223, 255, 0.62);
}
.title {
font-size: 22px;
font-weight: 700;
line-height: 1.1;
color: #f3f9ff;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.headerMeta {
display: flex;
gap: 10px;
flex-wrap: wrap;
font-size: 12px;
color: rgba(202, 230, 255, 0.78);
}
.headerMeta span {
display: inline-flex;
align-items: center;
gap: 4px;
}
.statusTag {
flex-shrink: 0;
display: inline-flex;
align-items: center;
gap: 6px;
padding: 6px 10px;
border-radius: 999px;
background: rgba(28, 69, 104, 0.62);
border: 1px solid rgba(112, 191, 255, 0.24);
color: #dff4ff;
font-size: 12px;
font-weight: 600;
}
.pulseDot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #49c7ff;
box-shadow: 0 0 0 0 rgba(73, 199, 255, 0.6);
animation: pulse 1.5s infinite;
}
@keyframes pulse {
0% {
transform: scale(0.85);
box-shadow: 0 0 0 0 rgba(73, 199, 255, 0.55);
}
70% {
transform: scale(1.05);
box-shadow: 0 0 0 8px rgba(73, 199, 255, 0);
}
100% {
transform: scale(0.85);
box-shadow: 0 0 0 0 rgba(73, 199, 255, 0);
}
}
.progressCard {
margin-top: 14px;
padding: 12px;
border-radius: 14px;
background: linear-gradient(145deg, rgba(19, 48, 77, 0.72) 0%, rgba(10, 24, 40, 0.86) 100%);
border: 1px solid rgba(104, 184, 255, 0.2);
}
.progressHead {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 13px;
color: #dcefff;
font-weight: 600;
}
.progressBar {
margin-top: 10px;
height: 8px;
border-radius: 999px;
overflow: hidden;
background: rgba(198, 225, 250, 0.18);
}
.progressFill {
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #2c9bff 0%, #43eeff 55%, #87ffd4 100%);
box-shadow: 0 0 10px rgba(67, 238, 255, 0.46);
transition: width 0.3s ease;
}
.metricRow {
margin-top: 12px;
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 10px;
}
.metricItem {
padding: 10px;
border-radius: 12px;
background: rgba(255, 255, 255, 0.04);
border: 1px solid rgba(123, 186, 236, 0.14);
}
.metricLabel {
display: inline-flex;
align-items: center;
gap: 4px;
font-size: 11px;
color: rgba(193, 224, 247, 0.68);
}
.metricValue {
display: block;
margin-top: 4px;
font-size: 15px;
font-weight: 700;
color: #f4fbff;
}
.waypointList {
margin-top: 14px;
display: flex;
flex-direction: column;
gap: 2px;
max-height: 290px;
overflow-y: auto;
padding-right: 2px;
}
.waypointList::-webkit-scrollbar {
width: 4px;
}
.waypointList::-webkit-scrollbar-thumb {
background: rgba(180, 217, 255, 0.28);
border-radius: 999px;
}
.waypointItem {
display: flex;
align-items: stretch;
gap: 10px;
min-height: 48px;
}
.trackColumn {
width: 24px;
position: relative;
display: flex;
flex-direction: column;
align-items: center;
}
.iconWrapper {
position: relative;
z-index: 2;
width: 24px;
height: 24px;
display: flex;
align-items: center;
justify-content: center;
background: rgba(8, 21, 36, 0.9);
}
.passedIcon {
color: #78ffcf;
font-size: 15px;
}
.currentIcon {
width: 14px;
height: 14px;
border-radius: 50%;
border: 2px solid #4ec8ff;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 0 10px rgba(78, 200, 255, 0.58);
}
.currentInner {
width: 6px;
height: 6px;
border-radius: 50%;
background: #4ec8ff;
}
.upcomingIcon {
width: 11px;
height: 11px;
border-radius: 50%;
border: 2px solid rgba(219, 235, 246, 0.36);
}
.connectingLine {
position: absolute;
top: 22px;
bottom: 0;
left: 50%;
transform: translateX(-50%);
width: 2px;
background: rgba(224, 239, 255, 0.14);
}
.linePassed {
background: linear-gradient(180deg, #78ffcf 0%, rgba(120, 255, 207, 0.2) 100%);
}
.lineCurrent {
background: linear-gradient(180deg, #55d0ff 0%, rgba(85, 208, 255, 0.2) 100%);
}
.contentColumn {
flex: 1;
min-width: 0;
padding: 2px 0 12px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.name {
font-size: 14px;
color: #edf7ff;
font-weight: 600;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.stateText {
flex-shrink: 0;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.4px;
color: rgba(194, 223, 244, 0.72);
}
.itemPassed .name,
.itemPassed .stateText {
color: rgba(194, 214, 229, 0.5);
}
.itemCurrent .contentColumn {
padding-left: 10px;
border-radius: 12px;
background: linear-gradient(90deg, rgba(62, 172, 244, 0.18) 0%, rgba(62, 172, 244, 0) 100%);
border-bottom-color: transparent;
}
.itemCurrent .stateText {
color: #7fdfff;
}
.itemUpcoming .name {
color: rgba(224, 239, 255, 0.72);
}
.footer {
margin-top: 10px;
padding-top: 12px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
display: flex;
justify-content: space-between;
gap: 12px;
font-size: 12px;
color: rgba(206, 228, 246, 0.72);
}
@media (max-width: 960px) {
.overlay {
width: calc(100% - 24px);
left: 12px;
top: 12px;
padding: 12px;
}
.header {
flex-direction: column;
align-items: stretch;
}
.statusTag {
align-self: flex-start;
}
.metricRow {
grid-template-columns: 1fr;
}
.footer {
flex-direction: column;
}
}
@@ -0,0 +1,167 @@
import React, { useMemo } from 'react';
import {
CheckCircleFilled,
ClockCircleOutlined,
EnvironmentOutlined,
FlagOutlined,
RadarChartOutlined,
} from '@ant-design/icons';
import styles from './index.less';
type NavigationMode = 'preview' | 'sailing';
export interface NavigationOverlayProps {
mode: NavigationMode;
routeName: string;
waypoints: Array<{
name: string;
waypointIndex: number;
}>;
currentWaypointIndex: number;
totalDistance: number;
remainingDistance: number;
estimatedRemainingTime: number;
progress: number;
}
const NavigationOverlay: React.FC<NavigationOverlayProps> = ({
mode,
routeName,
waypoints,
currentWaypointIndex,
totalDistance,
remainingDistance,
estimatedRemainingTime,
progress,
}) => {
const formatDistance = (m: number) => {
if (m >= 1000) {
return `${(m / 1000).toFixed(1)}km`;
}
return `${Math.round(m)}m`;
};
const formatTime = (s: number) => {
const safeSeconds = Math.max(0, Math.floor(s));
const mins = Math.floor(safeSeconds / 60);
const secs = Math.floor(safeSeconds % 60);
if (mins >= 60) {
const hours = Math.floor(mins / 60);
const restMins = mins % 60;
return `${hours}时${restMins}分`;
}
return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
};
const safeProgress = Math.max(0, Math.min(100, progress));
const modeText = mode === 'preview' ? '预览态' : '航行中';
const completedCount = waypoints.filter((wp) => wp.waypointIndex < currentWaypointIndex).length;
// Get visible waypoints
const visibleWaypoints = useMemo(() => {
// Current waypoint logic: showing ±2 around current.
let start = Math.max(0, currentWaypointIndex - 2);
let end = Math.min(waypoints.length - 1, start + 4);
// Adjust start if we are near the end
if (end - start < 4) {
start = Math.max(0, end - 4);
}
return waypoints.slice(start, end + 1);
}, [waypoints, currentWaypointIndex]);
return (
<div className={`${styles.overlay} ${mode === 'preview' ? styles.previewMode : styles.sailingMode}`}>
<div className={styles.header}>
<div className={styles.routeBlock}>
<div className={styles.caption}>导航总览</div>
<div className={styles.title}>{routeName || '未命名路线'}</div>
<div className={styles.headerMeta}>
<span><RadarChartOutlined /> 总里程 {formatDistance(totalDistance)}</span>
<span><FlagOutlined /> {waypoints.length} 航点</span>
</div>
</div>
<div className={styles.statusTag}>
<div className={styles.pulseDot} />
{modeText}
</div>
</div>
<div className={styles.progressCard}>
<div className={styles.progressHead}>
<span>路线进度</span>
<span>{Math.round(safeProgress)}%</span>
</div>
<div className={styles.progressBar}>
<div
className={styles.progressFill}
style={{ width: `${safeProgress}%` }}
/>
</div>
<div className={styles.metricRow}>
<div className={styles.metricItem}>
<span className={styles.metricLabel}><EnvironmentOutlined /> 剩余</span>
<span className={styles.metricValue}>{formatDistance(remainingDistance)}</span>
</div>
<div className={styles.metricItem}>
<span className={styles.metricLabel}><ClockCircleOutlined /> 预计</span>
<span className={styles.metricValue}>{formatTime(estimatedRemainingTime)}</span>
</div>
</div>
</div>
<div className={styles.waypointList}>
{visibleWaypoints.map((wp, i) => {
const isPassed = wp.waypointIndex < currentWaypointIndex;
const isCurrent = wp.waypointIndex === currentWaypointIndex;
const isUpcoming = wp.waypointIndex > currentWaypointIndex;
const isLastVisible = i === visibleWaypoints.length - 1;
return (
<div
key={`${wp.waypointIndex}-${wp.name}`}
className={[
styles.waypointItem,
isPassed ? styles.itemPassed : '',
isCurrent ? styles.itemCurrent : '',
isUpcoming ? styles.itemUpcoming : '',
].filter(Boolean).join(' ')}
>
<div className={styles.trackColumn}>
<div className={styles.iconWrapper}>
{isPassed && <CheckCircleFilled className={styles.passedIcon} />}
{isCurrent && (
<div className={styles.currentIcon}>
<div className={styles.currentInner} />
</div>
)}
{isUpcoming && <div className={styles.upcomingIcon} />}
</div>
{!isLastVisible && (
<div className={[
styles.connectingLine,
(isPassed && wp.waypointIndex < currentWaypointIndex - 1) ? styles.linePassed : '',
(isPassed && wp.waypointIndex === currentWaypointIndex - 1) ? styles.lineCurrent : '',
].filter(Boolean).join(' ')} />
)}
</div>
<div className={styles.contentColumn}>
<span className={styles.name}>{`${wp.waypointIndex + 1}. ${wp.name}`}</span>
<span className={styles.stateText}>{isCurrent ? '当前' : isPassed ? '已过' : '待达'}</span>
</div>
</div>
);
})}
</div>
<div className={styles.footer}>
<span>{`已通过 ${completedCount}/${waypoints.length} 航点`}</span>
<span>{`当前第 ${Math.max(1, currentWaypointIndex + 1)} 航点`}</span>
</div>
</div>
);
};
export default NavigationOverlay;
@@ -1,3 +1,15 @@
/* ========== 玻璃拟态变量 ========== */
@glass-border: rgba(65, 170, 255, 0.28);
@glass-border-light: rgba(92, 211, 255, 0.18);
@accent-cyan: #00d4ff;
@accent-blue: #0096ff;
@text-primary: #eaf6ff;
@text-secondary: rgba(255, 255, 255, 0.55);
@text-dim: rgba(255, 255, 255, 0.4);
@card-bg: linear-gradient(145deg, rgba(10, 24, 48, 0.7), rgba(8, 18, 38, 0.5));
@card-shadow: 0 2px 12px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.06);
@transition-fast: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
.panel {
height: 100%;
padding: 0;
@@ -8,14 +20,39 @@
.section {
padding: 16px;
border-bottom: 1px solid rgba(0, 212, 255, 0.1);
border-bottom: 1px solid @glass-border-light;
position: relative;
&::after {
content: '';
position: absolute;
bottom: -1px;
left: 16px;
right: 16px;
height: 1px;
background: linear-gradient(90deg, transparent, rgba(0, 212, 255, 0.15), transparent);
}
}
.sectionTitle {
font-size: 14px;
font-size: 13px;
font-weight: 600;
color: rgba(255, 255, 255, 0.9);
margin-bottom: 16px;
color: @text-secondary;
margin-bottom: 14px;
text-transform: uppercase;
letter-spacing: 1.5px;
font-family: 'Rajdhani', 'DIN', sans-serif;
display: flex;
align-items: center;
gap: 8px;
&::before {
content: '';
width: 3px;
height: 14px;
border-radius: 2px;
background: linear-gradient(180deg, @accent-cyan, @accent-blue);
}
}
/* ========== 罗盘 ========== */
@@ -23,13 +60,19 @@
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 12px;
margin-bottom: 14px;
padding: 12px;
background: @card-bg;
border-radius: 12px;
border: 1px solid rgba(0, 100, 200, 0.15);
box-shadow: @card-shadow;
}
.compass {
width: 180px;
height: 180px;
position: relative;
filter: drop-shadow(0 0 8px rgba(0, 150, 255, 0.15));
}
.compassSvg {
@@ -41,18 +84,24 @@
display: flex;
align-items: baseline;
gap: 6px;
margin-top: 4px;
margin-top: 8px;
}
.headingLabel {
font-size: 12px;
color: rgba(255, 255, 255, 0.5);
font-size: 11px;
color: @text-dim;
letter-spacing: 0.5px;
text-transform: uppercase;
font-family: 'Rajdhani', 'DIN', sans-serif;
}
.headingValue {
font-size: 22px;
font-weight: bold;
color: #0070d4;
font-size: 24px;
font-weight: 700;
color: @accent-cyan;
font-family: 'Rajdhani', 'DIN', monospace;
text-shadow: 0 0 12px rgba(0, 212, 255, 0.3);
letter-spacing: 1px;
}
/* ========== 左转/右转 ========== */
@@ -64,30 +113,34 @@
}
.turnBtn {
width: 48px;
height: 36px;
width: 52px;
height: 38px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 6px;
border: 1px solid rgba(0, 150, 220, 0.4);
background: rgba(0, 60, 100, 0.35);
color: rgba(255, 255, 255, 0.8);
border-radius: 8px;
border: 1px solid rgba(0, 150, 220, 0.35);
background: linear-gradient(145deg, rgba(0, 60, 120, 0.35), rgba(0, 40, 80, 0.25));
backdrop-filter: blur(6px);
color: rgba(255, 255, 255, 0.75);
font-size: 16px;
cursor: pointer;
transition: all 0.15s;
transition: @transition-fast;
padding: 0;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.06);
&:hover {
background: rgba(0, 100, 160, 0.5);
border-color: rgba(0, 180, 255, 0.6);
background: linear-gradient(145deg, rgba(0, 80, 160, 0.5), rgba(0, 60, 120, 0.35));
border-color: rgba(0, 180, 255, 0.5);
color: #fff;
box-shadow: 0 2px 12px rgba(0, 100, 200, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
&:active {
background: rgba(0, 130, 200, 0.7);
border-color: #00b4ff;
background: linear-gradient(145deg, rgba(0, 100, 200, 0.6), rgba(0, 80, 160, 0.45));
border-color: @accent-cyan;
transform: scale(0.95);
box-shadow: 0 0 16px rgba(0, 180, 255, 0.3);
}
}
@@ -97,46 +150,58 @@
align-items: center;
gap: 10px;
margin-bottom: 16px;
padding: 0 4px;
padding: 10px 12px;
background: @card-bg;
border-radius: 8px;
border: 1px solid rgba(0, 100, 200, 0.12);
}
.speedLabel {
font-size: 12px;
color: rgba(255, 255, 255, 0.5);
font-size: 11px;
color: @text-dim;
flex-shrink: 0;
text-transform: uppercase;
letter-spacing: 0.5px;
font-family: 'Rajdhani', 'DIN', sans-serif;
}
.speedSlider {
flex: 1;
:global(.ant-slider-rail) {
background: rgba(255, 255, 255, 0.1);
background: rgba(255, 255, 255, 0.08);
border-radius: 2px;
}
:global(.ant-slider-track) {
background: #0070d4;
background: linear-gradient(90deg, @accent-blue, @accent-cyan);
border-radius: 2px;
}
:global(.ant-slider-handle)::after {
box-shadow: 0 0 6px rgba(0, 112, 212, 0.6);
box-shadow: 0 0 8px rgba(0, 180, 255, 0.5);
border-color: @accent-cyan;
}
}
.speedValue {
font-size: 13px;
font-weight: 600;
color: #0070d4;
font-size: 14px;
font-weight: 700;
color: @accent-cyan;
font-family: 'Rajdhani', 'DIN', monospace;
flex-shrink: 0;
min-width: 60px;
text-align: right;
letter-spacing: 0.5px;
}
/* ========== 紧急停靠 ========== */
.emergencyBtn {
height: 42px;
border-radius: 6px;
border: none;
background: #d4380d;
height: 44px;
border-radius: 8px;
border: 1px solid rgba(255, 60, 60, 0.4);
background: linear-gradient(145deg, rgba(180, 30, 10, 0.7), rgba(140, 20, 5, 0.5));
backdrop-filter: blur(6px);
color: #fff;
font-size: 15px;
font-weight: 600;
@@ -145,62 +210,85 @@
justify-content: center;
gap: 8px;
cursor: pointer;
transition: all 0.2s;
transition: @transition-fast;
letter-spacing: 2px;
box-shadow: 0 2px 12px rgba(180, 30, 10, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.08);
&:hover {
background: #e84820;
background: linear-gradient(145deg, rgba(200, 40, 15, 0.8), rgba(160, 30, 10, 0.6));
border-color: rgba(255, 80, 60, 0.5);
box-shadow: 0 4px 20px rgba(200, 40, 15, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
&:active {
background: #cf1322;
background: linear-gradient(145deg, rgba(160, 20, 5, 0.8), rgba(120, 15, 0, 0.6));
transform: scale(0.98);
}
}
/* ========== 实时数据卡片 ========== */
.dataCard {
border-radius: 8px;
padding: 12px;
border-radius: 10px;
padding: 14px;
margin-bottom: 10px;
backdrop-filter: blur(6px);
position: relative;
overflow: hidden;
// 顶部高光线
&::before {
content: '';
position: absolute;
top: 0;
left: 10%;
right: 10%;
height: 1px;
background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent);
}
&:last-child {
margin-bottom: 0;
}
}
/* 三级透明层次 */
/* 三级玻璃层次 */
.dataCardLevel1 {
background: rgba(0, 112, 212, 0.12);
border: 1px solid rgba(0, 112, 212, 0.25);
background: linear-gradient(145deg, rgba(0, 80, 160, 0.18), rgba(0, 60, 120, 0.1));
border: 1px solid rgba(0, 112, 212, 0.28);
box-shadow: @card-shadow;
}
.dataCardLevel2 {
background: rgba(0, 180, 150, 0.08);
border: 1px solid rgba(0, 180, 150, 0.2);
background: linear-gradient(145deg, rgba(0, 140, 120, 0.12), rgba(0, 100, 80, 0.06));
border: 1px solid rgba(0, 180, 150, 0.22);
box-shadow: @card-shadow;
}
.dataCardLevel3 {
background: rgba(0, 212, 255, 0.05);
border: 1px solid rgba(0, 212, 255, 0.15);
background: linear-gradient(145deg, rgba(0, 160, 200, 0.1), rgba(0, 120, 160, 0.05));
border: 1px solid rgba(0, 212, 255, 0.18);
box-shadow: @card-shadow;
}
.dataCardHeader {
font-size: 12px;
font-weight: 600;
color: #0070d4;
margin-bottom: 8px;
padding-bottom: 6px;
font-size: 11px;
font-weight: 700;
color: @accent-blue;
margin-bottom: 10px;
padding-bottom: 8px;
border-bottom: 1px solid rgba(0, 112, 212, 0.15);
text-transform: uppercase;
letter-spacing: 1.2px;
font-family: 'Rajdhani', 'DIN', sans-serif;
}
.dataCardHeaderGreen {
color: #00b496;
border-bottom-color: rgba(0, 180, 150, 0.15);
color: #00c8a0;
border-bottom-color: rgba(0, 200, 160, 0.15);
}
.dataCardHeaderCyan {
color: #00a0cc;
color: @accent-cyan;
border-bottom-color: rgba(0, 212, 255, 0.12);
}
@@ -208,16 +296,19 @@
display: flex;
justify-content: space-between;
align-items: center;
padding: 4px 0;
padding: 5px 0;
}
.dataLabel {
font-size: 12px;
color: rgba(255, 255, 255, 0.45);
color: @text-dim;
letter-spacing: 0.3px;
}
.dataValue {
font-size: 13px;
color: rgba(255, 255, 255, 0.9);
font-weight: 500;
color: @text-primary;
font-weight: 600;
font-family: 'Rajdhani', 'DIN', monospace;
letter-spacing: 0.5px;
}
@@ -0,0 +1,56 @@
/**
* 设备认证与登出逻辑
* 从 sessionStorage 读取设备信息,提供登出操作
*/
import { useEffect, useState, useCallback, useMemo } from 'react';
import { history } from 'umi';
import { Modal } from 'antd';
interface DeviceInfo {
deviceSn: string;
deviceName: string;
deviceType: number;
}
interface UseClientAuthReturn {
deviceSn: string;
deviceInfo: DeviceInfo | null;
handleLogout: () => void;
}
export function useClientAuth(onBeforeLogout?: () => void): UseClientAuthReturn {
const [deviceInfo, setDeviceInfo] = useState<DeviceInfo | null>(null);
const deviceSn = useMemo(() => sessionStorage.getItem('client_device_sn') || '', []);
// 校验登录状态
useEffect(() => {
const sn = sessionStorage.getItem('client_device_sn');
const info = sessionStorage.getItem('client_device_info');
if (!sn || !info) {
history.push('/client/login');
return;
}
try {
setDeviceInfo(JSON.parse(info));
} catch {
history.push('/client/login');
}
}, []);
const handleLogout = useCallback(() => {
Modal.confirm({
title: '确认退出',
content: '退出后需要重新输入设备SN登录',
okText: '退出',
cancelText: '取消',
onOk: () => {
onBeforeLogout?.();
sessionStorage.removeItem('client_device_sn');
sessionStorage.removeItem('client_device_info');
history.push('/client/login');
},
});
}, [onBeforeLogout]);
return { deviceSn, deviceInfo, handleLogout };
}
@@ -0,0 +1,107 @@
/**
* 模拟遥测数据生成
* SSE 未连接时自动生成模拟船只遥测数据
*/
import { useEffect, useState, useCallback, useRef } from 'react';
import type { BoatTelemetryData } from '@/types/boatRoute';
/** 生成一帧模拟遥测 */
const createMockTelemetry = (
deviceSn: string,
prevData?: BoatTelemetryData | null,
initLon?: number,
initLat?: number,
): BoatTelemetryData => {
const baseLon = prevData?.longitude ?? initLon ?? 108.366;
const baseLat = prevData?.latitude ?? initLat ?? 22.817;
const baseHeading = prevData?.heading ?? 45;
const headingRad = (baseHeading + (Math.random() - 0.5) * 10) * Math.PI / 180;
const moveDistance = 0.00002 + Math.random() * 0.00003;
const newLon = baseLon + Math.cos(headingRad) * moveDistance;
const newLat = baseLat + Math.sin(headingRad) * moveDistance;
const newHeading = ((baseHeading + (Math.random() - 0.5) * 10) + 360) % 360;
return {
deviceSn,
longitude: newLon,
latitude: newLat,
heading: Number(newHeading.toFixed(1)),
speed: Number((1.5 + Math.random() * 2).toFixed(1)),
battery: Math.max(20, (prevData?.battery ?? 85) - Math.random() * 0.1),
signalStrength: 60 + Math.floor(Math.random() * 30),
status: '巡航中',
recordTime: new Date().toISOString(),
taskId: undefined,
currentWaypointIndex: undefined,
};
};
interface UseMockTelemetryReturn {
/** 合并后的遥测数据(SSE 优先,回退到模拟) */
boatData: BoatTelemetryData | null;
/** 模型中心位���回调,���于重置模拟数据起点 */
handleModelCenter: (lon: number, lat: number) => void;
}
export function useMockTelemetry(
deviceSn: string,
sseBoatData: BoatTelemetryData | null,
): UseMockTelemetryReturn {
const [mockBoatData, setMockBoatData] = useState<BoatTelemetryData | null>(null);
const mockTimerRef = useRef<NodeJS.Timeout | null>(null);
const mockDataRef = useRef<BoatTelemetryData | null>(null);
const modelCenterRef = useRef<{ lon: number; lat: number } | null>(null);
const handleModelCenter = useCallback((lon: number, lat: number) => {
modelCenterRef.current = { lon, lat };
if (mockDataRef.current) {
const newData = {
...mockDataRef.current,
longitude: lon + (Math.random() - 0.5) * 0.001,
latitude: lat + (Math.random() - 0.5) * 0.001,
};
mockDataRef.current = newData;
setMockBoatData(newData);
}
}, []);
useEffect(() => {
// 有真实 SSE 数据时停止模拟
if (sseBoatData) {
if (mockTimerRef.current) {
clearInterval(mockTimerRef.current);
mockTimerRef.current = null;
}
setMockBoatData(null);
mockDataRef.current = null;
return;
}
// 无真实数据且无模拟定时器,启动模拟
if (!mockTimerRef.current && deviceSn) {
const center = modelCenterRef.current;
const firstData = createMockTelemetry(deviceSn, null, center?.lon, center?.lat);
mockDataRef.current = firstData;
setMockBoatData(firstData);
mockTimerRef.current = setInterval(() => {
const center2 = modelCenterRef.current;
const newData = createMockTelemetry(deviceSn, mockDataRef.current, center2?.lon, center2?.lat);
mockDataRef.current = newData;
setMockBoatData(newData);
}, 2000);
}
return () => {
if (mockTimerRef.current) {
clearInterval(mockTimerRef.current);
mockTimerRef.current = null;
}
};
}, [sseBoatData, deviceSn]);
const boatData = sseBoatData || mockBoatData;
return { boatData, handleModelCenter };
}
@@ -0,0 +1,90 @@
/**
* 导航计算
* 根据当前遥测数据和航线信息,计算 HUD / Overlay 所需的导航指标
*/
import { useMemo } from 'react';
import type { BoatRouteListVO, BoatTelemetryData, BoatWaypointVO } from '@/types/boatRoute';
interface NextWaypoint {
name: string;
distance: number;
estimatedTime: number;
}
interface NavigationDataResult {
/** 当前激活航线的航点列表 */
activeWaypoints: BoatWaypointVO[];
/** 当前激活航线的基本信息 */
activeRouteInfo: BoatRouteListVO | null;
/** 下一航点信息 */
nextWaypoint: NextWaypoint | undefined;
/** 剩余距离(米) */
remainingDistance: number;
/** 预计剩余时间(秒) */
estimatedRemainingTime: number;
/** 进度百分比 0-100 */
progress: number;
}
export function useNavigationData(
activeRouteId: string | null,
routes: BoatRouteListVO[],
routeWaypointsMap: Record<string, BoatWaypointVO[]>,
boatData: BoatTelemetryData | null,
currentWaypointIndex: number,
): NavigationDataResult {
const activeWaypoints = useMemo(() => {
if (!activeRouteId) return [];
return routeWaypointsMap[activeRouteId] || [];
}, [activeRouteId, routeWaypointsMap]);
const activeRouteInfo = useMemo(() => {
if (!activeRouteId) return null;
return routes.find((r) => r.routeId === activeRouteId) || null;
}, [activeRouteId, routes]);
const { nextWaypoint, remainingDistance, estimatedRemainingTime, progress } = useMemo(() => {
if (!activeWaypoints.length || !boatData) {
return { nextWaypoint: undefined, remainingDistance: 0, estimatedRemainingTime: 0, progress: 0 };
}
const wpIdx = boatData.currentWaypointIndex ?? currentWaypointIndex;
const nextIdx = Math.min(wpIdx + 1, activeWaypoints.length - 1);
const nextWp = activeWaypoints[nextIdx];
// Haversine 距离计算
const R = 6371000;
const dLat = ((nextWp?.latitude ?? 0) - (boatData.latitude ?? 0)) * Math.PI / 180;
const dLon = ((nextWp?.longitude ?? 0) - (boatData.longitude ?? 0)) * Math.PI / 180;
const a = Math.sin(dLat / 2) ** 2 +
Math.cos((boatData.latitude ?? 0) * Math.PI / 180) *
Math.cos((nextWp?.latitude ?? 0) * Math.PI / 180) *
Math.sin(dLon / 2) ** 2;
const distToNext = R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
const totalDist = activeRouteInfo?.totalDistance ?? 1;
const prog = Math.min(100, Math.round((wpIdx / Math.max(1, activeWaypoints.length - 1)) * 100));
const remainDist = totalDist * (1 - prog / 100);
const estTime = boatData.speed > 0 ? remainDist / boatData.speed : 0;
return {
nextWaypoint: nextWp ? {
name: nextWp.pointName || `航点${nextIdx + 1}`,
distance: Math.round(distToNext),
estimatedTime: Math.round(boatData.speed > 0 ? distToNext / boatData.speed : 0),
} : undefined,
remainingDistance: Math.round(remainDist),
estimatedRemainingTime: Math.round(estTime),
progress: prog,
};
}, [activeWaypoints, boatData, currentWaypointIndex, activeRouteInfo]);
return {
activeWaypoints,
activeRouteInfo,
nextWaypoint,
remainingDistance,
estimatedRemainingTime,
progress,
};
}
@@ -0,0 +1,136 @@
/**
* 沉浸模式状态机
* 管理 sailing / preview / idle 三态切换及相关操作回调
*/
import { useState, useCallback } from 'react';
import { Modal, message } from 'antd';
import { sendBoatCommand } from '../services/clientApi';
type ActiveRouteMode = 'sailing' | 'preview' | null;
interface ActiveRouteState {
mode: ActiveRouteMode;
routeId: string | null;
}
interface UseNavigationStateReturn {
activeRoute: ActiveRouteState;
isPaused: boolean;
currentWaypointIndex: number;
previewStopSignal: number;
isSailing: boolean;
isPreviewing: boolean;
isImmersive: boolean;
activeRouteId: string | null;
handleStartSailing: (routeId: string) => void;
handlePauseSailing: () => void;
handleResumeSailing: () => void;
handleStopSailing: () => void;
handleStopPreview: () => void;
handleEmergencyStop: () => void;
handlePreviewChange: (previewing: boolean) => void;
}
export function useNavigationState(
deviceSn: string,
selectedRouteId: string | null,
setSelectedRouteId: (id: string | null) => void,
): UseNavigationStateReturn {
const [activeRoute, setActiveRoute] = useState<ActiveRouteState>({ mode: null, routeId: null });
const [isPaused, setIsPaused] = useState(false);
const [currentWaypointIndex, setCurrentWaypointIndex] = useState(0);
const [previewStopSignal, setPreviewStopSignal] = useState(0);
const isSailing = activeRoute.mode === 'sailing';
const isPreviewing = activeRoute.mode === 'preview';
const isImmersive = activeRoute.mode !== null;
const activeRouteId = activeRoute.routeId;
const handleStartSailing = useCallback((routeId: string) => {
if (activeRoute.mode === 'preview') {
setPreviewStopSignal((prev) => prev + 1);
}
setActiveRoute({ mode: 'sailing', routeId });
setSelectedRouteId(routeId);
setIsPaused(false);
setCurrentWaypointIndex(0);
}, [activeRoute.mode, setSelectedRouteId]);
const handlePauseSailing = useCallback(() => {
if (!isSailing) return;
setIsPaused(true);
sendBoatCommand(deviceSn, 'pause', 'press').catch(() => {
message.error('暂停指令发送失败');
});
}, [deviceSn, isSailing]);
const handleResumeSailing = useCallback(() => {
if (!isSailing) return;
setIsPaused(false);
sendBoatCommand(deviceSn, 'resume', 'press').catch(() => {
message.error('继续指令发送失败');
});
}, [deviceSn, isSailing]);
const handleStopSailing = useCallback(() => {
Modal.confirm({
title: '确认结束航行',
content: '结束后将退��导航模式,返回线路选择',
okText: '结束航行',
cancelText: '取消',
onOk: () => {
setActiveRoute({ mode: null, routeId: null });
setIsPaused(false);
setCurrentWaypointIndex(0);
sendBoatCommand(deviceSn, 'stop', 'press').catch(() => {});
},
});
}, [deviceSn]);
const handleStopPreview = useCallback(() => {
setPreviewStopSignal((prev) => prev + 1);
}, []);
const handleEmergencyStop = useCallback(() => {
setActiveRoute({ mode: null, routeId: null });
setIsPaused(false);
setCurrentWaypointIndex(0);
sendBoatCommand(deviceSn, 'stop', 'press').catch(() => {
message.error('紧急停靠指令发送失败');
});
message.warning('已执行紧急停靠');
}, [deviceSn]);
const handlePreviewChange = useCallback((previewing: boolean) => {
setActiveRoute((prev) => {
if (previewing) {
if (prev.mode === 'sailing') return prev;
const nextRouteId = selectedRouteId ?? prev.routeId;
if (!nextRouteId) return prev;
return { mode: 'preview', routeId: nextRouteId };
}
if (prev.mode === 'preview') {
return { mode: null, routeId: null };
}
return prev;
});
}, [selectedRouteId]);
return {
activeRoute,
isPaused,
currentWaypointIndex,
previewStopSignal,
isSailing,
isPreviewing,
isImmersive,
activeRouteId,
handleStartSailing,
handlePauseSailing,
handleResumeSailing,
handleStopSailing,
handleStopPreview,
handleEmergencyStop,
handlePreviewChange,
};
}
@@ -0,0 +1,50 @@
/**
* 航线列表加载 + 航点详情预加载
*/
import { useEffect, useState, useCallback } from 'react';
import { message } from 'antd';
import { getClientRoutes } from '../services/clientApi';
import { getBoatRouteDetail } from '@/services/boatRoute';
import type { BoatRouteListVO, BoatWaypointVO } from '@/types/boatRoute';
interface UseRouteDataReturn {
routes: BoatRouteListVO[];
routeWaypointsMap: Record<string, BoatWaypointVO[]>;
selectedRouteId: string | null;
setSelectedRouteId: (id: string | null) => void;
routeLoading: boolean;
}
export function useRouteData(deviceSn: string): UseRouteDataReturn {
const [routes, setRoutes] = useState<BoatRouteListVO[]>([]);
const [routeWaypointsMap, setRouteWaypointsMap] = useState<Record<string, BoatWaypointVO[]>>({});
const [selectedRouteId, setSelectedRouteId] = useState<string | null>(null);
const [routeLoading, setRouteLoading] = useState(false);
useEffect(() => {
if (!deviceSn) return;
setRouteLoading(true);
getClientRoutes(deviceSn)
.then(async (res) => {
const routeList = res.data;
if (res.resp_code === 0 && routeList && routeList.length > 0) {
setRoutes(routeList);
// 并行预加载所有线路的航点详情
const detailResults = await Promise.allSettled(
routeList.map((r) => getBoatRouteDetail(r.routeId)),
);
const wpMap: Record<string, BoatWaypointVO[]> = {};
detailResults.forEach((result, idx) => {
if (result.status === 'fulfilled' && result.value.resp_code === 0 && result.value.data?.waypoints) {
wpMap[routeList[idx].routeId] = result.value.data.waypoints;
}
});
setRouteWaypointsMap(wpMap);
}
})
.catch(() => message.error('线路加载失败'))
.finally(() => setRouteLoading(false));
}, [deviceSn]);
return { routes, routeWaypointsMap, selectedRouteId, setSelectedRouteId, routeLoading };
}
+110 -18
View File
@@ -1,51 +1,132 @@
/* ========== 全局变量 ========== */
@glass-bg: linear-gradient(135deg, rgba(7, 20, 40, 0.92), rgba(12, 28, 52, 0.88));
@glass-border: rgba(65, 170, 255, 0.28);
@glass-blur: blur(16px);
@glass-shadow: 0 4px 24px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.06);
@accent-cyan: #00d4ff;
@accent-blue: #0096ff;
@text-primary: #eaf6ff;
@text-secondary: rgba(255, 255, 255, 0.55);
@transition-smooth: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
.container {
width: 100vw;
height: 100vh;
display: flex;
background: #0a1628;
color: #fff;
background: #060e1a;
color: @text-primary;
overflow: hidden;
position: relative;
}
.leftPanel {
width: 280px;
height: calc(100vh - 36px);
background: rgba(15, 25, 40, 0.95);
border-right: 1px solid rgba(0, 212, 255, 0.15);
width: 290px;
height: calc(100vh - 40px);
background: @glass-bg;
backdrop-filter: @glass-blur;
-webkit-backdrop-filter: @glass-blur;
border-right: 1px solid @glass-border;
box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.04), 4px 0 20px rgba(0, 0, 0, 0.3);
overflow-y: auto;
flex-shrink: 0;
transition: @transition-smooth;
position: relative;
// 顶部高光线
&::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
height: 1px;
background: linear-gradient(90deg, transparent, rgba(0, 212, 255, 0.3), transparent);
}
}
.centerView {
flex: 1;
height: calc(100vh - 36px);
height: calc(100vh - 40px);
position: relative;
transition: @transition-smooth;
}
.rightPanel {
width: 320px;
height: calc(100vh - 36px);
background: rgba(15, 25, 40, 0.95);
border-left: 1px solid rgba(0, 212, 255, 0.15);
height: calc(100vh - 40px);
background: @glass-bg;
backdrop-filter: @glass-blur;
-webkit-backdrop-filter: @glass-blur;
border-left: 1px solid @glass-border;
box-shadow: inset 1px 0 0 rgba(255, 255, 255, 0.04), -4px 0 20px rgba(0, 0, 0, 0.3);
overflow-y: auto;
flex-shrink: 0;
transition: @transition-smooth;
position: relative;
&::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
height: 1px;
background: linear-gradient(90deg, transparent, rgba(0, 212, 255, 0.3), transparent);
}
}
/* ========== 沉浸模式 ========== */
.sailing {
.leftPanel {
width: 0;
opacity: 0;
overflow: hidden;
border-right: none;
padding: 0;
box-shadow: none;
}
.rightPanel {
width: 0;
opacity: 0;
overflow: hidden;
border-left: none;
padding: 0;
box-shadow: none;
}
.centerView {
height: 100vh;
}
.statusBar {
opacity: 0;
pointer-events: none;
transform: translateY(100%);
}
}
/* ========== 底部状态栏 ========== */
.statusBar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 36px;
background: rgba(10, 18, 32, 0.95);
border-top: 1px solid rgba(0, 212, 255, 0.15);
height: 40px;
background: linear-gradient(180deg, rgba(7, 16, 32, 0.92), rgba(5, 12, 24, 0.96));
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
border-top: 1px solid @glass-border;
box-shadow: 0 -2px 16px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.04);
display: flex;
align-items: center;
padding: 0 16px;
padding: 0 20px;
font-size: 12px;
color: rgba(255, 255, 255, 0.6);
color: @text-secondary;
z-index: 100;
transition: @transition-smooth;
font-family: 'Rajdhani', 'DIN', 'Roboto Mono', monospace;
letter-spacing: 0.5px;
}
.statusDot {
@@ -54,18 +135,29 @@
border-radius: 50%;
margin-right: 8px;
display: inline-block;
box-shadow: 0 0 6px currentColor;
animation: statusPulse 2s ease-in-out infinite;
}
/* 滚动条样式 */
@keyframes statusPulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
/* ========== 滚动条 ========== */
.leftPanel::-webkit-scrollbar,
.rightPanel::-webkit-scrollbar {
width: 4px;
width: 3px;
}
.leftPanel::-webkit-scrollbar-thumb,
.rightPanel::-webkit-scrollbar-thumb {
background: rgba(0, 212, 255, 0.3);
background: rgba(0, 212, 255, 0.25);
border-radius: 2px;
&:hover {
background: rgba(0, 212, 255, 0.4);
}
}
.leftPanel::-webkit-scrollbar-track,
+91 -169
View File
@@ -1,181 +1,62 @@
import React, { useEffect, useState, useMemo, useCallback, useRef } from 'react';
import { history } from 'umi';
import { ConfigProvider, message, Button, Modal } from 'antd';
import React, { useEffect } from 'react';
import { ConfigProvider, Button } from 'antd';
import { LogoutOutlined } from '@ant-design/icons';
import { darkTheme } from '@/theme';
import LeftPanel from './components/LeftPanel';
import CenterView from './components/CenterView';
import RightPanel from './components/RightPanel';
import NavigationHUD from './components/NavigationHUD';
import NavigationOverlay from './components/NavigationOverlay';
import EmergencyButton from './components/EmergencyButton';
import { useClientAuth } from './hooks/useClientAuth';
import { useClientSSE } from './hooks/useClientSSE';
import { getClientRoutes } from './services/clientApi';
import { getBoatRouteDetail } from '@/services/boatRoute';
import type { BoatRouteListVO, BoatTelemetryData, BoatWaypointVO } from '@/types/boatRoute';
import { useRouteData } from './hooks/useRouteData';
import { useMockTelemetry } from './hooks/useMockTelemetry';
import { useNavigationState } from './hooks/useNavigationState';
import { useNavigationData } from './hooks/useNavigationData';
import styles from './index.less';
// 模拟遥测数据生成器
const createMockTelemetry = (deviceSn: string, prevData?: BoatTelemetryData | null, initLon?: number, initLat?: number): BoatTelemetryData => {
// 使用传入的初始位置,或者前次位置,或默认位置
const baseLon = prevData?.longitude ?? initLon ?? 108.366;
const baseLat = prevData?.latitude ?? initLat ?? 22.817;
const baseHeading = prevData?.heading ?? 45;
// 模拟船只缓慢移动
const headingRad = (baseHeading + (Math.random() - 0.5) * 10) * Math.PI / 180;
const moveDistance = 0.00002 + Math.random() * 0.00003; // ~2-5m
const newLon = baseLon + Math.cos(headingRad) * moveDistance;
const newLat = baseLat + Math.sin(headingRad) * moveDistance;
const newHeading = ((baseHeading + (Math.random() - 0.5) * 10) + 360) % 360;
return {
deviceSn,
longitude: newLon,
latitude: newLat,
heading: Number(newHeading.toFixed(1)),
speed: Number((1.5 + Math.random() * 2).toFixed(1)),
battery: Math.max(20, (prevData?.battery ?? 85) - Math.random() * 0.1),
signalStrength: 60 + Math.floor(Math.random() * 30),
status: '巡航中',
recordTime: new Date().toISOString(),
taskId: undefined,
currentWaypointIndex: undefined,
};
};
const ClientPage: React.FC = () => {
const [deviceInfo, setDeviceInfo] = useState<any>(null);
const [routes, setRoutes] = useState<BoatRouteListVO[]>([]);
const [routeWaypointsMap, setRouteWaypointsMap] = useState<Record<string, BoatWaypointVO[]>>({});
const [selectedRouteId, setSelectedRouteId] = useState<string | null>(null);
const [routeLoading, setRouteLoading] = useState(false);
// ── 认证 ──
const { boatData: sseBoatData, sseConnected, connectSSE, disconnectSSE } = useClientSSE();
const { deviceSn, deviceInfo, handleLogout } = useClientAuth(disconnectSSE);
const deviceSn = useMemo(() => sessionStorage.getItem('client_device_sn') || '', []);
// ── 航线数据 ──
const { routes, routeWaypointsMap, selectedRouteId, setSelectedRouteId, routeLoading } =
useRouteData(deviceSn);
// 模拟数据:SSE未连接时自动生成模拟遥测数据
const [mockBoatData, setMockBoatData] = useState<BoatTelemetryData | null>(null);
const mockTimerRef = useRef<NodeJS.Timeout | null>(null);
const mockDataRef = useRef<BoatTelemetryData | null>(null);
const modelCenterRef = useRef<{ lon: number; lat: number } | null>(null);
// ── 模拟遥测 ──
const { boatData, handleModelCenter } = useMockTelemetry(deviceSn, sseBoatData);
// 模型中心位置回调:当模型加载完成后,重置模拟数据起始位置到模型附近
const handleModelCenter = useCallback((lon: number, lat: number) => {
modelCenterRef.current = { lon, lat };
// 立即重置当前模拟数据位置到模型中心附近
if (mockDataRef.current) {
const newData = {
...mockDataRef.current,
longitude: lon + (Math.random() - 0.5) * 0.001,
latitude: lat + (Math.random() - 0.5) * 0.001,
};
mockDataRef.current = newData;
setMockBoatData(newData);
}
}, []);
// ── 沉浸模式状态机 ──
const {
isPaused,
currentWaypointIndex,
previewStopSignal,
isSailing,
isPreviewing,
isImmersive,
activeRouteId,
handleStartSailing,
handlePauseSailing,
handleResumeSailing,
handleStopSailing,
handleStopPreview,
handleEmergencyStop,
handlePreviewChange,
} = useNavigationState(deviceSn, selectedRouteId, setSelectedRouteId);
// 启动/停止模拟数据:当真实SSE数据到达时停止模拟,否则持续模拟
useEffect(() => {
// 有真实SSE数据,停止模拟
if (sseBoatData) {
if (mockTimerRef.current) {
clearInterval(mockTimerRef.current);
mockTimerRef.current = null;
}
setMockBoatData(null);
mockDataRef.current = null;
return;
}
// ── 导航计算 ──
const {
activeWaypoints,
activeRouteInfo,
nextWaypoint,
remainingDistance,
estimatedRemainingTime,
progress,
} = useNavigationData(activeRouteId, routes, routeWaypointsMap, boatData, currentWaypointIndex);
// 无真实数据且无模拟定时器,启动模拟
if (!mockTimerRef.current && deviceSn) {
console.log('[Mock] 启动模拟数据');
// 立即生成第一帧
const center = modelCenterRef.current;
const firstData = createMockTelemetry(deviceSn, null, center?.lon, center?.lat);
mockDataRef.current = firstData;
setMockBoatData(firstData);
mockTimerRef.current = setInterval(() => {
const center2 = modelCenterRef.current;
const newData = createMockTelemetry(
deviceSn,
mockDataRef.current,
center2?.lon,
center2?.lat,
);
mockDataRef.current = newData;
setMockBoatData(newData);
}, 2000);
}
return () => {
if (mockTimerRef.current) {
clearInterval(mockTimerRef.current);
mockTimerRef.current = null;
}
};
}, [sseBoatData, deviceSn]);
// 优先使用真实SSE数据,回退到模拟数据
const boatData = sseBoatData || mockBoatData;
// 退出登录
const handleLogout = useCallback(() => {
Modal.confirm({
title: '确认退出',
content: '退出后需要重新输入设备SN登录',
okText: '退出',
cancelText: '取消',
onOk: () => {
disconnectSSE();
sessionStorage.removeItem('client_device_sn');
sessionStorage.removeItem('client_device_info');
history.push('/client/login');
},
});
}, [disconnectSSE]);
// 校验登录状态
useEffect(() => {
const sn = sessionStorage.getItem('client_device_sn');
const info = sessionStorage.getItem('client_device_info');
if (!sn || !info) {
history.push('/client/login');
return;
}
try {
setDeviceInfo(JSON.parse(info));
} catch {
history.push('/client/login');
}
}, []);
// 加载游览线路列表 + 预加载航点详情
useEffect(() => {
if (!deviceSn) return;
setRouteLoading(true);
getClientRoutes(deviceSn)
.then(async (res) => {
if (res.resp_code === 0 && res.data) {
setRoutes(res.data);
// 并行预加载所有线路的航点详情
const detailResults = await Promise.allSettled(
res.data.map((r) => getBoatRouteDetail(r.routeId)),
);
const wpMap: Record<string, BoatWaypointVO[]> = {};
detailResults.forEach((result, idx) => {
if (result.status === 'fulfilled' && result.value.resp_code === 0 && result.value.data?.waypoints) {
wpMap[res.data[idx].routeId] = result.value.data.waypoints;
}
});
setRouteWaypointsMap(wpMap);
}
})
.catch(() => message.error('线路加载失败'))
.finally(() => setRouteLoading(false));
}, [deviceSn]);
// 连接SSE
// ── SSE 连接 ──
useEffect(() => {
if (!deviceSn) return;
connectSSE(deviceSn);
@@ -184,9 +65,10 @@ const ClientPage: React.FC = () => {
if (!deviceInfo) return null;
// ── 渲染 ──
return (
<ConfigProvider theme={darkTheme}>
<div className={styles.container}>
<div className={`${styles.container} ${isImmersive ? styles.sailing : ''}`}>
{/* 左侧游览线路 */}
<div className={styles.leftPanel}>
<LeftPanel
@@ -206,16 +88,56 @@ const ClientPage: React.FC = () => {
selectedRouteId={selectedRouteId}
boatData={boatData}
onModelCenter={handleModelCenter}
isSailing={isSailing}
previewStopSignal={previewStopSignal}
onStartSailing={handleStartSailing}
onPreviewChange={handlePreviewChange}
/>
{/* 沉浸模式浮层(航行或预览) */}
{isImmersive && (
<>
{!!activeRouteId && (
<NavigationOverlay
mode={isPreviewing ? 'preview' : 'sailing'}
routeName={activeRouteInfo?.routeName || ''}
waypoints={activeWaypoints.map((wp) => ({
name: wp.pointName || `航点${wp.waypointIndex + 1}`,
waypointIndex: wp.waypointIndex,
}))}
currentWaypointIndex={boatData?.currentWaypointIndex ?? currentWaypointIndex}
totalDistance={activeRouteInfo?.totalDistance ?? 0}
remainingDistance={remainingDistance}
estimatedRemainingTime={estimatedRemainingTime}
progress={progress}
/>
)}
{isSailing && (
<EmergencyButton onEmergencyStop={handleEmergencyStop} deviceSn={deviceSn} />
)}
<NavigationHUD
mode={isPreviewing ? 'preview' : 'sailing'}
routeName={activeRouteInfo?.routeName || ''}
speed={boatData?.speed ?? 0}
heading={boatData?.heading ?? 0}
battery={boatData?.battery ?? 0}
signalStrength={boatData?.signalStrength}
nextWaypoint={nextWaypoint}
remainingDistance={remainingDistance}
estimatedRemainingTime={estimatedRemainingTime}
progress={progress}
isPaused={isPaused && isSailing}
onPause={handlePauseSailing}
onResume={handleResumeSailing}
onStop={isPreviewing ? handleStopPreview : handleStopSailing}
/>
</>
)}
</div>
{/* 右侧设备信息 */}
<div className={styles.rightPanel}>
<RightPanel
deviceInfo={deviceInfo}
boatData={boatData}
sseConnected={sseConnected}
/>
<RightPanel deviceInfo={deviceInfo} boatData={boatData} sseConnected={sseConnected} />
</div>
{/* 底部状态栏 */}
@@ -139,7 +139,7 @@ export function useBoundaryDrawing(options: UseBoundaryDrawingOptions = {}): Use
/**
* 添加顶点
*/
const addVertex = useCallback((point: { longitude: number; latitude: number }) => {
const addVertex = useCallback((point: { longitude: number; latitude: number; height?: number }) => {
const newVertex: BoundaryVertex = {
longitude: point.longitude,
latitude: point.latitude,
@@ -169,6 +169,12 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
const waylineEntityRef = useRef<any>(null);
const waypointEntitiesRef = useRef<any[]>([]);
// 前向引用 ref(解决 useCallback 声明顺序问题)
const loadWaypointsRef = useRef<any>(null);
const drawWaylineOnMapRef = useRef<any>(null);
const flyToWaylineRef = useRef<any>(null);
const clearWaylineEntitiesRef = useRef<any>(null);
// 实时位置 - 区分相对高度和海拔高度
const realtimePosition = useMemo(() => {
if (!droneData) return null;
@@ -190,7 +196,7 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
loadRoutesByDevice(deviceSn);
loadMissionsByDevice(deviceSn);
return () => {
clearWaylineEntities();
clearWaylineEntitiesRef.current?.();
};
} else {
setPosition({ x: 0, y: 0 });
@@ -256,7 +262,7 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
if (!selectedRouteId && unifiedRoutes.length > 0) {
const first = unifiedRoutes[0];
setSelectedRouteId(first.routeId);
loadWaypoints(first.routeId, first.routeType);
loadWaypointsRef.current?.(first.routeId, first.routeType);
}
} else {
console.warn('[TaskPanel] 加载无人船航线失败:', res);
@@ -283,7 +289,7 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
if (!selectedRouteId && unifiedRoutes.length > 0) {
const first = unifiedRoutes[0];
setSelectedRouteId(first.routeId);
loadWaypoints(first.routeId, first.routeType);
loadWaypointsRef.current?.(first.routeId, first.routeType);
}
} else {
console.warn('[TaskPanel] 加载无人机航线失败:', res);
@@ -297,7 +303,7 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
} finally {
setRouteLoading(false);
}
}, [isBoatDevice, selectedRouteId, loadWaypoints]);
}, [isBoatDevice, selectedRouteId]);
// 加载任务列表
const loadMissionsByDevice = useCallback(async (sn: string) => {
@@ -343,7 +349,7 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
}));
setWaypoints(unifiedWaypoints);
if (viewer && Cesium) {
await drawWaylineOnMap(unifiedWaypoints);
await drawWaylineOnMapRef.current?.(unifiedWaypoints);
}
} else {
console.warn('[TaskPanel] 加载无人船航点失败:', res);
@@ -364,7 +370,7 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
}));
setWaypoints(unifiedWaypoints);
if (viewer && Cesium) {
await drawWaylineOnMap(unifiedWaypoints);
await drawWaylineOnMapRef.current?.(unifiedWaypoints);
}
} else {
console.warn('[TaskPanel] 加载无人机航点失败:', res);
@@ -374,7 +380,8 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
console.error('[TaskPanel] 加载航点失败:', e);
message.error('加载航点失败');
}
}, [viewer, Cesium, routeList, drawWaylineOnMap, isBoatDevice]);
}, [viewer, Cesium, routeList, isBoatDevice]);
loadWaypointsRef.current = loadWaypoints;
// 绘制航线 - 支持无人机和无人船航线,使用clampToHeightMostDetailed贴模型
const drawWaylineOnMap = useCallback(async (waypoints: UnifiedWaypoint[]) => {
@@ -536,8 +543,9 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
});
// 飞到航线,传递渲染后的positions用于精确计算视角
flyToWayline(waypoints, polylinePositions.length >= 2 ? polylinePositions : waypointPositions);
}, [viewer, Cesium, flyToWayline, clearWaylineEntities]);
flyToWaylineRef.current?.(waypoints, polylinePositions.length >= 2 ? polylinePositions : waypointPositions);
}, [viewer, Cesium]);
drawWaylineOnMapRef.current = drawWaylineOnMap;
// 飞到航线位置 - 参考航线规划页面的实现
const flyToWayline = useCallback((waypoints: UnifiedWaypoint[], positions?: any[]) => {
@@ -600,8 +608,7 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
console.error('[航线视角] 飞到航线失败:', e);
}
}, [viewer, Cesium]);
// 检查 viewer 是否有效
flyToWaylineRef.current = flyToWayline;
const isViewerValid = useCallback(() => {
return viewer && !viewer.isDestroyed?.();
}, [viewer]);
@@ -624,8 +631,7 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
});
waypointEntitiesRef.current = [];
}, [viewer, isViewerValid]);
// 选择航线
clearWaylineEntitiesRef.current = clearWaylineEntities;
const handleSelectRoute = useCallback((routeId: string) => {
setSelectedRouteId(routeId);
loadWaypoints(routeId);
@@ -978,7 +984,7 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
allowClear
onClear={() => {
setSelectedRouteId(null);
clearWaylineEntities();
clearWaylineEntitiesRef.current?.();
}}
>
{routeList.map(route => (
@@ -22,8 +22,8 @@ interface UseCesiumRouteRendererOptions {
mode: EditorMode; // 'view' | 'draw' | 'select' | 'edit'
boundaryGeoJson?: string; // 用于边界检测
obstacles?: RouteObstacleItem[]; // 障碍物边界(多边形)
onWaypointAdd: (point: { longitude: number; latitude: number }) => void;
onWaypointMove: (index: number, point: { longitude: number; latitude: number }) => void;
onWaypointAdd: (point: { longitude: number; latitude: number; altitude?: number }) => void;
onWaypointMove: (index: number, point: { longitude: number; latitude: number; altitude?: number }) => void;
onWaypointSelect: (index: number) => void;
}
@@ -96,6 +96,13 @@ export function useCesiumRouteRenderer(options: UseCesiumRouteRendererOptions) {
timer: null,
});
/**
* 获取Cesium对象(提前声明,供后续 useCallback 引用)
*/
const getCesium = useCallback(() => {
return (window as any).Cesium;
}, []);
const applyHeightOffset = useCallback((cartesian: any) => {
const Cesium = getCesium();
if (!Cesium || !cartesian) return cartesian;
@@ -153,13 +160,6 @@ export function useCesiumRouteRenderer(options: UseCesiumRouteRendererOptions) {
return result;
}, []);
/**
* 获取Cesium对象
*/
const getCesium = useCallback(() => {
return (window as any).Cesium;
}, []);
const normalizeRing = useCallback((ring: any): Array<[number, number]> => {
if (!Array.isArray(ring)) return [];
const coords = ring
@@ -69,18 +69,6 @@ const RouteEditor: React.FC<RouteEditorProps> = ({
useEffect(() => {
setActiveRouteId(routeId);
}, [routeId]);
const goLibraryAfterSave = useCallback(async (savedRouteId: string) => {
// 退出“编辑态”,让航线出现在航线库列表中
setActiveRouteId(undefined);
setMode('view');
selectWaypoint(null);
setWaypoints([]);
setActiveTabKey('library');
setLibrarySelectedId(savedRouteId);
await loadRouteLibrary();
}, [loadRouteLibrary, selectWaypoint, setMode, setWaypoints]);
// 加载设备绑定的水域边界(用于规划航线)
useEffect(() => {
const sn = String(deviceSn || '').trim();
@@ -279,6 +267,17 @@ const RouteEditor: React.FC<RouteEditorProps> = ({
loadRouteLibrary();
}, [loadRouteLibrary]);
const goLibraryAfterSave = useCallback(async (savedRouteId: string) => {
// 退出“编辑态”,让航线出现在航线库列表中
setActiveRouteId(undefined);
setMode('view');
selectWaypoint(null);
setWaypoints([]);
setActiveTabKey('library');
setLibrarySelectedId(savedRouteId);
await loadRouteLibrary();
}, [loadRouteLibrary, selectWaypoint, setMode, setWaypoints]);
const ensureRouteDetail = useCallback(async (id: string) => {
if (!id) return;
if (routeDetailsRef.current[id]?.length) return;