From 130dd8be8f8e4a048ff0ce29b6cd86d3b1c46f65 Mon Sep 17 00:00:00 2001 From: wuyaxi <18682150237@163.com> Date: Fri, 13 Jun 2025 14:36:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=201,=E5=BC=80=E9=94=81=E9=A1=B5-=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE-=E5=9F=BA=E6=9C=AC=E4=BF=A1=E6=81=AF-=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=91=98=E5=BC=80=E9=94=81=E5=AF=86=E7=A0=81=20?= =?UTF-8?q?=E7=8E=B0=E5=8F=AF=E4=BF=AE=E6=94=B9=E6=88=90=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E9=87=8C=E5=B7=B2=E6=9C=89=E7=9A=84=E5=AF=86?= =?UTF-8?q?=E7=A0=81=EF=BC=8C=E5=BA=94=E4=B8=8D=E8=83=BD=E6=94=B9=202,?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=AE=A1=E7=90=86=E5=91=98=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E6=A1=86=E5=86=85=E6=9C=89=E6=97=A7=E5=AF=86=E7=A0=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminOpenLockPassword_logic.dart | 96 ++++++++++++++----- .../adminOpenLockPassword_page.dart | 26 +++-- lib/network/api.dart | 2 + lib/network/api_provider.dart | 8 ++ lib/network/api_repository.dart | 7 ++ 5 files changed, 106 insertions(+), 33 deletions(-) diff --git a/lib/main/lockDetail/lockSet/basicInformation/adminOpenLockPassword/adminOpenLockPassword_logic.dart b/lib/main/lockDetail/lockSet/basicInformation/adminOpenLockPassword/adminOpenLockPassword_logic.dart index 5886160d..a9ca5ade 100755 --- a/lib/main/lockDetail/lockSet/basicInformation/adminOpenLockPassword/adminOpenLockPassword_logic.dart +++ b/lib/main/lockDetail/lockSet/basicInformation/adminOpenLockPassword/adminOpenLockPassword_logic.dart @@ -1,9 +1,9 @@ - import 'dart:async'; import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; import 'package:star_lock/main/lockDetail/lockSet/lockTime/getServerDatetime_entity.dart'; +import 'package:star_lock/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKeyEntity.dart'; import '../../../../../blue/blue_manage.dart'; import '../../../../../blue/io_protocol/io_changeAdministratorPassword.dart'; @@ -18,14 +18,16 @@ import '../../../../../tools/eventBusEventManage.dart'; import '../../../../../tools/storage.dart'; import 'adminOpenLockPassword_state.dart'; -class AdminOpenLockPasswordLogic extends BaseGetXController{ +class AdminOpenLockPasswordLogic extends BaseGetXController { final AdminOpenLockPasswordState state = AdminOpenLockPasswordState(); // 获取解析后的数据 late StreamSubscription _replySubscription; void _initReplySubscription() { - _replySubscription = EventBusManager().eventBus!.on().listen((Reply reply) { - if (reply is ChangeAdministratorPasswordReply && state.ifCurrentScreen.value == true) { + _replySubscription = + EventBusManager().eventBus!.on().listen((Reply reply) { + if (reply is ChangeAdministratorPasswordReply && + state.ifCurrentScreen.value == true) { _replyChangeAdministratorPassword(reply); } @@ -49,11 +51,14 @@ class AdminOpenLockPasswordLogic extends BaseGetXController{ break; case 0x06: //无权限 - final List? signKey = await Storage.getStringList(saveBlueSignKey); + final List? signKey = + await Storage.getStringList(saveBlueSignKey); final List signKeyDataList = changeStringListToIntList(signKey!); - final List? privateKey = await Storage.getStringList(saveBluePrivateKey); - final List getPrivateKeyList = changeStringListToIntList(privateKey!); + final List? privateKey = + await Storage.getStringList(saveBluePrivateKey); + final List getPrivateKeyList = + changeStringListToIntList(privateKey!); final List token = reply.data.sublist(5, 9); final List saveStrList = changeIntListToStringList(token); @@ -63,7 +68,7 @@ class AdminOpenLockPasswordLogic extends BaseGetXController{ keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(), userID: await Storage.getUid(), pwdNo: state.lockBasicInfo.value.lockUserNo!, - pwd:state.changePwdController.text, + pwd: state.changePwdController.text, useCountLimit: 0xffff, startTime: 0, endTime: 0, @@ -179,23 +184,27 @@ class AdminOpenLockPasswordLogic extends BaseGetXController{ // 修改管理员密码(同添加自定义开锁密码,指纹/密码/卡片前5个是管理员) Future changeAdministratorPasswordCommand() async { - if(state.sureBtnState.value == 1){ + if (state.sureBtnState.value == 1) { return; } state.sureBtnState.value = 1; showEasyLoading(); - showBlueConnetctToastTimer(action: (){ + showBlueConnetctToastTimer(action: () { dismissEasyLoading(); state.sureBtnState.value = 0; }); - BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { + BlueManage().blueSendData(BlueManage().connectDeviceName, + (BluetoothConnectionState deviceConnectionState) async { if (deviceConnectionState == BluetoothConnectionState.connected) { - final List? signKey = await Storage.getStringList(saveBlueSignKey); + final List? signKey = + await Storage.getStringList(saveBlueSignKey); final List signKeyDataList = changeStringListToIntList(signKey!); - final List? privateKey = await Storage.getStringList(saveBluePrivateKey); - final List getPrivateKeyList = changeStringListToIntList(privateKey!); + final List? privateKey = + await Storage.getStringList(saveBluePrivateKey); + final List getPrivateKeyList = + changeStringListToIntList(privateKey!); final List? token = await Storage.getStringList(saveBlueToken); final List getTokenList = changeStringListToIntList(token!); @@ -204,7 +213,7 @@ class AdminOpenLockPasswordLogic extends BaseGetXController{ keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(), userID: await Storage.getUid(), pwdNo: state.lockBasicInfo.value.lockUserNo!, - pwd:state.changePwdController.text, + pwd: state.changePwdController.text, useCountLimit: 0xffff, startTime: 0, endTime: 0, @@ -213,11 +222,12 @@ class AdminOpenLockPasswordLogic extends BaseGetXController{ signKey: signKeyDataList, privateKey: getPrivateKeyList, token: getTokenList); - } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { + } else if (deviceConnectionState == + BluetoothConnectionState.disconnected) { state.sureBtnState.value = 0; dismissEasyLoading(); cancelBlueConnetctToastTimer(); - if(state.ifCurrentScreen.value == true){ + if (state.ifCurrentScreen.value == true) { showBlueConnetctToast(); } } @@ -226,25 +236,62 @@ class AdminOpenLockPasswordLogic extends BaseGetXController{ // 更新管理员密码 Future addLockAdminPassword(bool isChange) async { - final GetServerDatetimeEntity entity = await ApiRepository.to.setAdminPasswordData( + final GetServerDatetimeEntity entity = + await ApiRepository.to.setAdminPasswordData( lockId: state.lockSetInfoData.value.lockBasicInfo!.lockId!, adminPwd: state.adminPwd.value, ); if (entity.errorCode!.codeIsSuccessful) { - if(isChange == true){ - showToast('修改成功'.tr, something: (){ + if (isChange == true) { + showToast('修改成功'.tr, something: () { state.lockBasicInfo.value.adminPwd = state.adminPwd.value; - eventBus.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value)); + eventBus.fire( + PassCurrentLockInformationEvent(state.lockSetInfoData.value)); }); - }else{ - showToast('上传成功'.tr, something: (){ + } else { + showToast('上传成功'.tr, something: () { state.lockBasicInfo.value.adminPwd = state.adminPwd.value; - eventBus.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value)); + eventBus.fire( + PassCurrentLockInformationEvent(state.lockSetInfoData.value)); }); } } } + /// 检查管理员密码是否重复 + /// + /// 返回值: + /// - true: 密码不重复,可以使用 + /// - false: 密码重复,不可使用 + Future checkPassword() async { + try { + if (state.lockSetInfoData.value.lockBasicInfo?.lockId == null) { + showToast('锁ID不能为空'.tr); + return false; + } + + if (state.adminPwd.value.isEmpty) { + showToast('密码不能为空'.tr); + return false; + } + + final PasswordKeyEntity entity = await ApiRepository.to.checkAdminPwd( + lockId: state.lockSetInfoData.value.lockBasicInfo!.lockId!, + adminPwd: state.changePwdController.text, + ); + + if (entity.errorCode!.codeIsSuccessful) { + return true; + } else { + showToast(entity.errorMsg ?? '已存在相同的密码,请更换。'); + return false; + } + } catch (e) { + showToast('检查密码失败'.tr); + return false; + } + } + @override void onReady() { super.onReady(); @@ -257,5 +304,4 @@ class AdminOpenLockPasswordLogic extends BaseGetXController{ super.onClose(); _replySubscription.cancel(); } - } diff --git a/lib/main/lockDetail/lockSet/basicInformation/adminOpenLockPassword/adminOpenLockPassword_page.dart b/lib/main/lockDetail/lockSet/basicInformation/adminOpenLockPassword/adminOpenLockPassword_page.dart index ffa2e162..ff487734 100755 --- a/lib/main/lockDetail/lockSet/basicInformation/adminOpenLockPassword/adminOpenLockPassword_page.dart +++ b/lib/main/lockDetail/lockSet/basicInformation/adminOpenLockPassword/adminOpenLockPassword_page.dart @@ -1,4 +1,3 @@ - import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; @@ -16,12 +15,16 @@ class AdminOpenLockPasswordPage extends StatefulWidget { const AdminOpenLockPasswordPage({Key? key}) : super(key: key); @override - State createState() => _AdminOpenLockPasswordPageState(); + State createState() => + _AdminOpenLockPasswordPageState(); } -class _AdminOpenLockPasswordPageState extends State with RouteAware { - final AdminOpenLockPasswordLogic logic = Get.put(AdminOpenLockPasswordLogic()); - final AdminOpenLockPasswordState state = Get.find().state; +class _AdminOpenLockPasswordPageState extends State + with RouteAware { + final AdminOpenLockPasswordLogic logic = + Get.put(AdminOpenLockPasswordLogic()); + final AdminOpenLockPasswordState state = + Get.find().state; @override Widget build(BuildContext context) { @@ -95,16 +98,23 @@ class _AdminOpenLockPasswordPageState extends State w LengthLimitingTextInputFormatter(9), ], controller: state.changePwdController, - sureClick: () { - if(state.changePwdController.text.length < 6){ + sureClick: () async { + if (state.changePwdController.text.length < 6) { logic.showToast('请输入6-9位管理员密码'.tr); return; } - if(state.changePwdController.text == state.lockBasicInfo.value.adminPwd!){ + if (state.changePwdController.text == + state.lockBasicInfo.value.adminPwd!) { logic.showToast('请输入新的管理员密码'.tr); return; } + // 检查密码是否重复 + final bool isPasswordAvailable = await logic.checkPassword(); + if (!isPasswordAvailable) { + return; // 如果密码重复,直接返回 + } + Get.back(); logic.changeAdministratorPasswordCommand(); }, diff --git a/lib/network/api.dart b/lib/network/api.dart index db9ccf33..8f80e752 100755 --- a/lib/network/api.dart +++ b/lib/network/api.dart @@ -49,6 +49,8 @@ abstract class Api { final String passwordKeyAddURL = '/keyboardPwd/add'; //自定义密码 final String passwordKeyCheckKeyboardpwdNameURL = '/keyboardPwd/checkKeyboardpwdName'; //自定义密码校验密码跟名字是否重复 + final String adminPwdCheckKeyboardPwdURL = + '/keyboardPwd/checkKeyboardPwd'; //检查密码是否重复包括管理员密码 final String updatePasswordKeyURL = '/keyboardPwd/update'; //修改密码详情 final String updatePWDNumberURL = '/keyboardPwd/updatePwdUserNo'; //更新锁用户需要 final String clearOperationRecordURL = '/lockRecords/clear'; //清空操作记录 diff --git a/lib/network/api_provider.dart b/lib/network/api_provider.dart index 4cad97cc..aa841e1a 100755 --- a/lib/network/api_provider.dart +++ b/lib/network/api_provider.dart @@ -562,6 +562,14 @@ class ApiProvider extends BaseProvider { 'keyboardPwd': keyboardPwd, })); + //检查密码是否重复包括管理员密码 + Future checkAdminPwd(int lockId, String keyboardPwd) => post( + adminPwdCheckKeyboardPwdURL.toUrl, + jsonEncode({ + 'lockId': lockId, + 'keyboardPwd': keyboardPwd, + })); + Future updateKeyboardPwd( int lockId, String keyboardPwdId, diff --git a/lib/network/api_repository.dart b/lib/network/api_repository.dart index b5e09c33..36ac710b 100755 --- a/lib/network/api_repository.dart +++ b/lib/network/api_repository.dart @@ -579,6 +579,13 @@ class ApiRepository { return PasswordKeyEntity.fromJson(res.body); } + //检查密码是否重复包括管理员密码 + Future checkAdminPwd( + {required int lockId, required String adminPwd}) async { + final res = await apiProvider.checkAdminPwd(lockId, adminPwd); + return PasswordKeyEntity.fromJson(res.body); + } + //修改密码 Future updatePasswordKey( {required int lockId,