- 引入 DarkMode 工具类,提供系统栏、颜色、色调的暗色适配能力 - AppColors 调色板改为 CupertinoDynamicColor.withBrightness 自适应 - app.dart 增加 AnnotatedRegion 与 Material Theme 包裹以联动暗色系统栏 - 移除 system_ui_util 中硬编码的浅色图标配置,改由主题驱动 - CardBox、AppDivider、SectionTitle 等公共组件适配深色卡片与分割线 - settings_ui、change_mobile、change_password、login_devices、wechat_binding 等页面全面接入 DarkMode 颜色 - dio_client 新增 allowStale 响应缓存机制,网络异常时回退本地缓存 - token_storage 增加 currentAccountId(JWT 解析)及按用户隔离的设备偏好存取 - ApiException 改为通过私有构造持有真实 AppError 实例,appError getter 返回结构化错误 - 闹钟模块迁移至 FutureProvider.autoDispose.family,消除手动 loading 状态管理 - 闹钟编辑页 CupertinoTimerPicker 替换为 CupertinoDatePicker(24h 格式),标签输入改为 TextEditingController
75 lines
2.4 KiB
Dart
75 lines
2.4 KiB
Dart
import 'package:cupertino_ui/cupertino_ui.dart';
|
||
import 'package:ttstd_family_care/core/network/api_exception.dart';
|
||
import 'package:ttstd_family_care/core/network/dio_client.dart';
|
||
import 'package:ttstd_family_care/features/alarm/domain/alarm_models.dart';
|
||
|
||
/// 家属端闹钟接口访问层。
|
||
///
|
||
/// 对应后台 `/api/v1/client/sn/alarm`(GET 列表 / POST 新增 / PUT 修改 / DELETE 删除)。
|
||
class AlarmApi {
|
||
const AlarmApi();
|
||
|
||
/// 查询设备闹钟列表(按时间升序)。
|
||
Future<List<AlarmModel>> getAlarms(String sn) async {
|
||
final data = await DioClient.get(
|
||
'v1/client/sn/alarm',
|
||
allowStale: true,
|
||
queryParameters: {'sn': sn},
|
||
);
|
||
return (data as List<dynamic>)
|
||
.map(
|
||
(entry) =>
|
||
AlarmModel.fromJson(Map<String, dynamic>.from(entry as Map)),
|
||
)
|
||
.toList(growable: false);
|
||
}
|
||
|
||
/// 新增闹钟;成功返回新闹钟 id,失败 [error] 为错误提示。
|
||
Future<({int? id, String? error})> addAlarm(
|
||
String sn,
|
||
AlarmModel alarm,
|
||
) async {
|
||
try {
|
||
final data = await DioClient.post(
|
||
'v1/client/sn/alarm',
|
||
queryParameters: {'sn': sn},
|
||
data: alarm.toJson(),
|
||
);
|
||
debugPrint('[AlarmApi] addAlarm sn=$sn success, id=$data');
|
||
return (id: data is int ? data : null, error: null);
|
||
} on ApiException catch (e) {
|
||
debugPrint('[AlarmApi] addAlarm sn=$sn failed: ${e.message}');
|
||
return (id: null, error: e.message);
|
||
}
|
||
}
|
||
|
||
/// 修改闹钟;成功返回 null,失败返回错误提示。
|
||
Future<String?> updateAlarm(String sn, AlarmModel alarm) async {
|
||
try {
|
||
await DioClient.put(
|
||
'v1/client/sn/alarm?sn=${Uri.encodeQueryComponent(sn)}',
|
||
data: alarm.toJson(),
|
||
);
|
||
debugPrint('[AlarmApi] updateAlarm sn=$sn success, id=${alarm.id}');
|
||
return null;
|
||
} on ApiException catch (e) {
|
||
debugPrint('[AlarmApi] updateAlarm sn=$sn failed: ${e.message}');
|
||
return e.message;
|
||
}
|
||
}
|
||
|
||
/// 删除闹钟;成功返回 null,失败返回错误提示。
|
||
Future<String?> deleteAlarm(String sn, int id) async {
|
||
try {
|
||
await DioClient.delete(
|
||
'v1/client/sn/alarm?sn=${Uri.encodeQueryComponent(sn)}&id=$id',
|
||
);
|
||
debugPrint('[AlarmApi] deleteAlarm sn=$sn id=$id success');
|
||
return null;
|
||
} on ApiException catch (e) {
|
||
debugPrint('[AlarmApi] deleteAlarm sn=$sn id=$id failed: ${e.message}');
|
||
return e.message;
|
||
}
|
||
}
|
||
}
|