trend_controller.dart
1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import 'package:get/get.dart';
import '../../../health_trend/controllers/health_trend_control.dart';
import '../../../report_common/models/health_report_query.dart';
import '../../../report_common/models/report_period.dart';
enum TrendType {
hrv,
activity,
sleep;
int get tabIndex => index;
}
/// 趋势页顶层 Controller,仅负责:
/// 顶层 HRV / 活动 / 睡眠 类型切换 (selectedTypeIndex)
class TrendController extends GetxController with HealthTrendControl {
// 当前查看的用户。null 表示查看自己;非 null 表示查看指定用户。
final targetUserId = RxnInt();
HealthReportQuery get query => HealthReportQuery(
targetUserId: targetUserId.value,
period: selectedPeriod.value,
date: selectedDate.value,
);
HealthReportQuery queryForType(int typeIndex) => HealthReportQuery(
targetUserId: targetUserId.value,
period: periodForType(typeIndex),
date: dateForType(typeIndex),
);
void selectType(TrendType type, {DateTime? date, ReportPeriod? period}) {
changeType(type.tabIndex);
if (period != null) {
changePeriod(period);
}
if (date != null) {
changeDate(date);
}
}
void changeTargetUser(int? userId) {
if (userId == targetUserId.value) return;
targetUserId.value = userId;
}
}