蓝牙绑定设备+场站切换支持高清图层的一对一显示+设备实时状态的部分显示
This commit is contained in:
@@ -338,7 +338,7 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => BindDevicePage(scanResult: matchedDevice!.deviceId),
|
||||
builder: (_) => BindDevicePage(scanResult: matchedDevice!.name),
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
|
||||
@@ -125,6 +125,26 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
/// 🔥 机器人类型中文名关键字(接口 deviceTypeName 可能是纯中文)
|
||||
static const _robotTypeKeywords = ['除草', '巡检', '清洗', '割草', '机器人'];
|
||||
|
||||
/// 🔥 类型 tab 的 code → 别名集合。
|
||||
/// 筛选条用英文 code(inverter),但接口 deviceTypeName 可能返回中文名(逆变器),
|
||||
/// 只做 `device.type == code` 的精确比较会让这四个 tab 恒为空,所以两套写法都认。
|
||||
static const Map<String, Set<String>> _typeAliases = {
|
||||
'inverter': {'inverter', '逆变器'},
|
||||
'combiner_box': {'combiner_box', '汇流箱'},
|
||||
'module': {'module', '组件'},
|
||||
'monitor': {'monitor', '监控'},
|
||||
};
|
||||
|
||||
/// 设备类型是否命中当前 tab(大小写与首尾空格不敏感)
|
||||
static bool _matchTypeTab(String deviceType, String selectedType) {
|
||||
final normalized = deviceType.trim().toLowerCase();
|
||||
final aliases = _typeAliases[selectedType];
|
||||
if (aliases != null) {
|
||||
return aliases.any((alias) => alias.toLowerCase() == normalized);
|
||||
}
|
||||
return normalized == selectedType.toLowerCase();
|
||||
}
|
||||
|
||||
/// 🔥 通用判断:是否机器人(型号前缀 + 中文关键字双重匹配,新型号也能自动识别)
|
||||
static bool _isRobotDevice(String type, String name, String deviceId) {
|
||||
final haystacks = [
|
||||
@@ -506,24 +526,15 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
List filteredByType = state.devices;
|
||||
if (state.selectedType != 'all') {
|
||||
filteredByType = state.devices.where((device) {
|
||||
return device.type == state.selectedType;
|
||||
return _matchTypeTab(device.type, state.selectedType);
|
||||
}).toList();
|
||||
} else {
|
||||
// 🔥 "全部"模式下,排除已由专用组件渲染的类型,避免重复展示
|
||||
// drone_station 已通过 _buildDroneStationList 渲染
|
||||
// 机器人通过下面的 _isRobotDevice 通用匹配识别,已由 _buildEmbeddedRobotList 渲染
|
||||
filteredByType = state.devices.where((device) {
|
||||
if (device.type == 'drone_station') return false;
|
||||
final isRobot = _isRobotDevice(
|
||||
device.type,
|
||||
device.name,
|
||||
device.deviceId,
|
||||
);
|
||||
debugPrint(
|
||||
'🔍 [全部-过滤] deviceId=${device.deviceId} type=${device.type} name=${device.name} → isRobot=$isRobot ${isRobot ? '✅排除' : ''}',
|
||||
);
|
||||
return !isRobot;
|
||||
}).toList();
|
||||
// 🔥 "全部"模式下不渲染通用设备段:
|
||||
// 机器人段(RobotListBloc → /iot/device/getSiteList)零过滤,已渲染该接口全量设备,
|
||||
// 通用段数据源是同一个接口,恒为机器人段的子集 → 必然重复渲染。
|
||||
// 原先靠 _isRobotDevice 字符串猜测来排除,后端 deviceTypeName 缺失时判据即失效。
|
||||
// 类型 tab(逆变器/汇流箱/组件/监控)走上面的 if 分支,不受影响。
|
||||
filteredByType = const [];
|
||||
}
|
||||
|
||||
// 🔥 再根据搜索关键词过滤
|
||||
@@ -550,11 +561,21 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
_buildStatusCard(context, state),
|
||||
const SizedBox(height: 20.0),
|
||||
// 🔥 机器人列表(直接复用 RobotListPage 的布局)
|
||||
if (state.selectedType == 'all') _buildEmbeddedRobotList(context),
|
||||
// 🔥 无人机机场列表(直接复用 _buildDroneStationList 的布局)
|
||||
// 传入搜索关键词:通用段移除后,"全部"模式的搜索由机器人段承接
|
||||
if (state.selectedType == 'all')
|
||||
_buildDroneStationList(context, embedded: true),
|
||||
// 🔥 普通设备列表
|
||||
_buildEmbeddedRobotList(
|
||||
context,
|
||||
searchKeyword: state.searchKeyword,
|
||||
),
|
||||
// 🔥 无人机机场列表(直接复用 _buildDroneStationList 的布局)
|
||||
// 传 key:电站切换时强制重建 BlocProvider,否则不会用新 siteId 重新加载
|
||||
if (state.selectedType == 'all')
|
||||
_buildDroneStationList(
|
||||
context,
|
||||
embedded: true,
|
||||
key: ValueKey('embedded_drone_station_$_currentSiteId'),
|
||||
),
|
||||
// 🔥 普通设备列表(仅类型 tab 生效,"全部"模式下 filteredByType 为空)
|
||||
...filteredDevices
|
||||
.map(
|
||||
(device) => DeviceItemWidget(
|
||||
@@ -576,7 +597,10 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
}
|
||||
|
||||
/// 🔥 嵌入式机器人列表(直接复用 RobotListPage 的布局)
|
||||
Widget _buildEmbeddedRobotList(BuildContext context) {
|
||||
Widget _buildEmbeddedRobotList(
|
||||
BuildContext context, {
|
||||
String searchKeyword = '',
|
||||
}) {
|
||||
final selectedSite = sl<SiteCubit>().state.selectedSite;
|
||||
final siteId = selectedSite?.id;
|
||||
|
||||
@@ -619,11 +643,25 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
'✅ [EmbeddedRobotList] 加载成功,机器人数量: ${state.robots.length}',
|
||||
);
|
||||
|
||||
// 🔥 搜索联动:按 设备名 / deviceId / 别名 过滤
|
||||
final keyword = searchKeyword.trim().toLowerCase();
|
||||
final robots = keyword.isEmpty
|
||||
? state.robots
|
||||
: state.robots.where((robot) {
|
||||
return robot.name.toLowerCase().contains(keyword) ||
|
||||
robot.id.toLowerCase().contains(keyword) ||
|
||||
(robot.alias ?? '').toLowerCase().contains(keyword);
|
||||
}).toList();
|
||||
|
||||
if (robots.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
// 🔥 直接复用 RobotListPage 的布局结构(不显示标题)
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
...state.robots.map((robot) {
|
||||
...robots.map((robot) {
|
||||
debugPrint(
|
||||
'📍 [EmbeddedRobotList] 机器人 - name: ${robot.name}, id: ${robot.id}',
|
||||
);
|
||||
@@ -701,6 +739,8 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
final selectedSite = sl<SiteCubit>().state.selectedSite;
|
||||
|
||||
if (selectedSite == null) {
|
||||
// 🔥 嵌入式分组不输出占位内容,避免"全部"列表中间夹一段提示
|
||||
if (embedded) return const SizedBox.shrink();
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
@@ -762,6 +802,9 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
final stations = state.stations;
|
||||
|
||||
if (stations.isEmpty) {
|
||||
// 🔥 "全部"标签下的嵌入式分组为空时不输出文案,
|
||||
// 避免列表中间夹一行"该场站暂无无人机机场"
|
||||
if (embedded) return const SizedBox.shrink();
|
||||
return Center(
|
||||
child: Text(
|
||||
AppLocalizations.of(
|
||||
|
||||
@@ -19,6 +19,9 @@ class DeviceItemWidget extends StatelessWidget {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
// 🔥 卡片外边距:与 RobotItemCard 保持一致。
|
||||
// 外层 ListView 只有 bottom padding,缺了这里卡片就会通栏贴边、左右圆角被裁掉。
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 6.0),
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
decoration: BoxDecoration(
|
||||
color: context.appColors.cardBackground,
|
||||
@@ -81,24 +84,32 @@ class DeviceItemWidget extends StatelessWidget {
|
||||
IconData icon;
|
||||
Color color;
|
||||
|
||||
// 🔥 同一个 type 字段有两套取值体系:英文 code(inverter)与中文名(逆变器)。
|
||||
// 类型 tab 用英文 code 过滤,所以到达这里的设备大多是英文 code;
|
||||
// 两套写法都认,否则全部落到 default 的通用设备图标。
|
||||
switch (type) {
|
||||
case '机器人':
|
||||
case 'robot':
|
||||
icon = Icons.smart_toy;
|
||||
color = const Color(0xFF165DFF);
|
||||
break;
|
||||
case '逆变器':
|
||||
case 'inverter':
|
||||
icon = Icons.power;
|
||||
color = const Color(0xFF165DFF);
|
||||
break;
|
||||
case '汇流箱':
|
||||
case 'combiner_box':
|
||||
icon = Icons.electrical_services;
|
||||
color = const Color(0xFF722ED1);
|
||||
break;
|
||||
case '组件':
|
||||
case 'module':
|
||||
icon = Icons.solar_power;
|
||||
color = const Color(0xFF13C2C2);
|
||||
break;
|
||||
case '监控':
|
||||
case 'monitor':
|
||||
icon = Icons.videocam;
|
||||
color = const Color(0xFFEB2F96);
|
||||
break;
|
||||
@@ -153,7 +164,9 @@ class DeviceItemWidget extends StatelessWidget {
|
||||
Widget _buildDeviceData(BuildContext context, DeviceEntity device) {
|
||||
final dataItems = <Widget>[];
|
||||
|
||||
if (device.type == 'inverter') {
|
||||
// 🔥 与 _buildDeviceIcon 同理:英文 code 与中文名都认,
|
||||
// 否则匹配不上会落到 else 显示 "-- 数据"。
|
||||
if (device.type == 'inverter' || device.type == '逆变器') {
|
||||
dataItems.add(
|
||||
_buildDataItem(
|
||||
context,
|
||||
@@ -169,7 +182,7 @@ class DeviceItemWidget extends StatelessWidget {
|
||||
'${AppLocalizations.of(context).translate('device_list_v2.today_energy')}',
|
||||
),
|
||||
);
|
||||
} else if (device.type == 'combiner_box') {
|
||||
} else if (device.type == 'combiner_box' || device.type == '汇流箱') {
|
||||
if (device.current != null) {
|
||||
dataItems.add(
|
||||
_buildDataItem(
|
||||
@@ -189,7 +202,7 @@ class DeviceItemWidget extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
} else if (device.type == 'module') {
|
||||
} else if (device.type == 'module' || device.type == '组件') {
|
||||
dataItems.add(
|
||||
_buildDataItem(
|
||||
context,
|
||||
|
||||
@@ -4,6 +4,7 @@ class SiteEntity extends Equatable {
|
||||
final int id;
|
||||
final String siteName;
|
||||
final String? siteCode;
|
||||
final String? siteMapName; // GeoServer 图层名,形如 workSpace:suzhou
|
||||
final int orgId;
|
||||
final double? longitude;
|
||||
final double? latitude;
|
||||
@@ -14,6 +15,7 @@ class SiteEntity extends Equatable {
|
||||
required this.id,
|
||||
required this.siteName,
|
||||
this.siteCode,
|
||||
this.siteMapName,
|
||||
required this.orgId,
|
||||
this.longitude,
|
||||
this.latitude,
|
||||
@@ -26,6 +28,7 @@ class SiteEntity extends Equatable {
|
||||
id: json['id'] as int,
|
||||
siteName: json['name'] as String? ?? json['siteName'] as String? ?? '',
|
||||
siteCode: json['siteCode'] as String?,
|
||||
siteMapName: json['siteMapName'] as String?,
|
||||
orgId: json['orgId'] as int? ?? 0,
|
||||
longitude: (json['longitude'] as num?)?.toDouble(),
|
||||
latitude: (json['latitude'] as num?)?.toDouble(),
|
||||
@@ -39,6 +42,7 @@ class SiteEntity extends Equatable {
|
||||
'id': id,
|
||||
'siteName': siteName,
|
||||
'siteCode': siteCode,
|
||||
'siteMapName': siteMapName,
|
||||
'orgId': orgId,
|
||||
'longitude': longitude,
|
||||
'latitude': latitude,
|
||||
@@ -48,5 +52,6 @@ class SiteEntity extends Equatable {
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id, siteName, siteCode, orgId, longitude, latitude, address, status];
|
||||
List<Object?> get props =>
|
||||
[id, siteName, siteCode, siteMapName, orgId, longitude, latitude, address, status];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user