根据不同账号 显示的首页优化 规划界面 悬浮显示 状态信息 全局急停状态统一 割刀 根据新方案对接 两个状态 任务路线 显示为 抽拉式一行一个 xbox组件优化数据发送,重构数据
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
|
||||
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { subscribeEmergencyStop } from './emergencyStopControl';
|
||||
import {
|
||||
ChevronUp,
|
||||
ChevronDown,
|
||||
@@ -60,6 +61,10 @@ const DPadControl: React.FC<DPadControlProps> = ({
|
||||
|
||||
const [pressed, setPressed] = useState<Record<string, boolean>>({});
|
||||
const [speed, setSpeed] = useState(0.5);
|
||||
// 急停锁存状态:与其他入口(手柄 / 功能按钮)共享同一份状态
|
||||
const [eStopActive, setEStopActive] = useState(false);
|
||||
|
||||
useEffect(() => subscribeEmergencyStop(setEStopActive), []);
|
||||
|
||||
// 每个物理输入单独记录,避免同方向不同按键互相干扰
|
||||
// 例如 ArrowUp 和 W 可以同时按下
|
||||
@@ -69,7 +74,6 @@ const DPadControl: React.FC<DPadControlProps> = ({
|
||||
const speedRef = useRef(0.5);
|
||||
const pressTimer = useRef<number | null>(null);
|
||||
const disabledRef = useRef(disabled);
|
||||
const emergencyTimer = useRef<number | null>(null);
|
||||
|
||||
const onGamepadUpdateRef = useRef(onGamepadUpdate);
|
||||
const onSpeedChangeRef = useRef(onSpeedChange);
|
||||
@@ -204,29 +208,11 @@ const DPadControl: React.FC<DPadControlProps> = ({
|
||||
stopTimer();
|
||||
emit();
|
||||
}, [stopTimer, emit]);
|
||||
const startEmergency = useCallback(() => {
|
||||
// 急停:切换锁存状态(第一次按下→发送 eStop=1,第二次按下→发送 eStop=0)
|
||||
// 视觉由订阅到的共享锁存状态驱动,与手柄 / 其他入口保持一致
|
||||
const toggleEmergency = useCallback(() => {
|
||||
if (disabledRef.current) return;
|
||||
|
||||
pressedRef.current = {
|
||||
...pressedRef.current,
|
||||
center: true,
|
||||
};
|
||||
setPressed({ ...pressedRef.current });
|
||||
|
||||
onEmergencyStopRef.current?.();
|
||||
|
||||
if (emergencyTimer.current !== null) {
|
||||
window.clearTimeout(emergencyTimer.current);
|
||||
}
|
||||
|
||||
emergencyTimer.current = window.setTimeout(() => {
|
||||
pressedRef.current = {
|
||||
...pressedRef.current,
|
||||
center: false,
|
||||
};
|
||||
setPressed({ ...pressedRef.current });
|
||||
emergencyTimer.current = null;
|
||||
}, 350);
|
||||
}, []);
|
||||
|
||||
// 键盘控制:支持方向键 + WASD 组合
|
||||
@@ -247,7 +233,7 @@ const DPadControl: React.FC<DPadControlProps> = ({
|
||||
|
||||
// 防止长按空格时重复触发急停
|
||||
if (!e.repeat) {
|
||||
startEmergency();
|
||||
toggleEmergency();
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -287,7 +273,7 @@ const DPadControl: React.FC<DPadControlProps> = ({
|
||||
window.removeEventListener('keyup', handleKeyUp);
|
||||
window.removeEventListener('blur', handleBlur);
|
||||
};
|
||||
}, [startPress, endPress, releaseAll, startEmergency]);
|
||||
}, [startPress, endPress, releaseAll, toggleEmergency]);
|
||||
|
||||
// 禁用时立即停止;卸载时清理定时器
|
||||
useEffect(() => {
|
||||
@@ -317,17 +303,17 @@ const DPadControl: React.FC<DPadControlProps> = ({
|
||||
};
|
||||
}, [disabled, stopTimer]);
|
||||
|
||||
// 紧急停止按钮的短暂按压动画
|
||||
// 急停锁存相关清理
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (emergencyTimer.current !== null) {
|
||||
window.clearTimeout(emergencyTimer.current);
|
||||
}
|
||||
stopTimer();
|
||||
};
|
||||
}, [stopTimer]);
|
||||
//useEffect(() => {
|
||||
// return () => {
|
||||
// if (emergencyTimer.current !== null) {
|
||||
// window.clearTimeout(emergencyTimer.current);
|
||||
// }
|
||||
// stopTimer();
|
||||
// };
|
||||
//}, [stopTimer]);
|
||||
|
||||
const btnBase =
|
||||
'flex items-center justify-center w-8 h-8 rounded-xl border transition-all duration-150 select-none active:scale-95 touch-none';
|
||||
@@ -390,14 +376,14 @@ const DPadControl: React.FC<DPadControlProps> = ({
|
||||
type="button"
|
||||
aria-label={t('devices.emergencyStop')}
|
||||
disabled={disabled}
|
||||
className={`${btnBase} relative ${pressed.center
|
||||
className={`${btnBase} relative ${eStopActive
|
||||
? 'border-red-500 bg-red-500/40 text-white shadow-[0_0_16px_rgba(239,68,68,0.6)]'
|
||||
: 'border-red-500/70 bg-red-500/10 text-red-400 hover:bg-red-500/20'
|
||||
} ${disabled
|
||||
? 'opacity-40 cursor-not-allowed'
|
||||
: 'cursor-pointer'
|
||||
}`}
|
||||
onClick={startEmergency}
|
||||
onClick={toggleEmergency}
|
||||
>
|
||||
<ShieldAlert className="w-5 h-5" />
|
||||
<span className="absolute -top-1 -right-1 px-1 bg-slate-900/80 text-[8px] text-red-400/80 rounded border border-red-500/30 pointer-events-none">
|
||||
|
||||
Reference in New Issue
Block a user