fix: 1,开锁页-设置-基本信息-管理员开锁密码 现可修改成密码列表里已有的密码,应不能改 2,修改管理员密码框内有旧密码问题修改

This commit is contained in:
wuyaxi 2025-06-13 14:36:06 +08:00
parent 4c3da6d194
commit 130dd8be8f
5 changed files with 106 additions and 33 deletions

View File

@ -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<Reply> _replySubscription;
void _initReplySubscription() {
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
if (reply is ChangeAdministratorPasswordReply && state.ifCurrentScreen.value == true) {
_replySubscription =
EventBusManager().eventBus!.on<Reply>().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<String>? signKey = await Storage.getStringList(saveBlueSignKey);
final List<String>? signKey =
await Storage.getStringList(saveBlueSignKey);
final List<int> signKeyDataList = changeStringListToIntList(signKey!);
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
final List<String>? privateKey =
await Storage.getStringList(saveBluePrivateKey);
final List<int> getPrivateKeyList =
changeStringListToIntList(privateKey!);
final List<int> token = reply.data.sublist(5, 9);
final List<String> 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<void> 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<String>? signKey = await Storage.getStringList(saveBlueSignKey);
final List<String>? signKey =
await Storage.getStringList(saveBlueSignKey);
final List<int> signKeyDataList = changeStringListToIntList(signKey!);
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
final List<String>? privateKey =
await Storage.getStringList(saveBluePrivateKey);
final List<int> getPrivateKeyList =
changeStringListToIntList(privateKey!);
final List<String>? token = await Storage.getStringList(saveBlueToken);
final List<int> 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<void> 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<bool> 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();
}
}

View File

@ -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<AdminOpenLockPasswordPage> createState() => _AdminOpenLockPasswordPageState();
State<AdminOpenLockPasswordPage> createState() =>
_AdminOpenLockPasswordPageState();
}
class _AdminOpenLockPasswordPageState extends State<AdminOpenLockPasswordPage> with RouteAware {
final AdminOpenLockPasswordLogic logic = Get.put(AdminOpenLockPasswordLogic());
final AdminOpenLockPasswordState state = Get.find<AdminOpenLockPasswordLogic>().state;
class _AdminOpenLockPasswordPageState extends State<AdminOpenLockPasswordPage>
with RouteAware {
final AdminOpenLockPasswordLogic logic =
Get.put(AdminOpenLockPasswordLogic());
final AdminOpenLockPasswordState state =
Get.find<AdminOpenLockPasswordLogic>().state;
@override
Widget build(BuildContext context) {
@ -95,16 +98,23 @@ class _AdminOpenLockPasswordPageState extends State<AdminOpenLockPasswordPage> 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();
},

View File

@ -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'; //

View File

@ -562,6 +562,14 @@ class ApiProvider extends BaseProvider {
'keyboardPwd': keyboardPwd,
}));
//
Future<Response> checkAdminPwd(int lockId, String keyboardPwd) => post(
adminPwdCheckKeyboardPwdURL.toUrl,
jsonEncode({
'lockId': lockId,
'keyboardPwd': keyboardPwd,
}));
Future<Response> updateKeyboardPwd(
int lockId,
String keyboardPwdId,

View File

@ -579,6 +579,13 @@ class ApiRepository {
return PasswordKeyEntity.fromJson(res.body);
}
//
Future<PasswordKeyEntity> checkAdminPwd(
{required int lockId, required String adminPwd}) async {
final res = await apiProvider.checkAdminPwd(lockId, adminPwd);
return PasswordKeyEntity.fromJson(res.body);
}
//
Future<PasswordKeyEntity> updatePasswordKey(
{required int lockId,