更新界面布局
This commit is contained in:
@@ -8,6 +8,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/model/api_response.dart';
|
||||
|
||||
part 'mht_home_controller.g.dart'; // 由json_serializable自动生成的部分
|
||||
@@ -38,11 +39,14 @@ class MHTHomeController extends GetControllerEx<MHTHomeModel> {
|
||||
|
||||
RxInt bindDeviceNum = 0.obs; //设备数量
|
||||
RxMap deviceList = {}.obs; //设备列表
|
||||
RxMap<String, List<dynamic>> sleepReportData = <String, List<dynamic>>{}.obs;
|
||||
RxMap<String, List<dynamic>> sleepReportData =
|
||||
<String, List<dynamic>>{}.obs; //睡眠报告
|
||||
RxList personnelList = [].obs; //人员信息列表
|
||||
|
||||
RxString keyWord = "".obs;
|
||||
|
||||
String wifiMac = "";
|
||||
var sleepDays = [].obs;
|
||||
|
||||
Future<ApiResponse> getDeviceNum() async {
|
||||
try {
|
||||
@@ -194,95 +198,95 @@ class MHTHomeController extends GetControllerEx<MHTHomeModel> {
|
||||
return ApiResponse(code: -1, msg: "未知错误".tr); // Default return statement
|
||||
}
|
||||
|
||||
Future<ApiResponse> getSleepReport() async {
|
||||
try {
|
||||
sleepReportData.value = {};
|
||||
ApiResponse<Map<String, List<dynamic>>> apiResponse = ApiResponse(
|
||||
code: -1,
|
||||
msg: "请求失败".tr,
|
||||
);
|
||||
// Future<ApiResponse> getSleepReport() async {
|
||||
// try {
|
||||
// sleepReportData.value = {};
|
||||
// ApiResponse<Map<String, List<dynamic>>> apiResponse = ApiResponse(
|
||||
// code: -1,
|
||||
// msg: "请求失败".tr,
|
||||
// );
|
||||
|
||||
if (deviceList.value.isEmpty) {
|
||||
return ApiResponse(
|
||||
code: HttpStatusCodes.ok,
|
||||
msg: "请求成功".tr,
|
||||
);
|
||||
}
|
||||
// if (deviceList.value.isEmpty) {
|
||||
// return ApiResponse(
|
||||
// code: HttpStatusCodes.ok,
|
||||
// msg: "请求成功".tr,
|
||||
// );
|
||||
// }
|
||||
|
||||
String serviceAddress = ServiceConstant.service_address;
|
||||
String serviceName = ServiceConstant.server_service;
|
||||
String serviceApi = ServiceConstant.sleep_report;
|
||||
// String serviceAddress = ServiceConstant.service_address;
|
||||
// String serviceName = ServiceConstant.server_service;
|
||||
// String serviceApi = ServiceConstant.sleep_report;
|
||||
|
||||
// for (var device in deviceList.value) {
|
||||
// String mac = device['mac'] ?? "";
|
||||
// if (mac.isEmpty) continue;
|
||||
// // for (var device in deviceList.value) {
|
||||
// // String mac = device['mac'] ?? "";
|
||||
// // if (mac.isEmpty) continue;
|
||||
|
||||
// sleepReportData[mac] = []; // 初始化当前设备的数据列表
|
||||
// // sleepReportData[mac] = []; // 初始化当前设备的数据列表
|
||||
|
||||
// String queryUrl =
|
||||
// "$serviceAddress$serviceName$serviceApi?mac=$mac&time=${DateTime.now().millisecondsSinceEpoch}";
|
||||
// // String queryUrl =
|
||||
// // "$serviceAddress$serviceName$serviceApi?mac=$mac&time=${DateTime.now().millisecondsSinceEpoch}";
|
||||
|
||||
// try {
|
||||
// String? language = "";
|
||||
// if (languageController.selectLanguage != null) {
|
||||
// language = languageController.selectLanguage.value!.language_code;
|
||||
// }
|
||||
// if (language != null && language.isNotEmpty) {
|
||||
// if (queryUrl.contains("?")) {
|
||||
// queryUrl += "&lang=$language";
|
||||
// } else {
|
||||
// queryUrl += "?lang=$language";
|
||||
// }
|
||||
// }
|
||||
// var response = await EasyDartModule.dio.get(queryUrl);
|
||||
// if (response != null) {
|
||||
// var responseData = response.data is String
|
||||
// ? jsonDecode(response.data)
|
||||
// : response.data;
|
||||
// // try {
|
||||
// // String? language = "";
|
||||
// // if (languageController.selectLanguage != null) {
|
||||
// // language = languageController.selectLanguage.value!.language_code;
|
||||
// // }
|
||||
// // if (language != null && language.isNotEmpty) {
|
||||
// // if (queryUrl.contains("?")) {
|
||||
// // queryUrl += "&lang=$language";
|
||||
// // } else {
|
||||
// // queryUrl += "?lang=$language";
|
||||
// // }
|
||||
// // }
|
||||
// // var response = await EasyDartModule.dio.get(queryUrl);
|
||||
// // if (response != null) {
|
||||
// // var responseData = response.data is String
|
||||
// // ? jsonDecode(response.data)
|
||||
// // : response.data;
|
||||
|
||||
// ApiResponse res =
|
||||
// ApiResponse.fromJson(responseData, (object) => object);
|
||||
// // ApiResponse res =
|
||||
// // ApiResponse.fromJson(responseData, (object) => object);
|
||||
|
||||
// if (res.code == HttpStatusCodes.ok && res.data != null) {
|
||||
// // 确保数据是一个列表
|
||||
// if (res.data is List) {
|
||||
// sleepReportData[mac] = List.from(res.data);
|
||||
// } else {
|
||||
// sleepReportData[mac] = [res.data];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } catch (e) {
|
||||
// EasyDartModule.logger.warning("请求设备 $mac 的睡眠数据失败: $e");
|
||||
// }
|
||||
// }
|
||||
if (sleepReportData.value.isNotEmpty) {
|
||||
// 遍历 Map 中的每一个键值对
|
||||
sleepReportData.value.forEach((key, report) {
|
||||
// 确保 report 列表不为空
|
||||
if (report.isNotEmpty) {
|
||||
// 获取该列表的最后一个元素
|
||||
var lastElement = report.last;
|
||||
// // if (res.code == HttpStatusCodes.ok && res.data != null) {
|
||||
// // // 确保数据是一个列表
|
||||
// // if (res.data is List) {
|
||||
// // sleepReportData[mac] = List.from(res.data);
|
||||
// // } else {
|
||||
// // sleepReportData[mac] = [res.data];
|
||||
// // }
|
||||
// // }
|
||||
// // }
|
||||
// // } catch (e) {
|
||||
// // EasyDartModule.logger.warning("请求设备 $mac 的睡眠数据失败: $e");
|
||||
// // }
|
||||
// // }
|
||||
// if (sleepReportData.value.isNotEmpty) {
|
||||
// // 遍历 Map 中的每一个键值对
|
||||
// sleepReportData.value.forEach((key, report) {
|
||||
// // 确保 report 列表不为空
|
||||
// if (report.isNotEmpty) {
|
||||
// // 获取该列表的最后一个元素
|
||||
// var lastElement = report.last;
|
||||
|
||||
// 给最后一个元素添加 selected 属性
|
||||
lastElement['selected'] = true; // 假设每个元素是一个 Map 类型
|
||||
}
|
||||
});
|
||||
}
|
||||
// // 给最后一个元素添加 selected 属性
|
||||
// lastElement['selected'] = true; // 假设每个元素是一个 Map 类型
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
updateAll();
|
||||
// updateAll();
|
||||
|
||||
return ApiResponse(
|
||||
code: HttpStatusCodes.ok,
|
||||
msg: "请求成功".tr,
|
||||
data: sleepReportData,
|
||||
);
|
||||
} catch (e) {
|
||||
EasyDartModule.logger.info("设备请求列表异常: $e");
|
||||
DailyLogUtils.writeLog("设备请求列表异常: $e");
|
||||
return ApiResponse(code: -1, msg: "未知错误".tr, data: {});
|
||||
}
|
||||
}
|
||||
// return ApiResponse(
|
||||
// code: HttpStatusCodes.ok,
|
||||
// msg: "请求成功".tr,
|
||||
// data: sleepReportData,
|
||||
// );
|
||||
// } catch (e) {
|
||||
// EasyDartModule.logger.info("设备请求列表异常: $e");
|
||||
// DailyLogUtils.writeLog("设备请求列表异常: $e");
|
||||
// return ApiResponse(code: -1, msg: "未知错误".tr, data: {});
|
||||
// }
|
||||
// }
|
||||
|
||||
updateDeviceShow(device) async {
|
||||
try {
|
||||
@@ -327,4 +331,94 @@ class MHTHomeController extends GetControllerEx<MHTHomeModel> {
|
||||
}
|
||||
return ApiResponse(code: -1, msg: "未知错误".tr); // Default return statement
|
||||
}
|
||||
|
||||
//查询人员信息列表
|
||||
Future<void> getPersonList() async {
|
||||
ApiResponse apiResponse = ApiResponse(code: -1, msg: "设备.设备列表请求失败".tr);
|
||||
String serviceAddress = ServiceConstant.service_address;
|
||||
String serviceName = ServiceConstant.server_service;
|
||||
String serviceApi = ServiceConstant.personnel_info;
|
||||
|
||||
// 初始URL
|
||||
String queryUrl = "$serviceAddress$serviceName$serviceApi";
|
||||
await requestWithLog(
|
||||
logTitle: "请求人员信息列表",
|
||||
method: MyHttpMethod.get,
|
||||
queryUrl: queryUrl,
|
||||
onSuccess: (res) {
|
||||
personnelList.value = res.data ?? [];
|
||||
},
|
||||
onFailure: (res) {
|
||||
EasyDartModule.logger.warning("请求人员信息列表失败: ${res.msg}");
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> getSleeps(String? mac) async {
|
||||
String serviceAddress = ServiceConstant.service_address;
|
||||
String serviceName = ServiceConstant.server_service;
|
||||
String serviceApi = ServiceConstant.sleep_report;
|
||||
String queryUrl = "$serviceAddress$serviceName$serviceApi";
|
||||
|
||||
// 当前时间的毫秒时间戳
|
||||
int timestamp = DateTime.now().millisecondsSinceEpoch;
|
||||
|
||||
// 拼接参数
|
||||
List<String> queryParams = [];
|
||||
|
||||
if (mac != null && mac.isNotEmpty) {
|
||||
queryParams.add("mac=$mac");
|
||||
}
|
||||
queryParams.add("time=$timestamp");
|
||||
|
||||
if (queryParams.isNotEmpty) {
|
||||
queryUrl += "?${queryParams.join("&")}";
|
||||
}
|
||||
|
||||
await requestWithLog(
|
||||
logTitle: "请求睡眠信息列表",
|
||||
method: MyHttpMethod.get,
|
||||
queryUrl: queryUrl,
|
||||
onSuccess: (res) {
|
||||
if (res.data != null && res.data is List) {
|
||||
List<dynamic> rawList = res.data;
|
||||
List<Map<String, dynamic>> processedList =
|
||||
rawList.map<Map<String, dynamic>>((item) {
|
||||
Map<String, dynamic> map = Map<String, dynamic>.from(item);
|
||||
|
||||
// 取出 time
|
||||
String? timeStr = map['time'];
|
||||
int? timeMillis = timeStr != null ? int.tryParse(timeStr) : null;
|
||||
|
||||
if (timeMillis != null) {
|
||||
DateTime dateTime =
|
||||
DateTime.fromMillisecondsSinceEpoch(timeMillis);
|
||||
|
||||
// 格式化 week 和 date
|
||||
String week = MyUtils.formatDateTimeWeek(dateTime);
|
||||
String date = MyUtils.formatDateTimeDay(dateTime);
|
||||
|
||||
// 添加到 map 中
|
||||
map['week'] = week;
|
||||
map['date'] = date;
|
||||
}
|
||||
|
||||
return map;
|
||||
}).toList();
|
||||
|
||||
// 赋值给 sleepDays
|
||||
sleepDays.value = processedList;
|
||||
} else {
|
||||
// 为空时直接赋空数组
|
||||
sleepDays.value = [];
|
||||
}
|
||||
|
||||
// 更新UI
|
||||
updateAll();
|
||||
},
|
||||
onFailure: (res) {
|
||||
EasyDartModule.logger.warning("请求睡眠信息列表失败: ${res.msg}");
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user