From fc7b487f8a318731bb6ef49ba551be8c617dae28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=8F=E5=B0=91=E9=98=B3?= <786612630@qq.com> Date: Tue, 23 Apr 2024 15:15:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=94=A8=E6=88=B7=E7=AC=AC?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=E8=BF=9B=E8=A1=8C=E8=93=9D=E7=89=99=E5=8D=8F?= =?UTF-8?q?=E8=AE=AE=E4=BA=A4=E4=BA=92=EF=BC=8C=E6=B7=BB=E5=8A=A0=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- star_lock/lib/blue/io_reply.dart | 2 +- .../lib/blue/sender_beforeDataManage.dart | 158 ++++++++++ star_lock/lib/blue/sender_data.dart | 38 ++- .../lockDetail/lockDetail_logic.dart | 276 +++++++++--------- .../lockDetail/lockDetail_page.dart | 41 ++- .../lockSet/lockSet/lockSet_logic.dart | 3 + .../addLock/nearbyLock/nearbyLock_page.dart | 5 - .../mine/addLock/saveLock/saveLock_logic.dart | 2 +- star_lock/lib/tools/commonDataManage.dart | 8 +- star_lock/lib/tools/eventBusEventManage.dart | 7 + star_lock/lib/tools/storage.dart | 2 +- 11 files changed, 369 insertions(+), 173 deletions(-) create mode 100644 star_lock/lib/blue/sender_beforeDataManage.dart diff --git a/star_lock/lib/blue/io_reply.dart b/star_lock/lib/blue/io_reply.dart index 8b7252bc..d9e7f010 100644 --- a/star_lock/lib/blue/io_reply.dart +++ b/star_lock/lib/blue/io_reply.dart @@ -48,7 +48,7 @@ abstract class Reply{ case 0x06: // 需要鉴权 Get.log("${commandType!.typeName}需要鉴权"); - showErrorMessage("需要鉴权"); + // showErrorMessage("需要鉴权"); break; case 0x07: // 无权限 diff --git a/star_lock/lib/blue/sender_beforeDataManage.dart b/star_lock/lib/blue/sender_beforeDataManage.dart new file mode 100644 index 00000000..734aa793 --- /dev/null +++ b/star_lock/lib/blue/sender_beforeDataManage.dart @@ -0,0 +1,158 @@ + + +import 'dart:async'; + +import 'package:get/get.dart'; +import 'package:star_lock/blue/sender_manage.dart'; +import 'package:star_lock/tools/baseGetXController.dart'; +import 'package:star_lock/tools/eventBusEventManage.dart'; + +import '../main/lockDetail/lockDetail/lockNetToken_entity.dart'; +import '../network/api_repository.dart'; +import '../tools/commonDataManage.dart'; +import '../tools/storage.dart'; +import 'blue_manage.dart'; +import 'io_protocol/io_addUser.dart'; +import 'io_reply.dart'; +import 'io_tool/io_tool.dart'; +import 'io_tool/manager_event_bus.dart'; + +class SenderBeforeDataManage { + static SenderBeforeDataManage? _manager; + SenderBeforeDataManage._init(); + + static SenderBeforeDataManage? shareManager() { + _manager ??= SenderBeforeDataManage._init(); + _manager!._init(); + return _manager; + } + + factory SenderBeforeDataManage() => shareManager()!; + SenderBeforeDataManage? get manager => shareManager(); + + void _init() { + _initReplySubscription(); + } + + // 监听设备返回的数据 + StreamSubscription? _replySubscription; + void _initReplySubscription() { + _replySubscription ??= EventBusManager().eventBus!.on().listen((reply) async { + + // 添加用户 + if ((reply is AddUserReply)) { + _replyAddUserKey(reply); + } + }); + } + + // 添加用户 + Future _replyAddUserKey(Reply reply) async { + // var lockId = reply.data.sublist(2, 42); + // print("lockId:$lockId"); + + int status = reply.data[46]; + // print("status:$status reply.data:${reply.data}"); + + print("status:$status"); + switch (status) { + case 0x00: + //成功 + CommonDataManage().currentLockUserNo = reply.data[47]; + CommonDataManage().currentKeyInfo.lockUserNo = CommonDataManage().currentLockUserNo; + _updateLockUserNo(); + break; + case 0x06: + //无权限 + var privateKey = await Storage.getStringList(saveBluePrivateKey); + List getPrivateKeyList = changeStringListToIntList(privateKey!); + + var publicKey = await Storage.getStringList(saveBluePublicKey); + List publicKeyDataList = changeStringListToIntList(publicKey!); + + var token = reply.data.sublist(42, 46); + List strTokenList = changeIntListToStringList(token); + Storage.setStringList(saveBlueToken, strTokenList); + // print("token:$token"); + + // IoSenderManage.senderAddUser( + // lockID: BlueManage().connectDeviceName, + // authUserID: CommonDataManage().currentKeyInfo.senderUserId!.toString(), + // keyID: CommonDataManage().currentKeyInfo.keyId.toString(), + // userID: await Storage.getUid(), + // openMode: 1, + // keyType: 0, + // startDate: CommonDataManage().currentKeyInfo.startDate!~/10000, + // expireDate: CommonDataManage().currentKeyInfo.endDate!~/10000, + // role: CommonDataManage().currentKeyInfo.keyRight == 1 ? 1 : 0, + // password: "123456", + // needAuthor: 1, + // publicKey: publicKeyDataList, + // privateKey: getPrivateKeyList, + // token: token); + var addUserData = AddUserCommand( + lockID: BlueManage().connectDeviceName, + authUserID: CommonDataManage().currentKeyInfo.senderUserId!.toString(), + keyID: CommonDataManage().currentKeyInfo.keyId.toString(), + userID: await Storage.getUid(), + openMode: 1, + keyType: 0, + startDate: CommonDataManage().currentKeyInfo.startDate!~/10000, + expireDate: CommonDataManage().currentKeyInfo.endDate!~/10000, + role: CommonDataManage().currentKeyInfo.keyRight == 1 ? 1 : 0, + password: "123456", + needAuthor: 1, + publicKey: publicKeyDataList, + privateKey: getPrivateKeyList, + token: token); + eventBus.fire(LockAddUserSucceedEvent(addUserData.packageData(), 1)); + break; + default: + //失败 + break; + } + } + + Future> getAddUserKeyData() async { + var privateKey = await Storage.getStringList(saveBluePrivateKey); + List getPrivateKeyList = changeStringListToIntList(privateKey!); + + var publicKey = await Storage.getStringList(saveBluePublicKey); + List publicKeyDataList = changeStringListToIntList(publicKey!); + + var token = await Storage.getStringList(saveBlueToken); + List getTokenList = changeStringListToIntList(token!); + + var addUserData = AddUserCommand( + lockID: BlueManage().connectDeviceName, + authUserID: CommonDataManage().currentKeyInfo.senderUserId!.toString(), + keyID: CommonDataManage().currentKeyInfo.keyId.toString(), + userID: await Storage.getUid(), + openMode: 1, + keyType: 0, + startDate: CommonDataManage().currentKeyInfo.startDate!~/10000, + expireDate: CommonDataManage().currentKeyInfo.endDate!~/10000, + role: CommonDataManage().currentKeyInfo.keyRight == 1 ? 1 : 0, + password: "123456", + needAuthor: 1, + publicKey: publicKeyDataList, + privateKey: getPrivateKeyList, + token: getTokenList); + return addUserData.packageData(); + } + + // 普通用户接收电子钥匙之后 更新锁用户NO + void _updateLockUserNo() async { + LockNetTokenEntity entity = await ApiRepository.to.updateLockUserNo( + keyId: CommonDataManage().currentKeyInfo.keyId.toString(), + lockUserNo: CommonDataManage().currentKeyInfo.lockUserNo.toString() + ); + if (entity.errorCode!.codeIsSuccessful) { + eventBus.fire(LockAddUserSucceedEvent([0], 0)); + } + } + + dispose() { + _replySubscription!.cancel(); + } +} \ No newline at end of file diff --git a/star_lock/lib/blue/sender_data.dart b/star_lock/lib/blue/sender_data.dart index 38ef5ad9..90c45722 100644 --- a/star_lock/lib/blue/sender_data.dart +++ b/star_lock/lib/blue/sender_data.dart @@ -1,15 +1,19 @@ +import 'dart:async'; + import '../app_settings/app_settings.dart'; +import '../tools/commonDataManage.dart'; +import '../tools/eventBusEventManage.dart'; import 'io_sender.dart'; import 'io_type.dart'; import 'io_tool/io_model.dart'; import 'io_tool/manager_event_bus.dart'; +import 'sender_beforeDataManage.dart'; typedef CommandSendCallBack = void Function(ErrorType errorType); class CommandSenderManager { - static final CommandSenderManager _manager = CommandSenderManager - ._init(); + static final CommandSenderManager _manager = CommandSenderManager._init(); factory CommandSenderManager()=>_manager; static CommandSenderManager getInstance()=>_manager; CommandSenderManager._init(){ @@ -17,7 +21,21 @@ class CommandSenderManager { } init(){ + initLockAddUserSucceedEvent(); + } + // 下级界面修改成功后传递数据 + StreamSubscription? _passCurrentLockInformationEvent; + List dataBeforeAddTheUser = []; + void initLockAddUserSucceedEvent() { + // 蓝牙协议通知传输跟蓝牙之外的数据传输类不一样 eventBus + _passCurrentLockInformationEvent = eventBus.on().listen((event) { + if(event.type == 0){ + _sendNormalData(dataBeforeAddTheUser); + }else{ + _sendNormalData(event.dataList); + } + }); } // CommandType lastCommandType = CommandType.readLockStatusInfo; @@ -37,8 +55,17 @@ class CommandSenderManager { } List value = command.packageData(); - // print("sendData:${value}"); - _sendNormalData(value); + print("CommonDataManage().currentLockUserNo:${CommonDataManage().currentLockUserNo}"); + if(CommonDataManage().currentLockUserNo == 0){ + // 先添加用户 + var entity = await SenderBeforeDataManage().getAddUserKeyData(); + _sendNormalData(entity); + dataBeforeAddTheUser = value; + return; + }else{ + print("继续发送数据了继续发送数据了继续发送数据了"); + _sendNormalData(value); + } } void _sendNormalData(List data) async { @@ -102,4 +129,7 @@ class CommandSenderManager { // bufferList = []; // } + dispose() { + _passCurrentLockInformationEvent?.cancel(); + } } \ No newline at end of file diff --git a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart index f5c06470..a526a03f 100644 --- a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart +++ b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart @@ -57,9 +57,9 @@ class LockDetailLogic extends BaseGetXController { } // 添加用户 - if ((reply is AddUserReply) && (state.ifCurrentScreen.value == true)) { - _replyAddUserKey(reply); - } + // if ((reply is AddUserReply) && (state.ifCurrentScreen.value == true)) { + // _replyAddUserKey(reply); + // } }); } @@ -297,126 +297,126 @@ class LockDetailLogic extends BaseGetXController { } } - // 添加用户 - Future _replyAddUserKey(Reply reply) async { - var lockId = reply.data.sublist(2, 42); - // print("lockId:$lockId"); - - var token = reply.data.sublist(42, 46); - List strTokenList = changeIntListToStringList(token); - Storage.setStringList(saveBlueToken, strTokenList); - // print("token:$token"); - - int status = reply.data[46]; - // print("status:$status reply.data:${reply.data}"); - - print("status:$status"); - switch (status) { - case 0x00: - //成功 - Get.log("添加用户数据解析成功"); - cancelBlueConnetctToastTimer(); - state.lockUserNo = reply.data[47]; - _updateLockUserNo(); - - break; - case 0x06: - //无权限 - Get.log("需要鉴权"); - var privateKey = await Storage.getStringList(saveBluePrivateKey); - List getPrivateKeyList = changeStringListToIntList(privateKey!); - - var publicKey = await Storage.getStringList(saveBluePublicKey); - List publicKeyDataList = changeStringListToIntList(publicKey!); - - IoSenderManage.senderAddUser( - lockID: BlueManage().connectDeviceName, - authUserID: state.senderUserId.toString(), - keyID: state.keyInfos.value.keyId.toString(), - userID: await Storage.getUid(), - openMode: 1, - keyType: 0, - startDate: state.keyInfos.value.startDate!~/10000, - expireDate: state.keyInfos.value.endDate!~/10000, - role: state.keyInfos.value.keyRight == 1 ? 1 : 0, - password: "123456", - needAuthor: 1, - publicKey: publicKeyDataList, - privateKey: getPrivateKeyList, - token: token); - break; - default: - //失败 - Get.log("领锁失败"); - - break; - } - } + // // 添加用户 + // Future _replyAddUserKey(Reply reply) async { + // var lockId = reply.data.sublist(2, 42); + // // print("lockId:$lockId"); + // + // var token = reply.data.sublist(42, 46); + // List strTokenList = changeIntListToStringList(token); + // Storage.setStringList(saveBlueToken, strTokenList); + // // print("token:$token"); + // + // int status = reply.data[46]; + // // print("status:$status reply.data:${reply.data}"); + // + // print("status:$status"); + // switch (status) { + // case 0x00: + // //成功 + // Get.log("添加用户数据解析成功"); + // cancelBlueConnetctToastTimer(); + // state.lockUserNo = reply.data[47]; + // _updateLockUserNo(); + // + // break; + // case 0x06: + // //无权限 + // Get.log("需要鉴权"); + // var privateKey = await Storage.getStringList(saveBluePrivateKey); + // List getPrivateKeyList = changeStringListToIntList(privateKey!); + // + // var publicKey = await Storage.getStringList(saveBluePublicKey); + // List publicKeyDataList = changeStringListToIntList(publicKey!); + // + // IoSenderManage.senderAddUser( + // lockID: BlueManage().connectDeviceName, + // authUserID: state.senderUserId.toString(), + // keyID: state.keyInfos.value.keyId.toString(), + // userID: await Storage.getUid(), + // openMode: 1, + // keyType: 0, + // startDate: state.keyInfos.value.startDate!~/10000, + // expireDate: state.keyInfos.value.endDate!~/10000, + // role: state.keyInfos.value.keyRight == 1 ? 1 : 0, + // password: "123456", + // needAuthor: 1, + // publicKey: publicKeyDataList, + // privateKey: getPrivateKeyList, + // token: token); + // break; + // default: + // //失败 + // Get.log("领锁失败"); + // + // break; + // } + // } // 添加用户(普通用户接收电子钥匙) - Future addUserConnectBlue() async { - showBlueConnetctToastTimer(action: () { - state.openLockBtnState.value = 0; - eventBus.fire(RefreshLockDetailInfoDataEvent()); - }); - - // var listData = AddUserCommand( - // lockID: BlueManage().connectDeviceName, - // authUserID: state.senderUserId.toString(), - // keyID: state.keyInfos.value.keyId.toString(), - // userID: await Storage.getUid(), - // openMode: 1, - // keyType: 0, - // startDate: state.keyInfos.value.startDate!~/10000, - // expireDate: state.keyInfos.value.endDate!~/10000, - // role: state.keyInfos.value.keyRight == 1 ? 1 : 0, - // password: "123456", - // needAuthor: 1, - // publicKey: publicKeyDataList, - // privateKey: getPrivateKeyList, - // token: getTokenList).packageData(); - BlueManage().bludSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!, (BluetoothConnectionState deviceConnectionState) async { - if (deviceConnectionState == BluetoothConnectionState.connected) { - // 私钥 - var privateKey = await Storage.getStringList(saveBluePrivateKey); - List getPrivateKeyList = changeStringListToIntList(privateKey!); - - var publicKey = await Storage.getStringList(saveBluePublicKey); - List publicKeyDataList = changeStringListToIntList(publicKey!); - - var token = await Storage.getStringList(saveBlueToken); - List getTokenList = [0, 0, 0, 0]; - if (token != null) { - getTokenList = changeStringListToIntList(token); - } - - Get.log("BlueManage().connectDeviceName:${BlueManage().connectDeviceName} authUserID:${state.senderUserId.toString()} keyID:${state.keyInfos.value.keyId.toString()} userID:${await Storage.getUid()}"); - IoSenderManage.senderAddUser( - lockID: BlueManage().connectDeviceName, - authUserID: state.senderUserId.toString(), - keyID: state.keyInfos.value.keyId.toString(), - userID: await Storage.getUid(), - openMode: 1, - keyType: 0, - startDate: state.keyInfos.value.startDate!~/10000, - expireDate: state.keyInfos.value.endDate!~/10000, - role: state.keyInfos.value.keyRight == 1 ? 1 : 0, - password: "123456", - needAuthor: 1, - publicKey: publicKeyDataList, - privateKey: getPrivateKeyList, - token: getTokenList); - } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { - cancelBlueConnetctToastTimer(); - if (state.ifCurrentScreen.value == true) { - showBlueConnetctToast(); - } - - state.openLockBtnState.value = 0; - eventBus.fire(RefreshLockDetailInfoDataEvent()); - } - }); - } + // Future addUserConnectBlue() async { + // showBlueConnetctToastTimer(action: () { + // state.openLockBtnState.value = 0; + // eventBus.fire(RefreshLockDetailInfoDataEvent()); + // }); + // + // // var listData = AddUserCommand( + // // lockID: BlueManage().connectDeviceName, + // // authUserID: state.senderUserId.toString(), + // // keyID: state.keyInfos.value.keyId.toString(), + // // userID: await Storage.getUid(), + // // openMode: 1, + // // keyType: 0, + // // startDate: state.keyInfos.value.startDate!~/10000, + // // expireDate: state.keyInfos.value.endDate!~/10000, + // // role: state.keyInfos.value.keyRight == 1 ? 1 : 0, + // // password: "123456", + // // needAuthor: 1, + // // publicKey: publicKeyDataList, + // // privateKey: getPrivateKeyList, + // // token: getTokenList).packageData(); + // BlueManage().bludSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!, (BluetoothConnectionState deviceConnectionState) async { + // if (deviceConnectionState == BluetoothConnectionState.connected) { + // // 私钥 + // var privateKey = await Storage.getStringList(saveBluePrivateKey); + // List getPrivateKeyList = changeStringListToIntList(privateKey!); + // + // var publicKey = await Storage.getStringList(saveBluePublicKey); + // List publicKeyDataList = changeStringListToIntList(publicKey!); + // + // var token = await Storage.getStringList(saveBlueToken); + // List getTokenList = [0, 0, 0, 0]; + // if (token != null) { + // getTokenList = changeStringListToIntList(token); + // } + // + // Get.log("BlueManage().connectDeviceName:${BlueManage().connectDeviceName} authUserID:${state.senderUserId.toString()} keyID:${state.keyInfos.value.keyId.toString()} userID:${await Storage.getUid()}"); + // IoSenderManage.senderAddUser( + // lockID: BlueManage().connectDeviceName, + // authUserID: state.senderUserId.toString(), + // keyID: state.keyInfos.value.keyId.toString(), + // userID: await Storage.getUid(), + // openMode: 1, + // keyType: 0, + // startDate: state.keyInfos.value.startDate!~/10000, + // expireDate: state.keyInfos.value.endDate!~/10000, + // role: state.keyInfos.value.keyRight == 1 ? 1 : 0, + // password: "123456", + // needAuthor: 1, + // publicKey: publicKeyDataList, + // privateKey: getPrivateKeyList, + // token: getTokenList); + // } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { + // cancelBlueConnetctToastTimer(); + // if (state.ifCurrentScreen.value == true) { + // showBlueConnetctToast(); + // } + // + // state.openLockBtnState.value = 0; + // eventBus.fire(RefreshLockDetailInfoDataEvent()); + // } + // }); + // } // 点击开门事件 Future openDoorAction() async { @@ -508,23 +508,23 @@ class LockDetailLogic extends BaseGetXController { } // 普通用户接收电子钥匙之后 更新锁用户NO - void _updateLockUserNo() async { - LockNetTokenEntity entity = await ApiRepository.to.updateLockUserNo( - keyId: state.keyInfos.value.keyId.toString(), - lockUserNo: state.lockUserNo.toString() - ); - if (entity.errorCode!.codeIsSuccessful) { - eventBus.fire(RefreshLockDetailInfoDataEvent()); - SchedulerBinding.instance.addPostFrameCallback((_) { - eventBus.fire(RefreshLockListInfoDataEvent()); - }); - if (state.isOpenLockNeedOnline.value == 0) { - openDoorAction(); - } else { - getLockNetToken(); - } - } - } + // void _updateLockUserNo() async { + // LockNetTokenEntity entity = await ApiRepository.to.updateLockUserNo( + // keyId: state.keyInfos.value.keyId.toString(), + // lockUserNo: state.lockUserNo.toString() + // ); + // if (entity.errorCode!.codeIsSuccessful) { + // eventBus.fire(RefreshLockDetailInfoDataEvent()); + // SchedulerBinding.instance.addPostFrameCallback((_) { + // eventBus.fire(RefreshLockListInfoDataEvent()); + // }); + // if (state.isOpenLockNeedOnline.value == 0) { + // openDoorAction(); + // } else { + // getLockNetToken(); + // } + // } + // } // 查询锁记录最后时间 void getLockRecordLastUploadDataTime() async { diff --git a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart index b6789ada..f3bb3b20 100644 --- a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart +++ b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart @@ -17,6 +17,7 @@ import '../../../blue/blue_manage.dart'; import '../../../blue/io_tool/io_tool.dart'; import '../../../common/XSConstantMacro/XSConstantMacro.dart'; import '../../../tools/appRouteObserver.dart'; +import '../../../tools/commonDataManage.dart'; import '../../../tools/dateTool.dart'; import '../../../tools/eventBusEventManage.dart'; import '../../../tools/storage.dart'; @@ -48,7 +49,6 @@ class _LockDetailPageState extends State void initState() { // TODO: implement initState super.initState(); - Get.log("LockDetailPage initState1111"); // logic.startScanAction(); @@ -66,7 +66,6 @@ class _LockDetailPageState extends State @override void didChangeDependencies() { super.didChangeDependencies(); - Get.log("LockDetailPage didChangeDependencies2222"); /// 路由订阅 AppRouteObserver().routeObserver.subscribe(this, ModalRoute.of(context)!); @@ -84,12 +83,15 @@ class _LockDetailPageState extends State void loadData() { state.keyInfos.value = widget.lockListInfoItemEntity; + CommonDataManage().currentLockUserNo = state.keyInfos.value.lockUserNo!; + CommonDataManage().currentKeyInfo = state.keyInfos.value; + state.lockUserNo = state.keyInfos.value.lockUserNo!; - if (state.lockUserNo == 0) { - state.bottomBtnisEable.value = false; - } else { - state.bottomBtnisEable.value = true; - } + // if (state.lockUserNo == 0) { + // state.bottomBtnisEable.value = false; + // } else { + // state.bottomBtnisEable.value = true; + // } // print("state.keyInfos.value.keyStatus:${state.keyInfos.value.keyStatus}"); if (state.keyInfos.value.keyStatus == XSConstantMacro.keyStatusWaitIneffective || @@ -989,10 +991,10 @@ class _LockDetailPageState extends State state.openLockBtnState.value = 1; // state.animationController!.forward(); - if (state.lockUserNo == 0) { - // 电子钥匙lockUserNo为0 要先添加用户 - logic.addUserConnectBlue(); - } else { + // if (state.lockUserNo == 0) { + // // 电子钥匙lockUserNo为0 要先添加用户 + // logic.addUserConnectBlue(); + // } else { // print("state.isOpenLockNeedOnline.value:${state.isOpenLockNeedOnline.value}"); if (state.isOpenLockNeedOnline.value == 0) { // 不需要联网 @@ -1002,7 +1004,7 @@ class _LockDetailPageState extends State // 需要联网 logic.getLockNetToken(); } - } + // } // }); } @@ -1015,13 +1017,13 @@ class _LockDetailPageState extends State state.openLockBtnState.value = 1; state.animationController!.forward(); - if (state.lockUserNo == 0) { - // 电子钥匙lockUserNo为0 要先添加用户 - logic.addUserConnectBlue(); - } else { + // if (state.lockUserNo == 0) { + // // 电子钥匙lockUserNo为0 要先添加用户 + // logic.addUserConnectBlue(); + // } else { state.openDoorModel = 32; logic.openDoorAction(); - } + // } } @override @@ -1029,7 +1031,6 @@ class _LockDetailPageState extends State // TODO: implement dispose /// 取消路由订阅 - Get.log("LockDetailPage===dispose"); AppRouteObserver().routeObserver.unsubscribe(this); state.closedUnlockSuccessfulTimer?.cancel(); _lockRefreshLockDetailInfoDataEvent?.cancel(); @@ -1048,7 +1049,6 @@ class _LockDetailPageState extends State @override void didPush() { super.didPush(); - Get.log("LockDetailPage===didPush"); state.ifCurrentScreen.value = true; } @@ -1056,7 +1056,6 @@ class _LockDetailPageState extends State @override void didPop() { super.didPop(); - Get.log("LockDetailPage===didPop"); state.ifCurrentScreen.value = false; logic.cancelBlueConnetctToastTimer(); BlueManage().stopScan(); @@ -1069,14 +1068,12 @@ class _LockDetailPageState extends State void didPopNext() { super.didPopNext(); state.ifCurrentScreen.value = true; - Get.log("LockDetailPage===didPopNext"); } /// 进入下级界面 当前界面即将消失 @override void didPushNext() { super.didPushNext(); - Get.log("LockDetailPage===didPushNext"); state.ifCurrentScreen.value = false; logic.cancelBlueConnetctToastTimer(); BlueManage().stopScan(); diff --git a/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_logic.dart b/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_logic.dart index d45ce630..39eba93e 100644 --- a/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_logic.dart +++ b/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_logic.dart @@ -16,6 +16,7 @@ import '../../../../blue/io_tool/manager_event_bus.dart'; import '../../../../blue/sender_manage.dart'; import '../../../../network/api_repository.dart'; import '../../../../tools/baseGetXController.dart'; +import '../../../../tools/commonDataManage.dart'; import '../../../../tools/eventBusEventManage.dart'; import '../../../../tools/storage.dart'; import 'checkingInInfoData_entity.dart'; @@ -406,6 +407,8 @@ class LockSetLogic extends BaseGetXController { ); if (entity.errorCode!.codeIsSuccessful) { state.lockSetInfoData.value = entity.data!; + CommonDataManage().currentLockSetInfoData = entity.data!; + state.lockSettingInfo.value = state.lockSetInfoData.value.lockSettingInfo!; state.lockFeature.value = state.lockSetInfoData.value.lockFeature!; state.lockStatus.value = state.lockSetInfoData.value.lockStatus!; diff --git a/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_page.dart b/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_page.dart index 4af3f688..f8053a56 100644 --- a/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_page.dart +++ b/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_page.dart @@ -1,15 +1,10 @@ -import 'dart:convert'; -import 'dart:typed_data'; - import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; -// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; -import '../../../appRouters.dart'; import '../../../app_settings/app_colors.dart'; import '../../../blue/blue_manage.dart'; import '../../../tools/appRouteObserver.dart'; diff --git a/star_lock/lib/mine/addLock/saveLock/saveLock_logic.dart b/star_lock/lib/mine/addLock/saveLock/saveLock_logic.dart index edd1ec73..213c556b 100644 --- a/star_lock/lib/mine/addLock/saveLock/saveLock_logic.dart +++ b/star_lock/lib/mine/addLock/saveLock/saveLock_logic.dart @@ -30,7 +30,7 @@ class SaveLockLogic extends BaseGetXController { late StreamSubscription _replySubscription; void _initReplySubscription() { _replySubscription = EventBusManager().eventBus!.on().listen((reply) { - if (reply is AddUserReply) { + if (reply is AddUserReply && state.ifCurrentScreen.value == true) { _replyAddUserKey(reply); } diff --git a/star_lock/lib/tools/commonDataManage.dart b/star_lock/lib/tools/commonDataManage.dart index ab9037b3..1d7d12b6 100644 --- a/star_lock/lib/tools/commonDataManage.dart +++ b/star_lock/lib/tools/commonDataManage.dart @@ -2,6 +2,9 @@ // 实现一个CommonDataManage的单例,用来管理项目中使用的一些公共数据 import 'package:get/get.dart'; +import '../main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart'; +import '../main/lockMian/entity/lockListInfo_entity.dart'; + class CommonDataManage { static CommonDataManage? _manager; CommonDataManage._init(); @@ -20,12 +23,15 @@ class CommonDataManage { set setMainLockCount(int v) => _mainLockCount.value = v; get getMainLockCount => _mainLockCount; + // 锁信息 + LockListInfoItemEntity currentKeyInfo = LockListInfoItemEntity(); + // 当前锁的用户编号 int currentLockUserNo = 0; // set setCurrentLockUserNo(int v) => _currentLockUserNo = v; // get getCurrentLockUserNo => _currentLockUserNo; - + LockSetInfoData currentLockSetInfoData = LockSetInfoData(); } diff --git a/star_lock/lib/tools/eventBusEventManage.dart b/star_lock/lib/tools/eventBusEventManage.dart index fb6e20f9..d77d5c48 100644 --- a/star_lock/lib/tools/eventBusEventManage.dart +++ b/star_lock/lib/tools/eventBusEventManage.dart @@ -10,6 +10,13 @@ class RefreshLockListInfoDataEvent { RefreshLockListInfoDataEvent(); } +/// 蓝牙添加用户成功 +class LockAddUserSucceedEvent { + int type; // 0用户号更新成功 1token失效 + List dataList; + LockAddUserSucceedEvent(this.dataList, this.type); +} + /// 刷新锁详情数据 class RefreshLockDetailInfoDataEvent { RefreshLockDetailInfoDataEvent(); diff --git a/star_lock/lib/tools/storage.dart b/star_lock/lib/tools/storage.dart index 859d804b..2c476856 100644 --- a/star_lock/lib/tools/storage.dart +++ b/star_lock/lib/tools/storage.dart @@ -207,7 +207,7 @@ class Storage { if (data != null && data.isNotEmpty) { lockListInfoGroupEntity = LockListInfoGroupEntity.fromJson(jsonDecode(data)); } - print("lockListInfoEntity:$lockListInfoGroupEntity"); return lockListInfoGroupEntity; } + }