From 8687a4b0ddbaa874e7871e62bb850f915dc446b7 Mon Sep 17 00:00:00 2001 From: czz <862977248@qq.com> Date: Wed, 16 Jul 2025 18:48:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=BA=E5=91=98=E8=B5=84=E6=96=99=E7=94=9F?= =?UTF-8?q?=E6=97=A5=E6=95=B0=E6=8D=AE=E6=A0=BC=E5=BC=8F=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mh_controller/people_info_controller.dart | 19 +- lib/pages/common/selectDialog.dart | 209 +++++++++++++++++- lib/pages/mh_page/bluetooth.dart | 18 +- lib/pages/mh_page/device_people_info.dart | 5 +- lib/pages/mh_page/people_info.dart | 18 +- 5 files changed, 237 insertions(+), 32 deletions(-) diff --git a/lib/controller/mh_controller/people_info_controller.dart b/lib/controller/mh_controller/people_info_controller.dart index 5034a7d..42c8c80 100644 --- a/lib/controller/mh_controller/people_info_controller.dart +++ b/lib/controller/mh_controller/people_info_controller.dart @@ -1,10 +1,15 @@ +import 'dart:ui'; + import 'package:ef/ef.dart'; +import 'package:flutter/src/widgets/framework.dart'; import 'package:flutterflow_ui/flutterflow_ui.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:vbvs_app/common/color/ServiceConstant.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/controller/main_bottom/global_controller.dart'; +import 'package:vbvs_app/model/api_response.dart'; part 'people_info_controller.g.dart'; // 由json_serializable自动生成的部分 @@ -67,21 +72,27 @@ class PeopleInfoController extends GetControllerEx { ); } - savePeoples(Map data) async { + savePeoples(Map data, BuildContext context) async { String serviceAddress = ServiceConstant.service_address; String serviceName = ServiceConstant.server_service; String serviceApi = ServiceConstant.person_info; String queryUrl = "$serviceAddress$serviceName$serviceApi"; - requestWithLog( + String code = ''; + data['birthday'] = data['birthday'] is DateTime + ? DateFormat('yyyy-MM-dd').format(data['birthday']) + : data['birthday']; + await requestWithLog( logTitle: "更新人员信息", method: MyHttpMethod.put, queryUrl: queryUrl, data: data, onSuccess: (res) { - print("更新人员信息成功: $res"); + TopSlideNotification.show(context, + text: res.msg!, textColor: Color(0XFF00C1AA)); }, onFailure: (err) { - print("更新人员信息失败: $err"); + TopSlideNotification.show(context, + text: err.msg!, textColor: Color(0xFFFF7159)); }, ); } diff --git a/lib/pages/common/selectDialog.dart b/lib/pages/common/selectDialog.dart index 9146da1..ab22b72 100644 --- a/lib/pages/common/selectDialog.dart +++ b/lib/pages/common/selectDialog.dart @@ -271,6 +271,153 @@ Future showDateSelectionDialog(BuildContext context, ); } +// Future showMonthSelectionDialog( +// BuildContext context, { +// required DateTime checkDate, +// Function(DateTime)? checkChange, +// String title = "选择月份", +// }) { +// ThemeController themeController = Get.find(); + +// final List years = List.generate(100, (i) => DateTime.now().year - i) +// ..sort(); +// final List months = List.generate(12, (i) => i + 1); + +// final RxInt yearIndex = years.indexOf(checkDate.year).obs; +// final RxInt monthIndex = months.indexOf(checkDate.month).obs; + +// return showDialog( +// context: context, +// barrierDismissible: true, +// builder: (BuildContext context) { +// return Stack( +// children: [ +// Positioned( +// bottom: 0, +// left: 0, +// right: 0, +// child: Material( +// color: Colors.transparent, +// child: Dialog( +// backgroundColor: const Color(0xFF003058), +// insetPadding: EdgeInsets.zero, +// shape: RoundedRectangleBorder( +// borderRadius: BorderRadius.circular(0), +// ), +// child: Container( +// width: double.infinity, +// padding: EdgeInsets.fromLTRB(30.rpx, 10.rpx, 30.rpx, 90.rpx), +// child: Column( +// mainAxisSize: MainAxisSize.min, +// crossAxisAlignment: CrossAxisAlignment.center, +// children: [ +// Row( +// mainAxisAlignment: MainAxisAlignment.spaceBetween, +// children: [ +// ClickableContainer( +// backgroundColor: Colors.transparent, +// highlightColor: Colors.transparent, +// padding: EdgeInsets.zero, +// onTap: () => Navigator.of(context).pop(), +// child: Container( +// width: 100.rpx, +// height: 60.rpx, +// alignment: Alignment.center, +// child: Text("取消", +// style: TextStyle( +// fontSize: 30.rpx, color: Colors.white)), +// ), +// ), +// Text( +// title, +// style: TextStyle( +// fontFamily: 'Readex Pro', +// color: themeController.currentColor.sc3, +// fontSize: 30.rpx, +// ), +// ), +// ClickableContainer( +// backgroundColor: Colors.transparent, +// highlightColor: Colors.transparent, +// padding: EdgeInsets.zero, +// onTap: () { +// final selectedDate = DateTime( +// years[yearIndex.value], +// months[monthIndex.value], +// ); +// Navigator.of(context).pop(); +// checkChange?.call(selectedDate); +// }, +// child: Container( +// width: 100.rpx, +// height: 60.rpx, +// alignment: Alignment.center, +// child: Text("确定", +// style: TextStyle( +// fontSize: 30.rpx, +// color: stringToColor("#84F5FF"))), +// ), +// ), +// ], +// ), +// SizedBox(height: 20.rpx), +// Stack( +// children: [ +// Positioned.fill( +// child: IgnorePointer( +// child: Center( +// child: Container( +// height: 90.rpx, +// margin: +// EdgeInsets.symmetric(horizontal: 95.rpx), +// decoration: BoxDecoration( +// color: const Color(0xFF84F5FF), +// borderRadius: BorderRadius.circular(16.rpx), +// ), +// ), +// ), +// ), +// ), +// SizedBox( +// height: 240.rpx, +// child: Padding( +// padding: EdgeInsets.symmetric(horizontal: 95.rpx), +// child: Row( +// children: [ +// Expanded( +// child: getOnePickers( +// context, +// years, +// yearIndex, +// unit: "年", +// ), +// ), +// Expanded( +// child: getOnePickers( +// context, +// months, +// monthIndex, +// unit: "月", +// ), +// ), +// ], +// ), +// ), +// ), +// ], +// ), +// ], +// ), +// ), +// ), +// ), +// ), +// ], +// ); +// }, +// ); +// } + Future showMonthSelectionDialog( BuildContext context, { required DateTime checkDate, @@ -279,12 +426,42 @@ Future showMonthSelectionDialog( }) { ThemeController themeController = Get.find(); + final currentYear = DateTime.now().year; + final currentMonth = DateTime.now().month; + final List years = List.generate(100, (i) => DateTime.now().year - i) ..sort(); - final List months = List.generate(12, (i) => i + 1); - final RxInt yearIndex = years.indexOf(checkDate.year).obs; - final RxInt monthIndex = months.indexOf(checkDate.month).obs; + final RxList months = [].obs; + + // 初始化 yearIndex + final int initYearIndex = years.indexOf(checkDate.year); + final RxInt yearIndex = (initYearIndex >= 0 ? initYearIndex : 0).obs; + + final RxInt monthIndex = 0.obs; + + bool isInit = true; + + void updateMonthList() { + final selectedYear = years[yearIndex.value]; + final maxMonth = selectedYear == currentYear ? currentMonth : 12; + final newMonths = List.generate(maxMonth, (i) => i + 1); + months.value = newMonths; + + if (isInit) { + final int newMonthIndex = newMonths.indexOf(checkDate.month); + monthIndex.value = newMonthIndex >= 0 ? newMonthIndex : 0; + isInit = false; + } else { + if (monthIndex.value >= newMonths.length) { + monthIndex.value = newMonths.length - 1; + } + } + } + + updateMonthList(); + + ever(yearIndex, (_) => updateMonthList()); return showDialog( context: context, @@ -311,6 +488,7 @@ Future showMonthSelectionDialog( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.center, children: [ + // 顶部标题与按钮 Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -323,9 +501,13 @@ Future showMonthSelectionDialog( width: 100.rpx, height: 60.rpx, alignment: Alignment.center, - child: Text("取消", - style: TextStyle( - fontSize: 30.rpx, color: Colors.white)), + child: Text( + "取消", + style: TextStyle( + fontSize: 30.rpx, + color: Colors.white, + ), + ), ), ), Text( @@ -352,15 +534,19 @@ Future showMonthSelectionDialog( width: 100.rpx, height: 60.rpx, alignment: Alignment.center, - child: Text("确定", - style: TextStyle( - fontSize: 30.rpx, - color: stringToColor("#84F5FF"))), + child: Text( + "确定", + style: TextStyle( + fontSize: 30.rpx, + color: stringToColor("#84F5FF"), + ), + ), ), ), ], ), SizedBox(height: 20.rpx), + // 中间选中高亮背景 Stack( children: [ Positioned.fill( @@ -378,6 +564,7 @@ Future showMonthSelectionDialog( ), ), ), + // 滚轮选择器 SizedBox( height: 240.rpx, child: Padding( @@ -395,7 +582,7 @@ Future showMonthSelectionDialog( Expanded( child: getOnePickers( context, - months, + months, // 注意这里取 .value monthIndex, unit: "月", ), diff --git a/lib/pages/mh_page/bluetooth.dart b/lib/pages/mh_page/bluetooth.dart index 837a081..771fd2b 100644 --- a/lib/pages/mh_page/bluetooth.dart +++ b/lib/pages/mh_page/bluetooth.dart @@ -179,27 +179,27 @@ class _BluetoothPageState extends State { // 蓝牙连接状态 Column( children: [ - obsData['blueToothStatus'] == 1 + obsData['blueToothStatus'] == 2 ? SvgPicture.asset( - 'assets/img/icon/blue_fail.svg', + 'assets/img/icon/blue_success.svg', width: 68.rpx, height: 68.rpx, ) : SvgPicture.asset( - 'assets/img/icon/blue_success.svg', + 'assets/img/icon/blue_fail.svg', width: 68.rpx, height: 68.rpx, ), SizedBox(height: 4), //下面文字和颜色也根据上面变化 Text( - obsData['blueToothStatus'] == 1 - ? '未连接' - : '已连接', + obsData['blueToothStatus'] == 2 + ? '已连接' + : '未连接', style: TextStyle( - color: obsData['blueToothStatus'] == 1 - ? Color(0xFFFF7159) - : Color(0xFF6BFDAC), + color: obsData['blueToothStatus'] == 2 + ? Color(0xFF6BFDAC) + : Color(0xFFFF7159), fontSize: 26.rpx)), ], ), diff --git a/lib/pages/mh_page/device_people_info.dart b/lib/pages/mh_page/device_people_info.dart index 196a0a3..864d427 100644 --- a/lib/pages/mh_page/device_people_info.dart +++ b/lib/pages/mh_page/device_people_info.dart @@ -35,6 +35,9 @@ class DevicePeopleInfo extends GetView { @override Widget build(BuildContext context) { + WidgetsBinding.instance.addPostFrameCallback((_) { + controller.getPeoples (data['mac']); + }); return LayoutBuilder( builder: (context, boxConstraints) => GestureDetector( onTap: () => FocusScope.of(context).unfocus(), @@ -135,7 +138,7 @@ class DevicePeopleInfo extends GetView { "房间:${data["roomName"] ?? "-"}"), getInfoRow( context, - "网络:${data["status"]?["status"] == 1 ? "在线" : data["status"]?["status"] == 0 ? "不在线" : "-"}", + "设备状态:${data["status"]?["status"] == 1 ? "已绑定" : data["status"]?["status"] == 0 ? "已绑定" : "-"}", ), getInfoRow( context, "MAC:${data["mac"] ?? "-"}"), diff --git a/lib/pages/mh_page/people_info.dart b/lib/pages/mh_page/people_info.dart index 58061d5..aa99a8e 100644 --- a/lib/pages/mh_page/people_info.dart +++ b/lib/pages/mh_page/people_info.dart @@ -84,7 +84,6 @@ class PeopleInfoPage extends GetView { gradientDirection: GradientDirection.vertical, onTap: () async { bool isValid = true; - // 数据验证 for (int i = 0; i < controller.model.peopleList.length; @@ -125,15 +124,11 @@ class PeopleInfoPage extends GetView { break; } } - // 所有数据合法,开始保存 if (isValid) { for (var data in controller.model.peopleList) { try { - await controller.savePeoples(data); - TopSlideNotification.show(context, - text: "更新成功".tr, - textColor: Color(0XFF00C1AA)); + await controller.savePeoples(data, context); MHTHomeController mhtHomeController = Get.find(); mhtHomeController.getPersonList(); @@ -652,6 +647,16 @@ class PeopleInfoPage extends GetView { controller .updateAll(); print("$d"); + // final String dateStr = + // "${d.year}-${d.month.toString().padLeft(2, '0')}"; + + // controller.model.peopleList[ + // index] + // ['birthday'] = + // dateStr; + // controller + // .updateAll(); + // print(dateStr); }); }); }, @@ -781,7 +786,6 @@ class PeopleInfoPage extends GetView { .peopleList[ index] ['contact'] = value; - controller.updateAll(); }, controller: controller.onReDraw( TextEditingController(