diff --git a/star_lock/lib/blue/io_protocol/io_senderCustomPasswords.dart b/star_lock/lib/blue/io_protocol/io_senderCustomPasswords.dart index aae0abad..2d66e7ce 100644 --- a/star_lock/lib/blue/io_protocol/io_senderCustomPasswords.dart +++ b/star_lock/lib/blue/io_protocol/io_senderCustomPasswords.dart @@ -82,6 +82,7 @@ class SenderCustomPasswordsCommand extends SenderProtocol { // UseCountLimit subData.add(useCountLimit!); + print("useCountLimituseCountLimituseCountLimit:$useCountLimit"); // token subData.addAll(token!); diff --git a/star_lock/lib/blue/io_reply.dart b/star_lock/lib/blue/io_reply.dart index ec620a5b..5680d810 100644 --- a/star_lock/lib/blue/io_reply.dart +++ b/star_lock/lib/blue/io_reply.dart @@ -22,21 +22,21 @@ abstract class Reply{ break; case 0x01: // 包格式错误 - Get.log("${commandType!.typeName}包格式错误"); + Get.log("${commandType!.typeName} 包格式错误"); showErrorMessage("包格式错误"); break; case 0x02: // 密码错误 - Get.log("${commandType!.typeName}密码错误"); + Get.log("${commandType!.typeName} 密码错误"); showErrorMessage("密码错误"); break; case 0x03: // 网络中断 - Get.log("${commandType!.typeName}网络中断"); + Get.log("${commandType!.typeName} 网络中断"); break; case 0x04: // 用户未登记 - Get.log("${commandType!.typeName}用户未登记"); + Get.log("${commandType!.typeName} 用户未登记"); showErrorMessage("用户未登记"); break; case 0x05: diff --git a/star_lock/lib/main/lockDetail/lockSet/basicInformation/basicInformation/basicInformation_page.dart b/star_lock/lib/main/lockDetail/lockSet/basicInformation/basicInformation/basicInformation_page.dart index 48860815..51321167 100644 --- a/star_lock/lib/main/lockDetail/lockSet/basicInformation/basicInformation/basicInformation_page.dart +++ b/star_lock/lib/main/lockDetail/lockSet/basicInformation/basicInformation/basicInformation_page.dart @@ -146,14 +146,14 @@ class _BasicInformationPageState extends State { Obx(() => Visibility( visible: state.lockBasicInfo.value.lockName!.contains("T9A"), child: CommonItem( - leftTitel: "当前网络", - rightTitle: state.lockBasicInfo.value.lockName ?? "", + leftTitel: "当前网络".tr, + rightTitle: state.lockBasicInfo.value.network ?? "-", allHeight: 70.h, isHaveLine: true), )), Obx(() => CommonItem( - leftTitel: "位置信息", - rightTitle: state.lockBasicInfo.value.lockName ?? "", + leftTitel: "位置信息".tr, + rightTitle: state.lockBasicInfo.value.address ?? "-", allHeight: 70.h, isHaveLine: true)), /* 2024-01-12 会议确定去掉“微信二维码” by DaisyWu diff --git a/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart b/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart index e9c62300..9070fc43 100644 --- a/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart +++ b/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart @@ -339,6 +339,8 @@ class LockBasicInfo { int? senderUserId; int? lockUserNo; List? weekDays; + String? address; + String? network; LockBasicInfo( {this.lockId, @@ -361,7 +363,9 @@ class LockBasicInfo { this.keyRight, this.senderUserId, this.lockUserNo, - this.weekDays}); + this.weekDays, + this.address, + this.network}); LockBasicInfo.fromJson(Map json) { lockId = json['lockId']; @@ -390,6 +394,8 @@ class LockBasicInfo { senderUserId = json['senderUserId']; lockUserNo = json['lockUserNo']; weekDays = json['weekDays']; + address = json['address']; + network = json['network']; } Map toJson() { @@ -417,6 +423,8 @@ class LockBasicInfo { data['senderUserId'] = senderUserId; data['lockUserNo'] = lockUserNo; data['weekDays'] = weekDays; + data['address'] = address; + data['network'] = network; return data; } } diff --git a/star_lock/lib/main/lockDetail/passwordKey/passwordKeyDetail/passwordKeyDetail_logic.dart b/star_lock/lib/main/lockDetail/passwordKey/passwordKeyDetail/passwordKeyDetail_logic.dart index 5264a042..8b4d018d 100644 --- a/star_lock/lib/main/lockDetail/passwordKey/passwordKeyDetail/passwordKeyDetail_logic.dart +++ b/star_lock/lib/main/lockDetail/passwordKey/passwordKeyDetail/passwordKeyDetail_logic.dart @@ -1,3 +1,6 @@ +import 'dart:async'; + +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; import 'package:star_lock/main/lockDetail/passwordKey/passwordKeyDetail/passwordKeyDetail_state.dart'; import 'package:star_lock/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKeyEntity.dart'; @@ -5,15 +8,72 @@ import 'package:star_lock/network/api_repository.dart'; import 'package:star_lock/tools/baseGetXController.dart'; import 'package:star_lock/tools/eventBusEventManage.dart'; +import '../../../../blue/blue_manage.dart'; +import '../../../../blue/io_protocol/io_senderCustomPasswords.dart'; +import '../../../../blue/io_reply.dart'; +import '../../../../blue/io_tool/io_tool.dart'; +import '../../../../blue/io_tool/manager_event_bus.dart'; +import '../../../../blue/sender_manage.dart'; +import '../../../../tools/storage.dart'; + class PasswordKeyDetailLogic extends BaseGetXController { PasswordKeyDetailState state = PasswordKeyDetailState(); + // 监听设备返回的数据 + late StreamSubscription _replySubscription; + void _initReplySubscription() { + _replySubscription = EventBusManager().eventBus!.on().listen((reply) async { + // 设置自定义密码 + if ((reply is SenderCustomPasswordsReply) && (state.ifCurrentScreen.value == true)) { + var token = reply.data.sublist(5, 9); + var saveStrList = changeIntListToStringList(token); + Storage.setStringList(saveBlueToken, saveStrList); + + int status = reply.data[2]; + switch (status) { + case 0x00: + //成功 + state.sureBtnState.value = 0; + dismissEasyLoading(); + cancelBlueConnetctToastTimer(); + deletePwdRequest(); + break; + case 0x06: + //无权限 + var privateKey = await Storage.getStringList(saveBluePrivateKey); + List getPrivateKeyList = changeStringListToIntList(privateKey!); + + var signKey = await Storage.getStringList(saveBlueSignKey); + List signKeyDataList = changeStringListToIntList(signKey!); + + IoSenderManage.senderCustomPasswordsCommand( + keyID:state.keyId.value.toString(), + userID:await Storage.getUid(), + pwdNo: state.keyboardUserNo.value, + pwd: "000000", + useCountLimit: 0, + startTime:0x11223344, + endTime:0x11223344, + needAuthor: 1, + signKey: signKeyDataList, + privateKey: getPrivateKeyList, + token: token); + break; + default: + //失败 + cancelBlueConnetctToastTimer(); + break; + } + } + }); + } + //删除密码请求 deleteType:1-蓝牙 2-网关 Future deletePwdRequest() async { PasswordKeyEntity entity = await ApiRepository.to.deleteKeyboardPwd( - state.itemData.value.lockId.toString(), - state.itemData.value.keyboardPwdId.toString(), - 1); + lockId:state.itemData.value.lockId.toString(), + keyboardPwdId:state.itemData.value.keyboardPwdId.toString(), + deleteType:1); if (entity.errorCode!.codeIsSuccessful) { showToast("删除成功".tr, something: (){ Get.back(result: "deletScuess"); @@ -50,6 +110,48 @@ class PasswordKeyDetailLogic extends BaseGetXController { } } + // 设置自定义密码 这里用作删除密码 + Future senderCustomPasswords() async { + + showEasyLoading(); + showBlueConnetctToastTimer(action: (){ + dismissEasyLoading(); + state.sureBtnState.value = 0; + }); + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected) { + var signKey = await Storage.getStringList(saveBlueSignKey); + List signKeyDataList = changeStringListToIntList(signKey!); + + var privateKey = await Storage.getStringList(saveBluePrivateKey); + List getPrivateKeyList = changeStringListToIntList(privateKey!); + + var token = await Storage.getStringList(saveBlueToken); + List getTokenList = changeStringListToIntList(token!); + + IoSenderManage.senderCustomPasswordsCommand( + keyID:state.keyId.value.toString(), + userID:await Storage.getUid(), + pwdNo: state.keyboardUserNo.value, + pwd: "000000", + useCountLimit: 0, + startTime:0x11223344, + endTime:0x11223344, + needAuthor: 1, + signKey: signKeyDataList, + privateKey: getPrivateKeyList, + token: getTokenList); + } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { + dismissEasyLoading(); + cancelBlueConnetctToastTimer(); + state.sureBtnState.value = 0; + if(state.ifCurrentScreen.value == true){ + showBlueConnetctToast(); + } + } + }); + } + //使用期限详情显示 String getUseDateStr() { int? getPwdType = state.itemData.value.keyboardPwdType; @@ -213,4 +315,25 @@ class PasswordKeyDetailLogic extends BaseGetXController { return "您好,您的密码是:${state.itemData.value.keyboardPwd}\n$useDateStr\n密码名字:${state.itemData.value.keyboardPwdName}"; } + @override + void onReady() { + // TODO: implement onReady + super.onReady(); + + _initReplySubscription(); + // getPasswordTypeUpdateIndexAction(); + } + + @override + void onInit() { + // TODO: implement onInit + super.onInit(); + } + + @override + void onClose() { + // TODO: implement onClose + _replySubscription.cancel(); + } + } diff --git a/star_lock/lib/main/lockDetail/passwordKey/passwordKeyDetail/passwordKeyDetail_page.dart b/star_lock/lib/main/lockDetail/passwordKey/passwordKeyDetail/passwordKeyDetail_page.dart index 3060ee52..b42d5838 100644 --- a/star_lock/lib/main/lockDetail/passwordKey/passwordKeyDetail/passwordKeyDetail_page.dart +++ b/star_lock/lib/main/lockDetail/passwordKey/passwordKeyDetail/passwordKeyDetail_page.dart @@ -6,12 +6,13 @@ import 'package:star_lock/main/lockDetail/passwordKey/passwordKeyDetail/password import 'package:star_lock/main/lockDetail/passwordKey/passwordKeyList/passwordKeyListEntity.dart'; import 'package:star_lock/tools/dateTool.dart'; import 'package:star_lock/tools/showTFView.dart'; +import 'package:star_lock/tools/showTipView.dart'; import '../../../../appRouters.dart'; import '../../../../app_settings/app_colors.dart'; import '../../../../tools/NativeInteractionTool.dart'; +import '../../../../tools/appRouteObserver.dart'; import '../../../../tools/commonItem.dart'; -import '../../../../tools/showIosTipView.dart'; import '../../../../tools/submitBtn.dart'; import '../../../../tools/titleAppBar.dart'; import '../../../../translations/trans_lib.dart'; @@ -23,7 +24,7 @@ class PasswordKeyDetailPage extends StatefulWidget { State createState() => _PasswordKeyDetailPageState(); } -class _PasswordKeyDetailPageState extends State { +class _PasswordKeyDetailPageState extends State with RouteAware { final logic = Get.put(PasswordKeyDetailLogic()); final state = Get.find().state; @@ -200,7 +201,9 @@ class _PasswordKeyDetailPageState extends State { left: 30.w, right: 30.w, top: 30.w, bottom: 30.w), padding: EdgeInsets.only(top: 25.w, bottom: 25.w), onClick: () { - showIosTipViewDialog(context); + ShowTipView().showIosTipWithContentDialog("确定要删除吗?".tr, (){ + logic.senderCustomPasswords(); + }); }), ], ), @@ -364,21 +367,58 @@ class _PasswordKeyDetailPageState extends State { } } - void showIosTipViewDialog(BuildContext context) { - showDialog( - context: context, - builder: (BuildContext context) { - return ShowIosTipView( - title: "提示", - tipTitle: "确定要删除吗?", - sureClick: () { - Get.back(); - logic.deletePwdRequest(); - }, - cancelClick: () { - Get.back(); - }, - ); - }); + @override + void didChangeDependencies() { + // TODO: implement didChangeDependencies + super.didChangeDependencies(); + + /// 路由订阅 + AppRouteObserver().routeObserver.subscribe(this, ModalRoute.of(context)!); + } + + @override + void dispose() { + // TODO: implement dispose + /// 取消路由订阅 + AppRouteObserver().routeObserver.unsubscribe(this); + super.dispose(); + } + + /// 从上级界面进入 当前界面即将出现 + @override + void didPush() { + super.didPush(); + Get.log("PasswordKeyDetailPage===didPush"); + state.ifCurrentScreen.value = true; + } + + /// 返回上一个界面 当前界面即将消失 + @override + void didPop() { + super.didPop(); + Get.log("PasswordKeyDetailPage===didPop"); + logic.cancelBlueConnetctToastTimer(); + logic.dismissEasyLoading(); + state.ifCurrentScreen.value = false; + state.sureBtnState.value = 0; + } + + /// 从下级返回 当前界面即将出现 + @override + void didPopNext() { + super.didPopNext(); + Get.log("PasswordKeyDetailPage===didPopNext"); + state.ifCurrentScreen.value = true; + } + + /// 进入下级界面 当前界面即将消失 + @override + void didPushNext() { + super.didPushNext(); + Get.log("PasswordKeyDetailPage===didPushNext"); + logic.cancelBlueConnetctToastTimer(); + logic.dismissEasyLoading(); + state.ifCurrentScreen.value = false; + state.sureBtnState.value = 0; } } diff --git a/star_lock/lib/main/lockDetail/passwordKey/passwordKeyDetail/passwordKeyDetail_state.dart b/star_lock/lib/main/lockDetail/passwordKey/passwordKeyDetail/passwordKeyDetail_state.dart index 67c35e1a..3c12bb66 100644 --- a/star_lock/lib/main/lockDetail/passwordKey/passwordKeyDetail/passwordKeyDetail_state.dart +++ b/star_lock/lib/main/lockDetail/passwordKey/passwordKeyDetail/passwordKeyDetail_state.dart @@ -7,16 +7,17 @@ class PasswordKeyDetailState { final TextEditingController inputPwdController = TextEditingController(); final TextEditingController inputNameController = TextEditingController(); final changeType = '1'.obs; //1-通过APP走蓝牙修改,不传默认1,必需先通过APP SDK蓝牙修改后调用该接口 2-通过网关或WiFi锁修改,如果是WiFi锁或有连接网关,则可以传2,直接调用该接口修改生效 - final keyboardPwd = ''.obs; + final keyboardPwd = ''.obs;// + final keyboardUserNo = 0.obs;// final keyboardPwdName = ''.obs; final keyboardPwdType = ''.obs;// 1单次 2永久 3限时 4删除 5周末循环 6周日循环 7工作日循环 8周一循环 9周二循环 10周三循环 11周四循环 12周五循环 13周六循环 14周天循环 final isCirculation = false.obs;// 是否是循环 + var keyId = 0.obs;// 卡id + + var ifCurrentScreen = true.obs; // 是否是当前界面,用于判断是否需要针对当前界面进行展示 + var sureBtnState = 0.obs;// 0普通状态(可用) 1连接中(不可用) + final passwordKeyNumber = "".obs;// 密码号 - // final hoursStart = 0.obs; - // final hoursEnd = 0.obs; - // final startDate = 0.obs; - // final endDate = 0.obs; - // PasswordKeyDetailState() { Map map = Get.arguments; itemData.value = map["itemData"]; @@ -25,6 +26,9 @@ class PasswordKeyDetailState { keyboardPwdName.value = itemData.value.keyboardPwdName!; inputNameController.text = itemData.value.keyboardPwdName!; inputPwdController.text = itemData.value.keyboardPwd!; + keyId.value = itemData.value.keyboardPwdId!; + keyboardUserNo.value = itemData.value.pwdUserNo!; + // startDate.value = itemData.value.startDate!; // endDate.value = itemData.value.endDate!; // hoursStart.value = itemData.value.hoursStart!; diff --git a/star_lock/lib/main/lockDetail/passwordKey/passwordKeyList/passwordKeyListEntity.dart b/star_lock/lib/main/lockDetail/passwordKey/passwordKeyList/passwordKeyListEntity.dart index 70145f17..fd087ec4 100644 --- a/star_lock/lib/main/lockDetail/passwordKey/passwordKeyList/passwordKeyListEntity.dart +++ b/star_lock/lib/main/lockDetail/passwordKey/passwordKeyList/passwordKeyListEntity.dart @@ -82,6 +82,7 @@ class PasswordKeyListItem { int? isCoerced; int? hoursStart; int? hoursEnd; + int? pwdUserNo; PasswordKeyListItem( {this.apiUserId, @@ -100,7 +101,8 @@ class PasswordKeyListItem { this.validTimeStr, this.isCoerced, this.hoursStart, - this.hoursEnd}); + this.hoursEnd, + this.pwdUserNo}); PasswordKeyListItem.fromJson(Map json) { apiUserId = json['apiUserId']; @@ -120,6 +122,7 @@ class PasswordKeyListItem { isCoerced = json['isCoerced']; hoursStart = json['hoursStart']; hoursEnd = json['hoursEnd']; + pwdUserNo = json['pwdUserNo']; } Map toJson() { @@ -141,6 +144,7 @@ class PasswordKeyListItem { data['isCoerced'] = isCoerced; data['hoursStart'] = hoursStart; data['hoursEnd'] = hoursEnd; + data['pwdUserNo'] = pwdUserNo; return data; } } diff --git a/star_lock/lib/main/lockDetail/passwordKey/passwordKeyList/passwordKeyList_logic.dart b/star_lock/lib/main/lockDetail/passwordKey/passwordKeyList/passwordKeyList_logic.dart index 5afc02c4..46056c84 100644 --- a/star_lock/lib/main/lockDetail/passwordKey/passwordKeyList/passwordKeyList_logic.dart +++ b/star_lock/lib/main/lockDetail/passwordKey/passwordKeyList/passwordKeyList_logic.dart @@ -1,17 +1,91 @@ import 'dart:async'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; +import 'package:star_lock/blue/io_type.dart'; import 'package:star_lock/main/lockDetail/passwordKey/passwordKeyList/passwordKeyListEntity.dart'; import 'package:star_lock/main/lockDetail/passwordKey/passwordKeyList/passwordKeyList_state.dart'; import 'package:star_lock/network/api_repository.dart'; import 'package:star_lock/tools/baseGetXController.dart'; +import '../../../../blue/blue_manage.dart'; +import '../../../../blue/io_protocol/io_senderCustomPasswords.dart'; +import '../../../../blue/io_reply.dart'; +import '../../../../blue/io_tool/io_tool.dart'; +import '../../../../blue/io_tool/manager_event_bus.dart'; +import '../../../../blue/sender_manage.dart'; import '../../../../tools/eventBusEventManage.dart'; +import '../../../../tools/storage.dart'; import '../passwordKey_perpetual/passwordKeyEntity.dart'; class PasswordKeyListLogic extends BaseGetXController { final PasswordKeyListState state = PasswordKeyListState(); + // 获取解析后的数据 + late StreamSubscription _replySubscription; + void _initReplySubscription() { + _replySubscription = EventBusManager().eventBus!.on().listen((reply) { + + // 添加卡片开始(重置锁里面所有卡) + if((reply is SenderCustomPasswordsReply) && (state.ifCurrentScreen.value == true)) { + _replyAddICCardBegin(reply); + } + }); + } + + // 添加卡片开始(此处用作删除卡片) + Future _replyAddICCardBegin(Reply reply) async { + int status = reply.data[2]; + + switch(status){ + case 0x00: + //成功 + Get.log("${reply.commandType!.typeValue} 数据解析成功"); + state.isDeletPWDData = false; + cancelBlueConnetctToastTimer(); + if(state.isDeletAll){ + resetPasswordKeyListRequest(); + }else{ + deletePwdRequest(); + } + break; + case 0x06: + //无权限 + Get.log("${reply.commandType!.typeValue} 需要鉴权"); + var privateKey = await Storage.getStringList(saveBluePrivateKey); + List getPrivateKeyList = changeStringListToIntList(privateKey!); + + var signKey = await Storage.getStringList(saveBlueSignKey); + List signKeyDataList = changeStringListToIntList(signKey!); + + // var publicKey = await Storage.getStringList(saveBluePublicKey); + // List publicKeyDataList = changeStringListToIntList(publicKey!); + + var token = reply.data.sublist(5, 9); + var saveStrList = changeIntListToStringList(token); + Storage.setStringList(saveBlueToken, saveStrList); + + IoSenderManage.senderCustomPasswordsCommand( + keyID:state.deletKeyID, + userID:state.deletUserID, + pwdNo:state.pwdNo, + pwd:"000000",//state.deletPWD, + useCountLimit: 0, + startTime:0x11223344, + endTime:0x11223344, + needAuthor: 1, + signKey: signKeyDataList, + privateKey: getPrivateKeyList, + token: token); + break; + default: + //失败 + cancelBlueConnetctToastTimer(); + break; + } + } + + //请求密码钥匙列表 Future mockNetworkDataRequest() async { PasswordKeyListEntity entity = await ApiRepository.to.passwordKeyList( @@ -39,7 +113,6 @@ class PasswordKeyListLogic extends BaseGetXController { PasswordKeyListEntity entity = await ApiRepository.to .keyboardPwdReset(state.keyInfo.value.lockId.toString()); if (entity.errorCode!.codeIsSuccessful) { - // print("重置电子钥匙成功啦啦啦啦啦"); showToast("重置成功".tr, something: (){ pageNo = 1; mockNetworkDataRequest(); @@ -48,10 +121,11 @@ class PasswordKeyListLogic extends BaseGetXController { } //删除密码请求 deleteType:1-蓝牙 2-网关 - Future deletePwdRequest( - String lockId, String keyboardPwdId, int deleteType) async { - PasswordKeyEntity entity = await ApiRepository.to - .deleteKeyboardPwd(lockId, keyboardPwdId, deleteType); + Future deletePwdRequest() async { + PasswordKeyEntity entity = await ApiRepository.to.deleteKeyboardPwd( + lockId:state.itemData.lockId!.toString(), + keyboardPwdId:state.itemData.keyboardPwdId!.toString(), + deleteType:1); if (entity.errorCode!.codeIsSuccessful) { showToast("删除成功".tr, something: (){ pageNo = 1; @@ -60,6 +134,48 @@ class PasswordKeyListLogic extends BaseGetXController { } } + // 设置自定义密码 这里用作删除密码 + Future senderCustomPasswords() async { + + showEasyLoading(); + showBlueConnetctToastTimer(action: (){ + dismissEasyLoading(); + state.sureBtnState.value = 0; + }); + BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected) { + var signKey = await Storage.getStringList(saveBlueSignKey); + List signKeyDataList = changeStringListToIntList(signKey!); + + var privateKey = await Storage.getStringList(saveBluePrivateKey); + List getPrivateKeyList = changeStringListToIntList(privateKey!); + + var token = await Storage.getStringList(saveBlueToken); + List getTokenList = changeStringListToIntList(token!); + + IoSenderManage.senderCustomPasswordsCommand( + keyID:state.deletKeyID, + userID:state.deletUserID, + pwdNo:state.pwdNo, + pwd:"000000",//state.deletPWD, + useCountLimit: 0, + startTime:0x11223344, + endTime:0x11223344, + needAuthor: 1, + signKey: signKeyDataList, + privateKey: getPrivateKeyList, + token: getTokenList); + } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { + dismissEasyLoading(); + cancelBlueConnetctToastTimer(); + state.sureBtnState.value = 0; + if(state.ifCurrentScreen.value == true){ + showBlueConnetctToast(); + } + } + }); + } + //使用期限 String getUseDateStr(PasswordKeyListItem indexEntity) { int? getPwdType = indexEntity.keyboardPwdType; @@ -160,6 +276,7 @@ class PasswordKeyListLogic extends BaseGetXController { // TODO: implement onReady super.onReady(); _getPasswordListRefreshUIAction(); + _initReplySubscription(); } @override @@ -173,5 +290,6 @@ class PasswordKeyListLogic extends BaseGetXController { // TODO: implement onClose super.onClose(); _getPasswordListRefreshUIEvent?.cancel(); + _replySubscription.cancel(); } } diff --git a/star_lock/lib/main/lockDetail/passwordKey/passwordKeyList/passwordKeyList_page.dart b/star_lock/lib/main/lockDetail/passwordKey/passwordKeyList/passwordKeyList_page.dart index 6acb4273..c0808f61 100644 --- a/star_lock/lib/main/lockDetail/passwordKey/passwordKeyList/passwordKeyList_page.dart +++ b/star_lock/lib/main/lockDetail/passwordKey/passwordKeyList/passwordKeyList_page.dart @@ -10,6 +10,7 @@ import 'package:star_lock/tools/storage.dart'; import '../../../../appRouters.dart'; import '../../../../app_settings/app_colors.dart'; import '../../../../tools/EasyRefreshTool.dart'; +import '../../../../tools/appRouteObserver.dart'; import '../../../../tools/keySearchWidget.dart'; import '../../../../tools/showTipView.dart'; import '../../../../tools/submitBtn.dart'; @@ -23,7 +24,7 @@ class PasswordKeyListPage extends StatefulWidget { State createState() => _PasswordKeyListPageState(); } -class _PasswordKeyListPageState extends State { +class _PasswordKeyListPageState extends State with RouteAware { final logic = Get.put(PasswordKeyListLogic()); final state = Get.find().state; @@ -61,8 +62,14 @@ class _PasswordKeyListPageState extends State { var isDemoMode = await Storage.getBool(ifIsDemoModeOrNot); if (isDemoMode == false) { ShowTipView().showIosTipWithContentDialog('该锁的密码都将被删除'.tr, () { - logic.resetPasswordKeyListRequest(); - setState(() {}); + state.isDeletPWDData = true; + state.isDeletAll = true; + state.deletKeyID = "0"; + state.deletUserID = "DeleteAll!@#"; + // state.deletPWD = ""; + state.pwdNo = 255; + + logic.senderCustomPasswords(); }); } else { logic.showToast("演示模式".tr); @@ -134,9 +141,14 @@ class _PasswordKeyListPageState extends State { children: [ SlidableAction( onPressed: (BuildContext context){ - ShowTipView().showIosTipWithContentDialog("确定要删除吗?".tr, () { - logic.deletePwdRequest(passwordKeyListItem.lockId.toString(), - passwordKeyListItem.keyboardPwdId.toString(), 1); + ShowTipView().showIosTipWithContentDialog("确定要删除吗?".tr, () async { + state.isDeletAll = false; + state.deletUserID = (await Storage.getUid())!; + state.deletKeyID = passwordKeyListItem.keyboardPwdId.toString(); + state.deletPWD = passwordKeyListItem.keyboardPwd!; + state.itemData = passwordKeyListItem; + state.pwdNo = passwordKeyListItem.pwdUserNo!; + logic.senderCustomPasswords(); }); }, backgroundColor: Colors.red, @@ -232,4 +244,59 @@ class _PasswordKeyListPageState extends State { ); } + @override + void didChangeDependencies() { + // TODO: implement didChangeDependencies + super.didChangeDependencies(); + + /// 路由订阅 + AppRouteObserver().routeObserver.subscribe(this, ModalRoute.of(context)!); + } + + @override + void dispose() { + // TODO: implement dispose + /// 取消路由订阅 + AppRouteObserver().routeObserver.unsubscribe(this); + super.dispose(); + } + + /// 从上级界面进入 当前界面即将出现 + @override + void didPush() { + super.didPush(); + Get.log("PasswordKeyDetailPage===didPush"); + state.ifCurrentScreen.value = true; + } + + /// 返回上一个界面 当前界面即将消失 + @override + void didPop() { + super.didPop(); + Get.log("PasswordKeyDetailPage===didPop"); + logic.cancelBlueConnetctToastTimer(); + logic.dismissEasyLoading(); + state.ifCurrentScreen.value = false; + state.sureBtnState.value = 0; + } + + /// 从下级返回 当前界面即将出现 + @override + void didPopNext() { + super.didPopNext(); + Get.log("PasswordKeyDetailPage===didPopNext"); + state.ifCurrentScreen.value = true; + } + + /// 进入下级界面 当前界面即将消失 + @override + void didPushNext() { + super.didPushNext(); + Get.log("PasswordKeyDetailPage===didPushNext"); + logic.cancelBlueConnetctToastTimer(); + logic.dismissEasyLoading(); + state.ifCurrentScreen.value = false; + state.sureBtnState.value = 0; + } + } diff --git a/star_lock/lib/main/lockDetail/passwordKey/passwordKeyList/passwordKeyList_state.dart b/star_lock/lib/main/lockDetail/passwordKey/passwordKeyList/passwordKeyList_state.dart index 66e47686..9e53ff2b 100644 --- a/star_lock/lib/main/lockDetail/passwordKey/passwordKeyList/passwordKeyList_state.dart +++ b/star_lock/lib/main/lockDetail/passwordKey/passwordKeyList/passwordKeyList_state.dart @@ -7,8 +7,20 @@ import '../../../lockMian/entity/lockListInfo_entity.dart'; class PasswordKeyListState { final keyInfo = LockListInfoItemEntity().obs; final itemDataList = [].obs; + var itemData = PasswordKeyListItem(); final TextEditingController searchController = TextEditingController(); + var ifCurrentScreen = true.obs; // 是否是当前界面,用于判断是否需要针对当前界面进行展示 + var sureBtnState = 0.obs;// 0普通状态(可用) 1连接中(不可用) + + // 因为删除跟添加指纹用的同一个协议 所以这里用做判断 + var isDeletPWDData = false; + var isDeletAll = false; + var deletKeyID = ""; + var deletUserID = "DeleteAll!@#"; + var deletPWD = ""; + var pwdNo = 0; + PasswordKeyListState() { Map map = Get.arguments; keyInfo.value = map["keyInfo"]; diff --git a/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart index 73adc26f..4a57d055 100644 --- a/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart +++ b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart @@ -163,13 +163,23 @@ class PasswordKeyPerpetualLogic extends BaseGetXController { state.pwdController.text = ""; if (entity.data != null) { state.getPwdStr.value = entity.data!.keyboardPwd!; + updatePWDNumberRequest(entity.data!.keyboardPwdId.toString()); } - eventBus.fire(GetPasswordListRefreshUI()); } else { showToast('${entity.errorMsg}'); } } + Future updatePWDNumberRequest(String pwdNumberId) async { + var entity = await ApiRepository.to.updatePWDNumber( + lockId: state.keyInfo.value.lockId.toString(), + keyboardPwdId: pwdNumberId, + pwdUserNo: state.pwdNumber.value.toString()); + if (entity.errorCode!.codeIsSuccessful) { + eventBus.fire(GetPasswordListRefreshUI()); + } + } + Future checkKeyboardpwdNameRequest() async { if (state.nameController.text.isEmpty) { showToast("请输入姓名"); @@ -194,8 +204,7 @@ class PasswordKeyPerpetualLogic extends BaseGetXController { // 监听设备返回的数据 late StreamSubscription _replySubscription; void _initReplySubscription() { - _replySubscription = - EventBusManager().eventBus!.on().listen((reply) async { + _replySubscription = EventBusManager().eventBus!.on().listen((reply) async { // 设置自定义密码 if (reply is SenderCustomPasswordsReply) { var token = reply.data.sublist(5, 9); @@ -207,6 +216,7 @@ class PasswordKeyPerpetualLogic extends BaseGetXController { case 0x00: //成功 state.sureBtnState.value = 0; + state.pwdNumber.value = (reply.data[9]); dismissEasyLoading(); cancelBlueConnetctToastTimer(); addKeyboardPwdRequest(); diff --git a/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_state.dart b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_state.dart index 8bc4ef9d..6cd4e82b 100644 --- a/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_state.dart +++ b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_state.dart @@ -30,4 +30,6 @@ class PasswordKeyPerpetualState { var ifCurrentScreen = true.obs; // 是否是当前界面,用于判断是否需要针对当前界面进行展示 var sureBtnState = 0.obs;// 0普通状态(可用) 1连接中(不可用) + + var pwdNumber = 0.obs;// 密码编号 } diff --git a/star_lock/lib/mine/mineSet/lockUserManage/expireLockList/expirePassword/expirePassword_logic.dart b/star_lock/lib/mine/mineSet/lockUserManage/expireLockList/expirePassword/expirePassword_logic.dart index 9890f5a1..6ad96a31 100644 --- a/star_lock/lib/mine/mineSet/lockUserManage/expireLockList/expirePassword/expirePassword_logic.dart +++ b/star_lock/lib/mine/mineSet/lockUserManage/expireLockList/expirePassword/expirePassword_logic.dart @@ -31,9 +31,9 @@ class ExpirePasswordLogic extends BaseGetXController { //删除密码请求 deleteType:1-蓝牙 2-网关 Future deletePwdRequest(ExpirePasswordItemData expirePasswordItemData) async { PasswordKeyEntity entity = await ApiRepository.to.deleteKeyboardPwd( - expirePasswordItemData.lockId.toString(), - expirePasswordItemData.pwdId.toString(), - 1); + lockId:expirePasswordItemData.lockId.toString(), + keyboardPwdId:expirePasswordItemData.pwdId.toString(), + deleteType:1); if (entity.errorCode!.codeIsSuccessful) { showToast("删除成功", something: () { pageNo = 1; diff --git a/star_lock/lib/network/api.dart b/star_lock/lib/network/api.dart index dda5e6f9..440f9e89 100644 --- a/star_lock/lib/network/api.dart +++ b/star_lock/lib/network/api.dart @@ -45,9 +45,9 @@ abstract class Api { final String passwordKeyGetURL = '/keyboardPwd/get'; //获取密码 final String passwordKeyAddURL = '/keyboardPwd/add'; //自定义密码 - final String passwordKeyCheckKeyboardpwdNameURL = - '/keyboardPwd/checkKeyboardpwdName'; //自定义密码校验密码跟名字是否重复 + final String passwordKeyCheckKeyboardpwdNameURL = '/keyboardPwd/checkKeyboardpwdName'; //自定义密码校验密码跟名字是否重复 final String updatePasswordKeyURL = '/keyboardPwd/update'; //修改密码详情 + final String updatePWDNumberURL = '/keyboardPwd/updatePwdUserNo'; //更新锁用户需要 final String clearOperationRecordURL = '/lockRecords/clear'; //清空操作记录 final String addlockGroupURL = '/keyGroup/add'; //创建锁分组 final String editlockGroupURL = '/keyGroup/modifyGroupName'; //编辑锁分组 diff --git a/star_lock/lib/network/api_provider.dart b/star_lock/lib/network/api_provider.dart index 89512ab9..1ca0a5cf 100644 --- a/star_lock/lib/network/api_provider.dart +++ b/star_lock/lib/network/api_provider.dart @@ -431,6 +431,14 @@ class ApiProvider extends BaseProvider { 'isCoerced': isCoerced, })); + // 更新锁用户序号 + Future updatePWDNumber(String lockId, String keyboardPwdId, String pwdUserNo) => post( + updatePWDNumberURL.toUrl, + jsonEncode({ + 'lockId': lockId, + 'keyboardPwdId': keyboardPwdId, + 'pwdUserNo': pwdUserNo})); + Future addKeyboardPwd( String lockId, String keyboardPwdName, diff --git a/star_lock/lib/network/api_repository.dart b/star_lock/lib/network/api_repository.dart index b18d3e92..c640d067 100644 --- a/star_lock/lib/network/api_repository.dart +++ b/star_lock/lib/network/api_repository.dart @@ -444,6 +444,19 @@ class ApiRepository { return PasswordKeyEntity.fromJson(res.body); } + // 更新锁用户序号 + Future updatePWDNumber( + {required String lockId, + required String keyboardPwdId, + required String pwdUserNo}) async { + final res = await apiProvider.updatePWDNumber( + lockId, + keyboardPwdId, + pwdUserNo + ); + return PasswordKeyEntity.fromJson(res.body); + } + //自定义密码 Future addPasswordKey( String lockId, @@ -655,7 +668,11 @@ class ApiRepository { //删除密码 Future deleteKeyboardPwd( - String lockId, String keyboardPwdId, int deleteType) async { + { + required String lockId, + required String keyboardPwdId, + required int deleteType + }) async { final res = await apiProvider.deleteKeyboardPwd(lockId, keyboardPwdId, deleteType); return PasswordKeyEntity.fromJson(res.body);