更新睡眠习惯
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) {
|
||||
@@ -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) {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
@@ -136,7 +136,8 @@ class PeopleInfoPage extends GetView<PeopleInfoController> {
|
||||
textColor: Color(0XFF00C1AA));
|
||||
MHTHomeController mhtHomeController =
|
||||
Get.find();
|
||||
mhtHomeController.getPersonList();
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
await mhtHomeController.getPersonList();
|
||||
WebviewTestController
|
||||
webviewTestController = Get.find();
|
||||
webviewTestController
|
||||
|
||||
@@ -177,7 +177,8 @@ class Smys extends GetView<SleepingHabitController> {
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: const Color(0xFF929699),
|
||||
color: Color(0xFF929699),
|
||||
// color: Colors.red,
|
||||
width: 0.rpx),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -14,6 +14,7 @@ import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||
import 'package:vbvs_app/common/util/requestWithLog.dart';
|
||||
import 'package:vbvs_app/controller/user_info_controller.dart';
|
||||
import 'package:vbvs_app/model/WebSocketMessage.dart';
|
||||
import 'package:vbvs_app/pages/mh_page/device/controller/mht_bluetooth_controller.dart';
|
||||
import 'package:vbvs_app/pages/mh_page/homepage/controller/mht_home_controller.dart';
|
||||
|
||||
class WebviewTestModel {
|
||||
@@ -138,6 +139,27 @@ class WebviewTestController extends GetControllerEx<WebviewTestModel> {
|
||||
Get.toNamed("/mHTDeviceTypePage");
|
||||
return true;
|
||||
});
|
||||
bridge.sdk.saveSleepHabit((args) async {
|
||||
ef.log('更新睡眠习惯: $args[0]');
|
||||
try {
|
||||
MHTBlueToothController blueToothController = Get.find();
|
||||
blueToothController.saveHabitData(args[0]);
|
||||
} catch (e) {
|
||||
ef.log("[更新睡眠习惯失败]:$e");
|
||||
}
|
||||
return true;
|
||||
});
|
||||
bridge.sdk.loadSleepHabit((args) async {
|
||||
ef.log('查询睡眠习惯: $args[0]');
|
||||
try {
|
||||
MHTBlueToothController blueToothController = Get.find();
|
||||
var sleepData = await blueToothController.loadHabitDataApi(args[0]);
|
||||
return sleepData['data'];
|
||||
} catch (e) {
|
||||
ef.log("[查询睡眠习惯失败]:$e");
|
||||
}
|
||||
return true;
|
||||
});
|
||||
});
|
||||
} catch (e, s) {
|
||||
ef.log('$e,$s');
|
||||
|
||||
Reference in New Issue
Block a user