新增首页布局配置:支持调整老人端桌面分页顺序与默认页

This commit is contained in:
tongtong committed 2026-11-25 17:50:41 +08:00
1 parent 7d032d18a8
commit b12148cd76
12 files changed
+803 -1

No files matched your search

+50
View File
@@ -17,6 +17,9 @@ import 'package:ttstd_family_care/features/device/domain/device_models.dart';
class DeviceApi {
const DeviceApi();
/// 首页分页布局接口路径(家属端)。
static const String _homeLayoutPath = 'v1/client/sn/home-layout';
/// 获取当前用户已绑定的设备列表。
Future<List<DeviceBrief>> getMyDevices() async {
try {
@@ -176,6 +179,53 @@ class DeviceApi {
}
}
/// 获取已绑定设备首页分页布局(分页顺序 + 默认展示页)。
///
/// 对应后台 `GET /api/v1/client/sn/home-layout?sn=xxx`;未配置时后台返回默认布局。
/// 失败时返回 null。
Future<DeviceHomeLayout?> getHomeLayout(String sn) async {
try {
final data = await DioClient.get(
_homeLayoutPath,
allowStale: true,
queryParameters: {'sn': sn},
);
return data is Map<String, dynamic>
? DeviceHomeLayout.fromJson(data)
: null;
} on ApiException {
return null;
}
}
/// 保存设备首页分页布局并推送设备(老人端收到后重建桌面)。
///
/// 对应后台 `PUT /api/v1/client/sn/home-layout?sn=xxx`,请求体
/// `{pages, defaultPage}`。返回值直接使用后台已规范化的顺序回填本地,
/// 无需再发起一次 GET。
Future<({DeviceHomeLayout? layout, String? error})> saveHomeLayout(
String sn, List<String> pages, String defaultPage) async {
try {
final data = await DioClient.put(
'$_homeLayoutPath?sn=${Uri.encodeQueryComponent(sn)}',
data: {'pages': pages, 'defaultPage': defaultPage},
);
await DioClient.invalidateReadCache(
_homeLayoutPath,
queryParameters: {'sn': sn},
);
final layout =
data is Map<String, dynamic> ? DeviceHomeLayout.fromJson(data) : null;
debugPrint('[DeviceApi] saveHomeLayout sn=$sn pages=$pages data=$data');
return (layout: layout, error: null);
} on ApiException catch (e) {
debugPrint(
'[DeviceApi] saveHomeLayout sn=$sn pages=$pages failed: ${e.message}',
);
return (layout: null, error: e.message);
}
}
/// 向设备下发操作指令(重启/关机/截屏/刷新/定位/拍照等)。
///
/// [op] 为后端操作标识,如 `reboot` / `shutdown` / `screenshot` / `refresh` / `locate` / `take_photo`,