作业首页和机器状态的数据

This commit is contained in:
2026-11-06 08:41:44 +08:00
parent d882db7995
commit 85c83ec143
41 changed files with 3702 additions and 656 deletions

View File

@@ -0,0 +1,48 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../domain/usecases/search_device_usecase.dart';
import 'find_robot_state.dart';
/// 一键寻车 Cubit
///
/// 调用链:UI → FindRobotCubit → SearchDeviceUseCase → Repository → DataSource,
/// 弹窗不再直接依赖用例或数据源。
///
/// 下发口径:deviceId 传设备编码(deviceName,MC700- 开头),不是数字主键 id。
class FindRobotCubit extends Cubit<FindRobotState> {
final SearchDeviceUseCase _searchDevice;
FindRobotCubit(this._searchDevice) : super(const FindRobotState());
/// 下发一键寻车指令(GET /iot/host/searchDevice)
///
/// [deviceCode] 为空时直接判定失败,不发请求(避免后端把空串当全量)。
Future<void> startFind({required String deviceCode}) async {
if (state.isSubmitting) return;
final code = deviceCode.trim();
if (code.isEmpty) {
emit(const FindRobotState(errorMessage: ''));
return;
}
emit(FindRobotState(isSubmitting: true, deviceCode: code));
final result = await _searchDevice.execute(deviceCode: code);
result.fold(
(failure) => emit(
FindRobotState(errorMessage: failure.message, deviceCode: code),
),
(sent) => emit(
FindRobotState(isSuccess: sent, deviceCode: code),
),
);
}
/// 结果已被界面消费,复位避免重复弹提示
void reset() {
if (state.isSubmitting) return;
emit(const FindRobotState());
}
}

View File

@@ -0,0 +1,29 @@
import 'package:equatable/equatable.dart';
/// 一键寻车指令下发状态
///
/// 一次性结果用 [isSuccess] / [errorMessage] 表达:
/// [errorMessage] 非 null 即失败,空串表示只知失败、文案由 UI 套本地化提示。
class FindRobotState extends Equatable {
/// 请求进行中(用于拦截重复点击)
final bool isSubmitting;
/// 后端已成功下发寻车指令
final bool isSuccess;
/// 失败原因;null 表示尚无结果
final String? errorMessage;
/// 本次操作的设备编码(MC700- 开头)
final String? deviceCode;
const FindRobotState({
this.isSubmitting = false,
this.isSuccess = false,
this.errorMessage,
this.deviceCode,
});
@override
List<Object?> get props => [isSubmitting, isSuccess, errorMessage, deviceCode];
}

View File

@@ -5,7 +5,10 @@ import 'package:shared_preferences/shared_preferences.dart';
/// 使用静态变量存储状态,确保全局同步
class FloatBarSettingService {
final SharedPreferences _prefs;
static const String _key = 'float_bar_enabled';
/// key 升版:旧版(float_bar_enabled)可能残留 true,导致升级后悬浮条依然显示,
/// 故换用新 key,保证首次启动一律回到默认关闭。
static const String _key = 'float_bar_enabled_v2';
/// 🔥 静态实例引用
static FloatBarSettingService? _instance;
@@ -18,6 +21,7 @@ class FloatBarSettingService {
FloatBarSettingService(this._prefs) {
_instance = this;
// 默认关闭:未设置过时一律不显示悬浮条
_isEnabled = _prefs.getBool(_key) ?? false;
_settingNotifier.value = _isEnabled;
debugPrint('✅ [FloatBarSettingService] 初始化完成,初始状态: $_isEnabled');

View File

@@ -18,6 +18,7 @@ import '../../../../../../core/di/injection.dart';
import '../../../../../../core/managers/drone_task_state_manager.dart';
import '../../../../../../core/network/mqtt/domain/entities/drone_osd_entity.dart';
import '../../../../../../core/network/mqtt/data/datasources/drone_osd_datasource.dart';
import 'package:maibu_satabot_v2/features/home/presentation/widgets/map/app_base_map_layer.dart';
/// 模拟轨迹模式枚举
enum SimulationMode {
@@ -1501,14 +1502,8 @@ class FloatBarWidgetState extends State<FloatBarWidget> {
},
),
children: [
// ESRI World Imagery(WGS84 坐标系,全球高清卫星图)
// 替代高德地图(GCJ02),统一坐标系,无需坐标转换
TileLayer(
urlTemplate: 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
userAgentPackageName: 'com.example.app',
minZoom: 0,
maxZoom: 19,
),
// 底图:中文=ESRI,非中文=Google(不可达自动回退 ESRI)
const AppBaseMapLayer(),
// 轨迹线(中间层)
if (_trajectoryPoints.length >= 1)

View File

@@ -781,31 +781,33 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
'🔴🔴🔴 [全部-选中机器人] hasHost: ${robot.hasHost}',
);
// 🔥 hasHost 字段判定:false → 蓝牙连接流程
if (!robot.hasHost) {
debugPrint('⚠️ [全部-EmbeddedRobotList] hasHost=false,进入蓝牙连接流程');
// 从设备名中提取时间戳(如 MC700PRO-CN-JS-1751525588120-0000000A-9527 → 1751525588120)
final timestamp = _extractTimestamp(robot.name);
if (timestamp == null || timestamp.isEmpty) {
debugPrint('❌ [全部-EmbeddedRobotList] 未提取到时间戳');
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('设备名称异常,暂时无法连接'),
duration: Duration(seconds: 2),
),
);
return;
}
debugPrint('✅ [全部-EmbeddedRobotList] 提取到时间戳: $timestamp');
// 调用蓝牙连接流程
_connectToDeviceViaBluetooth(context, robot.name, timestamp);
return;
}
// ===== 【暂时停用】hasHost 分层判定 =====
// 需求:暂时不管有无宿主,点卡片一律直接进控制页。
// 恢复方式:取消下面整段注释即可(原逻辑:hasHost=false → 蓝牙连接流程)
// if (!robot.hasHost) {
// debugPrint('⚠️ [全部-EmbeddedRobotList] hasHost=false,进入蓝牙连接流程');
//
// // 从设备名中提取时间戳(如 MC700PRO-CN-JS-1751525588120-0000000A-9527 → 1751525588120)
// final timestamp = _extractTimestamp(robot.name);
// if (timestamp == null || timestamp.isEmpty) {
// debugPrint('❌ [全部-EmbeddedRobotList] 未提取到时间戳');
// ScaffoldMessenger.of(context).showSnackBar(
// const SnackBar(
// content: Text('设备名称异常,暂时无法连接'),
// duration: Duration(seconds: 2),
// ),
// );
// return;
// }
//
// debugPrint('✅ [全部-EmbeddedRobotList] 提取到时间戳: $timestamp');
//
// // 调用蓝牙连接流程
// _connectToDeviceViaBluetooth(context, robot.name, timestamp);
// return;
// }
// hasHost == true → 走原来的逻辑
// 原 hasHost == true 分支(现在所有设备都走这里)
debugPrint('✅ [全部-EmbeddedRobotList] hasHost=true,走正常控制流程');
// 1. 将当前机器人设置为全局待控制设备

View File

@@ -47,7 +47,8 @@ import '../../../local_camera/presentation/pages/local_camera_page.dart';
import '../../../usb_camera/presentation/pages/usb_camera_page.dart';
import '../../../../remote_control/presentation/bloc/remote_control_cubit.dart';
import '../../../../devices/domain/entities/device_entity.dart';
import '../../../../devices/domain/usecases/update_devicename_usecase.dart';
import '../cubit/rename_device_cubit.dart';
import '../cubit/rename_device_state.dart';
import 'package:get_it/get_it.dart';
/// 设备状态页面 V2 —— 按「02_设备卡片总览」设计稿换皮。
@@ -63,10 +64,16 @@ class DeviceStatusPageV2 extends StatelessWidget {
final selectedSite = sl<SiteCubit>().state.selectedSite;
final siteId = selectedSite?.id;
return BlocProvider(
create: (_) =>
sl<DeviceListBloc.DeviceStatusBloc>()
..add(DeviceListEvent.DeviceStatusLoadData(siteId: siteId)),
return MultiBlocProvider(
providers: [
BlocProvider(
create: (_) =>
sl<DeviceListBloc.DeviceStatusBloc>()
..add(DeviceListEvent.DeviceStatusLoadData(siteId: siteId)),
),
// 设备改名:UI 只调 Cubit,不直接依赖 UseCase/DataSource
BlocProvider(create: (_) => sl<RenameDeviceCubit>()),
],
child: const DeviceStatusViewV2(),
);
}
@@ -355,7 +362,10 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
}
},
builder: (context, stationState) =>
_buildV2Scaffold(context, robotState, stationState),
BlocListener<RenameDeviceCubit, RenameDeviceState>(
listener: _onRenameState,
child: _buildV2Scaffold(context, robotState, stationState),
),
),
),
);
@@ -408,8 +418,11 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
for (final r in robotState.robots) {
items.add(
_V2DeviceItem(
// 展示口径:deviceAlias 为空(首次绑定必为 null)就回退 deviceName;
// 后端改名接口只写 deviceAlias,deviceName 永远保持不变
name: (r.alias != null && r.alias!.isNotEmpty) ? r.alias! : r.name,
modelText: '${r.type} · ${DeviceV2Display.editionOf(r.id)}',
// 型号 · 版本:由 getSiteList 的 productModel 解析(如 MC700 · PRO 旗舰版)
modelText: r.modelLabelOf(AppLocalizations.of(context)),
snKey: r.id,
status: _robotV2Status(r),
battery: r.isOnline ? r.battery.round() : null,
@@ -424,7 +437,12 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
items.add(
_V2DeviceItem(
name: s.callsign.isNotEmpty ? s.callsign : sn,
modelText: '无人机机场 · ${DeviceV2Display.editionOf(sn)}',
modelText: AppLocalizations.of(context)
.translate('device_list_v2.drone_station_model')
.replaceAll(
'%s',
DeviceV2Display.editionOf(sn, AppLocalizations.of(context)),
),
snKey: sn,
status: s.isOnline ? DeviceV2Status.online : DeviceV2Status.offline,
battery: s.isOnline ? s.capacityPercent?.round() : null,
@@ -536,13 +554,18 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
),
)
else if (visible.isEmpty)
const SliverToBoxAdapter(
SliverToBoxAdapter(
child: Padding(
padding: EdgeInsets.all(40),
padding: const EdgeInsets.all(40),
child: Center(
child: Text(
'没有匹配的设备',
style: TextStyle(fontSize: 13, color: _v2Gray),
AppLocalizations.of(context).translate(
'device_list_v2.no_matching_device',
),
style: const TextStyle(
fontSize: 13,
color: _v2Gray,
),
),
),
),
@@ -591,25 +614,46 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
}
/// 卡片右上角「...」:进「设备归属与安全」页(仅机器人有归属关系;机场暂未开发)
void _v2ItemMore(BuildContext context, _V2DeviceItem item) {
Future<void> _v2ItemMore(BuildContext context, _V2DeviceItem item) async {
final robot = item.robot;
if (robot == null) {
CapsuleToast.show('功能暂未开发', showCheck: false);
CapsuleToast.show(
AppLocalizations.of(context).translate('device_list_v2.feature_todo'),
showCheck: false,
);
return;
}
Navigator.push(
// 归属页内完成解绑后会回传 true,此时卡片与统计卡都要重拉
// 当前选中场站一并传过去:设备就是从这个场站查出来的,
// 后端未下发设备归属时用于兜底展示真实场站与组织
final site = sl<SiteCubit>().state.selectedSite;
final unbound = await Navigator.push<bool>(
context,
MaterialPageRoute(
builder: (context) => RobotOwnershipPageV2(robot: robot),
builder: (context) => RobotOwnershipPageV2(
robot: robot,
siteId: site?.id,
siteName: site?.siteName,
orgId: site?.orgId,
),
),
);
if (unbound == true && context.mounted) {
context.read<RobotListBloc>().add(const RobotListRefresh());
context.read<DeviceListBloc.DeviceStatusBloc>().add(
const DeviceListEvent.DeviceStatusRefresh(),
);
}
}
/// 卡片铅笔图标:修改设备名称(弹窗只负责输入,下发走真实 updateDeviceAlias)
/// 卡片铅笔图标:只负责收集输入,下发交给 RenameDeviceCubit
Future<void> _v2ItemRename(BuildContext context, _V2DeviceItem item) async {
final robot = item.robot;
if (robot == null) {
CapsuleToast.show('功能暂未开发', showCheck: false);
CapsuleToast.show(
AppLocalizations.of(context).translate('device_list_v2.feature_todo'),
showCheck: false,
);
return;
}
final newName = await showRenameDeviceDialog(
@@ -621,33 +665,51 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
// 取消 / 名称未变(与旧页一致:不调接口直接返回)
if (newName == null || newName == item.name || !context.mounted) return;
final result = await sl<UpdateDevicenameUsecase>()(
UpdateDevicenameParams(robot.id, newName),
// 后端 updateDeviceAlias 的设备标识用设备编码(deviceName,MC700- 开头),
// 不是 getSiteList 返回的数字主键 robot.id;deviceName 异常为空时回退 id 兜底
final targetDeviceId = robot.name.isNotEmpty ? robot.name : robot.id;
debugPrint(
'>>> [V2-Rename] 下发 deviceId=$targetDeviceId alias=$newName (robot.id=${robot.id})',
);
if (!context.mounted) return;
result.fold(
(failure) => CapsuleToast.show(
failure.message.isEmpty ? '修改设备名称失败' : failure.message,
showCheck: false,
),
(code) {
if (code != 1) {
CapsuleToast.show('修改设备名称失败:状态码 $code', showCheck: false);
return;
}
CapsuleToast.show('设备名称已更新为「$newName」');
// 刷新卡片列表(别名优先展示,重拉后即可看到新名称)
context.read<RobotListBloc>().add(const RobotListRefresh());
context.read<DeviceListBloc.DeviceStatusBloc>().add(
const DeviceListEvent.DeviceStatusRefresh(),
);
},
context.read<RenameDeviceCubit>().rename(
deviceId: targetDeviceId,
alias: newName,
);
}
/// 改名结果回调:弹提示 + 重拉列表(deviceAlias 写入后卡片即显示新名称)
void _onRenameState(BuildContext context, RenameDeviceState state) {
// 提交中无 toast 需求
if (state.isSubmitting) return;
final l10n = AppLocalizations.of(context);
if (state.isSuccess) {
CapsuleToast.show(
l10n
.translate('device_list_v2.rename_success')
.replaceAll('%s', state.alias ?? ''),
);
// 卡片列表与统计卡是两套数据源,都要重拉
context.read<RobotListBloc>().add(const RobotListRefresh());
context.read<DeviceListBloc.DeviceStatusBloc>().add(
const DeviceListEvent.DeviceStatusRefresh(),
);
context.read<RenameDeviceCubit>().reset();
return;
}
final message = state.errorMessage;
if (message == null) return;
CapsuleToast.show(
message.isEmpty ? l10n.translate('device_list_v2.rename_failed') : message,
showCheck: false,
);
context.read<RenameDeviceCubit>().reset();
}
/// 卡片点击分发:与旧列表 onTap 逐行一致(机器人→hasHost 流程,机场→详情页)
void _v2ItemTap(BuildContext context, _V2DeviceItem item) {
Future<void> _v2ItemTap(BuildContext context, _V2DeviceItem item) async {
final robot = item.robot;
if (robot != null) {
debugPrint(
@@ -655,29 +717,31 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
);
debugPrint('🔴🔴🔴 [V2-选中机器人] hasHost: ${robot.hasHost}');
// 🔥 hasHost 字段判定:false → 蓝牙连接流程
if (!robot.hasHost) {
debugPrint('⚠️ [V2] hasHost=false,进入蓝牙连接流程');
// ===== 【暂时停用】hasHost 分层判定 =====
// 需求:暂时不管有无宿主,点卡片一律直接进设备详情页。
// 恢复方式:取消下面整段注释即可(原逻辑:hasHost=false → 蓝牙连接流程)
// if (!robot.hasHost) {
// debugPrint('⚠️ [V2] hasHost=false,进入蓝牙连接流程');
//
// // 从设备名中提取时间戳
// final timestamp = _extractTimestamp(robot.name);
// if (timestamp == null || timestamp.isEmpty) {
// debugPrint('❌ [V2] 未提取到时间戳');
// ScaffoldMessenger.of(context).showSnackBar(
// const SnackBar(
// content: Text('设备名称异常,暂时无法连接'),
// duration: Duration(seconds: 2),
// ),
// );
// return;
// }
//
// debugPrint('✅ [V2] 提取到时间戳: $timestamp');
// _connectToDeviceViaBluetooth(context, robot.name, timestamp);
// return;
// }
// 从设备名中提取时间戳
final timestamp = _extractTimestamp(robot.name);
if (timestamp == null || timestamp.isEmpty) {
debugPrint('❌ [V2] 未提取到时间戳');
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('设备名称异常,暂时无法连接'),
duration: Duration(seconds: 2),
),
);
return;
}
debugPrint('✅ [V2] 提取到时间戳: $timestamp');
_connectToDeviceViaBluetooth(context, robot.name, timestamp);
return;
}
// hasHost == true → 走原来的逻辑:前置(setTargetDevice)不变,
// 原 hasHost == true 分支(现在所有设备都走这里):前置(setTargetDevice)不变,
// 跳转目标换成新设备详情页(V2 概览设计稿);
// 页内铃铛/远程遥控再回旧 RobotControlPage,方便新旧对照。
debugPrint('✅ [V2] hasHost=true,走正常控制流程');
@@ -695,12 +759,19 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
final remoteCubit = GetIt.I<RemoteControlCubit>();
remoteCubit.setTargetDevice(device);
Navigator.push(
final renamed = await Navigator.push<bool>(
context,
MaterialPageRoute(
builder: (context) => DeviceDetailPageV2(robot: robot),
),
);
// 详情页改过名:卡片与统计卡都要重拉,否则列表还显示旧名字
if (renamed == true && context.mounted) {
context.read<RobotListBloc>().add(const RobotListRefresh());
context.read<DeviceListBloc.DeviceStatusBloc>().add(
const DeviceListEvent.DeviceStatusRefresh(),
);
}
return;
}
@@ -777,7 +848,10 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
}
void _v2Todo() {
CapsuleToast.show('功能暂未开发', showCheck: false);
CapsuleToast.show(
AppLocalizations.of(context).translate('device_list_v2.feature_todo'),
showCheck: false,
);
}
// ===== 切换场站入口:右上角按钮下方小字(场站名) =====
@@ -788,7 +862,10 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
return BlocBuilder<SiteCubit, SiteState>(
bloc: sl<SiteCubit>(),
builder: (context, siteState) {
final name = siteState.selectedSite?.siteName ?? '未选择场站';
final l10n = AppLocalizations.of(context);
final name =
siteState.selectedSite?.siteName ??
l10n.translate('device_list_v2.no_site_selected');
return Align(
alignment: Alignment.centerRight,
child: GestureDetector(
@@ -800,7 +877,13 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
mainAxisSize: MainAxisSize.min,
children: [
Text(
isPersonal ? '($name)· 个人账号' : '($name)',
isPersonal
? l10n
.translate('device_list_v2.site_suffix_personal')
.replaceAll('%s', name)
: l10n
.translate('device_list_v2.site_suffix')
.replaceAll('%s', name),
style: const TextStyle(fontSize: 12, color: _v2Gray),
),
if (!isPersonal)
@@ -823,12 +906,19 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
SiteState siteState,
bool isPersonal,
) {
final l10n = AppLocalizations.of(context);
if (isPersonal) {
CapsuleToast.show('个人账号仅绑定一个场站', showCheck: false);
CapsuleToast.show(
l10n.translate('device_list_v2.personal_single_site'),
showCheck: false,
);
return;
}
if (siteState.sites.isEmpty) {
CapsuleToast.show('暂无场站数据', showCheck: false);
CapsuleToast.show(
l10n.translate('device_list_v2.no_site_data'),
showCheck: false,
);
return;
}
final siteCubit = sl<SiteCubit>();
@@ -843,15 +933,19 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Padding(
padding: EdgeInsets.symmetric(vertical: 14),
child: Center(
child: Text(
'选择场站',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: _v2Navy,
Builder(
builder: (sheetCtx) => Padding(
padding: const EdgeInsets.symmetric(vertical: 14),
child: Center(
child: Text(
AppLocalizations.of(
sheetCtx,
).translate('device_list_v2.select_site'),
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: _v2Navy,
),
),
),
),
@@ -897,6 +991,7 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
// ===== 标题区 =====
Widget _buildV2Header() {
final l10n = AppLocalizations.of(context);
return Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 0),
// SizedBox 撑满宽:否则 Column 会收缩到文本宽并被外层 Column 居中,
@@ -905,19 +1000,19 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
children: [
Text(
'我的机器人',
style: TextStyle(
l10n.translate('device_list_v2.my_robots'),
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: _v2Navy,
),
),
SizedBox(height: 6),
const SizedBox(height: 6),
Text(
'多机型统一管理 · 按设备 SN 动态加载功能',
style: TextStyle(fontSize: 13, color: _v2Gray),
l10n.translate('device_list_v2.my_robots_desc'),
style: const TextStyle(fontSize: 13, color: _v2Gray),
),
],
),
@@ -928,6 +1023,7 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
// ===== 卡片视图 / 集中概览 切换(03 设计稿:浅蓝轨道 + 白色选中胶囊) =====
Widget _buildViewToggle() {
final isCard = _viewMode == 'card';
final l10n = AppLocalizations.of(context);
return Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 0),
child: Container(
@@ -941,7 +1037,7 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
children: [
Expanded(
child: _buildToggleSegment(
'卡片视图',
l10n.translate('device_list_v2.view_card'),
Icons.grid_view_rounded,
isCard,
() => setState(() => _viewMode = 'card'),
@@ -949,7 +1045,7 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
),
Expanded(
child: _buildToggleSegment(
'集中概览',
l10n.translate('device_list_v2.view_overview'),
Icons.bar_chart_rounded,
!isCard,
() => setState(() => _viewMode = 'overview'),
@@ -1018,14 +1114,19 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
borderRadius: BorderRadius.circular(14),
border: Border.all(color: _v2Border),
),
child: const Row(
child: Row(
children: [
SizedBox(width: 14),
Icon(Icons.search, size: 20, color: Color(0xFFC9CDD4)),
SizedBox(width: 10),
const SizedBox(width: 14),
const Icon(Icons.search, size: 20, color: Color(0xFFC9CDD4)),
const SizedBox(width: 10),
Text(
'搜索设备名称、型号或 SN',
style: TextStyle(fontSize: 14, color: Color(0xFFB9C2CF)),
AppLocalizations.of(
context,
).translate('device_list_v2.search_hint_full'),
style: const TextStyle(
fontSize: 14,
color: Color(0xFFB9C2CF),
),
),
],
),
@@ -1036,11 +1137,12 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
// ===== 状态过滤药丸:真实生效 =====
Widget _buildStatusPills(int all, int online, int working, int offline) {
final l10n = AppLocalizations.of(context);
final pills = [
('all', '全部', all),
('online', '在线', online),
('working', '作业中', working),
('offline', '离线', offline),
('all', l10n.translate('device_list_v2.all'), all),
('online', l10n.translate('device_list_v2.online'), online),
('working', l10n.translate('device_list_v2.stat_working'), working),
('offline', l10n.translate('device_list_v2.offline'), offline),
];
return Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 2),
@@ -1181,9 +1283,11 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
),
Expanded(
child: Text(
'设备集中概览',
AppLocalizations.of(
context,
).translate('device_list_v2.overview_title'),
textAlign: TextAlign.center,
style: TextStyle(
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: _v2Navy,
@@ -1197,25 +1301,26 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
}
Widget _buildOverviewHeader() {
final l10n = AppLocalizations.of(context);
return Padding(
padding: const EdgeInsets.fromLTRB(16, 4, 16, 0),
child: SizedBox(
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
children: [
Text(
'设备集中概览',
style: TextStyle(
l10n.translate('device_list_v2.overview_title'),
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: _v2Navy,
),
),
SizedBox(height: 6),
const SizedBox(height: 6),
Text(
'适合企业多机器人集中管理',
style: TextStyle(fontSize: 13, color: _v2Gray),
l10n.translate('device_list_v2.overview_desc'),
style: const TextStyle(fontSize: 13, color: _v2Gray),
),
],
),
@@ -1225,11 +1330,27 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
/// 四张统计卡:设备总数 / 在线设备 / 作业中 / 告警离线
Widget _buildStatCards(int all, int online, int working, int offline) {
final l10n = AppLocalizations.of(context);
final stats = [
(Icons.smart_toy_rounded, _v2Blue, all, '设备总数'),
(Icons.wifi_rounded, _v2Blue, online, '在线设备'),
(Icons.play_circle_fill_rounded, const Color(0xFF2FBF6B), working, '作业中'),
(Icons.warning_amber_rounded, const Color(0xFFE5484D), offline, '告警/离线'),
(Icons.smart_toy_rounded, _v2Blue, all, l10n.translate('device_list_v2.stat_total')),
(
Icons.wifi_rounded,
_v2Blue,
online,
l10n.translate('device_list_v2.stat_online_devices'),
),
(
Icons.play_circle_fill_rounded,
const Color(0xFF2FBF6B),
working,
l10n.translate('device_list_v2.stat_working'),
),
(
Icons.warning_amber_rounded,
const Color(0xFFE5484D),
offline,
l10n.translate('device_list_v2.stat_alarm_offline'),
),
];
return Row(
children: [
@@ -1285,9 +1406,11 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
padding: const EdgeInsets.fromLTRB(14, 12, 14, 10),
child: Row(
children: [
const Text(
'设备分布',
style: TextStyle(
Text(
AppLocalizations.of(
context,
).translate('device_list_v2.device_distribution'),
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
color: _v2Navy,
@@ -1300,7 +1423,11 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
child: Row(
children: [
Text(
'共 $all 台设备',
AppLocalizations.of(
context,
)
.translate('device_list_v2.total_devices_count')
.replaceAll('%s', '$all'),
style: const TextStyle(fontSize: 12, color: _v2Blue),
),
const Icon(Icons.chevron_right, size: 16, color: _v2Blue),
@@ -1331,48 +1458,58 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
),
child: Column(
children: [
const Padding(
padding: EdgeInsets.fromLTRB(14, 12, 14, 8),
Padding(
padding: const EdgeInsets.fromLTRB(14, 12, 14, 8),
child: Row(
children: [
Expanded(
flex: 5,
child: Text(
'设备信息',
style: TextStyle(fontSize: 12, color: _v2Gray),
AppLocalizations.of(
context,
).translate('device_list_v2.th_device_info'),
style: const TextStyle(fontSize: 12, color: _v2Gray),
),
),
Expanded(
flex: 3,
child: Text(
'状态',
style: TextStyle(fontSize: 12, color: _v2Gray),
AppLocalizations.of(
context,
).translate('device_list_v2.th_status'),
style: const TextStyle(fontSize: 12, color: _v2Gray),
),
),
Expanded(
flex: 2,
child: Text(
'电量',
style: TextStyle(fontSize: 12, color: _v2Gray),
AppLocalizations.of(
context,
).translate('device_list_v2.battery_level'),
style: const TextStyle(fontSize: 12, color: _v2Gray),
),
),
Expanded(
flex: 4,
child: Text(
'位置/当前任务',
style: TextStyle(fontSize: 12, color: _v2Gray),
AppLocalizations.of(
context,
).translate('device_list_v2.th_location_task'),
style: const TextStyle(fontSize: 12, color: _v2Gray),
),
),
SizedBox(width: 16),
const SizedBox(width: 16),
],
),
),
if (visible.isEmpty)
const Padding(
padding: EdgeInsets.all(32),
Padding(
padding: const EdgeInsets.all(32),
child: Text(
'没有匹配的设备',
style: TextStyle(fontSize: 13, color: _v2Gray),
AppLocalizations.of(
context,
).translate('device_list_v2.no_matching_device'),
style: const TextStyle(fontSize: 13, color: _v2Gray),
),
)
else
@@ -1417,7 +1554,8 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
),
const SizedBox(height: 2),
Text(
'${DeviceV2Display.versionOf(e.snKey)} SN: ${DeviceV2Display.maskedSn(e.snKey)}',
// 概览表第二行:型号 · 版本 + SN
'${e.modelText} SN: ${DeviceV2Display.maskedSn(e.snKey)}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 10, color: _v2Gray),
@@ -1444,8 +1582,11 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
flex: 4,
child: Text(
e.robot != null
? '${DeviceV2Display.locationOf(e.snKey)} · ${e.robot!.task}'
: DeviceV2Display.locationOf(e.snKey),
? '${DeviceV2Display.locationOf(e.snKey, AppLocalizations.of(context))} · ${e.robot!.task}'
: DeviceV2Display.locationOf(
e.snKey,
AppLocalizations.of(context),
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 11, color: _v2Gray),
@@ -1459,21 +1600,22 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
}
Widget _buildOverviewBadge(DeviceV2Status status) {
final l10n = AppLocalizations.of(context);
final (label, fg, bg, icon) = switch (status) {
DeviceV2Status.working => (
'作业中',
l10n.translate('device_list_v2.stat_working'),
const Color(0xFF2FBF6B),
const Color(0xFFE5F8EC),
Icons.play_arrow_rounded,
),
DeviceV2Status.online => (
'在线',
l10n.translate('device_list_v2.online'),
_v2Blue,
const Color(0xFFE7F3FE),
Icons.wifi_rounded,
),
DeviceV2Status.offline => (
'离线',
l10n.translate('device_list_v2.offline'),
const Color(0xFF6B7280),
const Color(0xFFF0F2F5),
Icons.pause_rounded,
@@ -1548,11 +1690,13 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
padding: const EdgeInsets.fromLTRB(16, 14, 8, 4),
child: Row(
children: [
const Expanded(
Expanded(
child: Center(
child: Text(
'添加机器人',
style: TextStyle(
AppLocalizations.of(
sheetCtx,
).translate('device_list_v2.add_robot'),
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: _v2Navy,
@@ -1569,7 +1713,9 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
),
_v2SheetItem(
icon: Icons.qr_code_scanner,
label: '扫一扫',
label: AppLocalizations.of(
sheetCtx,
).translate('device_list_v2.scan_action'),
onTap: () async {
Navigator.pop(sheetCtx);
final result = await Navigator.of(context).push<String>(
@@ -1594,7 +1740,9 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
const Divider(height: 1, indent: 20, color: Color(0xFFF0F4FA)),
_v2SheetItem(
icon: Icons.add_circle_outline,
label: '添加设备',
label: AppLocalizations.of(
sheetCtx,
).translate('device_list_v2.add_device'),
onTap: () {
Navigator.pop(sheetCtx);
// 原菜单该项即为 TODO,保持不跳转
@@ -1604,7 +1752,9 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
const Divider(height: 1, indent: 20, color: Color(0xFFF0F4FA)),
_v2SheetItem(
icon: Icons.videocam_outlined,
label: '本地视频',
label: AppLocalizations.of(
sheetCtx,
).translate('device_list_v2.local_video'),
onTap: () {
Navigator.pop(sheetCtx);
Navigator.of(context).push(
@@ -1615,7 +1765,9 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
const Divider(height: 1, indent: 20, color: Color(0xFFF0F4FA)),
_v2SheetItem(
icon: Icons.usb,
label: 'USB 摄像头',
label: AppLocalizations.of(
sheetCtx,
).translate('device_list_v2.usb_camera'),
onTap: () {
Navigator.pop(sheetCtx);
Navigator.of(context).push(
@@ -2168,6 +2320,7 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
id: robot.id,
alias: robot.alias,
type: robot.type,
modelText: robot.modelLabelOf(AppLocalizations.of(context)),
status: robot.status,
battery: robot.battery,
task: robot.task,
@@ -2177,39 +2330,41 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
);
debugPrint('🔴🔴🔴 [全部-选中机器人] hasHost: ${robot.hasHost}');
// 🔥 hasHost 字段判定:false → 蓝牙连接流程
if (!robot.hasHost) {
debugPrint(
'⚠️ [全部-EmbeddedRobotList] hasHost=false,进入蓝牙连接流程',
);
// ===== 【暂时停用】hasHost 分层判定 =====
// 需求:暂时不管有无宿主,点卡片一律直接进设备详情页。
// 恢复方式:取消下面整段注释即可(原逻辑:hasHost=false → 蓝牙连接流程)
// if (!robot.hasHost) {
// debugPrint(
// '⚠️ [全部-EmbeddedRobotList] hasHost=false,进入蓝牙连接流程',
// );
//
// // 从设备名中提取时间戳(如 MC700PRO-CN-JS-1751525588120-0000000A-9527 → 1751525588120)
// final timestamp = _extractTimestamp(robot.name);
// if (timestamp == null || timestamp.isEmpty) {
// debugPrint('❌ [全部-EmbeddedRobotList] 未提取到时间戳');
// ScaffoldMessenger.of(context).showSnackBar(
// const SnackBar(
// content: Text('设备名称异常,暂时无法连接'),
// duration: Duration(seconds: 2),
// ),
// );
// return;
// }
//
// debugPrint(
// '✅ [全部-EmbeddedRobotList] 提取到时间戳: $timestamp',
// );
//
// // 调用蓝牙连接流程
// _connectToDeviceViaBluetooth(
// context,
// robot.name,
// timestamp,
// );
// return;
// }
// 从设备名中提取时间戳(如 MC700PRO-CN-JS-1751525588120-0000000A-9527 → 1751525588120)
final timestamp = _extractTimestamp(robot.name);
if (timestamp == null || timestamp.isEmpty) {
debugPrint('❌ [全部-EmbeddedRobotList] 未提取到时间戳');
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('设备名称异常,暂时无法连接'),
duration: Duration(seconds: 2),
),
);
return;
}
debugPrint(
'✅ [全部-EmbeddedRobotList] 提取到时间戳: $timestamp',
);
// 调用蓝牙连接流程
_connectToDeviceViaBluetooth(
context,
robot.name,
timestamp,
);
return;
}
// hasHost == true → 走原来的逻辑:前置(setTargetDevice)不变,
// 原 hasHost == true 分支(现在所有设备都走这里):前置(setTargetDevice)不变,
// 跳转目标换成新设备详情页(V2 概览设计稿);
// 页内铃铛/远程遥控再回旧 RobotControlPage,方便新旧对照。
debugPrint(
@@ -2531,7 +2686,9 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
_buildMenuOption(
ctx,
icon: Icons.qr_code_scanner,
label: '扫一扫',
label: AppLocalizations.of(
ctx,
).translate('device_list_v2.scan_action'),
onTap: () async {
Navigator.pop(ctx);
final result = await Navigator.of(context).push<String>(
@@ -2553,7 +2710,9 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
_buildMenuOption(
ctx,
icon: Icons.add_circle_outline,
label: '添加设备',
label: AppLocalizations.of(
ctx,
).translate('device_list_v2.add_device'),
onTap: () {
Navigator.pop(ctx);
// TODO: 添加设备功能
@@ -2563,7 +2722,9 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
_buildMenuOption(
ctx,
icon: Icons.videocam_outlined,
label: '本地视频',
label: AppLocalizations.of(
ctx,
).translate('device_list_v2.local_video'),
onTap: () {
Navigator.pop(ctx);
Navigator.of(context).push(
@@ -2577,7 +2738,9 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
_buildMenuOption(
ctx,
icon: Icons.usb,
label: 'USB 摄像头',
label: AppLocalizations.of(
ctx,
).translate('device_list_v2.usb_camera'),
onTap: () {
Navigator.pop(ctx);
Navigator.of(context).push(
@@ -2766,16 +2929,29 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
);
} else {
debugPrint('⚠️ 未找到匹配的机场,请从无人机机场标签页进入');
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text('请从"无人机机场"标签页查看详情')));
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
AppLocalizations.of(
context,
).translate('device_list_v2.view_details_from_tab'),
),
),
);
}
} else {
// 其他设备类型,显示提示
debugPrint('⚠️ [DeviceStatusPage] 未知设备类型: $deviceType');
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('该设备类型暂不支持查看详情: $deviceType'),
content: Text(
AppLocalizations.of(
context,
).translate('device_list_v2.device_type_not_supported').replaceAll(
'%s',
deviceType,
),
),
duration: const Duration(seconds: 2),
),
);
@@ -2821,9 +2997,13 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
final isBluetoothOn = await bleManager.checkBluetooth();
if (!isBluetoothOn) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('请先打开手机蓝牙'),
duration: Duration(seconds: 2),
SnackBar(
content: Text(
AppLocalizations.of(
context,
).translate('device_list_v2.open_bluetooth_first'),
),
duration: const Duration(seconds: 2),
),
);
return;
@@ -2833,13 +3013,18 @@ class _DeviceStatusViewV2State extends State<DeviceStatusViewV2> {
showDialog(
context: context,
barrierDismissible: false,
builder: (_) => const Center(
builder: (_) => Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
CircularProgressIndicator(),
SizedBox(height: 16),
Text('正在搜索蓝牙设备...', style: TextStyle(color: Colors.white)),
const CircularProgressIndicator(),
const SizedBox(height: 16),
Text(
AppLocalizations.of(
context,
).translate('device_list_v2.searching_bluetooth'),
style: const TextStyle(color: Colors.white),
),
],
),
),

View File

@@ -19,6 +19,7 @@ import '../../domain/entities/drone_station_entity.dart';
import '../bloc/drone_station_bloc.dart';
import '../bloc/drone_station_event.dart';
import '../bloc/drone_station_state.dart';
import 'package:maibu_satabot_v2/features/home/presentation/widgets/map/app_base_map_layer.dart';
/// 无人机视频回传/远程控制页面
class DroneVideoControlPage extends StatefulWidget {
@@ -1293,14 +1294,8 @@ class _DroneVideoControlPageState extends State<DroneVideoControlPage> {
),
),
children: [
// ESRI World Imagery(WGS84 坐标系,全球高清卫星图)
// 替代高德地图(GCJ02),统一坐标系,无需坐标转换
TileLayer(
urlTemplate: 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
userAgentPackageName: 'com.example.app',
minZoom: 0,
maxZoom: 19,
),
// 底图:中文=ESRI,非中文=Google(不可达自动回退 ESRI)
const AppBaseMapLayer(),
// 🔥 轨迹线(中间层)
if (_trajectoryPoints.length >= 1)
@@ -1567,14 +1562,8 @@ class _DroneVideoControlPageState extends State<DroneVideoControlPage> {
),
),
children: [
// ESRI World Imagery(WGS84 坐标系,全球高清卫星图)
// 替代高德地图(GCJ02),统一坐标系,无需坐标转换
TileLayer(
urlTemplate: 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
userAgentPackageName: 'com.example.app',
minZoom: 0,
maxZoom: 19,
),
// 底图:中文=ESRI,非中文=Google(不可达自动回退 ESRI)
const AppBaseMapLayer(),
// 🔥 轨迹线(中间层)
if (_trajectoryPoints.length >= 1)

View File

@@ -3,6 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get_it/get_it.dart';
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
import 'package:maibu_satabot_v2/features/main_container/domain/tab_config.dart';
import 'package:maibu_satabot_v2/features/v2/local_camera/presentation/pages/local_camera_page.dart';
import 'package:maibu_satabot_v2/features/v2/site/presentation/cubit/site_cubit.dart';
@@ -40,12 +41,16 @@ class NoDevicePageV2 extends StatelessWidget {
stops: [0.0, 0.5, 1.0],
);
static void _todoTap() {
CapsuleToast.show('功能暂未开发', showCheck: false);
void _todoTap(BuildContext context) {
CapsuleToast.show(
AppLocalizations.of(context).translate('device_list_v2.feature_todo'),
showCheck: false,
);
}
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
return Scaffold(
backgroundColor: _bgTop,
body: Stack(
@@ -72,10 +77,10 @@ class NoDevicePageV2 extends StatelessWidget {
const SizedBox(height: 18),
_buildHeroCard(context),
const SizedBox(height: 26),
const Center(
Center(
child: Text(
'还没有添加机器人',
style: TextStyle(
l10n.translate('device_list_v2.no_device_title'),
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: _navy,
@@ -83,11 +88,11 @@ class NoDevicePageV2 extends StatelessWidget {
),
),
const SizedBox(height: 10),
const Center(
Center(
child: Text(
'您可以先了解 APP 的功能,\n收到机器人后随时绑定使用。',
l10n.translate('device_list_v2.no_device_desc'),
textAlign: TextAlign.center,
style: TextStyle(
style: const TextStyle(
fontSize: 13,
color: _grayText,
height: 1.6,
@@ -97,9 +102,9 @@ class NoDevicePageV2 extends StatelessWidget {
const SizedBox(height: 20),
_buildAddButton(context),
const SizedBox(height: 30),
const Text(
'新手入门',
style: TextStyle(
Text(
l10n.translate('device_list_v2.guide_title'),
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: _navy,
@@ -107,21 +112,24 @@ class NoDevicePageV2 extends StatelessWidget {
),
const SizedBox(height: 12),
_buildGuideCard(
context: context,
icon: Icons.list_alt,
title: '产品操作指南',
subtitle: '了解机器人基础功能和使用流程',
title: l10n.translate('device_list_v2.guide1_title'),
subtitle: l10n.translate('device_list_v2.guide1_desc'),
),
const SizedBox(height: 10),
_buildGuideCard(
context: context,
icon: Icons.videocam_outlined,
title: '观看产品视频',
subtitle: '快速上手遥控、图传及作业功能',
title: l10n.translate('device_list_v2.guide2_title'),
subtitle: l10n.translate('device_list_v2.guide2_desc'),
),
const SizedBox(height: 10),
_buildGuideCard(
context: context,
icon: Icons.help_outline,
title: '帮助与售后服务',
subtitle: '常见问题、报修及客服支持',
title: l10n.translate('device_list_v2.guide3_title'),
subtitle: l10n.translate('device_list_v2.guide3_desc'),
),
const SizedBox(height: 24),
],
@@ -145,7 +153,10 @@ class NoDevicePageV2 extends StatelessWidget {
),
Row(
children: [
_buildTopIconButton(Icons.notifications_none, onTap: _todoTap),
_buildTopIconButton(
Icons.notifications_none,
onTap: () => _todoTap(context),
),
const SizedBox(width: 10),
// 设计稿:右上角 ⊕ 是蓝底白号主色按钮,与铃铛的白底按钮区分
_buildTopIconButton(
@@ -201,7 +212,10 @@ class NoDevicePageV2 extends StatelessWidget {
return BlocBuilder<SiteCubit, SiteState>(
bloc: GetIt.I<SiteCubit>(),
builder: (context, siteState) {
final name = siteState.selectedSite?.siteName ?? '未选择场站';
final l10n = AppLocalizations.of(context);
final name =
siteState.selectedSite?.siteName ??
l10n.translate('device_list_v2.no_site_selected');
return Align(
alignment: Alignment.centerRight,
child: GestureDetector(
@@ -213,7 +227,13 @@ class NoDevicePageV2 extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
children: [
Text(
isPersonal ? '($name)· 个人账号' : '($name)',
isPersonal
? l10n
.translate('device_list_v2.site_suffix_personal')
.replaceAll('%s', name)
: l10n
.translate('device_list_v2.site_suffix')
.replaceAll('%s', name),
style: const TextStyle(fontSize: 12, color: _grayText),
),
if (!isPersonal)
@@ -232,12 +252,19 @@ class NoDevicePageV2 extends StatelessWidget {
}
void _onSiteTap(BuildContext context, SiteState siteState, bool isPersonal) {
final l10n = AppLocalizations.of(context);
if (isPersonal) {
CapsuleToast.show('个人账号仅绑定一个场站', showCheck: false);
CapsuleToast.show(
l10n.translate('device_list_v2.personal_single_site'),
showCheck: false,
);
return;
}
if (siteState.sites.isEmpty) {
CapsuleToast.show('暂无场站数据', showCheck: false);
CapsuleToast.show(
l10n.translate('device_list_v2.no_site_data'),
showCheck: false,
);
return;
}
final siteCubit = GetIt.I<SiteCubit>();
@@ -252,12 +279,12 @@ class NoDevicePageV2 extends StatelessWidget {
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Padding(
padding: EdgeInsets.symmetric(vertical: 14),
Padding(
padding: const EdgeInsets.symmetric(vertical: 14),
child: Center(
child: Text(
'选择场站',
style: TextStyle(
l10n.translate('device_list_v2.select_site'),
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: _navy,
@@ -374,14 +401,16 @@ class NoDevicePageV2 extends StatelessWidget {
),
],
),
child: const Row(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.add, color: Colors.white, size: 20),
SizedBox(width: 8),
const Icon(Icons.add, color: Colors.white, size: 20),
const SizedBox(width: 8),
Text(
'添加机器人',
style: TextStyle(
AppLocalizations.of(
context,
).translate('device_list_v2.add_robot'),
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.white,
@@ -410,11 +439,13 @@ class NoDevicePageV2 extends StatelessWidget {
padding: const EdgeInsets.fromLTRB(16, 14, 8, 4),
child: Row(
children: [
const Expanded(
Expanded(
child: Center(
child: Text(
'添加机器人',
style: TextStyle(
AppLocalizations.of(
sheetCtx,
).translate('device_list_v2.add_robot'),
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: _navy,
@@ -435,7 +466,9 @@ class NoDevicePageV2 extends StatelessWidget {
),
_sheetItem(
icon: Icons.qr_code_scanner,
label: '扫一扫',
label: AppLocalizations.of(
sheetCtx,
).translate('device_list_v2.scan_action'),
onTap: () async {
Navigator.pop(sheetCtx);
final result = await Navigator.of(context).push<String>(
@@ -459,17 +492,21 @@ class NoDevicePageV2 extends StatelessWidget {
_sheetDivider(),
_sheetItem(
icon: Icons.add_circle_outline,
label: '添加设备',
label: AppLocalizations.of(
sheetCtx,
).translate('device_list_v2.add_device'),
onTap: () {
Navigator.pop(sheetCtx);
// 原菜单该项即为 TODO,保持不跳转
_todoTap();
_todoTap(context);
},
),
_sheetDivider(),
_sheetItem(
icon: Icons.videocam_outlined,
label: '本地视频',
label: AppLocalizations.of(
sheetCtx,
).translate('device_list_v2.local_video'),
onTap: () {
Navigator.pop(sheetCtx);
Navigator.of(context).push(
@@ -480,7 +517,9 @@ class NoDevicePageV2 extends StatelessWidget {
_sheetDivider(),
_sheetItem(
icon: Icons.usb,
label: 'USB 摄像头',
label: AppLocalizations.of(
sheetCtx,
).translate('device_list_v2.usb_camera'),
onTap: () {
Navigator.pop(sheetCtx);
Navigator.of(context).push(
@@ -525,12 +564,13 @@ class NoDevicePageV2 extends StatelessWidget {
// ===== 新手入门卡片:二级未开发,统一提示 =====
Widget _buildGuideCard({
required BuildContext context,
required IconData icon,
required String title,
required String subtitle,
}) {
return GestureDetector(
onTap: _todoTap,
onTap: () => _todoTap(context),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
decoration: BoxDecoration(

View File

@@ -1,14 +1,20 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get_it/get_it.dart';
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
import '../../data/models/robot_data_model.dart';
import '../cubit/find_robot_cubit.dart';
import '../cubit/find_robot_state.dart';
import 'robot_summary_card_v2.dart';
/// 一键寻车底部弹窗(设计稿:设备控制 → 一键寻车)
///
/// 多处复用:全部功能中心、设备详情页、控制页都可以直接调用。
/// 寻车指令下发通道尚未接入,未注入回调时统一给出明确提示,不假装成功。
/// 启动寻车已接入真实接口(GET /iot/host/searchDevice,deviceId=设备编码),
/// 走 FindRobotCubit → UseCase → Repository → DataSource;停止/地图入口仍为占位。
Future<void> showFindRobotSheet(
BuildContext context, {
required RobotDataModel robot,
@@ -22,12 +28,15 @@ Future<void> showFindRobotSheet(
backgroundColor: Colors.transparent,
isScrollControlled: true,
barrierColor: const Color(0x8C0B1B2B),
builder: (_) => _FindRobotSheet(
robot: robot,
gnssValid: gnssValid ?? robot.isOnline,
onOpenMap: onOpenMap,
onStartFind: onStartFind,
onStopFind: onStopFind,
builder: (_) => BlocProvider(
create: (_) => GetIt.I<FindRobotCubit>(),
child: _FindRobotSheet(
robot: robot,
gnssValid: gnssValid ?? robot.isOnline,
onOpenMap: onOpenMap,
onStartFind: onStartFind,
onStopFind: onStopFind,
),
),
);
}
@@ -61,39 +70,81 @@ class _FindRobotSheet extends StatelessWidget {
bool get _online => robot.isOnline;
void _handleStart(BuildContext context) {
final l10n = AppLocalizations.of(context);
if (!_online) {
CapsuleToast.show('设备离线,无法触发声光寻车', showCheck: false);
CapsuleToast.show(
l10n.translate('device_list_v2.fr_toast_offline'),
showCheck: false,
);
return;
}
// 外部显式注入回调时优先使用(保留自定义下发通道的能力)
if (onStartFind != null) {
onStartFind!();
return;
}
CapsuleToast.show('声光寻车指令下发未接入', showCheck: false);
// 一键寻车:deviceId 传设备编码(deviceName,MC700- 开头),
// 不是 getSiteList 的数字主键 robot.id;deviceName 异常为空时回退 id 兜底。
final deviceCode = robot.name.isNotEmpty ? robot.name : robot.id;
context.read<FindRobotCubit>().startFind(deviceCode: deviceCode);
}
void _handleStop() {
if (onStopFind != null) {
onStopFind!();
/// 寻车下发结果:成功/失败均弹提示并复位,避免重复触发
void _handleFindState(BuildContext context, FindRobotState state) {
if (state.isSubmitting) return;
final l10n = AppLocalizations.of(context);
final cubit = context.read<FindRobotCubit>();
if (state.isSuccess) {
CapsuleToast.show(l10n.translate('device_list_v2.fr_toast_start_sent'));
cubit.reset();
return;
}
CapsuleToast.show('停止寻车指令下发未接入', showCheck: false);
final message = state.errorMessage;
if (message == null) return;
CapsuleToast.show(
message.isEmpty
? l10n.translate('device_list_v2.fr_toast_start_failed')
: message,
showCheck: false,
);
cubit.reset();
}
// 一键寻车为一次性下发,无「停止」语义,停止按钮已按需求注释掉(方法一并保留注释备恢复)。
// void _handleStop(BuildContext context) {
// if (onStopFind != null) {
// onStopFind!();
// return;
// }
// CapsuleToast.show(
// AppLocalizations.of(context).translate('device_list_v2.fr_toast_stop_todo'),
// showCheck: false,
// );
// }
void _handleOpenMap(BuildContext context) {
if (onOpenMap != null) {
onOpenMap!();
return;
}
CapsuleToast.show('地图定位入口暂未接入', showCheck: false);
CapsuleToast.show(
AppLocalizations.of(context).translate('device_list_v2.fr_toast_map_todo'),
showCheck: false,
);
}
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
final model = RobotSummaryCardV2.modelOf(robot);
return SafeArea(
top: false,
child: Container(
return BlocListener<FindRobotCubit, FindRobotState>(
listener: _handleFindState,
child: SafeArea(
top: false,
child: Container(
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
@@ -107,10 +158,10 @@ class _FindRobotSheet extends StatelessWidget {
// 标题行
Row(
children: [
const Expanded(
Expanded(
child: Text(
'一键寻车',
style: TextStyle(
l10n.translate('device_list_v2.fr_title'),
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.w800,
color: _navy,
@@ -163,7 +214,7 @@ class _FindRobotSheet extends StatelessWidget {
),
const SizedBox(height: 5),
Text(
'${gnssValid ? 'GNSS定位有效' : 'GNSS定位无效'} · $model 标准版',
'${gnssValid ? l10n.translate('device_list_v2.fr_gnss_valid') : l10n.translate('device_list_v2.fr_gnss_invalid')} · ${l10n.translate('device_list_v2.fr_model_std').replaceAll('%s', model)}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 12, color: _gray),
@@ -181,7 +232,9 @@ class _FindRobotSheet extends StatelessWidget {
borderRadius: BorderRadius.circular(9),
),
child: Text(
_online ? '在线' : '离线',
_online
? l10n.translate('device_list_v2.online')
: l10n.translate('device_list_v2.offline'),
style: TextStyle(
fontSize: 10.5,
fontWeight: FontWeight.w600,
@@ -219,22 +272,25 @@ class _FindRobotSheet extends StatelessWidget {
),
),
const SizedBox(width: 12),
const Expanded(
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'在地图中查看机器人',
style: TextStyle(
l10n.translate('device_list_v2.fr_map_entry'),
style: const TextStyle(
fontSize: 14.5,
fontWeight: FontWeight.w800,
color: _navy,
),
),
SizedBox(height: 4),
const SizedBox(height: 4),
Text(
'定位位置与最后更新时间',
style: TextStyle(fontSize: 12, color: _gray),
l10n.translate('device_list_v2.fr_map_entry_sub'),
style: const TextStyle(
fontSize: 12,
color: _gray,
),
),
],
),
@@ -260,25 +316,32 @@ class _FindRobotSheet extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'声光寻车',
style: TextStyle(
Text(
l10n.translate('device_list_v2.fr_sound_title'),
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w800,
color: _navy,
),
),
const SizedBox(height: 8),
const Text(
'触发蜂鸣与指示灯,帮助现场人员找到设备;默认自动停止。',
style: TextStyle(fontSize: 12, height: 1.5, color: _gray),
Text(
l10n.translate('device_list_v2.fr_sound_desc'),
style: const TextStyle(
fontSize: 12,
height: 1.5,
color: _gray,
),
),
const SizedBox(height: 12),
Row(
children: [
const Text(
'自动结束',
style: TextStyle(fontSize: 12.5, color: _gray),
Text(
l10n.translate('device_list_v2.fr_auto_stop'),
style: const TextStyle(
fontSize: 12.5,
color: _gray,
),
),
const Spacer(),
Container(
@@ -290,9 +353,9 @@ class _FindRobotSheet extends StatelessWidget {
color: _softBlue,
borderRadius: BorderRadius.circular(10),
),
child: const Text(
'10秒(示例)',
style: TextStyle(
child: Text(
l10n.translate('device_list_v2.fr_auto_stop_value'),
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w700,
color: _blue,
@@ -324,18 +387,18 @@ class _FindRobotSheet extends StatelessWidget {
]
: null,
),
child: const Row(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
const Icon(
Icons.volume_up_rounded,
size: 19,
color: Colors.white,
),
SizedBox(width: 8),
const SizedBox(width: 8),
Text(
'启动寻车提示',
style: TextStyle(
l10n.translate('device_list_v2.fr_start'),
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w700,
color: Colors.white,
@@ -345,38 +408,43 @@ class _FindRobotSheet extends StatelessWidget {
),
),
),
const SizedBox(height: 10),
// 停止寻车
GestureDetector(
onTap: _handleStop,
behavior: HitTestBehavior.opaque,
child: Container(
height: 48,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
border: Border.all(color: _blue, width: 1.2),
),
child: const Text(
'停止寻车',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w700,
color: _blue,
),
),
),
),
// 停止寻车:一次性下发无停止语义,按需求注释掉该按钮。
// const SizedBox(height: 10),
// GestureDetector(
// onTap: () => _handleStop(context),
// behavior: HitTestBehavior.opaque,
// child: Container(
// height: 48,
// alignment: Alignment.center,
// decoration: BoxDecoration(
// color: Colors.white,
// borderRadius: BorderRadius.circular(12),
// border: Border.all(color: _blue, width: 1.2),
// ),
// child: Text(
// l10n.translate('device_list_v2.fr_stop'),
// style: const TextStyle(
// fontSize: 15,
// fontWeight: FontWeight.w700,
// color: _blue,
// ),
// ),
// ),
// ),
const SizedBox(height: 12),
const Text(
'设备离线时不可触发声光寻车,只能查看最后已知位置。',
style: TextStyle(fontSize: 11.5, height: 1.5, color: _hint),
Text(
l10n.translate('device_list_v2.fr_note'),
style: const TextStyle(
fontSize: 11.5,
height: 1.5,
color: _hint,
),
),
],
),
),
),
),
);
}
}