1:修复远程遥控控制状态显示不正确的问题

2:更换端口映射为测试服的8081-59003,9001-59004
This commit is contained in:
2026-08-26 14:23:20 +08:00
parent ca616faf11
commit 7c01229b9e
22 changed files with 399 additions and 119 deletions

View File

@@ -742,15 +742,20 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
debugPrint('${_getTimePrefix()} ====权限弹窗响应结束=====');
}
/// 请求控制权限(HTTP 查询接口 /forward/device/remoteControl)
///
/// [grabControl] true = 查询后若无权限立即发 TCP 0x12 switch_control 抢占(手动点击时使用);
/// false = 仅查询,把接口 remoteControl 结果如实同步到 UI(进入页面时使用)
Future<void> requestControlPermissionS(
String deviceName,
String deviceId, {
String source = '自动',
bool grabControl = false,
}) async {
final timePrefix = _getTimePrefix();
final logPrefix = '$timePrefix 🔑 [RemoteControl] [请求权限接口-$source]';
debugPrint('$logPrefix =========================================');
debugPrint('$logPrefix 开始请求控制权');
debugPrint('$logPrefix 开始请求控制权 (grabControl=$grabControl)');
debugPrint('$logPrefix deviceName: $deviceName');
debugPrint('$logPrefix platform: $deviceId');
debugPrint(
@@ -808,8 +813,21 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
shouldLog: true,
);
// 🔥 关键逻辑: 如果没有权限 或owner为null,则发送TCP 请求
if (!hasPermission || owner == null) {
// 🔥 仅查询模式:不抢占,把接口 remoteControl 结果如实同步到 UI
if (!grabControl) {
debugPrint(
'$successLogPrefix 👀 仅查询模式,不发送TCP抢占,直接同步 remoteControl=$hasPermission',
);
_logger.logWithLevel(
'$successLogPrefix 👀 仅查询模式,直接同步 remoteControl=$hasPermission',
shouldLog: true,
);
if (state.hasPermission != hasPermission) {
emit(state.copyWith(hasPermission: hasPermission));
}
}
// 🔥 抢占模式: 如果没有权限 或owner为null,则发送TCP 请求
else if (!hasPermission || owner == null) {
debugPrint('$successLogPrefix ⚠️ APP无权限或owner为null,发送TCP请求...');
_logger.logWithLevel(
'$successLogPrefix ⚠️ APP无权限或owner为null,发送TCP请求',
@@ -850,6 +868,23 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
);
}
/// 🔥 退出遥控页时重置权限状态,避免单例状态残留导致下次进入不再查询接口
void resetPermissionState() {
if (!isClosed) {
emit(
state.copyWith(
hasPermission: false,
showPermissionRequestDialog: false,
),
);
debugPrint('🔑 [RemoteControl] 已重置权限状态 hasPermission=false');
_logger.logWithLevel(
'🔑 [RemoteControl] 已重置权限状态 hasPermission=false',
shouldLog: true,
);
}
}
/// 🔥 重置弹窗状态 - 在弹窗关闭后调用(已简化,不再需要标志位)
void resetPermissionCoolDown() {
// 标志位已移除,此方法保留以保持向后兼容性
@@ -972,9 +1007,12 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
}
}
//app退出远程遥控界面释放权限
Future<bool> releasePermission(String platform) async {
return await _repository.releasePermission(platform);
//app退出远程遥控界面释放权限(type=2),退出机器人详情页释放权限(type=1)
Future<bool> releasePermission({
required String deviceId,
required int type,
}) async {
return await _repository.releasePermission(deviceId: deviceId, type: type);
}
/// 🔥 设置待控制的设备(从机器人列表点击进入时调用)