diff --git a/lib/component/base/SleepCalendarWidget.dart b/lib/component/base/SleepCalendarWidget.dart index 7e5c707..029bd8e 100644 --- a/lib/component/base/SleepCalendarWidget.dart +++ b/lib/component/base/SleepCalendarWidget.dart @@ -57,7 +57,7 @@ class _SleepCalendarWidgetState extends State { // 初始化请求 fetchDate(initialDate); - + fetchSleepColor(); // 每当月份变化时,重新请求数据 ever(calendarController.displayedMonth, (DateTime newMonth) { fetchDate(newMonth); @@ -74,38 +74,26 @@ class _SleepCalendarWidgetState extends State { "https://sleepdata.he-info.com/api/analysis/sleep/analysis?mac=${widget.mac}&time=$dateStr&type=3", onSuccess: (res) { sleepDate.value = res.data; - showLabel.value = [ - ...res.data['scoreList']['type'], - {"level": 5, "name": "无报告", "color": "#9E9E9E"}, - // ✅ 注意拼写是 scoreList - ]; }, onFailure: (res) { sleepDate.value = {}; - showLabel.value = [ - {"level": 5, "name": "无报告", "color": "#9E9E9E"}, - ]; }, ); } - Future fetchSleepColor(DateTime timeStamp) async { - final dateStr = timeStamp.toString().split(' ')[0]; - + Future fetchSleepColor() async { await requestWithLog( logTitle: "查询睡眠报告", method: MyHttpMethod.get, queryUrl: "https://sleepdata.he-info.com/api/analysis/sleep/score/type", onSuccess: (res) { - sleepDate.value = res.data; showLabel.value = [ - ...res.data['scoreList']['type'], + ...res.data, {"level": 5, "name": "无报告", "color": "#9E9E9E"}, // ✅ 注意拼写是 scoreList ]; }, onFailure: (res) { - sleepDate.value = {}; showLabel.value = [ {"level": 5, "name": "无报告", "color": "#9E9E9E"}, ]; diff --git a/lib/pages/sleep_report/new_sleep_report_page.dart b/lib/pages/sleep_report/new_sleep_report_page.dart index 64315f4..22b1d65 100644 --- a/lib/pages/sleep_report/new_sleep_report_page.dart +++ b/lib/pages/sleep_report/new_sleep_report_page.dart @@ -1074,62 +1074,64 @@ class _NewSleepReportPageState extends State { ], ), ClickableContainer( - backgroundColor: Colors.transparent, - highlightColor: themeController.currentColor.sc3, - padding: EdgeInsets.zero, - borderRadius: 8, - onTap: () { - showSleepCalendarBottomSheet( - type: sleepReportController.model.type, - timestamp: selectedDate.millisecondsSinceEpoch, - context: context, - mac: widget.data['mac'], - onDateSelected: (newDate) { - sleepReportController.selectedDate.value = newDate; - calendarController.selectedDate.value = newDate; - String data = - MyUtils.formatDate(calendarController.selectedDate.value!); - requestWithLog( - logTitle: "查询睡眠报告", - method: MyHttpMethod.get, - queryUrl: - "https://sleepdata.he-info.com/api/analysis/sleep/analysis?mac=${widget.data['mac']}&time=${data}&type=${sleepReportController.model.type}", - onSuccess: (res) { - print(res); - sleepReportController.sleepReport.value = res.data; - sleepReportController.updateAll(); - }, - onFailure: (res) { - if (MainPageBBottomChange.getCurrentIndex() != null) { - if (MainPageBBottomChange.getCurrentIndex() == 1) { + backgroundColor: Colors.transparent, + highlightColor: themeController.currentColor.sc3, + padding: EdgeInsets.zero, + borderRadius: 8, + onTap: () { + showSleepCalendarBottomSheet( + type: sleepReportController.model.type, + timestamp: selectedDate.millisecondsSinceEpoch, + context: context, + mac: widget.data['mac'], + onDateSelected: (newDate) { + sleepReportController.selectedDate.value = newDate; + calendarController.selectedDate.value = newDate; + String data = MyUtils.formatDate( + calendarController.selectedDate.value!); + requestWithLog( + logTitle: "查询睡眠报告", + method: MyHttpMethod.get, + queryUrl: + "https://sleepdata.he-info.com/api/analysis/sleep/analysis?mac=${widget.data['mac']}&time=${data}&type=${sleepReportController.model.type}", + onSuccess: (res) { + print(res); + sleepReportController.sleepReport.value = res.data; + sleepReportController.updateAll(); + }, + onFailure: (res) { + if (MainPageBBottomChange.getCurrentIndex() != null) { + if (MainPageBBottomChange.getCurrentIndex() == 1) { + TopSlideNotification.show(context, + text: res.msg!, + textColor: themeController.currentColor.sc9); + } + } else { TopSlideNotification.show(context, text: res.msg!, textColor: themeController.currentColor.sc9); } - } else { - TopSlideNotification.show(context, - text: res.msg!, - textColor: themeController.currentColor.sc9); - } - sleepReportController.sleepReport.value = {}; - sleepReportController.updateAll(); - print(res); - }); - sleepReportController.updateAll(); - calendarController.updateAll(); - }, - ); - }, - child: Container( - width: 36.rpx, - height: 36.rpx, - child: SvgPicture.asset( - 'assets/img/icon/calendar.svg', - fit: BoxFit.cover, - color: themeController.currentColor.sc3, - ), - ), - ), + sleepReportController.sleepReport.value = {}; + sleepReportController.updateAll(); + print(res); + }); + sleepReportController.updateAll(); + calendarController.updateAll(); + }, + ); + }, + child: Padding( + padding: EdgeInsets.all(10.rpx), + child: Container( + width: 36.rpx, + height: 36.rpx, + child: SvgPicture.asset( + 'assets/img/icon/calendar.svg', + fit: BoxFit.cover, + color: themeController.currentColor.sc3, + ), + ), + )), ], ); }