更新睡眠习惯
This commit is contained in:
@@ -10,6 +10,7 @@ import 'package:vbvs_app/common/color/ServiceConstant.dart';
|
||||
import 'package:vbvs_app/common/color/app_uri_status.dart';
|
||||
import 'package:vbvs_app/common/util/DailyLogUtils.dart';
|
||||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||
import 'package:vbvs_app/common/util/requestWithLog.dart';
|
||||
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
|
||||
import 'package:vbvs_app/model/api_response.dart';
|
||||
import 'package:vbvs_app/pages/mh_page/device/model/BlueToothDataModel.dart';
|
||||
@@ -71,8 +72,6 @@ class MHTBlueToothController extends GetControllerEx<MHTBlueToothModel> {
|
||||
RxMap connect_wifi = {}.obs;
|
||||
RxString? cid = "".obs;
|
||||
|
||||
|
||||
|
||||
void startStatusPolling() {
|
||||
updateDeviceStatus().then((res) {
|
||||
if (res.code == HttpStatusCodes.ok) {
|
||||
@@ -189,7 +188,7 @@ class MHTBlueToothController extends GetControllerEx<MHTBlueToothModel> {
|
||||
return res;
|
||||
} else {
|
||||
model.deviceDataStatus = [];
|
||||
return ApiResponse(code:1, msg: "".tr);
|
||||
return ApiResponse(code: 1, msg: "".tr);
|
||||
}
|
||||
} catch (e) {
|
||||
print("获取设备状态异常: $e");
|
||||
@@ -257,6 +256,56 @@ class MHTBlueToothController extends GetControllerEx<MHTBlueToothModel> {
|
||||
}
|
||||
return ApiResponse(code: -1, msg: "未知错误".tr);
|
||||
}
|
||||
|
||||
saveHabitData(sleepData) async {
|
||||
String serviceAddress = ServiceConstant.service_address;
|
||||
String serviceName = ServiceConstant.server_service;
|
||||
String serviceApi = ServiceConstant.user_setting;
|
||||
String type = "sleep_habit_${sleepData['mac']}";
|
||||
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}";
|
||||
var data = {
|
||||
"type": type,
|
||||
"mac": sleepData['mac'],
|
||||
"time": DateTime.now().millisecondsSinceEpoch,
|
||||
"data": sleepData,
|
||||
};
|
||||
await requestWithLog(
|
||||
logTitle: "更新睡眠习惯",
|
||||
method: MyHttpMethod.put,
|
||||
queryUrl: queryUrl,
|
||||
data: data,
|
||||
);
|
||||
}
|
||||
|
||||
Future<Map> loadHabitDataApi(String mac, {int time = 3}) async {
|
||||
String serviceAddress = ServiceConstant.service_address;
|
||||
String serviceName = ServiceConstant.server_service;
|
||||
String serviceApi = ServiceConstant.user_setting;
|
||||
String type = "sleep_habit_${mac}";
|
||||
String queryUrl =
|
||||
"${serviceAddress}${serviceName}${serviceApi}?type=${type}";
|
||||
|
||||
// 使用 Future 来等待异步操作完成
|
||||
Map<String, dynamic> result = {};
|
||||
|
||||
await requestWithLog(
|
||||
logTitle: "更新睡眠习惯",
|
||||
method: MyHttpMethod.get,
|
||||
queryUrl: queryUrl,
|
||||
onSuccess: (res) {
|
||||
ef.log("加载睡眠习惯成功: ${res.data}");
|
||||
result = res.data; // 将返回的数据存入 result
|
||||
},
|
||||
onFailure: (res) {
|
||||
ef.log("加载睡眠习惯失败: ${res.msg}");
|
||||
result = {}; // 如果失败,可以返回空的 Map
|
||||
},
|
||||
);
|
||||
|
||||
return result; // 在 requestWithLog 完成之后返回 result
|
||||
}
|
||||
|
||||
//todo 解绑的时候删除自己所拥有的所有设备的睡眠习惯
|
||||
}
|
||||
|
||||
void safeShowNotification(String msg) {
|
||||
|
||||
Reference in New Issue
Block a user