From 9a56b0ae1d18b1b9e71bd4d6e00180c75e1d489f Mon Sep 17 00:00:00 2001 From: anfe <448468458@qq.com> Date: Wed, 22 May 2024 15:23:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=20=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E9=94=81=20=E5=8F=91=E9=80=81=E5=AE=8C?= =?UTF-8?q?=E5=BA=94=E6=B2=A1=E6=9C=89=E7=9F=AD=E4=BF=A1=E3=80=81=E9=82=AE?= =?UTF-8?q?=E4=BB=B6=E3=80=81=E5=BE=AE=E4=BF=A1=E9=80=9A=E7=9F=A5=EF=BC=8C?= =?UTF-8?q?=E5=BA=94=E7=9B=B4=E6=8E=A5=E6=8F=90=E7=A4=BA=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../authorizedAdmin_logic.dart | 180 +++++++++++------- .../authorizedAdmin/authorizedAdmin_page.dart | 7 +- .../authorizedAdmin_state.dart | 24 +-- .../notice_template_entity.dart | 0 .../volumeAuthorizationLock_logic.dart | 2 +- lib/network/api_repository.dart | 2 +- lib/tools/NativeInteractionTool.dart | 26 +-- 7 files changed, 141 insertions(+), 100 deletions(-) rename lib/main/lockDetail/authorizedAdmin/{volumeAuthorizationLock => authorizedAdmin}/notice_template_entity.dart (100%) diff --git a/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_logic.dart b/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_logic.dart index 3869b32f..c0eb4073 100755 --- a/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_logic.dart +++ b/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_logic.dart @@ -5,7 +5,11 @@ import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; import 'package:star_lock/appRouters.dart'; import 'package:star_lock/app_settings/app_settings.dart'; +import 'package:star_lock/login/login/entity/LoginEntity.dart'; +import 'package:star_lock/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_entity.dart'; +import 'package:star_lock/main/lockDetail/authorizedAdmin/authorizedAdmin/notice_template_entity.dart'; import 'package:star_lock/mine/valueAddedServices/advancedFunctionRecord/advancedFunctionRecord_entity.dart'; +import 'package:star_lock/tools/NativeInteractionTool.dart'; import 'package:star_lock/tools/dateTool.dart'; import 'package:star_lock/tools/showCupertinoAlertView.dart'; @@ -26,18 +30,21 @@ import 'authorizedAdmin_state.dart'; class AuthorizedAdminLogic extends BaseGetXController { final AuthorizedAdminState state = AuthorizedAdminState(); + int? keyId; + // 监听设备返回的数据 late StreamSubscription _replySubscription; + void _initReplySubscription() { _replySubscription = - EventBusManager().eventBus!.on().listen((reply) async { + EventBusManager().eventBus!.on().listen((Reply reply) async { // 转移权限 if (reply is TransferPermissionsReply) { - var token = reply.data.sublist(2, 6); - var saveStrList = changeIntListToStringList(token); + final List token = reply.data.sublist(2, 6); + final List saveStrList = changeIntListToStringList(token); Storage.setStringList(saveBlueToken, saveStrList); - int status = reply.data[6]; + final int status = reply.data[6]; switch (status) { case 0x00: @@ -45,20 +52,24 @@ class AuthorizedAdminLogic extends BaseGetXController { break; case 0x06: //无权限 - var privateKey = await Storage.getStringList(saveBluePrivateKey); - List getPrivateKeyList = + final List? privateKey = + await Storage.getStringList(saveBluePrivateKey); + final List getPrivateKeyList = changeStringListToIntList(privateKey!); - var publicKey = await Storage.getStringList(saveBluePublicKey); - List publicKeyDataList = changeStringListToIntList(publicKey!); + final List? publicKey = + await Storage.getStringList(saveBluePublicKey); + final List publicKeyDataList = + changeStringListToIntList(publicKey!); - var token = await Storage.getStringList(saveBlueToken); - List getTokenList = changeStringListToIntList(token!); + final List? token = + await Storage.getStringList(saveBlueToken); + final List getTokenList = changeStringListToIntList(token!); IoSenderManage.senderFactoryDataReset( lockID: BlueManage().connectDeviceName, userID: await Storage.getUid(), - keyID: "1", + keyID: '1', needAuthor: 1, publicKey: publicKeyDataList, privateKey: getPrivateKeyList, @@ -76,21 +87,25 @@ class AuthorizedAdminLogic extends BaseGetXController { BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState state) async { if (state == BluetoothConnectionState.connected) { - var privateKey = await Storage.getStringList(saveBluePrivateKey); - List getPrivateKeyList = changeStringListToIntList(privateKey!); + final List? privateKey = + await Storage.getStringList(saveBluePrivateKey); + final List getPrivateKeyList = + changeStringListToIntList(privateKey!); - var publicKey = await Storage.getStringList(saveBluePublicKey); - List publicKeyDataList = changeStringListToIntList(publicKey!); + final List? publicKey = + await Storage.getStringList(saveBluePublicKey); + final List publicKeyDataList = + changeStringListToIntList(publicKey!); - var token = await Storage.getStringList(saveBlueToken); - List getTokenList = changeStringListToIntList(token!); + final List? token = await Storage.getStringList(saveBlueToken); + final List getTokenList = changeStringListToIntList(token!); IoSenderManage.senderTransferPermissions( lockID: BlueManage().connectDeviceName, authUserID: await Storage.getUid(), - keyID: "1", + keyID: '1', oldUserID: await Storage.getUid(), - newUserID: "100002", + newUserID: '100002', needAuthor: 1, publicKey: publicKeyDataList, privateKey: getPrivateKeyList, @@ -102,40 +117,40 @@ class AuthorizedAdminLogic extends BaseGetXController { //发送授权管理员列表请求 Future sendElectronicKeyRequest() async { if (state.emailOrPhoneController.text.isEmpty) { - showToast("请输入接收者账号"); + showToast('请输入接收者账号'); return; } if (state.keyNameController.text.isEmpty) { - showToast("请输入接收者姓名"); + showToast('请输入接收者姓名'); return; } - var startDate = "0"; - var endDate = "0"; - var startTime = "0"; - var endTime = "0"; - AppLog.log("state.type.value:${state.seletType.value}"); - String getKeyType = "1"; + String startDate = '0'; + String endDate = '0'; + String startTime = '0'; + String endTime = '0'; + AppLog.log('state.type.value:${state.seletType.value}'); + String getKeyType = '1'; if (state.seletType.value == 0) { - getKeyType = "2"; + getKeyType = '2'; startDate = DateTool().dateToTimestamp(state.beginDate.value, 1).toString(); endDate = DateTool().dateToTimestamp(state.endDate.value, 1).toString(); - startTime = "0"; - endTime = "0"; + startTime = '0'; + endTime = '0'; if (startDate.isEmpty) { - showToast("请选择开始时间"); + showToast('请选择开始时间'); return; } if (endDate.isEmpty) { - showToast("请选择结束时间"); + showToast('请选择结束时间'); return; } if (int.parse(startDate) >= int.parse(endDate)) { - showToast("失效时间要大于生效时间"); + showToast('失效时间要大于生效时间'); return; } } @@ -143,12 +158,12 @@ class AuthorizedAdminLogic extends BaseGetXController { //如果打开了实名认证,需要弹出输入身份证信息框 if (state.isAuthentication.value == true) { if (state.realNameController.text.isEmpty) { - showToast("请输入真实姓名".tr); + showToast('请输入真实姓名'.tr); return; } if (state.idCardController.text.isEmpty) { - showToast("请输入身份证号".tr); + showToast('请输入身份证号'.tr); return; } //弹出身份证信息确认框 @@ -179,38 +194,39 @@ class AuthorizedAdminLogic extends BaseGetXController { required String startDate, required String startTime, required String endTime}) async { - var entity = await ApiRepository.to.sendElectronicKey( - createUser: state.isCreateUser.value ? "1" : "0", - countryCode: state.countryCode.value, - usernameType: '1', - endDate: int.parse(endDate), - faceAuthentication: state.isAuthentication.value == true ? '1' : '2', - isCameraEnable: '2', - isRemoteUnlock: '2', - keyNameForAdmin: state.keyNameController.text, - keyRight: '1', - keyType: getKeyType, - lockId: CommonDataManage().currentKeyInfo.lockId!.toString(), - operatorUid: '', - receiverUsername: state.emailOrPhoneController.text, - remarks: '', - startDate: int.parse(startDate), - weekDays: state.weekdaysList, - startTime: int.parse(startTime), - endTime: int.parse(endTime), - isOnlyManageSelf: state.onlyManageYouCreatesUser.value ? 1 : 0, - realName: state.isRequireAuth.value == true - ? state.realNameController.text - : "", - idCardNumber: state.isRequireAuth.value == true - ? state.idCardController.text - : ""); + final AuthorizedAdminSendEntity entity = await ApiRepository.to + .sendElectronicKey( + createUser: state.isCreateUser.value ? '1' : '0', + countryCode: state.countryCode.value, + usernameType: '1', + endDate: int.parse(endDate), + faceAuthentication: + state.isAuthentication.value == true ? '1' : '2', + isCameraEnable: '2', + isRemoteUnlock: '2', + keyNameForAdmin: state.keyNameController.text, + keyRight: '1', + keyType: getKeyType, + lockId: CommonDataManage().currentKeyInfo.lockId!.toString(), + operatorUid: '', + receiverUsername: state.emailOrPhoneController.text, + remarks: '', + startDate: int.parse(startDate), + weekDays: state.weekdaysList, + startTime: int.parse(startTime), + endTime: int.parse(endTime), + isOnlyManageSelf: state.onlyManageYouCreatesUser.value ? 1 : 0, + realName: state.isRequireAuth.value == true + ? state.realNameController.text + : '', + idCardNumber: state.isRequireAuth.value == true + ? state.idCardController.text + : ''); if (entity.errorCode!.codeIsSuccessful) { state.isCreateUser.value = false; state.isSendSuccess.value = true; - // Toast.show(msg: "添加成功"); state.addUserId.value = entity.data!.receiverUser!.id.toString(); - // addUserConnectBlue(state.addUserId.value); + keyId = entity.data!.keyId; eventBus.fire(AuthorizedAdminPageRefreshUI()); } else { if (entity.errorCode == 425) { @@ -218,16 +234,15 @@ class AuthorizedAdminLogic extends BaseGetXController { state.isCreateUser.value = true; ShowTipView().showIosTipWithContentDialog( '${"是否发送授权管理员给未注册账号".tr}\n${state.emailOrPhoneController.text}', - () { - sendElectronicKeyRequest(); - }); + sendElectronicKeyRequest); } } } //检测实名认证是否支持开启 Future keyCheckFace() async { - AdvancedFunctionRecordEntity entity = await ApiRepository.to.keyCheckFace( + final AdvancedFunctionRecordEntity entity = + await ApiRepository.to.keyCheckFace( lockId: CommonDataManage().currentKeyInfo.lockId ?? 0, ); if (entity.errorCode!.codeIsSuccessful) { @@ -240,7 +255,7 @@ class AuthorizedAdminLogic extends BaseGetXController { titleStr: '实名认证为付费功能,请购买后再使用'.tr, sureClick: () { Get.toNamed(Routers.advancedFeaturesWebPage, - arguments: {'isShop': false}); + arguments: {'isShop': false}); }); } else if (entity.errorCode == 433) { //需联系管理员购买 @@ -250,12 +265,12 @@ class AuthorizedAdminLogic extends BaseGetXController { //标记房间为已入住 isOn:已入住: 1 空闲:2 Future updateRoomCheckIn() async { - var entity = await ApiRepository.to.setRoomStatusData( + final LoginEntity entity = await ApiRepository.to.setRoomStatusData( lockId: CommonDataManage().currentKeyInfo.lockId!, roomStatus: 1, ); if (entity.errorCode!.codeIsSuccessful) { - showToast("标记成功"); + showToast('标记成功'); } } @@ -279,6 +294,31 @@ class AuthorizedAdminLogic extends BaseGetXController { return currentController; } + //发送消息 + Future sendMsg({required bool isPhone}) async { + if (keyId == null) { + return; + } + final NoticeTemplateEntity entity = await ApiRepository.to + .getNoticeTemplate( + lockId: CommonDataManage().currentKeyInfo.lockId!, + keyId: keyId!, + channelType: isPhone ? 1 : 2); + if (entity.errorCode!.codeIsSuccessful) { + final List list = + entity.data!.list!.where((Item item) => item.isUse == 0).toList(); + if (list.isNotEmpty) { + final Item item = list.first!; + final String template = item.template ?? ''; + NativeInteractionTool().loadNativeShare(shareText: template); + } else { + showToast('获取模板失败 0x02'); + } + } else { + showToast('获取模板失败 0x01'); + } + } + @override void onReady() { // TODO: implement onReady diff --git a/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_page.dart b/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_page.dart index 6f3d0d2f..d1e2bb3d 100755 --- a/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_page.dart +++ b/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_page.dart @@ -362,8 +362,7 @@ class _AuthorizedAdminPageState extends State if (state.emailOrPhoneController.text.contains('@')) { Get.toNamed(Routers.sendEmailNotificationPage); } else { - NativeInteractionTool() - .loadNativeShare(shareText: state.pwdShareStr); + logic.sendMsg(isPhone: true); } }, ), @@ -373,8 +372,8 @@ class _AuthorizedAdminPageState extends State OutLineBtn( btnName: '微信通知', onClick: () { - NativeInteractionTool() - .loadNativeShare(shareText: state.pwdShareStr); + logic.sendMsg( + isPhone: state.emailOrPhoneController.text.contains('@')); }, ), SizedBox( diff --git a/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_state.dart b/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_state.dart index 0a350e43..36dceadf 100755 --- a/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_state.dart +++ b/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_state.dart @@ -15,25 +15,25 @@ class AuthorizedAdminState { final FlutterContactPicker contactPicker = FlutterContactPicker(); late Contact contact; - var isAuthentication = false.obs; //是否可以实名认证 - final onlyManageYouCreatesUser = false.obs; // 只能管理自己创建的用户 + RxBool isAuthentication = false.obs; //是否可以实名认证 + final RxBool onlyManageYouCreatesUser = false.obs; // 只能管理自己创建的用户 - var beginDate = DateTool() + RxString beginDate = DateTool() .dateToYMDHNString(DateTime.now().millisecondsSinceEpoch.toString()) .obs; //默认为当前时间 开始时间 - var endDate = DateTool() + RxString endDate = DateTool() .dateToYMDHNString(DateTime.now().millisecondsSinceEpoch.toString()) .obs; //默认为当前时间 结束时间 - var isSendSuccess = false.obs; - var countryName = '中国'.obs; - var countryCode = '86'.obs; - var weekdaysList = [].obs; - var isCreateUser = false.obs; //用户未注册时传1 已注册传0 + RxBool isSendSuccess = false.obs; + RxString countryName = '中国'.obs; + RxString countryCode = '86'.obs; + RxList weekdaysList = [].obs; + RxBool isCreateUser = false.obs; //用户未注册时传1 已注册传0 - var seletType = 0.obs; + RxInt seletType = 0.obs; String pwdShareStr = '您好,您的授权管理员生成成功'; - var addUserId = ''.obs; - var isRequireAuth = false.obs; //是否需要实名认证的必填项 + RxString addUserId = ''.obs; + RxBool isRequireAuth = false.obs; //是否需要实名认证的必填项 } diff --git a/lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/notice_template_entity.dart b/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/notice_template_entity.dart similarity index 100% rename from lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/notice_template_entity.dart rename to lib/main/lockDetail/authorizedAdmin/authorizedAdmin/notice_template_entity.dart diff --git a/lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/volumeAuthorizationLock_logic.dart b/lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/volumeAuthorizationLock_logic.dart index d75cd07c..0c4ab05b 100755 --- a/lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/volumeAuthorizationLock_logic.dart +++ b/lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/volumeAuthorizationLock_logic.dart @@ -2,7 +2,7 @@ import 'dart:ffi'; import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:get/get.dart'; -import 'package:star_lock/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/notice_template_entity.dart'; +import 'package:star_lock/main/lockDetail/authorizedAdmin/authorizedAdmin/notice_template_entity.dart'; import 'package:star_lock/main/lockDetail/lockSet/basicInformation/basicInformation/KeyDetailEntity.dart'; import 'package:star_lock/network/api_repository.dart'; import 'package:star_lock/tools/baseGetXController.dart'; diff --git a/lib/network/api_repository.dart b/lib/network/api_repository.dart index d102f7be..133fdcea 100755 --- a/lib/network/api_repository.dart +++ b/lib/network/api_repository.dart @@ -1,7 +1,7 @@ import 'package:get/get.dart'; import 'package:star_lock/blue/entity/lock_user_no_list_entity.dart'; import 'package:star_lock/login/selectCountryRegion/common/countryRegionEntity.dart'; -import 'package:star_lock/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/notice_template_entity.dart'; +import 'package:star_lock/main/lockDetail/authorizedAdmin/authorizedAdmin/notice_template_entity.dart'; import 'package:star_lock/main/lockDetail/doorLockLog/doorLockLog_entity.dart'; import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyList/entity/ElectronicKeyListEntity.dart'; import 'package:star_lock/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/lockUserList/lockUserList_entity.dart'; diff --git a/lib/tools/NativeInteractionTool.dart b/lib/tools/NativeInteractionTool.dart index a94cf5e7..f971cfac 100755 --- a/lib/tools/NativeInteractionTool.dart +++ b/lib/tools/NativeInteractionTool.dart @@ -1,34 +1,38 @@ - import 'package:flutter/services.dart'; import '../app_settings/app_settings.dart'; ///原生交互配置 -class NativeInteractionConfig{ +class NativeInteractionConfig { static String methodSendChannel = 'starLockFlutterSend'; static String receiveEventChannel = 'starLockFlutterReceive'; } ///原生交互flutter向原生发送消息 typedef BlockBlueStatus = void Function(String status); -class NativeInteractionTool{ - var sendChannel = MethodChannel(NativeInteractionConfig.methodSendChannel); - var receiveChannel = MethodChannel(NativeInteractionConfig.receiveEventChannel); + +class NativeInteractionTool { + MethodChannel sendChannel = + MethodChannel(NativeInteractionConfig.methodSendChannel); + MethodChannel receiveChannel = + MethodChannel(NativeInteractionConfig.receiveEventChannel); ///加载原生分享 - loadNativeShare({required String shareText}){ - sendChannel.invokeMethod('loadNativeShare', {'shareText':shareText}); + void loadNativeShare({required String shareText}) { + sendChannel.invokeMethod( + 'loadNativeShare', {'shareText': shareText}); } ///获取设备蓝牙状态 - sendGetBlueStatus(){ + void sendGetBlueStatus() { sendChannel.invokeMethod('sendGetBlueStatus'); } ///获取设备蓝牙是否打开 - receiveChannelBlueIsOnEvent(BlockBlueStatus blockBlueStatus){ + void receiveChannelBlueIsOnEvent(BlockBlueStatus blockBlueStatus) { receiveChannel.setMethodCallHandler((MethodCall call) async { - AppLog.log('收到原生发送的信息call.method: ${call.method} call.arguments:${call.arguments}'); + AppLog.log( + '收到原生发送的信息call.method: ${call.method} call.arguments:${call.arguments}'); switch (call.method) { case 'getBlueStatus': // 获取设备蓝牙开启/关闭状态 @@ -42,5 +46,3 @@ class NativeInteractionTool{ }); } } - -