feat: 改进远程录屏保存与设备首页体验

This commit is contained in:
tongtong committed 2026-11-10 21:20:18 +08:00
1 parent 004bf6b137
commit 0ee4b2e1c7
15 files changed
+362 -197

No files matched your search

+25 -2
View File
@@ -87,6 +87,19 @@ class DeviceApi {
}
}
Future<List<DeviceBrief>> getCachedMyDevices() async {
final data = await DioClient.readCachedGet('v1/client/sn/my-devices');
return _parseList(data, DeviceBrief.fromJson);
}
Future<DeviceLocation?> getCachedLocation(String sn) async {
final data = await DioClient.readCachedGet(
'v1/client/sn/location',
queryParameters: {'sn': sn},
);
return data is Map<String, dynamic> ? DeviceLocation.fromJson(data) : null;
}
/// 获取已绑定设备最新定位信息(无上报数据时返回 null)。
Future<DeviceLocation?> getLocation(String sn) async {
try {
@@ -453,6 +466,18 @@ class DeviceApi {
allowStale: true,
queryParameters: query,
);
return _parseScreenshots(payload);
}
Future<List<ScreenshotVO>> getCachedRecentScreenshots(String sn) async {
final payload = await DioClient.readCachedGet(
'v1/client/sn/upload-screenshot',
queryParameters: {'sn': sn},
);
return _parseScreenshots(payload);
}
List<ScreenshotVO> _parseScreenshots(dynamic payload) {
// 防御性提取:兼容后台直接返回 List,或返回 { data: [...] } 的包裹结构。
final List<dynamic> listData;
if (payload is List) {
@@ -460,10 +485,8 @@ class DeviceApi {
} else if (payload is Map && payload['data'] is List) {
listData = payload['data'] as List;
} else {
debugPrint('[DeviceApi] getRecentScreenshots 返回非预期结构: sn=$sn payload=$payload');
return const [];
}
debugPrint('[DeviceApi] getRecentScreenshots sn=$sn count=${listData.length}');
final origin = Uri.parse(AppConstants.kBaseUrl).origin;
return listData.whereType<Map<String, dynamic>>().map((e) {
final vo = ScreenshotVO.fromJson(e);