远程控制模块的控制状态放在外面
This commit is contained in:
@@ -172,7 +172,7 @@ const DPadControl: React.FC<DPadControlProps> = ({ onGamepadUpdate, onSpeedChang
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col items-center gap-5 w-full">
|
<div className="flex flex-col items-center gap-1 w-full">
|
||||||
{/* 十字方向键 */}
|
{/* 十字方向键 */}
|
||||||
<div className="grid grid-cols-3 grid-rows-3 gap-2.5">
|
<div className="grid grid-cols-3 grid-rows-3 gap-2.5">
|
||||||
<div />
|
<div />
|
||||||
|
|||||||
@@ -34,6 +34,9 @@ import {
|
|||||||
EnvironmentOutlined,
|
EnvironmentOutlined,
|
||||||
DeleteOutlined,
|
DeleteOutlined,
|
||||||
SafetyOutlined,
|
SafetyOutlined,
|
||||||
|
LockOutlined,
|
||||||
|
UnlockOutlined,
|
||||||
|
LoadingOutlined,
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -87,6 +90,8 @@ export default function DeviceStatusPage() {
|
|||||||
const [isLoopMode, setIsLoopMode] = useState(true);
|
const [isLoopMode, setIsLoopMode] = useState(true);
|
||||||
const controllerRef = useRef<DeviceController | null>(null);
|
const controllerRef = useRef<DeviceController | null>(null);
|
||||||
const isFirstConnect = useRef(true);
|
const isFirstConnect = useRef(true);
|
||||||
|
// 标记本次会话是否已经发起过控制权限申请,避免手柄/方向盘高频更新时重复申请
|
||||||
|
const hasRequestedControlRef = useRef(false);
|
||||||
const [messageApi, contextHolder] = message.useMessage();
|
const [messageApi, contextHolder] = message.useMessage();
|
||||||
|
|
||||||
|
|
||||||
@@ -633,18 +638,34 @@ export default function DeviceStatusPage() {
|
|||||||
}, [device, uavState, currentDroneData]);
|
}, [device, uavState, currentDroneData]);
|
||||||
|
|
||||||
const handleGamepadUpdate = useCallback((state) => {
|
const handleGamepadUpdate = useCallback((state) => {
|
||||||
|
// 无控制权限时:不发送消息,且只发起一次权限申请(避免手柄/方向盘高频更新刷屏)
|
||||||
|
if (!isControlled) {
|
||||||
|
if (!hasRequestedControlRef.current && !connecting) {
|
||||||
|
hasRequestedControlRef.current = true;
|
||||||
|
handleControlModal();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
console.log('Gamepad state updated:', state);
|
console.log('Gamepad state updated:', state);
|
||||||
// 记录方向盘 xy 坐标,用于倒车影像叠加层
|
// 记录方向盘 xy 坐标,用于倒车影像叠加层
|
||||||
if (state?.axes) {
|
if (state?.axes) {
|
||||||
setSteerXY({ x: state.axes[0] || 0, y: state.axes[1] || 0 });
|
setSteerXY({ x: state.axes[0] || 0, y: state.axes[1] || 0 });
|
||||||
}
|
}
|
||||||
controllerRef.current?.sendGamepad(state);
|
controllerRef.current?.sendGamepad(state);
|
||||||
}, []);
|
}, [isControlled, connecting]);
|
||||||
|
|
||||||
const handleControlModal = useCallback(() => {
|
const handleControlModal = useCallback(() => {
|
||||||
|
console.log('请求控制权限');
|
||||||
controllerRef.current?.requestControl();
|
controllerRef.current?.requestControl();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// 获得控制权限后,重置"已申请"标记,以便后续失去权限时可再次提示
|
||||||
|
useEffect(() => {
|
||||||
|
if (isControlled) {
|
||||||
|
hasRequestedControlRef.current = false;
|
||||||
|
}
|
||||||
|
}, [isControlled]);
|
||||||
|
|
||||||
const handleOk = () => {
|
const handleOk = () => {
|
||||||
controllerRef.current?.sendPermissionRequest(
|
controllerRef.current?.sendPermissionRequest(
|
||||||
true,
|
true,
|
||||||
@@ -1423,24 +1444,66 @@ export default function DeviceStatusPage() {
|
|||||||
{t('devices.remoteControl')}
|
{t('devices.remoteControl')}
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
extra={
|
||||||
|
<Space size={8}>
|
||||||
|
{/* 权限状态标签 */}
|
||||||
|
<Tag
|
||||||
|
icon={connecting ? <LoadingOutlined /> : (isControlled ? <UnlockOutlined /> : <LockOutlined />)}
|
||||||
|
color={connecting ? 'gold' : (isControlled ? 'green' : 'default')}
|
||||||
|
style={{ margin: 0, fontSize: 12 }}
|
||||||
|
>
|
||||||
|
{connecting
|
||||||
|
? t('devices.controlRequesting')
|
||||||
|
: isControlled
|
||||||
|
? t('devices.controlGranted')
|
||||||
|
: t('devices.noControlRight')}
|
||||||
|
</Tag>
|
||||||
|
{/* 申请/释放控制按钮 */}
|
||||||
|
{isControlled ? (
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
danger
|
||||||
|
icon={<LockOutlined />}
|
||||||
|
onClick={() => {
|
||||||
|
controllerRef.current?.release?.();
|
||||||
|
setIsControlled(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t('devices.releaseControl')}
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
type="primary"
|
||||||
|
icon={<UnlockOutlined />}
|
||||||
|
loading={connecting}
|
||||||
|
onClick={handleControlModal}
|
||||||
|
>
|
||||||
|
{t('devices.requestControl')}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</Space>
|
||||||
|
}
|
||||||
variant="borderless"
|
variant="borderless"
|
||||||
className="ds-card"
|
className="ds-card"
|
||||||
style={{ borderRadius: 12, background: '#0f172a', flex: 1, minHeight: 0 }}
|
style={{ borderRadius: 12, background: '#0f172a', flex: 1, minHeight: 0, position: 'relative' }}
|
||||||
styles={{
|
styles={{
|
||||||
header: { color: '#fff' },
|
header: { color: '#fff' },
|
||||||
body: {
|
body: {
|
||||||
padding: 12,
|
padding: 12,
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
flexWrap: 'wrap', // ✅ 新增:空间不足自动换行
|
flexWrap: 'wrap',
|
||||||
gap: 12,
|
gap: 12,
|
||||||
height: 'calc(100% - 57px)',
|
height: 'calc(100% - 57px)',
|
||||||
overflow: 'auto', // ✅ 改成 auto,换行后内容不会被截断
|
overflow: 'auto',
|
||||||
alignItems: 'center', // 垂直居中,换行后美观
|
alignItems: 'center',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
||||||
|
|
||||||
{/* Xbox 手柄 - 左侧,缩小显示 */}
|
{/* Xbox 手柄 - 左侧,缩小显示 */}
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
@@ -1448,17 +1511,13 @@ export default function DeviceStatusPage() {
|
|||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
flex: '0 0 auto',
|
flex: '0 0 auto',
|
||||||
minWidth: 320, // ✅ 限制最小宽度,小于这个宽度就会换行
|
minWidth: 320,
|
||||||
transform: 'scale(0.82)',
|
transform: 'scale(0.82)',
|
||||||
transformOrigin: 'left center',
|
transformOrigin: 'left center',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<XboxController
|
<XboxController
|
||||||
onGamepadUpdate={handleGamepadUpdate}
|
onGamepadUpdate={handleGamepadUpdate}
|
||||||
handleControlModal={handleControlModal}
|
|
||||||
isControlled={isControlled}
|
|
||||||
hasControlRight={hasControlRight}
|
|
||||||
isConnecting={connecting}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -1466,7 +1525,6 @@ export default function DeviceStatusPage() {
|
|||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
flex: '1 1 auto',
|
flex: '1 1 auto',
|
||||||
//minWidth: 300, // ✅ 最小宽度,触发换行阈值,可按需调整
|
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { useEffect, useState, useRef } from 'react';
|
import React, { useEffect, useState, useRef } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
const XboxController = ({ onGamepadUpdate, handleControlModal, isControlled, isConnecting, hasControlRight }) => {
|
const XboxController = ({ onGamepadUpdate }) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [gamepadState, setGamepadState] = useState<{
|
const [gamepadState, setGamepadState] = useState<{
|
||||||
buttons: boolean[];
|
buttons: boolean[];
|
||||||
@@ -114,36 +114,15 @@ const XboxController = ({ onGamepadUpdate, handleControlModal, isControlled, isC
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative h-[252px] aspect-[4/3] flex items-center justify-center "
|
<div className="relative h-[252px] aspect-[4/3] flex items-center justify-center">
|
||||||
onClick={() => {
|
{/* 手柄硬件连接状态指示(仅表示物理手柄是否连接) */}
|
||||||
if (!isControlled) {
|
|
||||||
console.log("点击了无控制权限,发起权限请求");
|
|
||||||
// 示例:调用你代码中已有的权限请求弹窗逻辑
|
|
||||||
handleControlModal({ control: true, type: "switchPermission" });
|
|
||||||
}
|
|
||||||
}}>
|
|
||||||
{/* Gamepad Status Badge */}
|
|
||||||
<div
|
<div
|
||||||
className={`absolute top-0 right-0 px-2 py-0.5 rounded text-[8px] font-bold tracking-widest border
|
className={`absolute top-0 right-0 px-2 py-0.5 rounded text-[8px] font-bold tracking-widest border ${connected
|
||||||
${connected
|
|
||||||
? isConnecting
|
|
||||||
? 'bg-yellow-500/20 text-yellow-400 border-yellow-500/30'
|
|
||||||
: isControlled
|
|
||||||
? 'bg-cyan-500/20 text-cyan-400 border-cyan-500/30'
|
? 'bg-cyan-500/20 text-cyan-400 border-cyan-500/30'
|
||||||
: 'bg-red-500/20 text-red-400 border-red-500/30'
|
|
||||||
: 'bg-slate-800 text-slate-500 border-white/5'
|
: 'bg-slate-800 text-slate-500 border-white/5'
|
||||||
}
|
}`}
|
||||||
`}
|
|
||||||
>
|
>
|
||||||
{!connected ? (
|
{connected ? t('devices.controllerConnected') : t('devices.controllerNotConnected')}
|
||||||
t('devices.controllerNotConnected')
|
|
||||||
) : isConnecting ? (
|
|
||||||
t('devices.control2')
|
|
||||||
) : isControlled ? (
|
|
||||||
t('devices.controlling')
|
|
||||||
) : (
|
|
||||||
t('devices.clickToRequestControl')
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<svg viewBox="0 0 400 300" className="w-full h-full drop-shadow-[0_0_20px_rgba(34,211,238,0.15)]">
|
<svg viewBox="0 0 400 300" className="w-full h-full drop-shadow-[0_0_20px_rgba(34,211,238,0.15)]">
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const en = {
|
const en = {
|
||||||
common: {
|
common: {
|
||||||
save: 'Save',
|
save: 'Save',
|
||||||
saveChanges: 'Save Changes',
|
saveChanges: 'Save Changes',
|
||||||
@@ -814,6 +814,12 @@
|
|||||||
repeatTypeLabel: 'Repeat Type Label',
|
repeatTypeLabel: 'Repeat Type Label',
|
||||||
repeatWeekly: 'Repeat Weekly',
|
repeatWeekly: 'Repeat Weekly',
|
||||||
requestControlPermission: 'Request Control Permission',
|
requestControlPermission: 'Request Control Permission',
|
||||||
|
controlRequesting: 'Requesting...',
|
||||||
|
controlGranted: 'Control Granted',
|
||||||
|
noControlRight: 'No Control Right',
|
||||||
|
pleaseRequestControl: 'Please request control first',
|
||||||
|
requestControl: 'Request Control',
|
||||||
|
releaseControl: 'Release Control',
|
||||||
requestFail: 'Request Fail',
|
requestFail: 'Request Fail',
|
||||||
resumeAuto: 'Resume Auto',
|
resumeAuto: 'Resume Auto',
|
||||||
resumeBreakpoint: 'Resume Breakpoint',
|
resumeBreakpoint: 'Resume Breakpoint',
|
||||||
@@ -1057,6 +1063,7 @@
|
|||||||
workingCurrent: 'Working Current',
|
workingCurrent: 'Working Current',
|
||||||
zoomLens: 'Zoom Lens',
|
zoomLens: 'Zoom Lens',
|
||||||
controllerNotConnected: "controllerNotConnected",
|
controllerNotConnected: "controllerNotConnected",
|
||||||
|
controllerConnected: "Controller Connected",
|
||||||
otherWebConnected: "otherWebConnected",
|
otherWebConnected: "otherWebConnected",
|
||||||
clickToRequestControl: "clickToRequestControl",
|
clickToRequestControl: "clickToRequestControl",
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import WeatherRainy from "@/src/components/Weather/WeatherRainy";
|
import WeatherRainy from "@/src/components/Weather/WeatherRainy";
|
||||||
|
|
||||||
const zh = {
|
const zh = {
|
||||||
common: {
|
common: {
|
||||||
@@ -610,6 +610,7 @@ const zh = {
|
|||||||
firmwareVersion: '固件版本',
|
firmwareVersion: '固件版本',
|
||||||
fixed: '固定',
|
fixed: '固定',
|
||||||
controllerNotConnected: "控制器未连接",
|
controllerNotConnected: "控制器未连接",
|
||||||
|
controllerConnected: "控制器已连接",
|
||||||
otherWebConnected: "其他网页已连接",
|
otherWebConnected: "其他网页已连接",
|
||||||
clickToRequestControl: "点击请求控制",
|
clickToRequestControl: "点击请求控制",
|
||||||
|
|
||||||
@@ -839,6 +840,12 @@ const zh = {
|
|||||||
repeatTypeLabel: '重复类型标签',
|
repeatTypeLabel: '重复类型标签',
|
||||||
repeatWeekly: '重复每周',
|
repeatWeekly: '重复每周',
|
||||||
requestControlPermission: '请求控制权限',
|
requestControlPermission: '请求控制权限',
|
||||||
|
controlRequesting: '申请中...',
|
||||||
|
controlGranted: '已获得控制',
|
||||||
|
noControlRight: '无控制权限',
|
||||||
|
pleaseRequestControl: '请先申请控制权限',
|
||||||
|
requestControl: '申请控制',
|
||||||
|
releaseControl: '释放控制',
|
||||||
requestFail: '请求失败',
|
requestFail: '请求失败',
|
||||||
resumeAuto: '恢复自动',
|
resumeAuto: '恢复自动',
|
||||||
resumeBreakpoint: '恢复断点',
|
resumeBreakpoint: '恢复断点',
|
||||||
|
|||||||
Reference in New Issue
Block a user