1,发送钥匙成功后返回列表刷新

This commit is contained in:
Daisy 2023-08-31 18:50:28 +08:00
parent 7f44198536
commit d6570450cf
8 changed files with 182 additions and 158 deletions

View File

@ -1,4 +1,3 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
@ -21,9 +20,10 @@ class AuthorizedAdminLogic extends BaseGetXController {
// //
late StreamSubscription<Reply> _replySubscription; late StreamSubscription<Reply> _replySubscription;
void _initReplySubscription() { void _initReplySubscription() {
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((reply) async { _replySubscription =
EventBusManager().eventBus!.on<Reply>().listen((reply) async {
// //
if(reply is TransferPermissionsReply) { if (reply is TransferPermissionsReply) {
var token = reply.data.sublist(2, 6); var token = reply.data.sublist(2, 6);
var saveStrList = changeIntListToStringList(token); var saveStrList = changeIntListToStringList(token);
print("_replyFactoryDataResetKeyToken:$token"); print("_replyFactoryDataResetKeyToken:$token");
@ -32,17 +32,18 @@ class AuthorizedAdminLogic extends BaseGetXController {
int status = reply.data[6]; int status = reply.data[6];
print("status:$status"); print("status:$status");
switch(status){ switch (status) {
case 0x00: case 0x00:
// //
print("${reply.commandType!.typeValue} 数据解析成功"); print("${reply.commandType!.typeValue} 数据解析成功");
break; break;
case 0x06: case 0x06:
// //
print("${reply.commandType!.typeValue} 需要鉴权"); print("${reply.commandType!.typeValue} 需要鉴权");
var privateKey = await Storage.getStringList(saveBluePrivateKey); var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!); List<int> getPrivateKeyList =
changeStringListToIntList(privateKey!);
var publicKey = await Storage.getStringList(saveBluePublicKey); var publicKey = await Storage.getStringList(saveBluePublicKey);
List<int> publicKeyDataList = changeStringListToIntList(publicKey!); List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
@ -51,27 +52,26 @@ class AuthorizedAdminLogic extends BaseGetXController {
List<int> getTokenList = changeStringListToIntList(token!); List<int> getTokenList = changeStringListToIntList(token!);
IoSenderManage.senderFactoryDataReset( IoSenderManage.senderFactoryDataReset(
lockID:BlueManage().connectDeviceName, lockID: BlueManage().connectDeviceName,
userID:await Storage.getUid(), userID: await Storage.getUid(),
keyID:"1", keyID: "1",
needAuthor:1, needAuthor: 1,
publicKey:publicKeyDataList, publicKey: publicKeyDataList,
privateKey:getPrivateKeyList, privateKey: getPrivateKeyList,
token: getTokenList token: getTokenList);
);
break; break;
case 0x07: case 0x07:
// //
print("${reply.commandType!.typeValue} 用户无权限"); print("${reply.commandType!.typeValue} 用户无权限");
break; break;
case 0x09: case 0x09:
// //
print("${reply.commandType!.typeValue} 权限校验错误"); print("${reply.commandType!.typeValue} 权限校验错误");
break; break;
default: default:
// //
print("${reply.commandType!.typeValue} 失败"); print("${reply.commandType!.typeValue} 失败");
break; break;
@ -82,8 +82,10 @@ class AuthorizedAdminLogic extends BaseGetXController {
// //
Future<void> transferPermissionsAction() async { Future<void> transferPermissionsAction() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async { BlueManage().judgeReconnect(
if (state == DeviceConnectionState.connected){ BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName,
(DeviceConnectionState state) async {
if (state == DeviceConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey); var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!); List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -95,16 +97,15 @@ class AuthorizedAdminLogic extends BaseGetXController {
print("openDoorTokenPubToken:$getTokenList"); print("openDoorTokenPubToken:$getTokenList");
IoSenderManage.senderTransferPermissions( IoSenderManage.senderTransferPermissions(
lockID:BlueManage().connectDeviceName, lockID: BlueManage().connectDeviceName,
authUserID:await Storage.getUid(), authUserID: await Storage.getUid(),
keyID:"1", keyID: "1",
oldUserID:await Storage.getUid(), oldUserID: await Storage.getUid(),
newUserID:"100002", newUserID: "100002",
needAuthor:1, needAuthor: 1,
publicKey:publicKeyDataList, publicKey: publicKeyDataList,
privateKey:getPrivateKeyList, privateKey: getPrivateKeyList,
token: getTokenList token: getTokenList);
);
} }
}); });
} }
@ -121,7 +122,6 @@ class AuthorizedAdminLogic extends BaseGetXController {
void onInit() { void onInit() {
// TODO: implement onInit // TODO: implement onInit
super.onInit(); super.onInit();
} }
@override @override
@ -129,5 +129,4 @@ class AuthorizedAdminLogic extends BaseGetXController {
// TODO: implement onClose // TODO: implement onClose
_replySubscription.cancel(); _replySubscription.cancel();
} }
}
}

View File

@ -302,7 +302,7 @@ class _AuthorizedAdminPageState extends State<AuthorizedAdminPage> {
btnName: '完成', btnName: '完成',
onClick: () { onClick: () {
_isSendSuccess = false; _isSendSuccess = false;
setState(() {}); Navigator.pop(context, true);
}), }),
SizedBox( SizedBox(
height: 10.h, height: 10.h,

View File

@ -69,7 +69,12 @@ class _AuthorizedAdminListPageState extends State<AuthorizedAdminListPage> {
arguments: { arguments: {
"lockMainEntity": lockMainEntity, "lockMainEntity": lockMainEntity,
"keyInfo": keyInfo "keyInfo": keyInfo
}); }).then((val) {
if (val != null) {
mockNetworkDataRequest();
setState(() {});
}
});
}, },
), ),
SizedBox( SizedBox(

View File

@ -82,7 +82,12 @@ class _ElectronicKeyListPageState extends State<ElectronicKeyListPage> {
arguments: { arguments: {
"lockMainEntity": lockMainEntity, "lockMainEntity": lockMainEntity,
"keyInfo": keyInfo "keyInfo": keyInfo
}); }).then((val) {
if (val != null) {
mockNetworkDataRequest();
setState(() {});
}
});
}, },
), ),
SizedBox( SizedBox(

View File

@ -80,67 +80,63 @@ class _SendElectronicKeyPageState extends State<SendElectronicKeyPage> {
} }
Widget indexChangeWidget() { Widget indexChangeWidget() {
switch (int.parse(widget.type)) { if (_isSendSuccess) {
case 0: return sendElectronicKeySucceed();
{ } else {
// switch (int.parse(widget.type)) {
return _isSendSuccess case 0:
? sendElectronicKeySucceed() {
: Column( //
children: [ return Column(
keyInfoWidget(), children: [
keyTimeWidget(), keyInfoWidget(),
remoteUnlockingWidget(), keyTimeWidget(),
keyRealNameWidget(), remoteUnlockingWidget(),
keyBottomWidget() keyRealNameWidget(),
], keyBottomWidget()
); ],
} );
case 1: }
{ case 1:
// {
return _isSendSuccess //
? sendElectronicKeySucceed() return Column(
: Column( children: [
children: [ keyInfoWidget(),
keyInfoWidget(), remoteUnlockingWidget(),
remoteUnlockingWidget(), keyRealNameWidget(),
keyRealNameWidget(), keyBottomWidget()
keyBottomWidget() ],
], );
); }
} case 2:
case 2: {
{ //
// return Column(
return _isSendSuccess children: [
? sendElectronicKeySucceed() keyInfoWidget(),
: Column( remoteUnlockingWidget(),
children: [ keyRealNameWidget(),
keyInfoWidget(), keyBottomWidget()
remoteUnlockingWidget(), ],
keyRealNameWidget(), );
keyBottomWidget() }
], case 3:
); {
} //
case 3: return Column(
{ children: [
// keyInfoWidget(),
return _isSendSuccess keyPeriodValidityWidget(),
? sendElectronicKeySucceed() remoteUnlockingWidget(),
: Column( keyRealNameWidget(),
children: [ keyBottomWidget()
keyInfoWidget(), ],
keyPeriodValidityWidget(), );
remoteUnlockingWidget(), }
keyRealNameWidget(), default:
keyBottomWidget() return Container();
], }
);
}
default:
return Container();
} }
} }
@ -412,7 +408,7 @@ class _SendElectronicKeyPageState extends State<SendElectronicKeyPage> {
btnName: '完成', btnName: '完成',
onClick: () { onClick: () {
_isSendSuccess = false; _isSendSuccess = false;
setState(() {}); Navigator.pop(context, true);
}), }),
SizedBox( SizedBox(
height: 10.h, height: 10.h,

View File

@ -75,15 +75,20 @@ class _PasswordKeyListPageState extends State<PasswordKeyListPage> {
height: 20.h, height: 20.h,
), ),
AddBottomWhiteBtn( AddBottomWhiteBtn(
btnName: TranslationLoader.lanKeys!.getPassword!.tr, btnName: TranslationLoader.lanKeys!.getPassword!.tr,
onClick: () { onClick: () {
Navigator.pushNamed( Navigator.pushNamed(
context, Routers.passwordKeyManagePage, arguments: { context, Routers.passwordKeyManagePage,
"lockMainEntity": lockMainEntity, arguments: {
"keyInfo": keyInfo "lockMainEntity": lockMainEntity,
}); "keyInfo": keyInfo
}, }).then((val) {
), if (val != null) {
mockNetworkDataRequest();
setState(() {});
}
});
}),
SizedBox( SizedBox(
height: 42.h, height: 42.h,
) )

View File

@ -14,13 +14,14 @@ import '../../../../tools/baseGetXController.dart';
import '../../../../tools/storage.dart'; import '../../../../tools/storage.dart';
class PasswordKeyPerpetualLogic extends BaseGetXController { class PasswordKeyPerpetualLogic extends BaseGetXController {
late DateTime getStartDateTime;
// //
late StreamSubscription<Reply> _replySubscription; late StreamSubscription<Reply> _replySubscription;
void _initReplySubscription() { void _initReplySubscription() {
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((reply) async { _replySubscription =
EventBusManager().eventBus!.on<Reply>().listen((reply) async {
// //
if(reply is SenderCustomPasswordsReply) { if (reply is SenderCustomPasswordsReply) {
var token = reply.data.sublist(2, 6); var token = reply.data.sublist(2, 6);
var saveStrList = changeIntListToStringList(token); var saveStrList = changeIntListToStringList(token);
print("_replyFactoryDataResetKeyToken:$token"); print("_replyFactoryDataResetKeyToken:$token");
@ -29,47 +30,49 @@ class PasswordKeyPerpetualLogic extends BaseGetXController {
int status = reply.data[6]; int status = reply.data[6];
print("status:$status"); print("status:$status");
switch(status){ switch (status) {
case 0x00: case 0x00:
// //
print("${reply.commandType!.typeValue} 数据解析成功"); print("${reply.commandType!.typeValue} 数据解析成功");
break; break;
case 0x06: case 0x06:
// //
print("${reply.commandType!.typeValue} 需要鉴权"); print("${reply.commandType!.typeValue} 需要鉴权");
var privateKey = await Storage.getStringList(saveBluePrivateKey); var privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!); List<int> getPrivateKeyList =
changeStringListToIntList(privateKey!);
var publicKey = await Storage.getStringList(saveBluePublicKey); var publicKey = await Storage.getStringList(saveBluePublicKey);
List<int> publicKeyDataList = changeStringListToIntList(publicKey!); List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
print('得到的开始时间时间戳$getStartDate');
IoSenderManage.senderCustomPasswordsCommand( IoSenderManage.senderCustomPasswordsCommand(
keyID:"1", keyID: "1",
userID:await Storage.getUid(), userID: await Storage.getUid(),
pwdNo:1, pwdNo: 1,
pwd: "123456", pwd: "123456",
useCountLimit:0xff, useCountLimit: 0xff,
startTime:0x11223344, startTime: 0x11223344,
endTime:0x11223344, endTime: 0x11223344,
needAuthor:1, needAuthor: 1,
publicKey:publicKeyDataList, publicKey: publicKeyDataList,
privateKey:getPrivateKeyList, privateKey: getPrivateKeyList,
token: token token: token);
);
break; break;
case 0x07: case 0x07:
// //
print("${reply.commandType!.typeValue} 用户无权限"); print("${reply.commandType!.typeValue} 用户无权限");
break; break;
case 0x09: case 0x09:
// //
print("${reply.commandType!.typeValue} 权限校验错误"); print("${reply.commandType!.typeValue} 权限校验错误");
break; break;
default: default:
// //
print("${reply.commandType!.typeValue} 失败"); print("${reply.commandType!.typeValue} 失败");
break; break;
@ -78,10 +81,16 @@ class PasswordKeyPerpetualLogic extends BaseGetXController {
}); });
} }
void getStartDate(DateTime startDate) {
getStartDateTime = startDate;
}
// //
Future<void> senderCustomPasswords() async { Future<void> senderCustomPasswords() async {
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async { BlueManage().judgeReconnect(
if (state == DeviceConnectionState.connected){ BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName,
(DeviceConnectionState state) async {
if (state == DeviceConnectionState.connected) {
var publicKey = await Storage.getStringList(saveBluePublicKey); var publicKey = await Storage.getStringList(saveBluePublicKey);
List<int> publicKeyDataList = changeStringListToIntList(publicKey!); List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
@ -93,18 +102,17 @@ class PasswordKeyPerpetualLogic extends BaseGetXController {
print("openDoorTokenPubToken:$getTokenList"); print("openDoorTokenPubToken:$getTokenList");
IoSenderManage.senderCustomPasswordsCommand( IoSenderManage.senderCustomPasswordsCommand(
keyID:"1", keyID: "1",
userID:await Storage.getUid(), userID: await Storage.getUid(),
pwdNo:1, pwdNo: 1,
pwd: "123456", pwd: "123456",
useCountLimit:0xff, useCountLimit: 0xff,
startTime:0x11223344, startTime: 0x11223344,
endTime:0x11223344, endTime: 0x11223344,
needAuthor:1, needAuthor: 1,
publicKey:publicKeyDataList, publicKey: publicKeyDataList,
privateKey:getPrivateKeyList, privateKey: getPrivateKeyList,
token: getTokenList token: getTokenList);
);
} }
}); });
} }
@ -121,7 +129,6 @@ class PasswordKeyPerpetualLogic extends BaseGetXController {
void onInit() { void onInit() {
// TODO: implement onInit // TODO: implement onInit
super.onInit(); super.onInit();
} }
@override @override
@ -129,5 +136,4 @@ class PasswordKeyPerpetualLogic extends BaseGetXController {
// TODO: implement onClose // TODO: implement onClose
_replySubscription.cancel(); _replySubscription.cancel();
} }
}
}

View File

@ -6,6 +6,7 @@ import 'package:flutter_pickers/style/default_style.dart';
import 'package:flutter_pickers/time_picker/model/date_mode.dart'; import 'package:flutter_pickers/time_picker/model/date_mode.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:star_lock/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart';
import 'package:star_lock/main/lockMian/entity/lockInfoEntity.dart'; import 'package:star_lock/main/lockMian/entity/lockInfoEntity.dart';
import 'package:star_lock/network/api_repository.dart'; import 'package:star_lock/network/api_repository.dart';
import 'package:star_lock/tools/baseGetXController.dart'; import 'package:star_lock/tools/baseGetXController.dart';
@ -33,7 +34,10 @@ class PasswordKeyPerpetualPage extends StatefulWidget {
} }
class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> { class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
final TextEditingController _controller = TextEditingController(); final TextEditingController _nameController = TextEditingController();
final TextEditingController _pwdController = TextEditingController();
final logic = Get.put(PasswordKeyPerpetualLogic());
late bool _isSendSuccess; // late bool _isSendSuccess; //
late bool _isPermanent; // late bool _isPermanent; //
late String _getPwdStr; late String _getPwdStr;
@ -47,7 +51,9 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return indexChangeWidget(); return SingleChildScrollView(
child: indexChangeWidget(),
);
} }
@override @override
@ -85,7 +91,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
perpetualKeyWidget( perpetualKeyWidget(
TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.name!.tr,
TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr,
_controller), _nameController),
keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip1!.tr) keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip1!.tr)
], ],
); );
@ -99,7 +105,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
perpetualKeyWidget( perpetualKeyWidget(
TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.name!.tr,
TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr,
_controller), _nameController),
keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip2!.tr) keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip2!.tr)
], ],
); );
@ -112,7 +118,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
perpetualKeyWidget( perpetualKeyWidget(
TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.name!.tr,
TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr,
_controller), _nameController),
keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip3!.tr) keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip3!.tr)
], ],
); );
@ -127,9 +133,9 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
perpetualKeyWidget( perpetualKeyWidget(
TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.name!.tr,
TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr,
_controller), _nameController),
perpetualKeyWidget(TranslationLoader.lanKeys!.password!.tr, perpetualKeyWidget(TranslationLoader.lanKeys!.password!.tr,
"请输入6-9位数字", _controller), "请输入6-9位数字", _pwdController),
keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip4!.tr) keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip4!.tr)
], ],
); );
@ -143,7 +149,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
perpetualKeyWidget( perpetualKeyWidget(
TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.name!.tr,
TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr,
_controller), _nameController),
keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip5!.tr) keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip5!.tr)
], ],
); );
@ -156,7 +162,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
perpetualKeyWidget( perpetualKeyWidget(
TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.name!.tr,
TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr,
_controller), _nameController),
keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip6!.tr) keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip6!.tr)
], ],
); );
@ -179,7 +185,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
leftTitel: titleStr, leftTitel: titleStr,
rightTitle: "", rightTitle: "",
isHaveRightWidget: true, isHaveRightWidget: true,
rightWidget: getTFWidget(rightTitle)), rightWidget: getTFWidget(rightTitle, controller)),
), ),
SizedBox(height: 10.h), SizedBox(height: 10.h),
], ],
@ -346,6 +352,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
SubmitBtn( SubmitBtn(
btnName: TranslationLoader.lanKeys!.getPassword!.tr, btnName: TranslationLoader.lanKeys!.getPassword!.tr,
onClick: () { onClick: () {
logic.getStartDate(_effectiveDateTime);
getKeyboardPwdRequest(); getKeyboardPwdRequest();
}), }),
], ],
@ -403,7 +410,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
var entity = await ApiRepository.to.getPasswordKey( var entity = await ApiRepository.to.getPasswordKey(
getFailureDateTime, getFailureDateTime,
'0', '0',
_controller.text, _nameController.text,
getKeyType, getKeyType,
'0', '0',
lockId, lockId,
@ -466,7 +473,8 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
SubmitBtn( SubmitBtn(
btnName: '完成', btnName: '完成',
onClick: () { onClick: () {
Navigator.pop(context); _isSendSuccess = false;
Navigator.pop(context, true);
}), }),
SizedBox( SizedBox(
height: 10.h, height: 10.h,
@ -489,7 +497,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
} }
// //
Widget getTFWidget(String tfStr) { Widget getTFWidget(String tfStr, TextEditingController editController) {
return SizedBox( return SizedBox(
height: 50.h, height: 50.h,
width: 300.w, width: 300.w,
@ -499,7 +507,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
child: TextField( child: TextField(
// //
maxLines: 1, maxLines: 1,
controller: _controller, controller: editController,
autofocus: false, autofocus: false,
textAlign: TextAlign.end, textAlign: TextAlign.end,
decoration: InputDecoration( decoration: InputDecoration(