Merge branch 'feature/my' of http://1.95.137.212:57001/APP/FlutterApp into feature/my
This commit is contained in:
@@ -134,37 +134,53 @@ class PathRepositoryImpl implements PathRepository {
|
||||
required String workName,
|
||||
}) async {
|
||||
final timestamp = DateTime.now().millisecondsSinceEpoch;
|
||||
final url =
|
||||
Uri.parse(
|
||||
'https://serviceri.satabot.com/iot/workRecord/selectByWorkName',
|
||||
).replace(
|
||||
queryParameters: {
|
||||
'workName': workName,
|
||||
'_t': timestamp.toString(), // 防缓存
|
||||
},
|
||||
);
|
||||
print('请求URL: $url'); // 调试输出完整URL,检查参数是否正确附加
|
||||
final url = Uri.parse(
|
||||
'https://serviceri.satabot.com/iot/workRecord/selectByWorkName',
|
||||
).replace(
|
||||
queryParameters: {
|
||||
'workName': workName,
|
||||
'_t': timestamp.toString(),
|
||||
},
|
||||
);
|
||||
print('请求URL: $url');
|
||||
|
||||
try {
|
||||
final response = await http.get(url);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
print('响应数据: $data'); // 调试输出响应数据,检查结构和内容
|
||||
print('响应数据: $data');
|
||||
|
||||
if (data['code'] == 200 && data.containsKey('data')) {
|
||||
final List<dynamic> records = data['data'];
|
||||
return List<Map<String, dynamic>>.from(records);
|
||||
final dynamic rawData = data['data'];
|
||||
|
||||
// 🔧 关键修复:安全转换为 List
|
||||
|
||||
List<Map<String, dynamic>> records;
|
||||
if (rawData is List) {
|
||||
records = rawData.map((e) {
|
||||
if (e is Map) {
|
||||
return Map<String, dynamic>.from(e);
|
||||
}
|
||||
throw Exception('List item is not a Map: ${e.runtimeType}');
|
||||
}).toList();
|
||||
} else if (rawData is Map) {
|
||||
records = [Map<String, dynamic>.from(rawData)];
|
||||
} else {
|
||||
throw Exception('Unexpected data type for "data": ${rawData.runtimeType}');
|
||||
}
|
||||
|
||||
|
||||
return records;
|
||||
} else {
|
||||
throw Exception('API error: ${data['msg'] ?? 'Unknown'}');
|
||||
}
|
||||
} else {
|
||||
throw Exception(
|
||||
'HTTP ${response.statusCode}: ${response.reasonPhrase}',
|
||||
);
|
||||
throw Exception('HTTP ${response.statusCode}: ${response.reasonPhrase}');
|
||||
}
|
||||
} catch (e) {
|
||||
throw Exception('Network error in selectWorkRecordByName: $e');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user