- 引入 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
93 lines
3.2 KiB
Dart
93 lines
3.2 KiB
Dart
import 'package:flutter/foundation.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/contacts/domain/contact_models.dart';
|
||
|
||
/// 客户端(家属端)联系人接口访问层。
|
||
///
|
||
/// 后端接口前缀为 `/api/v1/client/sn/contact`,Dio 在 path 不以 `/` 开头时会
|
||
/// 直接拼接 baseUrl 的 path 段,故此处使用相对路径 `v1/client/sn/contact/...`。
|
||
/// [DioClient.get/post/put/delete] 已统一解析为后台返回体中的 `data` 字段;
|
||
/// 业务失败时抛出 [ApiException],本层将其降级为「空数据/错误提示」以适配家属端展示。
|
||
class ContactApi {
|
||
const ContactApi();
|
||
|
||
/// 联系人列表(家属端)。
|
||
Future<List<Contact>> getContacts(String sn) async {
|
||
try {
|
||
final data = await DioClient.get(
|
||
'v1/client/sn/contact/list',
|
||
allowStale: true,
|
||
queryParameters: {'sn': sn},
|
||
);
|
||
return _parseList(data, Contact.fromJson);
|
||
} on ApiException {
|
||
return const [];
|
||
}
|
||
}
|
||
|
||
/// 新增联系人(家属端)。
|
||
///
|
||
/// 成功返回 null;失败返回后台错误提示。
|
||
Future<String?> addContact(String sn, Contact contact) async {
|
||
try {
|
||
await DioClient.post(
|
||
'v1/client/sn/contact/insert',
|
||
queryParameters: {'sn': sn},
|
||
data: contact.toFormJson(),
|
||
);
|
||
debugPrint('[ContactApi] addContact sn=$sn name=${contact.name} success');
|
||
return null;
|
||
} on ApiException catch (e) {
|
||
debugPrint('[ContactApi] addContact sn=$sn name=${contact.name} failed: ${e.message}');
|
||
return e.message;
|
||
}
|
||
}
|
||
|
||
/// 修改联系人(家属端)。
|
||
///
|
||
/// 成功返回 null;失败返回后台错误提示。
|
||
/// 注意:[DioClient.put] 无 queryParameters 参数,故 id/sn 直接拼入路径。
|
||
Future<String?> updateContact(String sn, Contact contact) async {
|
||
try {
|
||
final path =
|
||
'v1/client/sn/contact/update?id=${contact.id}&sn=${Uri.encodeQueryComponent(sn)}';
|
||
await DioClient.put(path, data: contact.toFormJson());
|
||
debugPrint('[ContactApi] updateContact sn=$sn id=${contact.id} success');
|
||
return null;
|
||
} on ApiException catch (e) {
|
||
debugPrint('[ContactApi] updateContact sn=$sn id=${contact.id} failed: ${e.message}');
|
||
return e.message;
|
||
}
|
||
}
|
||
|
||
/// 删除联系人(家属端)。
|
||
///
|
||
/// 成功返回 null;失败返回后台错误提示。
|
||
Future<String?> deleteContact(String sn, int id) async {
|
||
try {
|
||
await DioClient.delete(
|
||
'v1/client/sn/contact/delete?sn=${Uri.encodeQueryComponent(sn)}&id=$id',
|
||
);
|
||
debugPrint('[ContactApi] deleteContact sn=$sn id=$id success');
|
||
return null;
|
||
} on ApiException catch (e) {
|
||
debugPrint('[ContactApi] deleteContact sn=$sn id=$id failed: ${e.message}');
|
||
return e.message;
|
||
}
|
||
}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
|
||
static List<T> _parseList<T>(
|
||
dynamic data,
|
||
T Function(Map<String, dynamic>) fromJson,
|
||
) {
|
||
if (data is! List) return const [];
|
||
return data
|
||
.whereType<Map<String, dynamic>>()
|
||
.map(fromJson)
|
||
.toList(growable: false);
|
||
}
|
||
}
|