From 327a78e8294217ef8968647631585d6b1ee8e496 Mon Sep 17 00:00:00 2001 From: Daisy <> Date: Thu, 16 May 2024 10:19:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=93=8D=E4=BD=9C=E8=AE=B0?= =?UTF-8?q?=E5=BD=95bug--=E6=B2=A1=E6=9C=89=E6=97=B6=E9=97=B4=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../doorLockLog/doorLockLog_logic.dart | 65 +++++++++++-------- .../doorLockLog/doorLockLog_page.dart | 54 +++++++++++---- .../doorLockLog/doorLockLog_state.dart | 12 +++- .../tools/advancedCalendar/src/header.dart | 3 +- .../tools/advancedCalendar/src/widget.dart | 2 + 5 files changed, 92 insertions(+), 44 deletions(-) diff --git a/star_lock/lib/main/lockDetail/doorLockLog/doorLockLog_logic.dart b/star_lock/lib/main/lockDetail/doorLockLog/doorLockLog_logic.dart index d70d0b97..d58f7011 100644 --- a/star_lock/lib/main/lockDetail/doorLockLog/doorLockLog_logic.dart +++ b/star_lock/lib/main/lockDetail/doorLockLog/doorLockLog_logic.dart @@ -1,7 +1,7 @@ - import 'dart:async'; import 'package:flutter_blue_plus/flutter_blue_plus.dart'; +import 'package:get_storage/get_storage.dart'; import 'package:star_lock/main/lockDetail/doorLockLog/doorLockLog_entity.dart'; import 'package:star_lock/main/lockDetail/doorLockLog/doorLockLog_state.dart'; @@ -26,16 +26,17 @@ class DoorLockLogLogic extends BaseGetXController { // 获取解析后的数据 late StreamSubscription _replySubscription; void _initReplySubscription() { - _replySubscription = EventBusManager().eventBus!.on().listen((reply) { - - if (reply is SenderReferEventRecordTimeReply && state.ifCurrentScreen.value == true) { + _replySubscription = + EventBusManager().eventBus!.on().listen((reply) { + if (reply is SenderReferEventRecordTimeReply && + state.ifCurrentScreen.value == true) { _replyReferEventRecordTime(reply); } }); } // 根据时间查解析数据 - Future _replyReferEventRecordTime(Reply reply) async { + Future _replyReferEventRecordTime(Reply reply) async { cancelBlueConnetctToastTimer(); int status = reply.data[2]; switch (status) { @@ -47,7 +48,7 @@ class DoorLockLogLogic extends BaseGetXController { if (dataLength > 0) { reply.data.removeRange(0, 7); // 把得到的数据按8位分割成数组 然后塞进一个新的数组里面 - if(reply.data.length < 17){ + if (reply.data.length < 17) { return; } var getList = splitList(reply.data, 17); @@ -59,27 +60,27 @@ class DoorLockLogLogic extends BaseGetXController { var indexMap = {}; indexMap["type"] = indexList[0].toString(); - if(indexList[0] == 2){ + if (indexList[0] == 2) { var passwordData = indexList.sublist(7, 17); var password = utf8String(passwordData); indexMap["user"] = password.toString(); - }else{ - int userNo = (indexList[1]*255) + indexList[2]; + } else { + int userNo = (indexList[1] * 255) + indexList[2]; indexMap["user"] = userNo.toString(); } indexMap["success"] = "1"; int time = ((0xff & indexList[(3)]) << 24 | - (0xff & indexList[4]) << 16 | - (0xff & indexList[5]) << 8 | - (0xFF & indexList[6])); + (0xff & indexList[4]) << 16 | + (0xff & indexList[5]) << 8 | + (0xFF & indexList[6])); indexMap["date"] = "${time * 1000}"; uploadList.add(indexMap); } lockRecordUploadData(uploadList); - if(dataLength == state.logCountPage){ + if (dataLength == state.logCountPage) { state.ifHaveNext = true; } } @@ -97,10 +98,11 @@ class DoorLockLogLogic extends BaseGetXController { // 查询事件记录(时间查询) Future senderReferEventRecordTime() async { showEasyLoading(); - showBlueConnetctToastTimer(action: (){ + showBlueConnetctToastTimer(action: () { dismissEasyLoading(); }); - BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionStateState) async { + BlueManage().bludSendData(BlueManage().connectDeviceName, + (BluetoothConnectionState connectionStateState) async { if (connectionStateState == BluetoothConnectionState.connected) { var privateKey = await Storage.getStringList(saveBluePrivateKey); List getPrivateKeyList = changeStringListToIntList(privateKey!); @@ -122,10 +124,11 @@ class DoorLockLogLogic extends BaseGetXController { publicKey: getPublicKeyList, privateKey: getPrivateKeyList, ); - } else if (connectionStateState == BluetoothConnectionState.disconnected) { + } else if (connectionStateState == + BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); - if(state.ifCurrentScreen.value == true){ + if (state.ifCurrentScreen.value == true) { showBlueConnetctToast(); } } @@ -141,9 +144,16 @@ class DoorLockLogLogic extends BaseGetXController { pageSize: int.parse(pageSize), startDate: state.startDate.value, endDate: state.endDate.value); - if (entity.errorCode!.codeIsSuccessful) { - state.lockLogItemList.value = entity.data!.itemList!; + if (pageNo == 1) { + state.lockLogItemList.value = entity.data!.itemList!; + pageNo++; + } else { + if (entity.data!.itemList!.isNotEmpty) { + state.lockLogItemList.addAll(entity.data!.itemList!); + pageNo++; + } + } } } @@ -152,15 +162,18 @@ class DoorLockLogLogic extends BaseGetXController { void _getDoorLockLogListRefreshUIAction() { _getDoorLockLogListRefreshUIEvent = eventBus.on().listen((event) { + state.currentSelectDate.value = event.getDoorLockLogTime; // 设置startDate为当天的0点 - state.startDate.value = DateTime(event.getDoorLockLogTime.year, - event.getDoorLockLogTime.month, event.getDoorLockLogTime.day) + state.startDate.value = DateTime( + state.currentSelectDate.value.year, + state.currentSelectDate.value.month, + state.currentSelectDate.value.day) .millisecondsSinceEpoch; // 设置endDate为下一天的0点,然后减去1毫秒 state.endDate.value = (DateTime( - event.getDoorLockLogTime.year, - event.getDoorLockLogTime.month, - event.getDoorLockLogTime.day + 1) + state.currentSelectDate.value.year, + state.currentSelectDate.value.month, + state.currentSelectDate.value.day + 1) .subtract(const Duration(milliseconds: 1))) .millisecondsSinceEpoch; @@ -186,9 +199,9 @@ class DoorLockLogLogic extends BaseGetXController { .lockRecordUploadData( lockId: state.keyInfos.value.lockId.toString(), records: list); if (entity.errorCode!.codeIsSuccessful) { - if(state.ifHaveNext == true){ + if (state.ifHaveNext == true) { getLockRecordLastUploadDataTime(); - }else{ + } else { pageNo = 1; mockNetworkDataRequest(); } diff --git a/star_lock/lib/main/lockDetail/doorLockLog/doorLockLog_page.dart b/star_lock/lib/main/lockDetail/doorLockLog/doorLockLog_page.dart index 37dc796e..7350085e 100644 --- a/star_lock/lib/main/lockDetail/doorLockLog/doorLockLog_page.dart +++ b/star_lock/lib/main/lockDetail/doorLockLog/doorLockLog_page.dart @@ -5,6 +5,7 @@ import 'package:get/get.dart'; import 'package:star_lock/appRouters.dart'; import 'package:star_lock/main/lockDetail/doorLockLog/doorLockLog_entity.dart'; import 'package:star_lock/main/lockDetail/doorLockLog/doorLockLog_logic.dart'; +import 'package:star_lock/tools/EasyRefreshTool.dart'; import 'package:star_lock/tools/advancedCalendar/src/widget.dart'; import 'package:star_lock/tools/menuItem/xsDropDownWidget.dart'; import 'package:star_lock/tools/noData.dart'; @@ -52,7 +53,17 @@ class _DoorLockLogPageState extends State with RouteAware { endIndent: 30.w, ), eventDropDownWidget(), - Expanded(child: Obx(() => timeLineView(state.lockLogItemList))) + Expanded( + child: EasyRefreshTool( + onRefresh: () { + logic.pageNo = 1; + logic.mockNetworkDataRequest(); + }, + onLoad: () { + logic.mockNetworkDataRequest(); + }, + child: Obx(() => timeLineView(state.lockLogItemList)), + )) ], ), ); @@ -81,19 +92,34 @@ class _DoorLockLogPageState extends State with RouteAware { highlightColor: Colors.yellow, disabledColor: Colors.grey, ), - child: AdvancedCalendar( - controller: state.calendarControllerCustom, - events: state.events, - weekLineHeight: 48.0, - startWeekDay: 1, - innerDot: true, - keepLineSize: true, - calendarTextStyle: const TextStyle( - fontSize: 18, - fontWeight: FontWeight.w400, - height: 1.3125, - letterSpacing: 0, - ), + child: Stack( + children: [ + AdvancedCalendar( + controller: state.calendarControllerCustom, + events: state.events, + weekLineHeight: 48.0, + startWeekDay: 1, + innerDot: true, + keepLineSize: true, + calendarTextStyle: const TextStyle( + fontSize: 18, + fontWeight: FontWeight.w400, + height: 1.3125, + letterSpacing: 0, + ), + ), + Positioned( + top: 8.0, + right: 8.0, + child: Obx(() => Text( + '${state.currentSelectDate.value.year}年${state.currentSelectDate.value.month}月', + style: theme.textTheme.titleMedium!.copyWith( + fontSize: 16, + color: theme.colorScheme.secondary, + ), + )), + ), + ], ), ); } diff --git a/star_lock/lib/main/lockDetail/doorLockLog/doorLockLog_state.dart b/star_lock/lib/main/lockDetail/doorLockLog/doorLockLog_state.dart index 5edae651..0fd6d1a7 100644 --- a/star_lock/lib/main/lockDetail/doorLockLog/doorLockLog_state.dart +++ b/star_lock/lib/main/lockDetail/doorLockLog/doorLockLog_state.dart @@ -17,8 +17,15 @@ class DoorLockLogState { DateTime(2024, 10, 10), ]; - final startDate = DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day).millisecondsSinceEpoch.obs; - final endDate = (DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day + 1).subtract(const Duration(milliseconds: 1))).millisecondsSinceEpoch.obs; + final startDate = + DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day) + .millisecondsSinceEpoch + .obs; + final endDate = (DateTime( + DateTime.now().year, DateTime.now().month, DateTime.now().day + 1) + .subtract(const Duration(milliseconds: 1))) + .millisecondsSinceEpoch + .obs; var dropdownTitle = '全部事件'.obs; var dropdownValue = XSConstantMacro.lockEventTypeAll.obs; @@ -50,6 +57,7 @@ class DoorLockLogState { var operateDate = 0; // 按日期查询消息记录的时间戳 var ifHaveNext = false; // 页码 var logCountPage = 10; // 蓝牙记录一页多少个 + var currentSelectDate = DateTime.now().obs; // 当前选择的日期 DoorLockLogState() { keyInfos.value = Get.arguments["keyInfo"]; diff --git a/star_lock/lib/tools/advancedCalendar/src/header.dart b/star_lock/lib/tools/advancedCalendar/src/header.dart index 1a09140e..026da55b 100644 --- a/star_lock/lib/tools/advancedCalendar/src/header.dart +++ b/star_lock/lib/tools/advancedCalendar/src/header.dart @@ -15,8 +15,7 @@ class Header extends StatelessWidget { this.todayStyle, }) : super(key: key); - static final _dateFormatter = DateFormat().add_yMMMM(); - // static final _dateFormatter = DateFormat('MM月dd日', 'zh_CN'); + static final _dateFormatter = DateFormat.yM('zh_CN'); final DateTime monthDate; final EdgeInsetsGeometry margin; final VoidCallback? onPressed; diff --git a/star_lock/lib/tools/advancedCalendar/src/widget.dart b/star_lock/lib/tools/advancedCalendar/src/widget.dart index 001840af..04ab9c31 100644 --- a/star_lock/lib/tools/advancedCalendar/src/widget.dart +++ b/star_lock/lib/tools/advancedCalendar/src/widget.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:intl/date_symbol_data_local.dart';