机器列表和远程喊话等ui
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../../../../core/consts/http_api_consts.dart';
|
||||
import '../../../../../core/network/error_handler.dart';
|
||||
import '../../data/models/robot_data_model.dart';
|
||||
import '../../domain/entities/device_model_info.dart';
|
||||
import 'robot_list_event.dart';
|
||||
import 'robot_list_state.dart';
|
||||
|
||||
@@ -50,6 +52,7 @@ class RobotListBloc extends Bloc<RobotListEvent, RobotListState> {
|
||||
}
|
||||
|
||||
final List<dynamic> rows = responseData['rows'] ?? [];
|
||||
_logProductModel(rows, scene: 'load', siteId: event.siteId);
|
||||
final robots = rows.map((item) => RobotDataModel.fromJson(item)).toList();
|
||||
|
||||
emit(RobotListLoaded(
|
||||
@@ -100,6 +103,11 @@ class RobotListBloc extends Bloc<RobotListEvent, RobotListState> {
|
||||
}
|
||||
|
||||
final List<dynamic> rows = responseData['rows'] ?? [];
|
||||
_logProductModel(
|
||||
rows,
|
||||
scene: 'refresh',
|
||||
siteId: currentState.siteId,
|
||||
);
|
||||
final robots = rows.map((item) => RobotDataModel.fromJson(item)).toList();
|
||||
|
||||
emit(currentState.copyWith(robots: robots));
|
||||
@@ -112,6 +120,103 @@ class RobotListBloc extends Bloc<RobotListEvent, RobotListState> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 🔍 专项日志:只核查 getSiteList 返回体里是否带 productModel 字段
|
||||
/// 整体打印 row 时内容过长会被截断,这里只摘取关键字段 + 型号相关候选字段
|
||||
void _logProductModel(
|
||||
List<dynamic> rows, {
|
||||
required String scene,
|
||||
required int? siteId,
|
||||
}) {
|
||||
debugPrint(
|
||||
'>>> [getSiteList/$scene] siteId=$siteId 返回 ${rows.length} 条',
|
||||
);
|
||||
if (rows.isEmpty) {
|
||||
debugPrint('>>> [getSiteList/$scene] rows 为空,无法判断 productModel 是否存在');
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < rows.length; i++) {
|
||||
final row = rows[i];
|
||||
if (row is! Map) {
|
||||
debugPrint(
|
||||
'>>> [getSiteList/$scene] rows[$i] 非 Map 结构: ${row.runtimeType}',
|
||||
);
|
||||
continue;
|
||||
}
|
||||
final json = Map<String, dynamic>.from(row);
|
||||
final head =
|
||||
'deviceId=${json['deviceId']} name=${json['deviceName'] ?? json['name']}';
|
||||
if (json.containsKey('productModel')) {
|
||||
final value = json['productModel'];
|
||||
// 同时输出解析结果,方便确认机型(STD/PLUS/PRO)是否识别正确
|
||||
final info = DeviceModelInfo.parse(value?.toString());
|
||||
debugPrint(
|
||||
'>>> [getSiteList/$scene] rows[$i] $head 有 productModel=$value '
|
||||
'(${value.runtimeType}) → 解析: series=${info.series} edition=${info.edition.name}',
|
||||
);
|
||||
} else {
|
||||
// 字段缺失时列出所有“疑似型号”字段,便于确认后端真实字段名
|
||||
final candidates = json.entries
|
||||
.where((e) => _isModelLikeKey(e.key))
|
||||
.map((e) => '${e.key}=${e.value}')
|
||||
.join(', ');
|
||||
debugPrint(
|
||||
'>>> [getSiteList/$scene] rows[$i] $head 无 productModel 字段;型号候选字段: '
|
||||
'${candidates.isEmpty ? '无' : candidates}',
|
||||
);
|
||||
// 彻底核实:打印顶层全部字段名,并递归扫描子对象/数组
|
||||
_printChunked(
|
||||
'>>> [getSiteList/$scene] rows[$i] 全部顶层字段(${json.length}): ',
|
||||
json.keys.join('|'),
|
||||
);
|
||||
final nested = _findKeyPaths(json, 'productModel');
|
||||
debugPrint(
|
||||
'>>> [getSiteList/$scene] rows[$i] 嵌套层 productModel 命中: '
|
||||
'${nested.isEmpty ? '无(子对象/数组均未找到)' : nested.join(', ')}',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 递归查找指定 key(含子对象与数组),返回“路径=值”列表
|
||||
List<String> _findKeyPaths(dynamic node, String key, [String path = '']) {
|
||||
final hits = <String>[];
|
||||
if (node is Map) {
|
||||
node.forEach((k, v) {
|
||||
final p = path.isEmpty ? '$k' : '$path.$k';
|
||||
if (k.toString() == key) {
|
||||
hits.add('$p=$v');
|
||||
} else {
|
||||
hits.addAll(_findKeyPaths(v, key, p));
|
||||
}
|
||||
});
|
||||
} else if (node is List) {
|
||||
for (int i = 0; i < node.length; i++) {
|
||||
hits.addAll(_findKeyPaths(node[i], key, '$path[$i]'));
|
||||
}
|
||||
}
|
||||
return hits;
|
||||
}
|
||||
|
||||
/// 长文本分段打印,避免 debugPrint 单条过长被截断
|
||||
void _printChunked(String prefix, String content) {
|
||||
const chunk = 700;
|
||||
var head = prefix;
|
||||
for (int start = 0; start < content.length; start += chunk) {
|
||||
final end =
|
||||
start + chunk < content.length ? start + chunk : content.length;
|
||||
debugPrint('$head${content.substring(start, end)}');
|
||||
head = ' ↳ ';
|
||||
}
|
||||
}
|
||||
|
||||
bool _isModelLikeKey(String key) {
|
||||
final k = key.toLowerCase();
|
||||
return k.contains('model') ||
|
||||
k.contains('product') ||
|
||||
k.contains('type') ||
|
||||
k.contains('version');
|
||||
}
|
||||
|
||||
void _onChangeType(
|
||||
RobotListChangeType event,
|
||||
Emitter<RobotListState> emit,
|
||||
|
||||
Reference in New Issue
Block a user