日报周报数据紊乱
This commit is contained in:
@@ -15,6 +15,17 @@ Widget WeekDataWidget(
|
|||||||
Map<dynamic, dynamic> sleepReport,
|
Map<dynamic, dynamic> sleepReport,
|
||||||
dynamic data,
|
dynamic data,
|
||||||
) {
|
) {
|
||||||
|
List<String> getDate() {
|
||||||
|
var s = buildWeekDatesAndPoints(sleepReport['scoreList']);
|
||||||
|
if (s == null ||
|
||||||
|
s['dates'] == null ||
|
||||||
|
s['dates'] is! List<String> ||
|
||||||
|
s['dates'].length != 7) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return s['dates'];
|
||||||
|
}
|
||||||
|
|
||||||
List<Widget> _buildSectionList() {
|
List<Widget> _buildSectionList() {
|
||||||
EdgeInsetsDirectional padding =
|
EdgeInsetsDirectional padding =
|
||||||
EdgeInsetsDirectional.fromSTEB(30.rpx, 0, 30.rpx, 25.rpx);
|
EdgeInsetsDirectional.fromSTEB(30.rpx, 0, 30.rpx, 25.rpx);
|
||||||
@@ -34,8 +45,7 @@ Widget WeekDataWidget(
|
|||||||
min: 0, //最小值0
|
min: 0, //最小值0
|
||||||
max: 7, //最大值30
|
max: 7, //最大值30
|
||||||
q: 6, //labels第一个与最后一个的真实距离,也就是30-1 = 29
|
q: 6, //labels第一个与最后一个的真实距离,也就是30-1 = 29
|
||||||
labels:
|
labels: getDate(),
|
||||||
buildWeekDatesAndPoints(sleepReport['scoreList'])['dates'],
|
|
||||||
indexs: [0, 1, 2, 3, 4, 5, 6], //每一个标签的对应在X轴的真实位置
|
indexs: [0, 1, 2, 3, 4, 5, 6], //每一个标签的对应在X轴的真实位置
|
||||||
offset: Offset(0, -16.rpx), //标签相对于原点的偏移,下方20像素位置
|
offset: Offset(0, -16.rpx), //标签相对于原点的偏移,下方20像素位置
|
||||||
ondrawer: (canvas, offset, index, label, align, style) {
|
ondrawer: (canvas, offset, index, label, align, style) {
|
||||||
@@ -766,8 +776,72 @@ int getWeekdayX(DateTime current, DateTime first) {
|
|||||||
return weekOffset * 7 + (current.weekday - 1);
|
return weekOffset * 7 + (current.weekday - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> buildWeekDatesAndPoints(Map<String, dynamic> scoreList) {
|
// Map<String, dynamic> buildWeekDatesAndPoints(Map<String, dynamic> scoreList) {
|
||||||
if (!scoreList.containsKey('data') || (scoreList['data'] as List).isEmpty) {
|
|
||||||
|
// if (scoreList == null ||
|
||||||
|
// !scoreList.containsKey('data') ||
|
||||||
|
// (scoreList['data'] as List).isEmpty) {
|
||||||
|
// return {
|
||||||
|
// 'dates': [],
|
||||||
|
// 'points': [],
|
||||||
|
// 'colors': [],
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
// List<Map<String, dynamic>> data = (scoreList['data'] as List)
|
||||||
|
// .where((item) => item is Map<String, dynamic>)
|
||||||
|
// .cast<Map<String, dynamic>>()
|
||||||
|
// .toList();
|
||||||
|
|
||||||
|
// // 提取 level -> color 映射表
|
||||||
|
// Map<int, String> levelColorMap = {};
|
||||||
|
// if (scoreList.containsKey('type')) {
|
||||||
|
// List typeList = scoreList['type'];
|
||||||
|
// for (var item in typeList) {
|
||||||
|
// if (item is Map &&
|
||||||
|
// item.containsKey('level') &&
|
||||||
|
// item.containsKey('color')) {
|
||||||
|
// levelColorMap[item['level']] = item['color'];
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// DateTime baseDate = DateTime.fromMillisecondsSinceEpoch(data.first['st']);
|
||||||
|
// int weekday = baseDate.weekday;
|
||||||
|
// DateTime monday = baseDate.subtract(Duration(days: weekday - 1));
|
||||||
|
// List<String> dates = List.generate(7, (i) {
|
||||||
|
// DateTime d = monday.add(Duration(days: i));
|
||||||
|
// String month = d.month.toString().padLeft(2, '0');
|
||||||
|
// String day = d.day.toString().padLeft(2, '0');
|
||||||
|
// return "$month/$day";
|
||||||
|
// });
|
||||||
|
|
||||||
|
// List<Offset> points = [];
|
||||||
|
// List<String> colors = [];
|
||||||
|
|
||||||
|
// for (var item in data) {
|
||||||
|
// DateTime dt = DateTime.fromMillisecondsSinceEpoch(item['st']);
|
||||||
|
// double x = getWeekdayX(dt, baseDate).toDouble();
|
||||||
|
// double y = (item['value'] as num?)?.toDouble() ?? 0;
|
||||||
|
// int level = item['level'];
|
||||||
|
// String color = levelColorMap[level] ?? "#FFFF00";
|
||||||
|
|
||||||
|
// points.add(Offset(x, y));
|
||||||
|
// colors.add(color);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return {
|
||||||
|
// 'dates': dates,
|
||||||
|
// 'points': points,
|
||||||
|
// 'colors': colors,
|
||||||
|
// };
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
Map<String, dynamic> buildWeekDatesAndPoints(Map<String, dynamic>? scoreList) {
|
||||||
|
try {
|
||||||
|
if (scoreList == null ||
|
||||||
|
!scoreList.containsKey('data') ||
|
||||||
|
(scoreList['data'] as List).isEmpty) {
|
||||||
return {
|
return {
|
||||||
'dates': [],
|
'dates': [],
|
||||||
'points': [],
|
'points': [],
|
||||||
@@ -780,6 +854,14 @@ Map<String, dynamic> buildWeekDatesAndPoints(Map<String, dynamic> scoreList) {
|
|||||||
.cast<Map<String, dynamic>>()
|
.cast<Map<String, dynamic>>()
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
|
if (data.isEmpty) {
|
||||||
|
return {
|
||||||
|
'dates': [],
|
||||||
|
'points': [],
|
||||||
|
'colors': [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// 提取 level -> color 映射表
|
// 提取 level -> color 映射表
|
||||||
Map<int, String> levelColorMap = {};
|
Map<int, String> levelColorMap = {};
|
||||||
if (scoreList.containsKey('type')) {
|
if (scoreList.containsKey('type')) {
|
||||||
@@ -793,9 +875,15 @@ Map<String, dynamic> buildWeekDatesAndPoints(Map<String, dynamic> scoreList) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DateTime baseDate = DateTime.fromMillisecondsSinceEpoch(data.first['st']);
|
// 如果 st 字段异常,使用当前时间作为基准
|
||||||
|
int stValue = (data.first['st'] is int)
|
||||||
|
? data.first['st']
|
||||||
|
: DateTime.now().millisecondsSinceEpoch;
|
||||||
|
DateTime baseDate = DateTime.fromMillisecondsSinceEpoch(stValue);
|
||||||
|
|
||||||
int weekday = baseDate.weekday;
|
int weekday = baseDate.weekday;
|
||||||
DateTime monday = baseDate.subtract(Duration(days: weekday - 1));
|
DateTime monday = baseDate.subtract(Duration(days: weekday - 1));
|
||||||
|
|
||||||
List<String> dates = List.generate(7, (i) {
|
List<String> dates = List.generate(7, (i) {
|
||||||
DateTime d = monday.add(Duration(days: i));
|
DateTime d = monday.add(Duration(days: i));
|
||||||
String month = d.month.toString().padLeft(2, '0');
|
String month = d.month.toString().padLeft(2, '0');
|
||||||
@@ -807,10 +895,12 @@ Map<String, dynamic> buildWeekDatesAndPoints(Map<String, dynamic> scoreList) {
|
|||||||
List<String> colors = [];
|
List<String> colors = [];
|
||||||
|
|
||||||
for (var item in data) {
|
for (var item in data) {
|
||||||
|
if (item['st'] == null) continue;
|
||||||
|
|
||||||
DateTime dt = DateTime.fromMillisecondsSinceEpoch(item['st']);
|
DateTime dt = DateTime.fromMillisecondsSinceEpoch(item['st']);
|
||||||
double x = getWeekdayX(dt, baseDate).toDouble();
|
double x = getWeekdayX(dt, baseDate).toDouble();
|
||||||
double y = (item['value'] as num?)?.toDouble() ?? 0;
|
double y = (item['value'] as num?)?.toDouble() ?? 0;
|
||||||
int level = item['level'];
|
int level = (item['level'] is int) ? item['level'] : 0;
|
||||||
String color = levelColorMap[level] ?? "#FFFF00";
|
String color = levelColorMap[level] ?? "#FFFF00";
|
||||||
|
|
||||||
points.add(Offset(x, y));
|
points.add(Offset(x, y));
|
||||||
@@ -822,6 +912,18 @@ Map<String, dynamic> buildWeekDatesAndPoints(Map<String, dynamic> scoreList) {
|
|||||||
'points': points,
|
'points': points,
|
||||||
'colors': colors,
|
'colors': colors,
|
||||||
};
|
};
|
||||||
|
} catch (e, s) {
|
||||||
|
// ⚠️ 捕获异常并返回空结构
|
||||||
|
debugPrint("❌ buildWeekDatesAndPoints 出错:$e");
|
||||||
|
debugPrint("—— 异常堆栈 ——");
|
||||||
|
debugPrintStack(stackTrace: s);
|
||||||
|
debugPrint("———————————");
|
||||||
|
return {
|
||||||
|
'dates': [],
|
||||||
|
'points': [],
|
||||||
|
'colors': [],
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Offset> buildGeneralPoints(Map<String, dynamic> dyspData) {
|
List<Offset> buildGeneralPoints(Map<String, dynamic> dyspData) {
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ class _NewSleepReportPageState extends State<NewSleepReportPage> {
|
|||||||
Future.microtask(() {
|
Future.microtask(() {
|
||||||
if (Get.isRegistered<SleepReportController>()) {
|
if (Get.isRegistered<SleepReportController>()) {
|
||||||
sleepReportController.isLoading.value = false;
|
sleepReportController.isLoading.value = false;
|
||||||
|
sleepReportController.model.type = 1;
|
||||||
sleepReportController.sleepReport.value = {};
|
sleepReportController.sleepReport.value = {};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -876,7 +877,7 @@ class _NewSleepReportPageState extends State<NewSleepReportPage> {
|
|||||||
// }
|
// }
|
||||||
// }),
|
// }),
|
||||||
Obx(() {
|
Obx(() {
|
||||||
try {
|
|
||||||
if (sleepReportController.isLoading.value) {
|
if (sleepReportController.isLoading.value) {
|
||||||
return Center(
|
return Center(
|
||||||
child: CircularProgressIndicator(
|
child: CircularProgressIndicator(
|
||||||
@@ -908,12 +909,7 @@ class _NewSleepReportPageState extends State<NewSleepReportPage> {
|
|||||||
default:
|
default:
|
||||||
return NullDataWidget();
|
return NullDataWidget();
|
||||||
}
|
}
|
||||||
} catch (e, s) {
|
|
||||||
debugPrint("❌ Obx 构建异常: $e");
|
|
||||||
debugPrintStack(
|
|
||||||
stackTrace: s, label: "Obx build 详细堆栈:");
|
|
||||||
return NullDataWidget();
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
Column(
|
Column(
|
||||||
children: [
|
children: [
|
||||||
|
|||||||
Reference in New Issue
Block a user