diff --git a/lib/main/lockDetail/passwordKey/passwordKeyDetail/passwordKeyDetail_logic.dart b/lib/main/lockDetail/passwordKey/passwordKeyDetail/passwordKeyDetail_logic.dart index e53bccf0..bc0a3615 100755 --- a/lib/main/lockDetail/passwordKey/passwordKeyDetail/passwordKeyDetail_logic.dart +++ b/lib/main/lockDetail/passwordKey/passwordKeyDetail/passwordKeyDetail_logic.dart @@ -1,4 +1,3 @@ - import 'dart:async'; import 'package:flutter_blue_plus/flutter_blue_plus.dart'; @@ -22,68 +21,77 @@ class PasswordKeyDetailLogic extends BaseGetXController { // 监听设备返回的数据 late StreamSubscription _replySubscription; + void _initReplySubscription() { - _replySubscription = EventBusManager().eventBus!.on().listen((Reply reply) async { - // 设置自定义密码 - if (reply is SenderCustomPasswordsReply && state.ifCurrentScreen.value == true) { - final int status = reply.data[2]; - switch (status) { - case 0x00: - //成功 - state.sureBtnState.value = 0; - dismissEasyLoading(); - cancelBlueConnetctToastTimer(); - if(state.isDeletPasswordKey.value == true){ - deletePwdRequest(); - }else{ - updatePwdRequest(2); - } - break; - case 0x06: - //无权限 - final List? privateKey = await Storage.getStringList(saveBluePrivateKey); - final List getPrivateKeyList = changeStringListToIntList(privateKey!); - - final List? signKey = await Storage.getStringList(saveBlueSignKey); - final List signKeyDataList = changeStringListToIntList(signKey!); - - final List token = reply.data.sublist(5, 9); - final List saveStrList = changeIntListToStringList(token); - Storage.setStringList(saveBlueToken, saveStrList); - - IoSenderManage.senderCustomPasswordsCommand( - keyID:state.itemData.value.keyboardPwdId!.toString(), - userID:await Storage.getUid(), - pwdNo: state.itemData.value.pwdUserNo!, - pwd: state.inputPwdController.text, - useCountLimit: 0xffff, - operate: state.itemData.value.isCustom == 1 ? (state.isDeletPasswordKey.value == true ? 2 : 1) : 3, - isAdmin: state.isAdministrator.value == true ? 1 : 0, - startTime:state.itemData.value.startDate! ~/ 1000, - endTime:state.itemData.value.endDate! ~/ 1000, - needAuthor: 1, - isBeforeAddUser: false, - signKey: signKeyDataList, - privateKey: getPrivateKeyList, - token: token); - break; - default: - //失败 - cancelBlueConnetctToastTimer(); - break; + _replySubscription = + EventBusManager().eventBus!.on().listen((Reply reply) async { + // 设置自定义密码 + if (reply is SenderCustomPasswordsReply && + state.ifCurrentScreen.value == true) { + final int status = reply.data[2]; + switch (status) { + case 0x00: + //成功 + state.sureBtnState.value = 0; + dismissEasyLoading(); + cancelBlueConnetctToastTimer(); + if (state.isDeletPasswordKey.value == true) { + deletePwdRequest(); + } else { + updatePwdRequest(2); } - } - }); + break; + case 0x06: + //无权限 + final List? privateKey = + await Storage.getStringList(saveBluePrivateKey); + final List getPrivateKeyList = + changeStringListToIntList(privateKey!); + + final List? signKey = + await Storage.getStringList(saveBlueSignKey); + final List signKeyDataList = + changeStringListToIntList(signKey!); + + final List token = reply.data.sublist(5, 9); + final List saveStrList = changeIntListToStringList(token); + Storage.setStringList(saveBlueToken, saveStrList); + + IoSenderManage.senderCustomPasswordsCommand( + keyID: state.itemData.value.keyboardPwdId!.toString(), + userID: await Storage.getUid(), + pwdNo: state.itemData.value.pwdUserNo!, + pwd: state.inputPwdController.text, + useCountLimit: 0xffff, + operate: state.itemData.value.isCustom == 1 + ? (state.isDeletPasswordKey.value == true ? 2 : 1) + : 3, + isAdmin: state.isAdministrator.value == true ? 1 : 0, + startTime: state.itemData.value.startDate! ~/ 1000, + endTime: state.itemData.value.endDate! ~/ 1000, + needAuthor: 1, + isBeforeAddUser: false, + signKey: signKeyDataList, + privateKey: getPrivateKeyList, + token: token); + break; + default: + //失败 + cancelBlueConnetctToastTimer(); + break; + } + } + }); } //删除密码请求 deleteType:1-蓝牙 2-网关 Future deletePwdRequest() async { final PasswordKeyEntity entity = await ApiRepository.to.deleteKeyboardPwd( - lockId:state.itemData.value.lockId.toString(), - keyboardPwdId:state.itemData.value.keyboardPwdId.toString(), - deleteType:1); + lockId: state.itemData.value.lockId.toString(), + keyboardPwdId: state.itemData.value.keyboardPwdId.toString(), + deleteType: 1); if (entity.errorCode!.codeIsSuccessful) { - showToast('删除成功'.tr, something: (){ + showToast('删除成功'.tr, something: () { // eventBus.fire(GetPasswordListRefreshUI()); Get.back(result: 'deletScuess'); }); @@ -107,12 +115,12 @@ class PasswordKeyDetailLogic extends BaseGetXController { pwdRight: state.isAdministrator.value == true ? 1 : 0); if (entity.errorCode!.codeIsSuccessful) { Get.back(); - showToast('修改成功'.tr, something: (){ - if(changType == 1){ + showToast('修改成功'.tr, something: () { + if (changType == 1) { // 修改名字 state.keyboardPwdName.value = state.inputNameController.text; state.itemData.value.keyboardPwdName = state.keyboardPwdName.value; - }else if(changType == 2){ + } else if (changType == 2) { // 修改密码 state.keyboardPwd.value = state.inputPwdController.text; state.itemData.value.keyboardPwd = state.keyboardPwd.value; @@ -124,43 +132,49 @@ class PasswordKeyDetailLogic extends BaseGetXController { // 设置自定义密码 这里用作修改或者删除密码 Future senderCustomPasswords() async { - 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!); IoSenderManage.senderCustomPasswordsCommand( - keyID:state.itemData.value.keyboardPwdId!.toString(), - userID:await Storage.getUid(), + keyID: state.itemData.value.keyboardPwdId!.toString(), + userID: await Storage.getUid(), pwdNo: state.itemData.value.pwdUserNo!, pwd: state.inputPwdController.text, useCountLimit: 0xffff, - operate: state.itemData.value.isCustom == 1 ? (state.isDeletPasswordKey.value == true ? 2 : 1) : 3, + operate: state.itemData.value.isCustom == 1 + ? (state.isDeletPasswordKey.value == true ? 2 : 1) + : 3, isAdmin: state.isAdministrator.value == true ? 1 : 0, - startTime:state.itemData.value.startDate! ~/ 1000, - endTime:state.itemData.value.endDate! ~/ 1000, + startTime: state.itemData.value.startDate! ~/ 1000, + endTime: state.itemData.value.endDate! ~/ 1000, needAuthor: 1, isBeforeAddUser: false, signKey: signKeyDataList, privateKey: getPrivateKeyList, token: getTokenList); - } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { + } else if (deviceConnectionState == + BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); state.sureBtnState.value = 0; - if(state.ifCurrentScreen.value == true){ + if (state.ifCurrentScreen.value == true) { showBlueConnetctToast(); } } @@ -171,162 +185,359 @@ class PasswordKeyDetailLogic extends BaseGetXController { String getUseDateStr() { final int? getPwdType = state.itemData.value.keyboardPwdType; String useDateStr = ''; - final DateTime startDateStr = DateTime.fromMillisecondsSinceEpoch(state.itemData.value.startDate!); - final DateTime endDateStr = DateTime.fromMillisecondsSinceEpoch(state.itemData.value.endDate!); + final DateTime startDateStr = + DateTime.fromMillisecondsSinceEpoch(state.itemData.value.startDate!); + final DateTime endDateStr = + DateTime.fromMillisecondsSinceEpoch(state.itemData.value.endDate!); final String starHour = '${state.itemData.value.hoursStart}'; final String endHour = '${state.itemData.value.hoursEnd}'; switch (getPwdType) { case 1: - //单次 1 只能在开始时间后6小时内使用一次 - useDateStr = - '${startDateStr.toLocal().toString().substring(0, 16)}\n${endDateStr.toLocal().toString().substring(0, 16)}'; - state.isCirculation.value = false; + //单次 1 只能在开始时间后6小时内使用一次 + useDateStr = '\n' + + '类型'.tr + + ':' + + '单次'.tr + + '\n' + + '\n' + + '有效期'.tr + + ':${startDateStr.toLocal().toString().substring(0, 16)} -- ${endDateStr.toLocal().toString().substring(0, 16)}\n\n' + + '这是单次密码,只能使用一次\n'; break; case 2: - //永久 2 从开始时间开始永久有效,必需在开始时间24小时内使用一次,否则将失效 - useDateStr = '永久'; - state.isCirculation.value = false; + //永久 2 从开始时间开始永久有效,必需在开始时间24小时内使用一次,否则将失效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '永久'.tr + + '\n' + + '\n注:\n' + + '必需在开始时间24小时内使用一次,否则将失效\n'; break; case 3: - //限期 3 在开始和结束时间内有效,必需在开始时间24小时内使用一次,否则将失效 - useDateStr = - '${startDateStr.toLocal().toString().substring(0, 16)}\n${DateTime.fromMillisecondsSinceEpoch(state.itemData.value.endDate!-1).toLocal().toString().substring(0, 16)}'; - state.isCirculation.value = false; + //限期 3 在开始和结束时间内有效,必需在开始时间24小时内使用一次,否则将失效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '限时'.tr + + '\n' + + '\n' + + '有效期'.tr + + ':${startDateStr.toLocal().toString().substring(0, 16)}-${endDateStr.toLocal().toString().substring(0, 16)}' + + '\n' + + '\n注:\n' + + '必需在开始时间24小时内使用一次,否则将失效\n'; break; case 4: - //删除 4 在锁上使用后会删除之前在锁上使用过的密码 - useDateStr = - '${startDateStr.toLocal().toString().substring(0, 16)}\n${endDateStr.toLocal().toString().substring(0, 16)}'; - state.isCirculation.value = false; + //删除 4 在锁上使用后会删除之前在锁上使用过的密码 + useDateStr = '类型'.tr + ':' + '清空'.tr; break; case 5: - //周未循环 5 在周未开始和结束时间指定时间段内有效 - useDateStr = '周末'.tr + '$starHour:00-$endHour:00'; - state.isCirculation.value = true; + //周未循环 5 在周未开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周末'.tr + + ' $starHour:00-$endHour:00' + + '\n'; break; case 6: - //每日循环 6 每天开始和结束时间指定时间段内有效 - useDateStr = '每日'.tr + '$starHour:00-$endHour:00'; - state.isCirculation.value = true; + //每日循环 6 每天开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '每日'.tr + + ' $starHour:00-$endHour:00' + + '\n'; break; case 7: - //工作日循环 7 工作日开始和结束时间指定的时间段内有效 - useDateStr = '工作日'.tr + '$starHour:00-$endHour:00'; - state.isCirculation.value = true; + //工作日循环 7 工作日开始和结束时间指定的时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '工作日'.tr + + ' $starHour:00-$endHour:00' + + '\n'; break; case 8: - //周一循环 8 每周一开始和结束时间指定时间段内有效 - useDateStr = '周一'.tr + '$starHour:00-$endHour:00'; - state.isCirculation.value = true; + //周一循环 8 每周一开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周一'.tr + + ' $starHour:00-$endHour:00' + + '\n'; break; case 9: - //周二循环 9 每周二开始和结束时间指定时间段内有效 - useDateStr = '周二'.tr + '$starHour:00-$endHour:00'; - state.isCirculation.value = true; + //周二循环 9 每周二开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周二'.tr + + ' $starHour:00-$endHour:00' + + '\n'; break; case 10: - //周三循环 10 每周三开始和结束时间指定时间段内有效 - useDateStr = '周三'.tr + '$starHour:00-$endHour:00'; - state.isCirculation.value = true; + //周三循环 10 每周三开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周三'.tr + + ' $starHour:00-$endHour:00' + + '\n'; break; case 11: - //周四循环 11 每周四开始和结束时间指定时间段内有效 - useDateStr = '周四'.tr + '$starHour:00-$endHour:00'; - state.isCirculation.value = true; + //周四循环 11 每周四开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周四'.tr + + ' $starHour:00 -$endHour:00' + + '\n'; break; case 12: - //周五循环 12 每周五开始和结束时间指定时间段内有效 - useDateStr = '周五'.tr + '$starHour:00-$endHour:00'; - state.isCirculation.value = true; + //周五循环 12 每周五开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周五'.tr + + ' $starHour:00-$endHour:00' + + '\n'; break; case 13: - //周六循环 13 每周六开始和结束时间指定时间段内有效 - useDateStr = '周六'.tr + '$starHour:00-$endHour:00'; - state.isCirculation.value = true; + //周六循环 13 每周六开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周六'.tr + + ' $starHour:00-$endHour:00' + + '\n'; break; case 14: - //周日循环 14 每周日开始和结束时间指定时间段内有效 - useDateStr = '周日'.tr + '$starHour:00-$endHour:00'; - state.isCirculation.value = true; + //周日循环 14 每周日开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周日'.tr + + ' $starHour:00-$endHour:00' + + '\n'; break; default: } - return useDateStr; + // return '您好,您的密码是'.tr + ':${state.itemData.value.keyboardPwd}\n$useDateStr\n${'密码名字'.tr}:${state.itemData.value.keyboardPwdName}'; + return '您好' + + ',\n您的开门密码是' + + ':${state.itemData.value.keyboardPwd}\n$useDateStr\n${'密码名字'.tr}:${state.itemData.value.keyboardPwdName}\n\n开锁时,先激活锁键盘,再输入密码,以#号结束,#号键在键盘右下角,有可能是其他图标'; } String getShareContentStr() { final int? getPwdType = state.itemData.value.keyboardPwdType; String useDateStr = ''; final DateTime startDateStr = - DateTime.fromMillisecondsSinceEpoch(state.itemData.value.startDate!); + DateTime.fromMillisecondsSinceEpoch(state.itemData.value.startDate!); final DateTime endDateStr = - DateTime.fromMillisecondsSinceEpoch(state.itemData.value.endDate!); + DateTime.fromMillisecondsSinceEpoch(state.itemData.value.endDate!); final int starHour = startDateStr.hour; final int endHour = endDateStr.hour; switch (getPwdType) { case 1: - //单次 1 只能在开始时间后6小时内使用一次 - useDateStr = - '类型'.tr + ':' + '永久'.tr + '\n' + '有效期'.tr + ':${startDateStr.toLocal().toString().substring(0, 16)} -- ${endDateStr.toLocal().toString().substring(0, 16)}'; + //单次 1 只能在开始时间后6小时内使用一次 + useDateStr = '\n' + + '类型'.tr + + ':' + + '单次'.tr + + '\n' + + '\n' + + '有效期'.tr + + ':${startDateStr.toLocal().toString().substring(0, 16)} -- ${endDateStr.toLocal().toString().substring(0, 16)}\n\n' + + '这是单次密码,只能使用一次\n'; break; case 2: - //永久 2 从开始时间开始永久有效,必需在开始时间24小时内使用一次,否则将失效 - useDateStr = '类型'.tr + ':' + '永久'.tr; + //永久 2 从开始时间开始永久有效,必需在开始时间24小时内使用一次,否则将失效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '永久'.tr + + '\n' + + '\n注:\n' + + '必需在开始时间24小时内使用一次,否则将失效\n'; break; case 3: - //限期 3 在开始和结束时间内有效,必需在开始时间24小时内使用一次,否则将失效 - useDateStr = - '类型'.tr + ':' + '限时'.tr + '\n' + '有效期'.tr + ':${startDateStr.toLocal().toString().substring(0, 16)}-${endDateStr.toLocal().toString().substring(0, 16)}'; + //限期 3 在开始和结束时间内有效,必需在开始时间24小时内使用一次,否则将失效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '限时'.tr + + '\n' + + '\n' + + '有效期'.tr + + ':${startDateStr.toLocal().toString().substring(0, 16)}-${endDateStr.toLocal().toString().substring(0, 16)}' + + '\n' + + '\n注:\n' + + '必需在开始时间24小时内使用一次,否则将失效\n'; break; case 4: - //删除 4 在锁上使用后会删除之前在锁上使用过的密码 + //删除 4 在锁上使用后会删除之前在锁上使用过的密码 useDateStr = '类型'.tr + ':' + '清空'.tr; break; case 5: - //周未循环 5 在周未开始和结束时间指定时间段内有效 - useDateStr = '类型'.tr + ':' + '循环'.tr + '\n' + '周末'.tr + ' $starHour:00-$endHour:00'; + //周未循环 5 在周未开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周末'.tr + + ' $starHour:00-$endHour:00' + + '\n'; break; case 6: - //每日循环 6 每天开始和结束时间指定时间段内有效 - useDateStr = '类型'.tr + ':' + '循环'.tr + '\n' + '每日'.tr + ' $starHour:00-$endHour:00'; + //每日循环 6 每天开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '每日'.tr + + ' $starHour:00-$endHour:00' + + '\n'; break; case 7: - //工作日循环 7 工作日开始和结束时间指定的时间段内有效 - useDateStr = '类型'.tr + ':' + '循环'.tr + '\n' + '工作日'.tr + ' $starHour:00-$endHour:00'; + //工作日循环 7 工作日开始和结束时间指定的时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '工作日'.tr + + ' $starHour:00-$endHour:00' + + '\n'; break; case 8: - //周一循环 8 每周一开始和结束时间指定时间段内有效 - useDateStr = '类型'.tr + ':' + '循环'.tr + '\n' + '周一'.tr + ' $starHour:00-$endHour:00'; + //周一循环 8 每周一开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周一'.tr + + ' $starHour:00-$endHour:00' + + '\n'; break; case 9: - //周二循环 9 每周二开始和结束时间指定时间段内有效 - useDateStr = '类型'.tr + ':' + '循环'.tr + '\n' + '周二'.tr + ' $starHour:00-$endHour:00'; + //周二循环 9 每周二开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周二'.tr + + ' $starHour:00-$endHour:00' + + '\n'; break; case 10: - //周三循环 10 每周三开始和结束时间指定时间段内有效 - useDateStr = '类型'.tr + ':' + '循环'.tr + '\n' + '周三'.tr + ' $starHour:00-$endHour:00'; + //周三循环 10 每周三开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周三'.tr + + ' $starHour:00-$endHour:00' + + '\n'; break; case 11: - //周四循环 11 每周四开始和结束时间指定时间段内有效 - useDateStr = '类型'.tr + ':' + '循环'.tr + '\n' + '周四'.tr + ' $starHour:00 -$endHour:00'; + //周四循环 11 每周四开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周四'.tr + + ' $starHour:00 -$endHour:00' + + '\n'; break; case 12: - //周五循环 12 每周五开始和结束时间指定时间段内有效 - useDateStr = '类型'.tr + ':' + '循环'.tr + '\n' + '周五'.tr + ' $starHour:00-$endHour:00'; + //周五循环 12 每周五开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周五'.tr + + ' $starHour:00-$endHour:00' + + '\n'; break; case 13: - //周六循环 13 每周六开始和结束时间指定时间段内有效 - useDateStr = '类型'.tr + ':' + '循环'.tr + '\n' + '周六'.tr + ' $starHour:00-$endHour:00'; + //周六循环 13 每周六开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周六'.tr + + ' $starHour:00-$endHour:00' + + '\n'; break; case 14: - //周日循环 14 每周日开始和结束时间指定时间段内有效 - useDateStr = '类型'.tr + ':' + '循环'.tr + '\n' + '周日'.tr + ' $starHour:00-$endHour:00'; + //周日循环 14 每周日开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周日'.tr + + ' $starHour:00-$endHour:00' + + '\n'; break; default: } - return '您好,您的密码是'.tr + ':${state.itemData.value.keyboardPwd}\n$useDateStr\n${'密码名字'.tr}:${state.itemData.value.keyboardPwdName}'; + // return '您好,您的密码是'.tr + ':${state.itemData.value.keyboardPwd}\n$useDateStr\n${'密码名字'.tr}:${state.itemData.value.keyboardPwdName}'; + return '您好' + + ',\n您的开门密码是' + + ':${state.itemData.value.keyboardPwd}\n$useDateStr\n${'密码名字'.tr}:${state.itemData.value.keyboardPwdName}\n\n开锁时,先激活锁键盘,再输入密码,以#号结束,#号键在键盘右下角,有可能是其他图标'; } @override @@ -341,5 +552,4 @@ class PasswordKeyDetailLogic extends BaseGetXController { void onClose() { _replySubscription.cancel(); } - } diff --git a/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart b/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart index b0cf5756..36d4372f 100755 --- a/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart +++ b/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart @@ -183,10 +183,11 @@ class PasswordKeyPerpetualLogic extends BaseGetXController { final String getMobile = (await Storage.getMobile())!; if (entity.errorCode!.codeIsSuccessful) { ApmHelper.instance.trackEvent('add_password', { - 'lock_name':BlueManage().connectDeviceName, - 'account':getMobile.isNotEmpty ? getMobile : (await Storage.getEmail())!, - 'date':DateTool().getNowDateWithType(1), - 'add_password_result':'成功', + 'lock_name': BlueManage().connectDeviceName, + 'account': + getMobile.isNotEmpty ? getMobile : (await Storage.getEmail())!, + 'date': DateTool().getNowDateWithType(1), + 'add_password_result': '成功', }); state.isSendSuccess.value = true; @@ -200,10 +201,11 @@ class PasswordKeyPerpetualLogic extends BaseGetXController { } } else { ApmHelper.instance.trackEvent('add_password', { - 'lock_name':BlueManage().connectDeviceName, - 'account':getMobile.isNotEmpty ? getMobile : (await Storage.getEmail())!, - 'date':DateTool().getNowDateWithType(1), - 'add_password_result':'${entity.errorMsg}', + 'lock_name': BlueManage().connectDeviceName, + 'account': + getMobile.isNotEmpty ? getMobile : (await Storage.getEmail())!, + 'date': DateTool().getNowDateWithType(1), + 'add_password_result': '${entity.errorMsg}', }); showToast('${entity.errorMsg}'); } @@ -244,15 +246,16 @@ class PasswordKeyPerpetualLogic extends BaseGetXController { late StreamSubscription _replySubscription; void _initReplySubscription() { - _replySubscription = EventBusManager().eventBus!.on().listen((Reply reply) async { + _replySubscription = + EventBusManager().eventBus!.on().listen((Reply reply) async { // 设置自定义密码 - if ((reply is SenderCustomPasswordsReply) && (state.ifCurrentScreen.value == true)) { + if ((reply is SenderCustomPasswordsReply) && + (state.ifCurrentScreen.value == true)) { BuglyTool.uploadException( message: '添加密码结果,解析数据', detail: '添加密码结果,解析数据:${reply.data}', eventStr: '添加密码事件结果', - upload: true - ); + upload: true); final int status = reply.data[2]; switch (status) { @@ -393,45 +396,45 @@ class PasswordKeyPerpetualLogic extends BaseGetXController { final List? signKey = await Storage.getStringList(saveBlueSignKey); final List signKeyDataList = changeStringListToIntList(signKey!); - final List? privateKey = await Storage.getStringList(saveBluePrivateKey); + final List? privateKey = + await Storage.getStringList(saveBluePrivateKey); final List getPrivateKeyList = changeStringListToIntList(privateKey!); final List? token = await Storage.getStringList(saveBlueToken); final List getTokenList = changeStringListToIntList(token!); final String command = SenderCustomPasswordsCommand( - keyID: '1', - userID: await Storage.getUid(), - pwdNo: 0, - pwd: state.pwdController.text, - operate: 0, - isAdmin: state.isAdministrator.value == true ? 1 : 0, - useCountLimit: 0xffff, - startTime: startDate ~/ 1000, - endTime: endDate ~/ 1000, - needAuthor: 1, - signKey: signKeyDataList, - privateKey: getPrivateKeyList, - token: getTokenList - ).toString(); - + keyID: '1', + userID: await Storage.getUid(), + pwdNo: 0, + pwd: state.pwdController.text, + operate: 0, + isAdmin: state.isAdministrator.value == true ? 1 : 0, + useCountLimit: 0xffff, + startTime: startDate ~/ 1000, + endTime: endDate ~/ 1000, + needAuthor: 1, + signKey: signKeyDataList, + privateKey: getPrivateKeyList, + token: getTokenList) + .toString(); showEasyLoading(); showBlueConnetctToastTimer(action: () async { final String getMobile = (await Storage.getMobile())!; ApmHelper.instance.trackEvent('add_password', { - 'lock_name':BlueManage().connectDeviceName, - 'account':getMobile.isNotEmpty ? getMobile : (await Storage.getEmail())!, - 'date':DateTool().getNowDateWithType(1), - 'add_password_result':'添加自定义密码超时', + 'lock_name': BlueManage().connectDeviceName, + 'account': + getMobile.isNotEmpty ? getMobile : (await Storage.getEmail())!, + 'date': DateTool().getNowDateWithType(1), + 'add_password_result': '添加自定义密码超时', }); BuglyTool.uploadException( message: '添加密码超时处理-添加密码失败', detail: '添加密码超时,添加密码失败--senderCustomPasswordsCommand:$command', eventStr: '添加密码事件超时', - upload: true - ); + upload: true); dismissEasyLoading(); state.sureBtnState.value = 0; @@ -439,11 +442,14 @@ class PasswordKeyPerpetualLogic extends BaseGetXController { 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!); @@ -463,21 +469,22 @@ class PasswordKeyPerpetualLogic extends BaseGetXController { signKey: signKeyDataList, privateKey: getPrivateKeyList, token: getTokenList); - } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { + } else if (deviceConnectionState == + BluetoothConnectionState.disconnected) { final String getMobile = (await Storage.getMobile())!; ApmHelper.instance.trackEvent('add_password', { - 'lock_name':BlueManage().connectDeviceName, - 'account':getMobile.isNotEmpty ? getMobile : (await Storage.getEmail())!, - 'date':DateTool().getNowDateWithType(1), - 'add_password_result':'添加自定义密码断开', + 'lock_name': BlueManage().connectDeviceName, + 'account': + getMobile.isNotEmpty ? getMobile : (await Storage.getEmail())!, + 'date': DateTool().getNowDateWithType(1), + 'add_password_result': '添加自定义密码断开', }); BuglyTool.uploadException( message: '添加密码断开-添加密码失败', detail: '添加密码断开,添加密码失败--senderCustomPasswordsCommand:$command', eventStr: '添加密码事件断开连接', - upload: true - ); + upload: true); dismissEasyLoading(); cancelBlueConnetctToastTimer(); @@ -492,27 +499,49 @@ class PasswordKeyPerpetualLogic extends BaseGetXController { String getShareContentStr() { final int getPwdType = state.widgetType.value; String useDateStr = ''; - // DateTime startDateStr = DateTime.fromMillisecondsSinceEpoch(state.itemData.value.startDate!); - // DateTime endDateStr = DateTime.fromMillisecondsSinceEpoch(state.itemData.value.endDate!); - // int starHour = startDateStr.hour; - // int endHour = endDateStr.hour; + + DateTime startDateStr = DateTime.parse(state.beginTime.value)!; + DateTime endDateStr = DateTime.parse(state.endTime.value)!; + + int starHour = startDateStr.hour; + int endHour = endDateStr.hour; switch (getPwdType) { + case 2: + //单次 1 只能在开始时间后6小时内使用一次 + useDateStr = '\n' + + '类型'.tr + + ':' + + '单次'.tr + + '\n' + + '\n' + + '有效期'.tr + + ':${startDateStr.toLocal().toString().substring(0, 16)} -- ${endDateStr.toLocal().toString().substring(0, 16)}\n\n' + + '这是单次密码,只能使用一次\n'; + break; case 0: - // 永久 从开始时间开始永久有效,必需在开始时间24小时内使用一次,否则将失效 - useDateStr = '类型'.tr + ':' + '永久'; + //永久 2 从开始时间开始永久有效,必需在开始时间24小时内使用一次,否则将失效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '永久'.tr + + '\n' + + '\n注:\n' + + '必需在开始时间24小时内使用一次,否则将失效\n'; break; case 1: - //限时 在开始和结束时间内有效,必需在开始时间24小时内使用一次,否则将失效 - useDateStr = '类型'.tr + + //限期 3 在开始和结束时间内有效,必需在开始时间24小时内使用一次,否则将失效 + useDateStr = '\n' + + '类型'.tr + ':' + - '限时\n${'有效期'.tr}:${state.beginTime.value} -- ${state.endTime.value}'; - break; - case 2: - //单次 只能在开始时间后6小时内使用一次 - useDateStr = '类型'.tr + - ':' + - '单次\n${'有效期'.tr}:${state.beginTime.value} -- ${state.endTime.value}'; + '限时'.tr + + '\n' + + '\n' + + '有效期'.tr + + ':${startDateStr.toLocal().toString().substring(0, 16)}-${endDateStr.toLocal().toString().substring(0, 16)}' + + '\n' + + '\n注:\n' + + '必需在开始时间24小时内使用一次,否则将失效\n'; break; case 3: //自定义 @@ -524,20 +553,177 @@ class PasswordKeyPerpetualLogic extends BaseGetXController { useDateStr = '类型:自定义-永久'.tr; } break; - case 4: - //周未循环 在周未开始和结束时间指定时间段内有效 - useDateStr = '类型'.tr + - ':' + - '循环\n${state.loopModeStr.value} ${state.loopEffectiveDate.value}:00-${state.loopFailureDate.value}'; - break; case 5: //删除 4 在锁上使用后会删除之前在锁上使用过的密码 - useDateStr = '类型:清空'; + useDateStr = '类型'.tr + ':' + '清空'.tr; + break; + case 4: + //周未循环 5 在周未开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周末'.tr + + ' $starHour:00-$endHour:00' + + '\n'; + break; + case 6: + //每日循环 6 每天开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '每日'.tr + + ' $starHour:00-$endHour:00' + + '\n'; + break; + case 7: + //工作日循环 7 工作日开始和结束时间指定的时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '工作日'.tr + + ' $starHour:00-$endHour:00' + + '\n'; + break; + case 8: + //周一循环 8 每周一开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周一'.tr + + ' $starHour:00-$endHour:00' + + '\n'; + break; + case 9: + //周二循环 9 每周二开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周二'.tr + + ' $starHour:00-$endHour:00' + + '\n'; + break; + case 10: + //周三循环 10 每周三开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周三'.tr + + ' $starHour:00-$endHour:00' + + '\n'; + break; + case 11: + //周四循环 11 每周四开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周四'.tr + + ' $starHour:00 -$endHour:00' + + '\n'; + break; + case 12: + //周五循环 12 每周五开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周五'.tr + + ' $starHour:00-$endHour:00' + + '\n'; + break; + case 13: + //周六循环 13 每周六开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周六'.tr + + ' $starHour:00-$endHour:00' + + '\n'; + break; + case 14: + //周日循环 14 每周日开始和结束时间指定时间段内有效 + useDateStr = '\n' + + '类型'.tr + + ':' + + '循环'.tr + + '\n' + + '\n' + + '周日'.tr + + ' $starHour:00-$endHour:00' + + '\n'; break; - default: } - return '${'您好,您的密码是'.tr}:${state.getPwdStr.value}\n$useDateStr\n${'密码名字'.tr}:${state.pwdNameStr}'; + // return '您好,您的密码是'.tr + ':${state.itemData.value.keyboardPwd}\n$useDateStr\n${'密码名字'.tr}:${state.itemData.value.keyboardPwdName}'; + return '您好' + + ',\n您的开门密码是' + + ':${state.getPwdStr.value}\n$useDateStr\n${'密码名字'.tr}:${state.pwdNameStr}\n\n开锁时,先激活锁键盘,再输入密码,以#号结束,#号键在键盘右下角,有可能是其他图标'; + // switch (getPwdType) { + // case 0: + // // 永久 从开始时间开始永久有效,必需在开始时间24小时内使用一次,否则将失效 + // useDateStr = '类型'.tr + ':' + '永久'; + // break; + // case 1: + // //限时 在开始和结束时间内有效,必需在开始时间24小时内使用一次,否则将失效 + // useDateStr = '类型'.tr + + // ':' + + // '限时\n${'有效期'.tr}:${state.beginTime.value} -- ${state.endTime.value}'; + // break; + // case 2: + // //单次 只能在开始时间后6小时内使用一次 + // useDateStr = '类型'.tr + + // ':' + + // '单次\n${'有效期'.tr}:${state.beginTime.value} -- ${state.endTime.value}'; + // break; + // case 3: + // //自定义 + // if (state.isPermanent.value == false) { + // useDateStr = '类型'.tr + + // ':' + + // '自定义-限时\n${'有效期'.tr}:${state.customBeginTime.value} -- ${state.customEndTime.value}'; + // } else { + // useDateStr = '类型:自定义-永久'.tr; + // } + // break; + // case 4: + // //周未循环 在周未开始和结束时间指定时间段内有效 + // useDateStr = '类型'.tr + + // ':' + + // '循环\n${state.loopModeStr.value} ${state.loopEffectiveDate.value}:00-${state.loopFailureDate.value}'; + // break; + // case 5: + // //删除 4 在锁上使用后会删除之前在锁上使用过的密码 + // useDateStr = '类型:清空'; + // break; + // + // default: + // } + // return '${'您好,您的密码是'.tr}:${state.getPwdStr.value}\n$useDateStr\n${'密码名字'.tr}:${state.pwdNameStr}'; } String addSpaces(String input) { diff --git a/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_state.dart b/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_state.dart index 3e872b82..55b9a16e 100755 --- a/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_state.dart +++ b/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_state.dart @@ -23,6 +23,7 @@ class PasswordKeyPerpetualState { RxString beginTime = DateTool().getNowDateWithType(3).obs; //默认为当前时间 开始时间 RxString endTime = DateTool().getNowDateWithType(3).obs; //默认为当前时间 结束时间 + RxString loopEffectiveDate = DateTool().getNowDateWithType(7).obs; //生效时间 RxString loopFailureDate = DateTool().getNowDateWithType(7).obs; //失效时间 RxInt loopStartHours = DateTime.now().hour.obs;