diff --git a/images/.DS_Store b/images/.DS_Store index 0e394cd1..5329245e 100755 Binary files a/images/.DS_Store and b/images/.DS_Store differ diff --git a/images/icon_remoteControl.png b/images/icon_remoteControl.png new file mode 100644 index 00000000..8568eee2 Binary files /dev/null and b/images/icon_remoteControl.png differ diff --git a/images/lan/lan_en.json b/images/lan/lan_en.json index 077942d5..f8755200 100755 --- a/images/lan/lan_en.json +++ b/images/lan/lan_en.json @@ -931,5 +931,6 @@ "感应到门前约0.8米有人时,将自动启动面部识别开锁。": "When someone is sensed about 0.8 meters in front of the door, the face recognition unlocking will be automatically started.", "感应到门前约0.5米有人时,将自动启动面部识别开锁。": "When someone is sensed about 0.5 meters in front of the door, the face recognition unlocking will be automatically started.", "感应距离已关闭,需手动触摸键盘任意键,进行面部识别开锁。": "The sensing distance has been turned off, you need to manually touch any key on the keyboard to perform face recognition unlocking.", - "防误开已打开,时间是": "The anti-mistake opening has been turned on, and the time is" + "防误开已打开,开锁后": "The anti-mistake opening has been turned on, and after unlocking", + "秒内不可使用面容开锁": "Face unlocking cannot be used within seconds" } diff --git a/images/lan/lan_keys.json b/images/lan/lan_keys.json index 457f83ac..bf7404a6 100755 --- a/images/lan/lan_keys.json +++ b/images/lan/lan_keys.json @@ -964,5 +964,6 @@ "感应到门前约0.8米有人时,将自动启动面部识别开锁。": "感应到门前约0.8米有人时,将自动启动面部识别开锁。", "感应到门前约0.5米有人时,将自动启动面部识别开锁。": "感应到门前约0.5米有人时,将自动启动面部识别开锁。", "感应距离已关闭,需手动触摸键盘任意键,进行面部识别开锁。": "感应距离已关闭,需手动触摸键盘任意键,进行面部识别开锁。", - "防误开已打开,时间是": "防误开已打开,时间是" + "防误开已打开,开锁后": "防误开已打开,开锁后", + "秒内不可使用面容开锁": "秒内不可使用面容开锁" } diff --git a/images/lan/lan_zh.json b/images/lan/lan_zh.json index 35256364..bcf35060 100755 --- a/images/lan/lan_zh.json +++ b/images/lan/lan_zh.json @@ -929,5 +929,6 @@ "感应到门前约0.8米有人时,将自动启动面部识别开锁。": "感应到门前约0.8米有人时,将自动启动面部识别开锁。", "感应到门前约0.5米有人时,将自动启动面部识别开锁。": "感应到门前约0.5米有人时,将自动启动面部识别开锁。", "感应距离已关闭,需手动触摸键盘任意键,进行面部识别开锁。": "感应距离已关闭,需手动触摸键盘任意键,进行面部识别开锁。", - "防误开已打开,时间是": "防误开已打开,时间是" + "防误开已打开,开锁后": "防误开已打开,开锁后", + "秒内不可使用面容开锁": "秒内不可使用面容开锁" } diff --git a/images/main/icon_addRemoteControl_tip.png b/images/main/icon_addRemoteControl_tip.png new file mode 100644 index 00000000..02dc2898 Binary files /dev/null and b/images/main/icon_addRemoteControl_tip.png differ diff --git a/lib/appRouters.dart b/lib/appRouters.dart index bc56cf3e..04c9a2b1 100755 --- a/lib/appRouters.dart +++ b/lib/appRouters.dart @@ -138,6 +138,8 @@ import 'main/lockDetail/passwordKey/passwordKeyList/passwordKeyList_page.dart'; import 'main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_page.dart'; import 'main/lockDetail/realTimePicture/realTimePicture_page.dart'; import 'main/lockDetail/remoteControl/addRemoteControl/addRemoteControl_page.dart'; +import 'main/lockDetail/remoteControl/addRemoteControlType/addRemoteControlType_page.dart'; +import 'main/lockDetail/remoteControl/remoteControlDetail/remoteControlDetail_page.dart'; import 'main/lockDetail/remoteControl/remoteControlList/remoteControlList_page.dart'; import 'main/lockDetail/videoLog/editVideoLog/editVideoLog_page.dart'; import 'main/lockDetail/videoLog/videoLog/videoLog_page.dart'; @@ -448,6 +450,8 @@ abstract class Routers { static const String remoteControlListPage = '/RemoteControlListPage'; // 遥控列表 static const String addRemoteControlPage = '/AddRemoteControlPage'; // 添加遥控 + static const String addRemoteControlTypePage = '/AddRemoteControlTypePage'; // 添加遥控类型 + static const String remoteControlDetailPage = '/RemoteControlDetailPage'; // 遥控详情 static const String cardListPage = '/CardListPage'; // 卡列表 // static const addCardTypeManagePage = '/AddCardTypeManagePage'; // 添加卡 @@ -1150,5 +1154,9 @@ abstract class AppRouters { name: Routers.expireKeyChangeValidityDatePage, page: () => const ExpireKeyChangeValidityDatePage()), GetPage( name: Routers.doorLockLogDetailPage, page: () => const DoorLockLogDetailPage()), + GetPage( + name: Routers.addRemoteControlTypePage, page: () => const AddRemoteControlTypePage()), + GetPage( + name: Routers.remoteControlDetailPage, page: () => const RemoteControlDetailPage()), ]; } diff --git a/lib/blue/io_protocol/io_addRemoteControlCancel.dart b/lib/blue/io_protocol/io_addRemoteControlCancel.dart new file mode 100644 index 00000000..d09f64a0 --- /dev/null +++ b/lib/blue/io_protocol/io_addRemoteControlCancel.dart @@ -0,0 +1,95 @@ + +import 'dart:convert'; + +import 'package:crypto/crypto.dart' as crypto; + +import '../io_sender.dart'; +import '../io_tool/io_tool.dart'; +import '../io_type.dart'; +import '../sm4Encipher/sm4.dart'; + +/// TODO:取消添加遥控 +class SenderCancelAddRemoteControlCommand extends SenderProtocol { + + SenderCancelAddRemoteControlCommand({ + this.keyID, + this.userID, + this.token, + this.needAuthor, + this.signKey, + this.privateKey, + }) : super(CommandType.generalExtendedCommond); + String? keyID; + String? userID; + List? token; + int? needAuthor; + List? signKey; + List? privateKey; + + @override + String toString() { + return 'SenderCancelAddRemoteControlCommand{keyID: $keyID, ' + 'userID: $userID, token: $token, needAuthor: $needAuthor, signKey: $signKey, privateKey: $privateKey}'; + } + + @override + List messageDetail() { + List data = []; + List subData = []; + List ebcData = []; + + // 指令类型 + data.addAll(intChangList(commandType!.typeValue)); + + // 子命令类型 + data.add(28); + + // keyID 40 + int keyIDLength = utf8.encode(keyID!).length; + subData.addAll(utf8.encode(keyID!)); + subData = getFixedLengthList(subData, 40 - keyIDLength); + + //userID 20 + int userIDLength = utf8.encode(userID!).length; + subData.addAll(utf8.encode(userID!)); + subData = getFixedLengthList(subData, 20 - userIDLength); + + if(needAuthor == 0){ + //AuthCodeLen 1 + subData.add(0); + } else { + List authCodeData = []; + //KeyID + authCodeData.addAll(utf8.encode(keyID!)); + + //authUserID + authCodeData.addAll(utf8.encode(userID!)); + + //token 4 首次请求 Token 填 0,如果锁需要鉴权操作者身份,则会分配动态口令并在应答消息中返回,二次请求时带上。 + authCodeData.addAll(token!); + + authCodeData.addAll(signKey!); + + // 把KeyID、authUserID、时间戳、公钥通过md5加密之后就是authCode + var authCode = crypto.md5.convert(authCodeData); + + subData.add(authCode.bytes.length); + subData.addAll(authCode.bytes); + } + + data.add(subData.length); + data.addAll(subData); + + if ((data.length % 16) != 0) { + int add = 16 - data.length % 16; + for (int i = 0; i < add; i++) { + data.add(0); + } + } + + printLog(data); + // 拿到数据之后通过LockId进行SM4 ECB加密 key:544d485f633335373034383064613864 + ebcData = SM4.encrypt(data, key: privateKey, mode: SM4CryptoMode.ECB); + return ebcData; + } +} diff --git a/lib/blue/io_protocol/io_addRemoteControlWithTimeCycleCoercion.dart b/lib/blue/io_protocol/io_addRemoteControlWithTimeCycleCoercion.dart new file mode 100644 index 00000000..f81c35b8 --- /dev/null +++ b/lib/blue/io_protocol/io_addRemoteControlWithTimeCycleCoercion.dart @@ -0,0 +1,207 @@ + +import 'dart:convert'; + +import 'package:star_lock/tools/dateTool.dart'; + +import '../io_tool/io_tool.dart'; +import '../sm4Encipher/sm4.dart'; +import '../io_reply.dart'; +import '../io_sender.dart'; +import '../io_type.dart'; +import 'package:crypto/crypto.dart' as crypto; + +///TODO:添加遥控 +/* +备注: +删除单个指纹规则:UseCountLimit 设置为 0。删除全部指纹规则: UseCountLimit 设置为 0,FingerNo 设置为 255,userId 设置为“Delete All !@#”,只有门锁管理员才有权限 +**/ +class SenderAddRemoteControlWithTimeCycleCoercionCommand extends SenderProtocol { + + SenderAddRemoteControlWithTimeCycleCoercionCommand({ + this.keyID, + this.userID, + this.remoteControlNo, + this.useCountLimit, + this.isForce, + this.operate, + this.isAdmin, + this.token, + this.isRound, + this.weekRound, + this.startDate, + this.endDate, + this.startTime, + this.endTime, + this.needAuthor, + this.signKey, + this.privateKey, + }) : super(CommandType.generalExtendedCommond); + + String? keyID; + String? userID; + int? remoteControlNo; + int? useCountLimit; + int? isForce; + int? operate; + int? isAdmin; + List? token; + int? isRound; + int? weekRound; + int? startDate; + int? endDate; + String? startTime; + String? endTime; + int? needAuthor; + List? signKey; + List? privateKey; + + + @override + String toString() { + return 'SenderAddRemoteControlWithTimeCycleCoercionCommand{keyID: $keyID, ' + 'userID: $userID, remoteControlNo: $remoteControlNo, useCountLimit: $useCountLimit, ' + 'isForce: $isForce, token: $token, isRound: $isRound, ' + 'weekRound: $weekRound, ' + 'startDate: ${DateTool().dateIntToYMDHNString(startDate)}, ' + 'endDate: ${DateTool().dateIntToYMDHNString(endDate)}, ' + 'startTime: $startTime,' + 'endTime: $endTime, ' + 'needAuthor: $needAuthor, signKey: $signKey, privateKey: $privateKey}'; + } + + @override + List messageDetail() { + final List data = []; + List subData = []; + List ebcData = []; + + // 指令类型 + data.addAll(intChangList(commandType!.typeValue)); + + // 子命令类型 + data.add(26); + + // keyID 40 + final int keyIDLength = utf8.encode(keyID!).length; + subData.addAll(utf8.encode(keyID!)); + subData = getFixedLengthList(subData, 40 - keyIDLength); + + //userID 20 + final int userIDLength = utf8.encode(userID!).length; + subData.addAll(utf8.encode(userID!)); + subData = getFixedLengthList(subData, 20 - userIDLength); + + // remoteControlNo + subData.addAll(intChangList(remoteControlNo!)); + + // UseCountLimit + subData.addAll(intChangList(useCountLimit!)); + + // Operate 0:注册 1:修改 2:删除 3:删除全部 + subData.add(operate!); + // AppLog.log("addCard operate:$operate"); + + // isAdmin + subData.add(isAdmin!); + // AppLog.log("addCard isAdmin:$isAdmin"); + + // isForce + subData.add(isForce!); + // AppLog.log("addCard isForce:$isForce"); + + // token + subData.addAll(token!); + + // isRound + subData.add(isRound!); + + // weekRound + subData.add(weekRound!); + + // startDate 4 + subData.add((startDate! & 0xff000000) >> 24); + subData.add((startDate! & 0xff0000) >> 16); + subData.add((startDate! & 0xff00) >> 8); + subData.add(startDate! & 0xff); + + // endDate 4 + subData.add((endDate! & 0xff000000) >> 24); + subData.add((endDate! & 0xff0000) >> 16); + subData.add((endDate! & 0xff00) >> 8); + subData.add(endDate! & 0xff); + + // startTime 4 + final List startTimeList = [0,0,0,0]; + if(startTime!.contains(':')){ + final List getStartTimeList = startTime!.split(':'); + startTimeList[2] = int.parse(getStartTimeList[0]); + startTimeList[3] = int.parse(getStartTimeList[1]); + } + subData.addAll(startTimeList); + + // endTime 4 + final List endTimeList = [0,0,0,0]; + if(endTime!.contains(':')){ + final List getendTimeList = endTime!.split(':'); + endTimeList[2] = int.parse(getendTimeList[0]); + endTimeList[3] = int.parse(getendTimeList[1]); + } + subData.addAll(endTimeList); + + if(needAuthor == 0){ + //AuthCodeLen 1 + subData.add(0); + } else { + final List authCodeData = []; + //KeyID + authCodeData.addAll(utf8.encode(keyID!)); + + //authUserID + authCodeData.addAll(utf8.encode(userID!)); + + //token 4 首次请求 Token 填 0,如果锁需要鉴权操作者身份,则会分配动态口令并在应答消息中返回,二次请求时带上。 + authCodeData.addAll(token!); + + authCodeData.addAll(signKey!); + + // 把KeyID、authUserID、时间戳、公钥通过md5加密之后就是authCode + final authCode = crypto.md5.convert(authCodeData); + + subData.add(authCode.bytes.length); + subData.addAll(authCode.bytes); + } + + data.add(subData.length); + data.addAll(subData); + + if ((data.length % 16) != 0) { + final int add = 16 - data.length % 16; + for (int i = 0; i < add; i++) { + data.add(0); + } + } + + printLog(data); + // 拿到数据之后通过LockId进行SM4 ECB加密 key:544d485f633335373034383064613864 + ebcData = SM4.encrypt(data, key: privateKey, mode: SM4CryptoMode.ECB); + return ebcData; + } +} + +class SenderAddRemoteControlWithTimeCycleCoercionReply extends Reply { + SenderAddRemoteControlWithTimeCycleCoercionReply.parseData(CommandType commandType, List dataDetail) + : super.parseData(commandType, dataDetail) { + data = dataDetail; + final int status = data[2]; + errorWithStstus(status); + } +} + +class SenderAddRemoteControlConfirmationReply extends Reply { + SenderAddRemoteControlConfirmationReply.parseData(CommandType commandType, List dataDetail) + : super.parseData(commandType, dataDetail) { + data = dataDetail; + final int status = data[2]; + errorWithStstus(status); + } +} diff --git a/lib/blue/reciver_data.dart b/lib/blue/reciver_data.dart index 6069abb7..d57f4c3e 100755 --- a/lib/blue/reciver_data.dart +++ b/lib/blue/reciver_data.dart @@ -24,6 +24,7 @@ import 'package:star_lock/blue/io_protocol/io_transferPermissions.dart'; import '../tools/storage.dart'; import 'io_protocol/io_addFingerprintWithTimeCycleCoercion.dart'; import 'io_protocol/io_addICCardWithTimeCycleCoercion.dart'; +import 'io_protocol/io_addRemoteControlWithTimeCycleCoercion.dart'; import 'io_protocol/io_addStressPassword.dart'; import 'io_protocol/io_addUser.dart'; import 'io_protocol/io_checkingCardStatus.dart'; @@ -308,6 +309,20 @@ class CommandReciverManager { commandType, data); } break; + case 26: + { + // 注册遥控开始 + reply = SenderAddRemoteControlWithTimeCycleCoercionReply.parseData( + commandType, data); + } + break; + case 27: + { + // 注册遥控确认 + reply = SenderAddRemoteControlConfirmationReply.parseData( + commandType, data); + } + break; case 30: { // 查询指纹状态 diff --git a/lib/blue/sender_manage.dart b/lib/blue/sender_manage.dart index 04e3097c..20cd27b9 100755 --- a/lib/blue/sender_manage.dart +++ b/lib/blue/sender_manage.dart @@ -13,6 +13,8 @@ import 'io_protocol/io_addFaceCancel.dart'; import 'io_protocol/io_addFingerprintCancel.dart'; import 'io_protocol/io_addFingerprintWithTimeCycleCoercion.dart'; import 'io_protocol/io_addICCardWithTimeCycleCoercion.dart'; +import 'io_protocol/io_addRemoteControlCancel.dart'; +import 'io_protocol/io_addRemoteControlWithTimeCycleCoercion.dart'; import 'io_protocol/io_addStressPassword.dart'; import 'io_protocol/io_addUser.dart'; import 'io_protocol/io_checkingCardStatus.dart'; @@ -605,6 +607,72 @@ class IoSenderManage { callBack: callBack); } + //todo:添加遥控开始(带限时、循环、胁迫...) + static void senderAddRemoteControlWithTimeCycleCoercionCommand( + {required String? keyID, + required String? userID, + required int? remoteControlNo, + required int? useCountLimit, + required int? operate, + required int? isAdmin, + required int? isForce, + required List? token, + required int? isRound, + required int? weekRound, + required int? startDate, + required int? endDate, + required String? startTime, + required String? endTime, + required int? needAuthor, + required List? signKey, + required List? privateKey, + required bool? isBeforeAddUser, + CommandSendCallBack? callBack}) { + CommandSenderManager().managerSendData( + command: SenderAddRemoteControlWithTimeCycleCoercionCommand( + keyID: keyID, + userID: userID, + remoteControlNo: remoteControlNo, + useCountLimit: useCountLimit, + operate: operate, + isAdmin: isAdmin, + isForce: isForce, + token: token, + isRound: isRound, + weekRound: weekRound, + startDate: startDate, + endDate: endDate, + startTime: startTime, + endTime: endTime, + needAuthor: needAuthor, + signKey: signKey, + privateKey: privateKey, + ), + isBeforeAddUser: isBeforeAddUser!, + callBack: callBack); + } + + //todo:取消添加遥控 + static void senderCancelAddRemoteControlCommand( + {required String? keyID, + required String? userID, + required List? token, + required int? needAuthor, + required List? signKey, + required List? privateKey, + CommandSendCallBack? callBack}) { + CommandSenderManager().managerSendData( + command: SenderCancelAddRemoteControlCommand( + keyID: keyID, + userID: userID, + token: token, + needAuthor: needAuthor, + signKey: signKey, + privateKey: privateKey, + ), + callBack: callBack); + } + //todo:添加人脸开始 static void senderAddFaceCommand( {required String? keyID, diff --git a/lib/login/login/starLock_login_logic.dart b/lib/login/login/starLock_login_logic.dart index c0edc5bd..7f02667e 100755 --- a/lib/login/login/starLock_login_logic.dart +++ b/lib/login/login/starLock_login_logic.dart @@ -11,6 +11,7 @@ import 'package:star_lock/mine/mine/starLockMine_state.dart'; import 'package:star_lock/tools/baseGetXController.dart'; import 'package:star_lock/tools/push/xs_jPhush.dart'; +import '../../main/lockMian/lockMain/lockMain_logic.dart'; import '../../mine/mine/starLockMine_logic.dart'; import '../../network/api_repository.dart'; import '../../tools/eventBusEventManage.dart'; @@ -53,6 +54,9 @@ class StarLockLoginLogic extends BaseGetXController { Storage.saveLoginData(entity.data); Storage.setBool(saveIsVip, entity.data!.isVip == 1); eventBus.fire(MineInfoChangeRefreshUI()); + if (Get.isRegistered()) { + Get.find().getStarLockInfo(isUnShowLoading: true); + } Get.offNamedUntil(Routers.starLockMain, (Route route) => false); BlueManage().scanDevices.clear(); //清除设备缓存 // 初始化JPush服务并绑定设备ID diff --git a/lib/main/lockDetail/card/otherTypeKeyChangeDate/otherTypeKeyChangeDate_logic.dart b/lib/main/lockDetail/card/otherTypeKeyChangeDate/otherTypeKeyChangeDate_logic.dart index 170ea711..df21ce95 100755 --- a/lib/main/lockDetail/card/otherTypeKeyChangeDate/otherTypeKeyChangeDate_logic.dart +++ b/lib/main/lockDetail/card/otherTypeKeyChangeDate/otherTypeKeyChangeDate_logic.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; +import 'package:star_lock/blue/io_protocol/io_addRemoteControlWithTimeCycleCoercion.dart'; import 'package:star_lock/login/login/entity/LoginEntity.dart'; import 'package:star_lock/tools/baseGetXController.dart'; import '../../../../blue/blue_manage.dart'; @@ -35,6 +36,11 @@ class OtherTypeKeyChangeDateLogic extends BaseGetXController{ _replyAddFingerprintBegin(reply); } + // 添加遥控开始(此处用作修改遥控) + if ((reply is SenderAddRemoteControlWithTimeCycleCoercionReply) && (state.ifCurrentScreen.value == true)) { + _replyAddRemoteControlBegin(reply); + } + // 添加人脸开始(此处用作修改人脸) if ((reply is SenderAddFaceReply) && (state.ifCurrentScreen.value == true)) { _replyAddFaceBegin(reply); @@ -42,7 +48,157 @@ class OtherTypeKeyChangeDateLogic extends BaseGetXController{ }); } - // 添加人脸开始 + // 修改卡片,接收消息 + Future _replyAddICCardBegin(Reply reply) async { + final int status = reply.data[2]; + + switch(status){ + case 0x00: + //成功 + cancelBlueConnetctToastTimer(); + dismissEasyLoading(); + editICCardData(); + 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.senderAddCardWithTimeCycleCoercionCommand( + keyID:state.fingerprintItemData.value.cardId!.toString(), + userID:await Storage.getUid(), + cardNo:int.parse(state.fingerprintItemData.value.cardNumber!), + useCountLimit:0xffff, + operate: 1, // 0:注册 1:修改 2:删除 3:删除全部 + isAdmin:state.fingerprintItemData.value.cardRight!, + isForce:state.fingerprintItemData.value.isCoerced, // 是否是胁迫 + isRound:0, // 是否是循环 + weekRound:0, // 周循环 + startDate: state.beginTimeTimestamp.value~/1000, + endDate: state.endTimeTimestamp.value~/1000, + startTime:'0', + endTime:'0', + needAuthor:1, + signKey:signKeyDataList, + privateKey:getPrivateKeyList, + token: token, + isBeforeAddUser: false + ); + break; + default: + //失败 + break; + } + } + + // 修改指纹,接收消息 + Future _replyAddFingerprintBegin(Reply reply) async { + final int status = reply.data[2]; + switch(status){ + case 0x00: + //成功 + state.sureBtnState.value = 0; + cancelBlueConnetctToastTimer(); + dismissEasyLoading(); + editFingerprintsData(); + 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.senderAddFingerprintWithTimeCycleCoercionCommand( + keyID:state.fingerprintItemData.value.fingerprintId.toString(), + userID:await Storage.getUid(), + fingerNo:int.parse(state.fingerprintItemData.value.fingerprintNumber!), + useCountLimit:0xffff, + operate:1, // 0:注册 1:修改 2:删除 3:删除全部 + isAdmin:state.fingerprintItemData.value.fingerRight, + isForce:state.fingerprintItemData.value.isCoerced, // 是否是胁迫 + isRound:0, // 是否是循环 + weekRound:0, // 周循环 + startDate: state.beginTimeTimestamp.value~/1000, + endDate: state.endTimeTimestamp.value~/1000, + startTime:'0', + endTime:'0', + needAuthor:1, + signKey:signKeyDataList, + privateKey:getPrivateKeyList, + token: token, + isBeforeAddUser: false + ); + break; + default: + //失败 + break; + } + } + + // 修改遥控,接收消息 + Future _replyAddRemoteControlBegin(Reply reply) async { + final int status = reply.data[2]; + + switch(status){ + case 0x00: + //成功 + cancelBlueConnetctToastTimer(); + dismissEasyLoading(); + editRemoteControlData(); + 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.senderAddRemoteControlWithTimeCycleCoercionCommand( + keyID:state.fingerprintItemData.value.remoteId!.toString(), + userID:await Storage.getUid(), + remoteControlNo:int.parse(state.fingerprintItemData.value.remoteNumber!), + useCountLimit:0xffff, + operate: 1, // 0:注册 1:修改 2:删除 3:删除全部 + isAdmin:state.fingerprintItemData.value.remoteRight!, + isForce:state.fingerprintItemData.value.isCoerced, // 是否是胁迫 + isRound:0, // 是否是循环 + weekRound:0, // 周循环 + startDate: state.beginTimeTimestamp.value~/1000, + endDate: state.endTimeTimestamp.value~/1000, + startTime:'0', + endTime:'0', + needAuthor:1, + signKey:signKeyDataList, + privateKey:getPrivateKeyList, + token: token, + isBeforeAddUser: false + ); + break; + default: + //失败 + break; + } + } + + // 修改人脸,接收消息 Future _replyAddFaceBegin(Reply reply) async { final int status = reply.data[2]; @@ -67,23 +223,23 @@ class OtherTypeKeyChangeDateLogic extends BaseGetXController{ Storage.setStringList(saveBlueToken, saveStrList); IoSenderManage.senderAddFaceCommand( - keyID:state.fingerprintItemData.value.cardId!.toString(), - userID:await Storage.getUid(), - faceNo:int.parse(state.fingerprintItemData.value.faceNumber!), - useCountLimit:0xffff, - operate: 1, // 0:注册 1:修改 2:删除 3:删除全部 - isAdmin:state.fingerprintItemData.value.faceRight!, - isForce:state.fingerprintItemData.value.isCoerced, // 是否是胁迫 - isRound:0, // 是否是循环 - weekRound:0, // 周循环 - startDate: state.beginTimeTimestamp.value~/1000, - endDate: state.endTimeTimestamp.value~/1000, - startTime:'0', - endTime:'0', - needAuthor:1, - signKey:signKeyDataList, - privateKey:getPrivateKeyList, - token: token, + keyID:state.fingerprintItemData.value.cardId!.toString(), + userID:await Storage.getUid(), + faceNo:int.parse(state.fingerprintItemData.value.faceNumber!), + useCountLimit:0xffff, + operate: 1, // 0:注册 1:修改 2:删除 3:删除全部 + isAdmin:state.fingerprintItemData.value.faceRight!, + isForce:state.fingerprintItemData.value.isCoerced, // 是否是胁迫 + isRound:0, // 是否是循环 + weekRound:0, // 周循环 + startDate: state.beginTimeTimestamp.value~/1000, + endDate: state.endTimeTimestamp.value~/1000, + startTime:'0', + endTime:'0', + needAuthor:1, + signKey:signKeyDataList, + privateKey:getPrivateKeyList, + token: token, isBeforeAddUser: false ); break; @@ -93,162 +249,7 @@ class OtherTypeKeyChangeDateLogic extends BaseGetXController{ } } - // 删除/修改人脸信息 - Future senderAddFace() async { - if (state.sureBtnState.value == 1) { - return; - } - state.sureBtnState.value = 1; - - showEasyLoading(); - showBlueConnetctToastTimer(action: () { - dismissEasyLoading(); - state.sureBtnState.value = 0; - }); - BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { - if (deviceConnectionState == BluetoothConnectionState.connected) { - 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 List? signKey = await Storage.getStringList(saveBlueSignKey); - final List signKeyDataList = changeStringListToIntList(signKey!); - - IoSenderManage.senderAddFaceCommand( - keyID:state.fingerprintItemData.value.faceId!.toString(), - userID:await Storage.getUid(), - faceNo:int.parse(state.fingerprintItemData.value.faceNumber!), - useCountLimit:0xffff, - operate: 1, // 0:注册 1:修改 2:删除 3:删除全部 - isAdmin:state.fingerprintItemData.value.faceRight!, - isForce:state.fingerprintItemData.value.isCoerced, // 是否是胁迫 - isRound:0, // 是否是循环 - weekRound:0, // 周循环 - startDate: state.beginTimeTimestamp.value~/1000, - endDate: state.endTimeTimestamp.value~/1000, - startTime:'0', - endTime:'0', - needAuthor:1, - signKey:signKeyDataList, - privateKey:getPrivateKeyList, - token: getTokenList, - isBeforeAddUser: false - ); - } else if (deviceConnectionState == - BluetoothConnectionState.disconnected) { - dismissEasyLoading(); - cancelBlueConnetctToastTimer(); - state.sureBtnState.value = 0; - if (state.ifCurrentScreen.value == true) { - showBlueConnetctToast(); - } - } - }); - } - - // 添加卡片开始(此处用作删除卡片) - Future _replyAddICCardBegin(Reply reply) async { - final int status = reply.data[2]; - - switch(status){ - case 0x00: - //成功 - cancelBlueConnetctToastTimer(); - dismissEasyLoading(); - editICCardData(); - 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.senderAddCardWithTimeCycleCoercionCommand( - keyID:state.fingerprintItemData.value.cardId!.toString(), - userID:await Storage.getUid(), - cardNo:int.parse(state.fingerprintItemData.value.cardNumber!), - useCountLimit:0xffff, - operate: 1, // 0:注册 1:修改 2:删除 3:删除全部 - isAdmin:state.fingerprintItemData.value.cardRight!, - isForce:state.fingerprintItemData.value.isCoerced, // 是否是胁迫 - isRound:0, // 是否是循环 - weekRound:0, // 周循环 - startDate: state.beginTimeTimestamp.value~/1000, - endDate: state.endTimeTimestamp.value~/1000, - startTime:'0', - endTime:'0', - needAuthor:1, - signKey:signKeyDataList, - privateKey:getPrivateKeyList, - token: token, - isBeforeAddUser: false - ); - break; - default: - //失败 - break; - } - } - - // 添加指纹开始 - Future _replyAddFingerprintBegin(Reply reply) async { - final int status = reply.data[2]; - switch(status){ - case 0x00: - //成功 - state.sureBtnState.value = 0; - cancelBlueConnetctToastTimer(); - dismissEasyLoading(); - editFingerprintsData(); - 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.senderAddFingerprintWithTimeCycleCoercionCommand( - keyID:state.fingerprintItemData.value.fingerprintId.toString(), - userID:await Storage.getUid(), - fingerNo:int.parse(state.fingerprintItemData.value.fingerprintNumber!), - useCountLimit:0xffff, - operate:1, // 0:注册 1:修改 2:删除 3:删除全部 - isAdmin:state.fingerprintItemData.value.fingerRight, - isForce:state.fingerprintItemData.value.isCoerced, // 是否是胁迫 - isRound:0, // 是否是循环 - weekRound:0, // 周循环 - startDate: state.beginTimeTimestamp.value~/1000, - endDate: state.endTimeTimestamp.value~/1000, - startTime:'0', - endTime:'0', - needAuthor:1, - signKey:signKeyDataList, - privateKey:getPrivateKeyList, - token: token, - isBeforeAddUser: false - ); - break; - default: - //失败 - break; - } - } - - // 删除指纹 + // 修改指纹调用协议 Future senderAddFingerprint() async { if(state.sureBtnState.value == 1){ return; @@ -305,7 +306,7 @@ class OtherTypeKeyChangeDateLogic extends BaseGetXController{ }); } - // 添加卡片 + // 修改卡片调用协议 Future senderAddICCard() async { if(state.sureBtnState.value == 1){ return; @@ -360,7 +361,117 @@ class OtherTypeKeyChangeDateLogic extends BaseGetXController{ }); } - // 修改指纹信息 + // 修改遥控调用协议 + Future senderAddRemoteControl() async { + if(state.sureBtnState.value == 1){ + return; + } + state.sureBtnState.value = 1; + + showEasyLoading(); + showBlueConnetctToastTimer(action: (){ + dismissEasyLoading(); + state.sureBtnState.value = 0; + }); + BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected){ + + 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? token = await Storage.getStringList(saveBlueToken); + final List getTokenList = changeStringListToIntList(token!); + + IoSenderManage.senderAddRemoteControlWithTimeCycleCoercionCommand( + keyID:state.fingerprintItemData.value.remoteId!.toString(), + userID:await Storage.getUid(), + remoteControlNo:int.parse(state.fingerprintItemData.value.remoteNumber!), + useCountLimit:0xffff, + operate: 1, // 0:注册 1:修改 2:删除 3:删除全部 + isAdmin:state.fingerprintItemData.value.remoteRight!, + isForce:state.fingerprintItemData.value.isCoerced, // 是否是胁迫 + isRound:0, // 是否是循环 + weekRound:0, // 周循环 + startDate: state.beginTimeTimestamp.value~/1000, + endDate: state.endTimeTimestamp.value~/1000, + startTime:'0', + endTime:'0', + needAuthor:1, + signKey:signKeyDataList, + privateKey:getPrivateKeyList, + token: getTokenList, + isBeforeAddUser: false + ); + } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { + dismissEasyLoading(); + cancelBlueConnetctToastTimer(); + state.sureBtnState.value = 0; + if(state.ifCurrentScreen.value == true){ + showBlueConnetctToast(); + } + } + }); + } + + // 修改人脸调用协议 + Future senderAddFace() async { + if (state.sureBtnState.value == 1) { + return; + } + state.sureBtnState.value = 1; + + showEasyLoading(); + showBlueConnetctToastTimer(action: () { + dismissEasyLoading(); + state.sureBtnState.value = 0; + }); + BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected) { + 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 List? signKey = await Storage.getStringList(saveBlueSignKey); + final List signKeyDataList = changeStringListToIntList(signKey!); + + IoSenderManage.senderAddFaceCommand( + keyID:state.fingerprintItemData.value.faceId!.toString(), + userID:await Storage.getUid(), + faceNo:int.parse(state.fingerprintItemData.value.faceNumber!), + useCountLimit:0xffff, + operate: 1, // 0:注册 1:修改 2:删除 3:删除全部 + isAdmin:state.fingerprintItemData.value.faceRight!, + isForce:state.fingerprintItemData.value.isCoerced, // 是否是胁迫 + isRound:0, // 是否是循环 + weekRound:0, // 周循环 + startDate: state.beginTimeTimestamp.value~/1000, + endDate: state.endTimeTimestamp.value~/1000, + startTime:'0', + endTime:'0', + needAuthor:1, + signKey:signKeyDataList, + privateKey:getPrivateKeyList, + token: getTokenList, + isBeforeAddUser: false + ); + } else if (deviceConnectionState == + BluetoothConnectionState.disconnected) { + dismissEasyLoading(); + cancelBlueConnetctToastTimer(); + state.sureBtnState.value = 0; + if (state.ifCurrentScreen.value == true) { + showBlueConnetctToast(); + } + } + }); + } + + // 修改指纹调用接口 Future editFingerprintsData() async{ final LoginEntity entity = await ApiRepository.to.editFingerprintsData( fingerprintId: state.fingerprintItemData.value.fingerprintId.toString(), @@ -387,7 +498,7 @@ class OtherTypeKeyChangeDateLogic extends BaseGetXController{ } } - // 编辑iC卡 + // 修改卡片调用接口 Future editICCardData() async{ final LoginEntity entity = await ApiRepository.to.editICCardData( cardId: state.fingerprintItemData.value.cardId.toString(), @@ -414,7 +525,34 @@ class OtherTypeKeyChangeDateLogic extends BaseGetXController{ } } - // 修改人脸有效期 + // 编辑遥控 + Future editRemoteControlData() async { + final LoginEntity entity = await ApiRepository.to.editRemoteControlData( + lockId: state.fingerprintItemData.value.lockId ?? 0, + remoteId: state.fingerprintItemData.value.remoteId!, + startDate: state.beginTimeTimestamp.value, + endDate: state.endTimeTimestamp.value, + startTime: 0, + endTime: 0, + remoteType: 2, + weekDay: [], + remoteName: state.fingerprintItemData.value.remoteName!, + addType: 1, + isCoerced: 2, + remoteRight: 2, + ); + if (entity.errorCode!.codeIsSuccessful) { + showToast('修改成功'.tr, something: (){ + Get.back(result: { + 'beginTimeTimestamp':state.beginTimeTimestamp.value.toString(), + 'endTimeTimestamp':state.endTimeTimestamp.value.toString(), + }); + eventBus.fire(OtherTypeRefreshListEvent()); + }); + } + } + + // 修改人脸调用接口 Future editFaceData() async { final LoginEntity entity = await ApiRepository.to.updateFaceValidity( lockId: state.fingerprintItemData.value.lockId!, diff --git a/lib/main/lockDetail/card/otherTypeKeyChangeDate/otherTypeKeyChangeDate_page.dart b/lib/main/lockDetail/card/otherTypeKeyChangeDate/otherTypeKeyChangeDate_page.dart index a0c0908a..f56fded8 100755 --- a/lib/main/lockDetail/card/otherTypeKeyChangeDate/otherTypeKeyChangeDate_page.dart +++ b/lib/main/lockDetail/card/otherTypeKeyChangeDate/otherTypeKeyChangeDate_page.dart @@ -53,13 +53,13 @@ class _OtherTypeKeyChangeDatePageState extends State state.endTimeTimestamp.value || state.beginTimeTimestamp.value == state.endTimeTimestamp.value) { - logic.showToast("失效时间需大于生效时间".tr); + logic.showToast('失效时间需大于生效时间'.tr); return; } if (state.endTimeTimestamp.value < DateTime.now().millisecondsSinceEpoch) { - logic.showToast("生效时间需大于当前时间".tr); + logic.showToast('生效时间需大于当前时间'.tr); return; } switch (state.pushType.value) { @@ -73,7 +73,7 @@ class _OtherTypeKeyChangeDatePageState extends State break; case 2: // 遥控 - + logic.senderAddRemoteControl(); break; case 3: // 人脸 @@ -99,7 +99,7 @@ class _OtherTypeKeyChangeDatePageState extends State isHaveLine: true, isHaveDirection: true, action: () { - PDuration selectDate = + final PDuration selectDate = PDuration.parse(DateTime.tryParse(state.beginTime.value)); Pickers.showDatePicker(context, selectDate: selectDate, mode: DateMode.YMDHM, onConfirm: (PDuration p) { @@ -113,7 +113,7 @@ class _OtherTypeKeyChangeDatePageState extends State rightTitle: state.endTime.value, isHaveDirection: true, action: () { - PDuration selectDate = + final PDuration selectDate = PDuration.parse(DateTime.tryParse(state.endTime.value)); Pickers.showDatePicker(context, selectDate: selectDate, mode: DateMode.YMDHM, onConfirm: (PDuration p) { @@ -153,7 +153,9 @@ class _OtherTypeKeyChangeDatePageState extends State void didPop() { super.didPop(); logic.cancelBlueConnetctToastTimer(); - if (EasyLoading.isShow) EasyLoading.dismiss(animation: true); + if (EasyLoading.isShow) { + EasyLoading.dismiss(animation: true); + } state.ifCurrentScreen.value = false; state.sureBtnState.value = 0; } @@ -170,7 +172,9 @@ class _OtherTypeKeyChangeDatePageState extends State void didPushNext() { super.didPushNext(); logic.cancelBlueConnetctToastTimer(); - if (EasyLoading.isShow) EasyLoading.dismiss(animation: true); + if (EasyLoading.isShow) { + EasyLoading.dismiss(animation: true); + } state.ifCurrentScreen.value = false; state.sureBtnState.value = 0; } diff --git a/lib/main/lockDetail/card/otherTypeKeyChangeValidityDate/otherTypeKeyChangeValidityDate_logic.dart b/lib/main/lockDetail/card/otherTypeKeyChangeValidityDate/otherTypeKeyChangeValidityDate_logic.dart index 2e771ce6..4b338982 100755 --- a/lib/main/lockDetail/card/otherTypeKeyChangeValidityDate/otherTypeKeyChangeValidityDate_logic.dart +++ b/lib/main/lockDetail/card/otherTypeKeyChangeValidityDate/otherTypeKeyChangeValidityDate_logic.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; +import 'package:star_lock/blue/io_protocol/io_addRemoteControlWithTimeCycleCoercion.dart'; import 'package:star_lock/login/login/entity/LoginEntity.dart'; import 'package:star_lock/tools/baseGetXController.dart'; @@ -37,6 +38,11 @@ class OtherTypeKeyChangeValidityDateLogic extends BaseGetXController{ _replyAddFingerprintBegin(reply); } + // 添加遥控开始(此处用作修改或者删除指纹) + if((reply is SenderAddRemoteControlWithTimeCycleCoercionReply) && (state.ifCurrentScreen.value == true)) { + _replyAddRemoteControlBegin(reply); + } + // 添加人脸开始(此处用作修改人脸) if ((reply is SenderAddFaceReply) && (state.ifCurrentScreen.value == true)) { _replyAddFaceBegin(reply); @@ -44,10 +50,159 @@ class OtherTypeKeyChangeValidityDateLogic extends BaseGetXController{ }); } - // 添加人脸开始 - Future _replyAddFaceBegin(Reply reply) async { + // 修改卡片,接收协议数据 + Future _replyAddICCardBegin(Reply reply) async { final int status = reply.data[2]; + switch(status){ + case 0x00: + //成功 + cancelBlueConnetctToastTimer(); + dismissEasyLoading(); + editICCardData(); + 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.senderAddCardWithTimeCycleCoercionCommand( + keyID:state.fingerprintItemData.value.cardId!.toString(), + userID:await Storage.getUid(), + cardNo:int.parse(state.fingerprintItemData.value.cardNumber!), + useCountLimit:0xffff, + operate: 1, // 0:注册 1:修改 2:删除 3:删除全部 + isAdmin:state.fingerprintItemData.value.cardRight!, + isForce:state.fingerprintItemData.value.isCoerced, // 是否是胁迫 + isRound:1, // 是否是循环 + weekRound:DateTool().accordingTheCycleIntoTheCorrespondingNumber(state.weekDay.value), // 周循环 + startDate: state.starDateTimestamp.value~/1000, + endDate: state.endDateTimestamp.value~/1000, + startTime:DateTool().dateToHNString(state.starTimeTimestamp.value.toString()), + endTime:DateTool().dateToHNString(state.endTimeTimestamp.value.toString()), + needAuthor:1, + signKey:signKeyDataList, + privateKey:getPrivateKeyList, + token: token, + isBeforeAddUser: false + ); + break; + default: + //失败 + break; + } + } + + // 修改指纹,接收协议数据 + Future _replyAddFingerprintBegin(Reply reply) async { + final int status = reply.data[2]; + switch(status){ + case 0x00: + //成功 + state.sureBtnState.value = 0; + cancelBlueConnetctToastTimer(); + dismissEasyLoading(); + editFingerprintsData(); + 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.senderAddFingerprintWithTimeCycleCoercionCommand( + keyID:state.fingerprintItemData.value.fingerprintId.toString(), + userID:await Storage.getUid(), + fingerNo:int.parse(state.fingerprintItemData.value.fingerprintNumber!), + useCountLimit:0xffff, + operate:1, // 0:注册 1:修改 2:删除 3:删除全部 + isAdmin:state.fingerprintItemData.value.fingerRight, + isForce:state.fingerprintItemData.value.isCoerced, // 是否是胁迫 + isRound:1, // 是否是循环 + weekRound:DateTool().accordingTheCycleIntoTheCorrespondingNumber(state.weekDay.value), // 周循环 + startDate: state.starDateTimestamp.value~/1000, + endDate: state.endDateTimestamp.value~/1000, + startTime:DateTool().dateToHNString(state.starTimeTimestamp.value.toString()), + endTime:DateTool().dateToHNString(state.endTimeTimestamp.value.toString()), + needAuthor:1, + signKey:signKeyDataList, + privateKey:getPrivateKeyList, + token: token, + isBeforeAddUser: false + ); + break; + default: + //失败 + break; + } + } + + // 修改遥控,接收协议数据 + Future _replyAddRemoteControlBegin(Reply reply) async { + final int status = reply.data[2]; + + switch(status){ + case 0x00: + //成功 + cancelBlueConnetctToastTimer(); + dismissEasyLoading(); + editRemoteControlData(); + 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.senderAddRemoteControlWithTimeCycleCoercionCommand( + keyID:state.fingerprintItemData.value.remoteId!.toString(), + userID:await Storage.getUid(), + remoteControlNo:int.parse(state.fingerprintItemData.value.remoteNumber!), + useCountLimit:0xffff, + operate: 1, // 0:注册 1:修改 2:删除 3:删除全部 + isAdmin:state.fingerprintItemData.value.remoteRight!, + isForce:state.fingerprintItemData.value.isCoerced, // 是否是胁迫 + isRound:1, // 是否是循环 + weekRound:DateTool().accordingTheCycleIntoTheCorrespondingNumber(state.weekDay.value), // 周循环 + startDate: state.starDateTimestamp.value~/1000, + endDate: state.endDateTimestamp.value~/1000, + startTime:DateTool().dateToHNString(state.starTimeTimestamp.value.toString()), + endTime:DateTool().dateToHNString(state.endTimeTimestamp.value.toString()), + needAuthor:1, + signKey:signKeyDataList, + privateKey:getPrivateKeyList, + token: token, + isBeforeAddUser: false + ); + break; + default: + //失败 + break; + } + } + + // 修改人脸,接收协议数据 + Future _replyAddFaceBegin(Reply reply) async { + final int status = reply.data[2]; switch (status) { case 0x00: //成功 @@ -95,162 +250,63 @@ class OtherTypeKeyChangeValidityDateLogic extends BaseGetXController{ } } - // 删除/修改人脸信息 - Future senderAddFace() async { - if (state.sureBtnState.value == 1) { + + // 修改卡片,发送协议 + Future senderAddICCard() async { + 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 { - if (deviceConnectionState == BluetoothConnectionState.connected) { + if (deviceConnectionState == BluetoothConnectionState.connected){ + + 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? token = await Storage.getStringList(saveBlueToken); final List getTokenList = changeStringListToIntList(token!); - final List? signKey = await Storage.getStringList(saveBlueSignKey); - final List signKeyDataList = changeStringListToIntList(signKey!); - - IoSenderManage.senderAddFaceCommand( - keyID:state.fingerprintItemData.value.faceId!.toString(), - userID:await Storage.getUid(), - faceNo:int.parse(state.fingerprintItemData.value.faceNumber!), - useCountLimit:0xffff, - operate: 1, // 0:注册 1:修改 2:删除 3:删除全部 - isAdmin:state.fingerprintItemData.value.faceRight!, - isForce:state.fingerprintItemData.value.isCoerced, // 是否是胁迫 - isRound:1, // 是否是循环 - weekRound:DateTool().accordingTheCycleIntoTheCorrespondingNumber(state.weekDay.value), // 周循环 - startDate: state.starDateTimestamp.value~/1000, - endDate: state.endDateTimestamp.value~/1000, - startTime:DateTool().dateToHNString(state.starTimeTimestamp.value.toString()), - endTime:DateTool().dateToHNString(state.endTimeTimestamp.value.toString()), - needAuthor:1, - signKey:signKeyDataList, - privateKey:getPrivateKeyList, - token: getTokenList, + IoSenderManage.senderAddCardWithTimeCycleCoercionCommand( + keyID:state.fingerprintItemData.value.cardId!.toString(), + userID:await Storage.getUid(), + cardNo:int.parse(state.fingerprintItemData.value.cardNumber!), + useCountLimit:0xffff, + operate: 1, // 0:注册 1:修改 2:删除 3:删除全部 + isAdmin:state.fingerprintItemData.value.cardRight!, + isForce:state.fingerprintItemData.value.isCoerced, // 是否是胁迫 + isRound:1, // 是否是循环 + weekRound:DateTool().accordingTheCycleIntoTheCorrespondingNumber(state.weekDay.value), // 周循环 + startDate: state.starDateTimestamp.value~/1000, + endDate: state.endDateTimestamp.value~/1000, + startTime:DateTool().dateToHNString(state.starTimeTimestamp.value.toString()), + endTime:DateTool().dateToHNString(state.endTimeTimestamp.value.toString()), + needAuthor:1, + signKey:signKeyDataList, + privateKey:getPrivateKeyList, + token: getTokenList, isBeforeAddUser: false ); - } 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(); } } }); } - // 添加卡片开始(此处用作删除卡片) - Future _replyAddICCardBegin(Reply reply) async { - final int status = reply.data[2]; - - switch(status){ - case 0x00: - //成功 - cancelBlueConnetctToastTimer(); - dismissEasyLoading(); - editICCardData(); - 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.senderAddCardWithTimeCycleCoercionCommand( - keyID:state.fingerprintItemData.value.cardId!.toString(), - userID:await Storage.getUid(), - cardNo:int.parse(state.fingerprintItemData.value.cardNumber!), - useCountLimit:0xffff, - operate: 1, // 0:注册 1:修改 2:删除 3:删除全部 - isAdmin:state.fingerprintItemData.value.cardRight!, - isForce:state.fingerprintItemData.value.isCoerced, // 是否是胁迫 - isRound:1, // 是否是循环 - weekRound:DateTool().accordingTheCycleIntoTheCorrespondingNumber(state.weekDay.value), // 周循环 - startDate: state.starDateTimestamp.value~/1000, - endDate: state.endDateTimestamp.value~/1000, - startTime:DateTool().dateToHNString(state.starTimeTimestamp.value.toString()), - endTime:DateTool().dateToHNString(state.endTimeTimestamp.value.toString()), - needAuthor:1, - signKey:signKeyDataList, - privateKey:getPrivateKeyList, - token: token, - isBeforeAddUser: false - ); - break; - default: - //失败 - break; - } - } - - // 添加指纹开始 - Future _replyAddFingerprintBegin(Reply reply) async { - final int status = reply.data[2]; - switch(status){ - case 0x00: - //成功 - state.sureBtnState.value = 0; - cancelBlueConnetctToastTimer(); - dismissEasyLoading(); - editFingerprintsData(); - 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.senderAddFingerprintWithTimeCycleCoercionCommand( - keyID:state.fingerprintItemData.value.fingerprintId.toString(), - userID:await Storage.getUid(), - fingerNo:int.parse(state.fingerprintItemData.value.fingerprintNumber!), - useCountLimit:0xffff, - operate:1, // 0:注册 1:修改 2:删除 3:删除全部 - isAdmin:state.fingerprintItemData.value.fingerRight, - isForce:state.fingerprintItemData.value.isCoerced, // 是否是胁迫 - isRound:1, // 是否是循环 - weekRound:DateTool().accordingTheCycleIntoTheCorrespondingNumber(state.weekDay.value), // 周循环 - startDate: state.starDateTimestamp.value~/1000, - endDate: state.endDateTimestamp.value~/1000, - startTime:DateTool().dateToHNString(state.starTimeTimestamp.value.toString()), - endTime:DateTool().dateToHNString(state.endTimeTimestamp.value.toString()), - needAuthor:1, - signKey:signKeyDataList, - privateKey:getPrivateKeyList, - token: token, - isBeforeAddUser: false - ); - break; - default: - //失败 - break; - } - } - - // 删除指纹 + // 修改指纹,发送协议 Future senderAddFingerprint() async { if(state.sureBtnState.value == 1){ return; @@ -307,8 +363,8 @@ class OtherTypeKeyChangeValidityDateLogic extends BaseGetXController{ }); } - // 添加卡片 - Future senderAddICCard() async { + // 修改遥控,发送协议 + Future senderAddRemoteControl() async { if(state.sureBtnState.value == 1){ return; } @@ -331,25 +387,25 @@ class OtherTypeKeyChangeValidityDateLogic extends BaseGetXController{ final List? token = await Storage.getStringList(saveBlueToken); final List getTokenList = changeStringListToIntList(token!); - IoSenderManage.senderAddCardWithTimeCycleCoercionCommand( - keyID:state.fingerprintItemData.value.cardId!.toString(), - userID:await Storage.getUid(), - cardNo:int.parse(state.fingerprintItemData.value.cardNumber!), - useCountLimit:0xffff, - operate: 1, // 0:注册 1:修改 2:删除 3:删除全部 - isAdmin:state.fingerprintItemData.value.cardRight!, - isForce:state.fingerprintItemData.value.isCoerced, // 是否是胁迫 - isRound:1, // 是否是循环 - weekRound:DateTool().accordingTheCycleIntoTheCorrespondingNumber(state.weekDay.value), // 周循环 - startDate: state.starDateTimestamp.value~/1000, - endDate: state.endDateTimestamp.value~/1000, - startTime:DateTool().dateToHNString(state.starTimeTimestamp.value.toString()), - endTime:DateTool().dateToHNString(state.endTimeTimestamp.value.toString()), - needAuthor:1, - signKey:signKeyDataList, - privateKey:getPrivateKeyList, - token: getTokenList, - isBeforeAddUser: false + IoSenderManage.senderAddRemoteControlWithTimeCycleCoercionCommand( + keyID:state.fingerprintItemData.value.remoteId!.toString(), + userID:await Storage.getUid(), + remoteControlNo:int.parse(state.fingerprintItemData.value.remoteNumber!), + useCountLimit:0xffff, + operate: 1, // 0:注册 1:修改 2:删除 3:删除全部 + isAdmin:state.fingerprintItemData.value.remoteRight!, + isForce:state.fingerprintItemData.value.isCoerced, // 是否是胁迫 + isRound:1, // 是否是循环 + weekRound:DateTool().accordingTheCycleIntoTheCorrespondingNumber(state.weekDay.value), // 周循环 + startDate: state.starDateTimestamp.value~/1000, + endDate: state.endDateTimestamp.value~/1000, + startTime:DateTool().dateToHNString(state.starTimeTimestamp.value.toString()), + endTime:DateTool().dateToHNString(state.endTimeTimestamp.value.toString()), + needAuthor:1, + signKey:signKeyDataList, + privateKey:getPrivateKeyList, + token: getTokenList, + isBeforeAddUser: false ); } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); @@ -362,8 +418,64 @@ class OtherTypeKeyChangeValidityDateLogic extends BaseGetXController{ }); } - // 修改指纹信息 - void editFingerprintsData() async{ + // 修改人脸,发送协议 + Future senderAddFace() async { + if (state.sureBtnState.value == 1) { + return; + } + state.sureBtnState.value = 1; + + showEasyLoading(); + showBlueConnetctToastTimer(action: () { + dismissEasyLoading(); + state.sureBtnState.value = 0; + }); + BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected) { + 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 List? signKey = await Storage.getStringList(saveBlueSignKey); + final List signKeyDataList = changeStringListToIntList(signKey!); + + IoSenderManage.senderAddFaceCommand( + keyID:state.fingerprintItemData.value.faceId!.toString(), + userID:await Storage.getUid(), + faceNo:int.parse(state.fingerprintItemData.value.faceNumber!), + useCountLimit:0xffff, + operate: 1, // 0:注册 1:修改 2:删除 3:删除全部 + isAdmin:state.fingerprintItemData.value.faceRight!, + isForce:state.fingerprintItemData.value.isCoerced, // 是否是胁迫 + isRound:1, // 是否是循环 + weekRound:DateTool().accordingTheCycleIntoTheCorrespondingNumber(state.weekDay.value), // 周循环 + startDate: state.starDateTimestamp.value~/1000, + endDate: state.endDateTimestamp.value~/1000, + startTime:DateTool().dateToHNString(state.starTimeTimestamp.value.toString()), + endTime:DateTool().dateToHNString(state.endTimeTimestamp.value.toString()), + needAuthor:1, + signKey:signKeyDataList, + privateKey:getPrivateKeyList, + token: getTokenList, + isBeforeAddUser: false + ); + } else if (deviceConnectionState == + BluetoothConnectionState.disconnected) { + dismissEasyLoading(); + cancelBlueConnetctToastTimer(); + state.sureBtnState.value = 0; + if (state.ifCurrentScreen.value == true) { + showBlueConnetctToast(); + } + } + }); + } + + + // 修改指纹,调用接口 + Future editFingerprintsData() async{ final LoginEntity entity = await ApiRepository.to.editFingerprintsData( fingerprintId: state.fingerprintItemData.value.fingerprintId.toString(), lockId: state.fingerprintItemData.value.lockId.toString(), @@ -392,8 +504,8 @@ class OtherTypeKeyChangeValidityDateLogic extends BaseGetXController{ } } - // 编辑iC卡 - void editICCardData() async{ + // 修改卡片,调用接口 + Future editICCardData() async{ final LoginEntity entity = await ApiRepository.to.editICCardData( cardId: state.fingerprintItemData.value.cardId.toString(), lockId: state.fingerprintItemData.value.lockId.toString(), @@ -422,8 +534,38 @@ class OtherTypeKeyChangeValidityDateLogic extends BaseGetXController{ } } - // 修改人脸有效期 - void editFaceData() async { + // 编辑遥控 + Future editRemoteControlData() async { + final LoginEntity entity = await ApiRepository.to.editRemoteControlData( + lockId: state.fingerprintItemData.value.lockId ?? 0, + remoteId: state.fingerprintItemData.value.remoteId!, + startDate: state.starDateTimestamp.value, + endDate: state.endDateTimestamp.value, + startTime: state.starTimeTimestamp.value, + endTime: state.endTimeTimestamp.value, + remoteType: state.fingerprintItemData.value.remoteType!, + weekDay: state.weekDay.value, + remoteName: state.fingerprintItemData.value.remoteName!, + addType: 1, + isCoerced: 2, + remoteRight: 2, + ); + if (entity.errorCode!.codeIsSuccessful) { + showToast('修改成功'.tr, something: (){ + eventBus.fire(OtherTypeRefreshListEvent()); + Get.back(result: { + 'starDate':state.starDateTimestamp.value.toString(), + 'endDate':state.endDateTimestamp.value.toString(), + 'starTime':state.starTimeTimestamp.value.toString(), + 'endTime':state.endTimeTimestamp.value.toString(), + 'validityValue':state.weekDay.value, + }); + }); + } + } + + // 修改人脸,调用接口 + Future editFaceData() async { final LoginEntity entity = await ApiRepository.to.updateFaceValidity( lockId: state.fingerprintItemData.value.lockId!, faceId: state.fingerprintItemData.value.faceId!, diff --git a/lib/main/lockDetail/card/otherTypeKeyChangeValidityDate/otherTypeKeyChangeValidityDate_page.dart b/lib/main/lockDetail/card/otherTypeKeyChangeValidityDate/otherTypeKeyChangeValidityDate_page.dart index 2fc418fe..7bc49ece 100755 --- a/lib/main/lockDetail/card/otherTypeKeyChangeValidityDate/otherTypeKeyChangeValidityDate_page.dart +++ b/lib/main/lockDetail/card/otherTypeKeyChangeValidityDate/otherTypeKeyChangeValidityDate_page.dart @@ -84,7 +84,7 @@ class _OtherTypeKeyChangeValidityDatePageState extends State passwordData = indexList.sublist(7, 17); final String password = utf8String(passwordData); indexMap['password'] = password.toString(); + AppLog.log('passwordpasswordpassword:$password'); } else { final int userNo = (indexList[1] * 256) + indexList[2]; indexMap['user'] = userNo.toString(); diff --git a/lib/main/lockDetail/fingerprint/fingerprintList/fingerprintListData_entity.dart b/lib/main/lockDetail/fingerprint/fingerprintList/fingerprintListData_entity.dart index 920eec33..55d3eff4 100755 --- a/lib/main/lockDetail/fingerprint/fingerprintList/fingerprintListData_entity.dart +++ b/lib/main/lockDetail/fingerprint/fingerprintList/fingerprintListData_entity.dart @@ -1,8 +1,4 @@ class FingerprintListDataEntity { - int? errorCode; - String? description; - String? errorMsg; - Data? data; FingerprintListDataEntity( {this.errorCode, this.description, this.errorMsg, this.data}); @@ -13,6 +9,10 @@ class FingerprintListDataEntity { errorMsg = json['errorMsg']; data = json['data'] != null ? Data.fromJson(json['data']) : null; } + int? errorCode; + String? description; + String? errorMsg; + Data? data; Map toJson() { final Map data = {}; @@ -27,11 +27,6 @@ class FingerprintListDataEntity { } class Data { - List? list; - int? pageNo; - int? pageSize; - int? pages; - int? total; Data({this.list, this.pageNo, this.pageSize, this.pages, this.total}); @@ -47,6 +42,11 @@ class Data { pages = json['pages']; total = json['total']; } + List? list; + int? pageNo; + int? pageSize; + int? pages; + int? total; Map toJson() { final Map data = {}; @@ -62,6 +62,96 @@ class Data { } class FingerprintItemData { + + FingerprintItemData( + {this.fingerprintStatus, + this.lockId, + this.createDate, + this.fingerprintName, + this.endDate, + this.apiUserId, + this.nickName, + this.isCoerced, + this.startDate, + this.fingerprintNumber, + this.fingerprintType, + this.fingerprintId, + this.senderUsername, + this.weekDay, + this.validTimeStr, + this.cardName, + this.cardNumber, + this.cardType, + this.cardId, + this.faceId, + this.faceName, + this.faceNumber, + this.status, + this.addType, + this.faceType, + this.cyclicConfig, + this.featureData, + this.faceRight, + this.cardStatus, + this.cardRight, + this.fingerRight, + + this.remoteId, + this.remoteName, + this.remoteNumber, + this.mac, + this.electricQuantity, + this.remoteStatus, + this.remoteType, + this.adminUid, + this.remoteRight, + this.lockAlias + }); + + FingerprintItemData.fromJson(Map json) { + fingerprintStatus = json['fingerprintStatus']; + lockId = json['lockId']; + createDate = json['createDate']; + fingerprintName = json['fingerprintName']; + endDate = json['endDate']; + apiUserId = json['apiUserId']; + nickName = json['nickName']; + isCoerced = json['isCoerced']; + startDate = json['startDate']; + fingerprintNumber = json['fingerprintNumber']; + fingerprintType = json['fingerprintType']; + fingerprintId = json['fingerprintId']; + senderUsername = json['senderUsername']; + weekDay = json['weekDay']; + validTimeStr = json['validTimeStr']; + cardName = json['cardName']; + cardNumber = json['cardNumber']; + cardType = json['cardType']; + cardId = json['cardId']; + faceId = json['faceId']; + faceName = json['faceName']; + faceNumber = json['faceNumber']; + status = json['status']; + addType = json['addType']; + faceType = json['faceType']; + cyclicConfig = json['cyclicConfig']; + featureData = json['featureData']; + faceRight = json['faceRight']; + cardStatus = json['cardStatus']; + cardRight = json['cardRight']; + fingerRight = json['fingerRight']; + + remoteId = json['remoteId']; + remoteName = json['remoteName']; + remoteNumber = json['remoteNumber']; + mac = json['mac']; + electricQuantity = json['electricQuantity']; + remoteStatus = json['remoteStatus']; + remoteType = json['remoteType']; + adminUid = json['adminUid']; + remoteRight = json['remoteRight']; + lockAlias = json['lockAlias']; + } int? fingerprintStatus; int? lockId; int? createDate; @@ -96,72 +186,16 @@ class FingerprintItemData { String? featureData; int? faceRight; - FingerprintItemData( - {this.fingerprintStatus, - this.lockId, - this.createDate, - this.fingerprintName, - this.endDate, - this.apiUserId, - this.nickName, - this.isCoerced, - this.startDate, - this.fingerprintNumber, - this.fingerprintType, - this.fingerprintId, - this.senderUsername, - this.weekDay, - this.validTimeStr, - this.cardName, - this.cardNumber, - this.cardType, - this.cardId, - this.faceId, - this.faceName, - this.faceNumber, - this.status, - this.addType, - this.faceType, - this.cyclicConfig, - this.featureData, - this.faceRight, - this.cardStatus, - this.cardRight, - this.fingerRight}); - - FingerprintItemData.fromJson(Map json) { - fingerprintStatus = json['fingerprintStatus']; - lockId = json['lockId']; - createDate = json['createDate']; - fingerprintName = json['fingerprintName']; - endDate = json['endDate']; - apiUserId = json['apiUserId']; - nickName = json['nickName']; - isCoerced = json['isCoerced']; - startDate = json['startDate']; - fingerprintNumber = json['fingerprintNumber']; - fingerprintType = json['fingerprintType']; - fingerprintId = json['fingerprintId']; - senderUsername = json['senderUsername']; - weekDay = json['weekDay']; - validTimeStr = json['validTimeStr']; - cardName = json['cardName']; - cardNumber = json['cardNumber']; - cardType = json['cardType']; - cardId = json['cardId']; - faceId = json['faceId']; - faceName = json['faceName']; - faceNumber = json['faceNumber']; - status = json['status']; - addType = json['addType']; - faceType = json['faceType']; - cyclicConfig = json['cyclicConfig']; - featureData = json['featureData']; - faceRight = json['faceRight']; - cardStatus = json['cardStatus']; - cardRight = json['cardRight']; - fingerRight = json['fingerRight']; - } + int? remoteId; + String? remoteName; + String? remoteNumber; + String? mac; + int? electricQuantity; + int? remoteStatus; + int? remoteType; + int? adminUid; + int? remoteRight; + String? lockAlias; Map toJson() { final Map data = {}; @@ -196,6 +230,17 @@ class FingerprintItemData { data['cardStatus'] = cardStatus; data['cardRight'] = cardRight; data['fingerRight'] = fingerRight; + + data['remoteId'] = remoteId; + data['remoteName'] = remoteName; + data['remoteNumber'] = remoteNumber; + data['mac'] = mac; + data['electricQuantity'] = electricQuantity; + data['remoteStatus'] = remoteStatus; + data['remoteType'] = remoteType; + data['adminUid'] = adminUid; + data['remoteRight'] = remoteRight; + data['lockAlias'] = lockAlias; return data; } } diff --git a/lib/main/lockDetail/lockDetail/lockDetail_page.dart b/lib/main/lockDetail/lockDetail/lockDetail_page.dart index 8c8ff1fd..320616f5 100755 --- a/lib/main/lockDetail/lockDetail/lockDetail_page.dart +++ b/lib/main/lockDetail/lockDetail/lockDetail_page.dart @@ -1096,7 +1096,9 @@ class _LockDetailPageState extends State 'images/main/icon_main_remoteControl.png', TranslationLoader.lanKeys!.remoteControl!.tr, state.bottomBtnisEable.value, () { - Get.toNamed(Routers.remoteControlListPage); + Get.toNamed(Routers.remoteControlListPage, arguments: { + 'lockId': state.keyInfos.value.lockId, + }); })); } diff --git a/lib/main/lockDetail/lockOperatingRecord/lockOperatingRecord_logic.dart b/lib/main/lockDetail/lockOperatingRecord/lockOperatingRecord_logic.dart index 0e30ab29..6d710392 100755 --- a/lib/main/lockDetail/lockOperatingRecord/lockOperatingRecord_logic.dart +++ b/lib/main/lockDetail/lockOperatingRecord/lockOperatingRecord_logic.dart @@ -56,10 +56,18 @@ class LockOperatingRecordLogic extends BaseGetXController { indexMap['type'] = indexList[0].toString(); if(indexList[0] == 2){ + // final List passwordData = indexList.sublist(7, 17); + // final String password = utf8String(passwordData); + // AppLog.log('password:$password passwordData:$passwordData'); + // indexMap['user'] = password; + + final int userNo = (indexList[1] * 256) + indexList[2]; + indexMap['user'] = userNo.toString(); + AppLog.log('userNouserNouserNouserNo:$userNo'); final List passwordData = indexList.sublist(7, 17); final String password = utf8String(passwordData); - AppLog.log('password:$password passwordData:$passwordData'); - indexMap['user'] = password; + indexMap['password'] = password.toString(); + AppLog.log('passwordpasswordpassword:$password'); }else{ final int userNo = (indexList[1]*256) + indexList[2]; indexMap['user'] = userNo.toString(); diff --git a/lib/main/lockDetail/lockOperatingRecord/lockOperatingRecord_state.dart b/lib/main/lockDetail/lockOperatingRecord/lockOperatingRecord_state.dart index 4574189a..8f96ed49 100755 --- a/lib/main/lockDetail/lockOperatingRecord/lockOperatingRecord_state.dart +++ b/lib/main/lockDetail/lockOperatingRecord/lockOperatingRecord_state.dart @@ -4,31 +4,31 @@ import 'package:get/get.dart'; import '../../lockMian/entity/lockListInfo_entity.dart'; import 'keyOperationRecord_entity.dart'; -class LockOperatingRecordState { - final lockOperatingRecordListData = [].obs; - final TextEditingController searchController = TextEditingController(); - - var ifCurrentScreen = true.obs; // 是否是当前界面,用于判断是否需要针对当前界面进行展示 - var operateDate = 0; // 按日期查询消息记录的时间戳 - var ifHaveNext = false; // 页码 - var logCountPage = 10; // 蓝牙记录一页多少个 - var idStr = ""; // - var type = 0; // 1:密码 2:卡 3:指纹 4:人脸 5:钥匙 - var recordName = "".obs; // 记录名称 +class LockOperatingRecordState { // 记录名称 LockOperatingRecordState() { Map map = Get.arguments; - if(map["id"] != null){ - idStr = Get.arguments["id"]; + if(map['id'] != null){ + idStr = Get.arguments['id']; } - if(map["idStr"] != null){ - idStr = Get.arguments["idStr"]; + if(map['idStr'] != null){ + idStr = Get.arguments['idStr']; } - if(map["type"] != null){ - type = Get.arguments["type"]; + if(map['type'] != null){ + type = Get.arguments['type']; } - if(map["recordName"] != null){ - recordName.value = Get.arguments["recordName"]; + if(map['recordName'] != null){ + recordName.value = Get.arguments['recordName']; } } + final RxList lockOperatingRecordListData = [].obs; + final TextEditingController searchController = TextEditingController(); + + RxBool ifCurrentScreen = true.obs; // 是否是当前界面,用于判断是否需要针对当前界面进行展示 + int operateDate = 0; // 按日期查询消息记录的时间戳 + bool ifHaveNext = false; // 页码 + int logCountPage = 10; // 蓝牙记录一页多少个 + String idStr = ''; // + int type = 0; // 1:密码 2:卡 3:指纹 4:人脸 5:钥匙 + RxString recordName = ''.obs; } diff --git a/lib/main/lockDetail/lockSet/burglarAlarm/burglarAlarm_logic.dart b/lib/main/lockDetail/lockSet/burglarAlarm/burglarAlarm_logic.dart index ec231e32..1d7ec440 100755 --- a/lib/main/lockDetail/lockSet/burglarAlarm/burglarAlarm_logic.dart +++ b/lib/main/lockDetail/lockSet/burglarAlarm/burglarAlarm_logic.dart @@ -80,9 +80,10 @@ class BurglarAlarmLogic extends BaseGetXController{ break; case 0x06: //无权限 - + state.sureBtnState.value = 0; break; default: + state.sureBtnState.value = 0; break; } } diff --git a/lib/main/lockDetail/lockSet/faceUnlock/faceUnlock_page.dart b/lib/main/lockDetail/lockSet/faceUnlock/faceUnlock_page.dart index 1a0dfdd1..cdcedb5f 100755 --- a/lib/main/lockDetail/lockSet/faceUnlock/faceUnlock_page.dart +++ b/lib/main/lockDetail/lockSet/faceUnlock/faceUnlock_page.dart @@ -59,7 +59,7 @@ class _FaceUnlockPageState extends State { TranslationLoader.lanKeys!.preventWrongOpening!.tr, state.antiMisoperation.value == 0 ? TranslationLoader.lanKeys!.preventWrongOpeningTip!.tr - :'防误开已打开,时间是'.tr + state.antiMisoperation.value.toString() + '秒'.tr, + :'防误开已打开,开锁后'.tr + state.antiMisoperation.value.toString() + '秒内不可使用面容开锁'.tr, // state.antiMisoperation.value == 0 ? '关闭' : '${state.antiMisoperation.value}' + '秒'.tr, state.faceOn.value, () { diff --git a/lib/main/lockDetail/lockSet/lockSet/lockSet_logic.dart b/lib/main/lockDetail/lockSet/lockSet/lockSet_logic.dart index 83849fc0..b99435f0 100755 --- a/lib/main/lockDetail/lockSet/lockSet/lockSet_logic.dart +++ b/lib/main/lockDetail/lockSet/lockSet/lockSet_logic.dart @@ -124,15 +124,11 @@ class LockSetLogic extends BaseGetXController { break; case 0x06: //无权限 - 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? publicKey = - await Storage.getStringList(saveBluePublicKey); - final List publicKeyDataList = - changeStringListToIntList(publicKey!); + final List? publicKey = await Storage.getStringList(saveBluePublicKey); + final List publicKeyDataList = changeStringListToIntList(publicKey!); final List? token = await Storage.getStringList(saveBlueToken); final List getTokenList = changeStringListToIntList(token!); @@ -180,6 +176,7 @@ class LockSetLogic extends BaseGetXController { //成功 // Toast.show(msg: "操作成功");featureEnable = state.isOpenStayWarn.value == 1 ? 0 : 1; dismissEasyLoading(); + state.sureBtnState.value = 0; cancelBlueConnetctToastTimer(); if (state.settingUpSupportFeatures == 55) { // APP开锁时是否需联网 @@ -208,8 +205,10 @@ class LockSetLogic extends BaseGetXController { break; case 0x06: //无权限 + state.sureBtnState.value = 0; break; default: + state.sureBtnState.value = 0; break; } } @@ -354,8 +353,14 @@ class LockSetLogic extends BaseGetXController { // 设置支持功能(带参数) Future sendBurglarAlarm(int type) async { + if(state.sureBtnState.value == 1){ + return; + } + state.sureBtnState.value = 1; + showEasyLoading(); showBlueConnetctToastTimer(action: () { + state.sureBtnState.value = 0; dismissEasyLoading(); }); BlueManage().blueSendData(BlueManage().connectDeviceName, @@ -402,6 +407,7 @@ class LockSetLogic extends BaseGetXController { } else if (connectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); + state.sureBtnState.value = 0; if (state.ifCurrentScreen.value == true) { showBlueConnetctToast(); } diff --git a/lib/main/lockDetail/lockSet/lockSet/lockSet_page.dart b/lib/main/lockDetail/lockSet/lockSet/lockSet_page.dart index d943e667..81e7153f 100755 --- a/lib/main/lockDetail/lockSet/lockSet/lockSet_page.dart +++ b/lib/main/lockDetail/lockSet/lockSet/lockSet_page.dart @@ -701,7 +701,7 @@ class _LockSetPageState extends State trackColor: CupertinoColors.systemGrey5, thumbColor: CupertinoColors.white, value: state.isOpenLockNeedOnline.value == 1, - onChanged: (bool value) { + onChanged: state.sureBtnState.value == 1 ? null : (bool value) { setState(() { logic.sendBurglarAlarm(55); }); @@ -740,31 +740,31 @@ class _LockSetPageState extends State // } // 支持蓝牙广播 - CupertinoSwitch _lockBlueBroadcastSwitch() { - return CupertinoSwitch( - activeColor: CupertinoColors.activeBlue, - trackColor: CupertinoColors.systemGrey5, - thumbColor: CupertinoColors.white, - value: state.isOpenBlueBroadcast.value == 1, - onChanged: (bool value) { - setState(() { - logic.sendBurglarAlarm(56); - }); - }, - ); - } - - CupertinoSwitch _otherUnHaveDoneSwitch() { - return CupertinoSwitch( - activeColor: CupertinoColors.activeBlue, - trackColor: CupertinoColors.systemGrey5, - thumbColor: CupertinoColors.white, - value: false, - onChanged: (bool value) { - logic.showToast('功能暂未开放'); - }, - ); - } + // CupertinoSwitch _lockBlueBroadcastSwitch() { + // return CupertinoSwitch( + // activeColor: CupertinoColors.activeBlue, + // trackColor: CupertinoColors.systemGrey5, + // thumbColor: CupertinoColors.white, + // value: state.isOpenBlueBroadcast.value == 1, + // onChanged: (bool value) { + // setState(() { + // logic.sendBurglarAlarm(56); + // }); + // }, + // ); + // } + // + // CupertinoSwitch _otherUnHaveDoneSwitch() { + // return CupertinoSwitch( + // activeColor: CupertinoColors.activeBlue, + // trackColor: CupertinoColors.systemGrey5, + // thumbColor: CupertinoColors.white, + // value: false, + // onChanged: (bool value) { + // logic.showToast('功能暂未开放'); + // }, + // ); + // } @override void didChangeDependencies() { diff --git a/lib/main/lockDetail/lockSet/lockSet/lockSet_state.dart b/lib/main/lockDetail/lockSet/lockSet/lockSet_state.dart index 4ad0d0d7..b5fef828 100755 --- a/lib/main/lockDetail/lockSet/lockSet/lockSet_state.dart +++ b/lib/main/lockDetail/lockSet/lockSet/lockSet_state.dart @@ -27,6 +27,7 @@ class LockSetState { int settingUpSupportFeatures = 0; RxBool ifCurrentScreen = true.obs; // 是否是当前界面,用于判断是否需要针对当前界面进行展示 RxBool deleteAdministratorIsHaveAllData = false.obs; // 删除管理员是否有所有数据 + RxInt sureBtnState = 0.obs;// 0普通状态(可用) 1连接中(不可用) LockSetState() { Map map = Get.arguments; diff --git a/lib/main/lockDetail/remoteControl/addRemoteControl/addRemoteControl_entity.dart b/lib/main/lockDetail/remoteControl/addRemoteControl/addRemoteControl_entity.dart new file mode 100644 index 00000000..07c746ff --- /dev/null +++ b/lib/main/lockDetail/remoteControl/addRemoteControl/addRemoteControl_entity.dart @@ -0,0 +1,43 @@ +class AddRemoteControlEntity { + + AddRemoteControlEntity( + {this.errorCode, this.description, this.errorMsg, this.data}); + + AddRemoteControlEntity.fromJson(Map json) { + errorCode = json['errorCode']; + description = json['description']; + errorMsg = json['errorMsg']; + data = json['data'] != null ? Data.fromJson(json['data']) : null; + } + int? errorCode; + String? description; + String? errorMsg; + Data? data; + + Map toJson() { + final Map data = {}; + data['errorCode'] = errorCode; + data['description'] = description; + data['errorMsg'] = errorMsg; + if (this.data != null) { + data['data'] = this.data!.toJson(); + } + return data; + } +} + +class Data { + + Data({this.remoteId}); + + Data.fromJson(Map json) { + remoteId = json['remoteId']; + } + int? remoteId; + + Map toJson() { + final Map data = {}; + data['remoteId'] = remoteId; + return data; + } +} \ No newline at end of file diff --git a/lib/main/lockDetail/remoteControl/addRemoteControl/addRemoteControl_logic.dart b/lib/main/lockDetail/remoteControl/addRemoteControl/addRemoteControl_logic.dart old mode 100755 new mode 100644 index 07161d66..ec634e41 --- a/lib/main/lockDetail/remoteControl/addRemoteControl/addRemoteControl_logic.dart +++ b/lib/main/lockDetail/remoteControl/addRemoteControl/addRemoteControl_logic.dart @@ -1,19 +1,277 @@ +import 'dart:async'; + +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; +import 'package:get/get.dart'; import 'package:star_lock/tools/baseGetXController.dart'; -import 'package:star_lock/tools/pickers/time_picker/time_utils.dart'; +import '../../../../app_settings/app_settings.dart'; +import '../../../../blue/blue_manage.dart'; +import '../../../../blue/io_protocol/io_addRemoteControlWithTimeCycleCoercion.dart'; +import '../../../../blue/io_reply.dart'; +import '../../../../blue/io_tool/io_tool.dart'; +import '../../../../blue/io_tool/manager_event_bus.dart'; +import '../../../../blue/sender_manage.dart'; +import '../../../../login/login/entity/LoginEntity.dart'; +import '../../../../network/api_repository.dart'; +import '../../../../tools/dateTool.dart'; +import '../../../../tools/eventBusEventManage.dart'; +import '../../../../tools/storage.dart'; +import 'addRemoteControl_entity.dart'; import 'addRemoteControl_state.dart'; -class AddRemoteControlLoigc extends BaseGetXController{ +class AddRemoteControlLogic extends BaseGetXController{ AddRemoteControlState state = AddRemoteControlState(); - List get weekDayStr { - return state.weekdaysList.map((e) => TimeUtils.translateWeekday(e)).toList(); + // 监听设备返回的数据 + late StreamSubscription _replySubscription; + void _initReplySubscription() { + _replySubscription = EventBusManager().eventBus!.on().listen((Reply reply) async { + // 添加遥控开始 + if((reply is SenderAddRemoteControlWithTimeCycleCoercionReply) && (state.ifCurrentScreen.value == true)) { + _replyAddRemoteControlBegin(reply); + } + + // 添加遥控确认 + if(reply is SenderAddRemoteControlConfirmationReply) { + _replyAddRemoteControlConfirmation(reply); + } + }); + } + + Future _replyAddRemoteControlBegin(Reply reply) async { + final int status = reply.data[2]; + + switch(status){ + case 0x00: + //成功 + final List remoteControlNumberList = reply.data.sublist(reply.data.length - 2); + final String remoteControlNumber = listChangInt(remoteControlNumberList).toString(); + // AppLog.log("添加卡号:$cardNumberList cardNumber:$cardNumber"); + state.remoteControlNumber.value = remoteControlNumber.toString(); + cancelBlueConnetctToastTimer(); + + state.ifAddState.value = true; + state.ifConnectScuess.value = true; + 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!); + + // var publicKey = await Storage.getStringList(saveBluePublicKey); + // List publicKeyDataList = changeStringListToIntList(publicKey!); + + final List token = reply.data.sublist(5, 9); + final List saveStrList = changeIntListToStringList(token); + Storage.setStringList(saveBlueToken, saveStrList); + AppLog.log('添加卡token:$token'); + + IoSenderManage.senderAddRemoteControlWithTimeCycleCoercionCommand( + keyID:'1', + userID:await Storage.getUid(), + remoteControlNo:0, + useCountLimit:0xffff, + operate:0, // 0:注册 1:修改 2:删除 3:删除全部 + isAdmin:state.isAdministrator.value == '2' ? 1 : 0, + isForce:state.isCoerced.value == '1' ? 1 : 0, // 是否是胁迫 + isRound:state.selectType.value == '2' ? 1: 0, // 是否是循环 + weekRound:DateTool().accordingTheCycleIntoTheCorrespondingNumber(state.weekDay.value), // 周循环 + startDate: int.parse(state.startDate.value)~/1000, + endDate: int.parse(state.endDate.value)~/1000, + startTime:DateTool().dateToHNString(state.effectiveDateTime.value), + endTime:DateTool().dateToHNString(state.failureDateTime.value), + needAuthor:1, + signKey:signKeyDataList, + privateKey:getPrivateKeyList, + token: token, + isBeforeAddUser: false + ); + break; + default: + //失败 + state.ifAddState.value = false; + break; + } + } + + Future _replyAddRemoteControlConfirmation(Reply reply) async { + final int status = reply.data[2]; + state.ifAddState.value = false; + switch(status){ + case 0x00: + //成功 + switch(reply.data[5]){ + case 0xff: + // 注册指纹失败 + showToast('退出添加'.tr); + Get.close(1); + break; + case 0xFE: + // 管理员已满 + showToast('管理员已满'.tr); + Get.close(1); + break; + case 0xFD: + // 用户已满 + showToast('用户已满'.tr); + Get.close(1); + break; + case 0xFC: + // 遥控已满 + showToast('锁上面添加卡已满'.tr); + Get.close(1); + break; + case 0xFB: + // 遥控已存在 + showToast('遥控已存在'.tr); + break; + default: + // 添加指纹中 + // 当前注册数 + _addRemoteControlData(); + break; + } + break; + default: + //失败 + break; + } + } + + // 添加卡片 + Future senderAddRemoteControl() async { + showBlueConnetctToastTimer(action: (){ + Get.close(1); + }); + BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected){ + cancelBlueConnetctToastTimer(); + + 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? token = await Storage.getStringList(saveBlueToken); + final List getTokenList = changeStringListToIntList(token!); + + IoSenderManage.senderAddRemoteControlWithTimeCycleCoercionCommand( + keyID:'1', + userID:await Storage.getUid(), + remoteControlNo:0, + useCountLimit:0xffff, + operate:0, // 0:注册 1:修改 2:删除 3:删除全部 + isAdmin:state.isAdministrator.value == '2' ? 1 : 0, + isForce:state.isCoerced.value == '1' ? 1 : 0, // 是否是胁迫 + isRound:state.selectType.value == '2' ? 1: 0, // 是否是循环 + weekRound:DateTool().accordingTheCycleIntoTheCorrespondingNumber(state.weekDay.value), // 周循环 + startDate: int.parse(state.startDate.value)~/1000, + endDate: int.parse(state.endDate.value)~/1000, + startTime:DateTool().dateToHNString(state.effectiveDateTime.value), + endTime:DateTool().dateToHNString(state.failureDateTime.value), + needAuthor:1, + signKey:signKeyDataList, + privateKey:getPrivateKeyList, + token: getTokenList, + isBeforeAddUser: false + ); + } else if (deviceConnectionState == BluetoothConnectionState.disconnected){ + if(state.ifCurrentScreen.value == true){ + showBlueConnetctToast(); + } + cancelBlueConnetctToastTimer(); + Get.close(1); + } + }); + } + + // 取消添加指纹 + Future senderCancelAddRemoteControlCommand() async { + BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected){ + 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 = await Storage.getStringList(saveBlueToken); + final List getTokenList = changeStringListToIntList(token!); + + IoSenderManage.senderCancelAddRemoteControlCommand( + keyID:'1', + userID:await Storage.getUid(), + needAuthor:1, + signKey:signKeyDataList, + privateKey:getPrivateKeyList, + token: getTokenList, + ); + }else if (deviceConnectionState == BluetoothConnectionState.disconnected){ + if(state.ifCurrentScreen.value == true){ + showBlueConnetctToast(); + } + cancelBlueConnetctToastTimer(); + Get.close(1); + } + }); + } + + Future _addRemoteControlData() async { + final AddRemoteControlEntity entity = await ApiRepository.to.addRemoteControlData( + lockId: state.lockId.value.toString(), + remoteName: state.remoteControlName.value.toString(), + remoteNumber: state.remoteControlNumber.value.toString(), + remoteType: int.parse(state.remoteControlType.value), + startDate: int.parse(state.startDate.value), + endDate: int.parse(state.endDate.value), + addType: int.parse(state.addType.value), + weekDay: state.weekDay.value, + startTime: int.parse(state.effectiveDateTime.value), + endTime: int.parse(state.failureDateTime.value), + // remoteRight: state.isAdministrator.value == '2' ? 1 : 0, + remoteRight: 0, + ); + if (entity.errorCode!.codeIsSuccessful) { + updateRemoteUserNoLoadData(entity.data!.remoteId ?? 0); + } + } + + Future updateRemoteUserNoLoadData(int cardId) async{ + final LoginEntity entity = await ApiRepository.to.updateRemoteUserNoLoadData( + lockId: state.lockId.value, + remoteId: cardId, + remoteUserNo: state.remoteControlNumber.value, + ); + if(entity.errorCode!.codeIsSuccessful){ + showToast('添加成功'.tr, something:(){ + eventBus.fire(OtherTypeRefreshListEvent()); + Get.close(2); + }); + } + } + + @override + void onReady() { + super.onReady(); + + _initReplySubscription(); } @override void onInit() { + super.onInit(); + senderAddRemoteControl(); + } + + @override + void onClose() { + _replySubscription.cancel(); } } \ No newline at end of file diff --git a/lib/main/lockDetail/remoteControl/addRemoteControl/addRemoteControl_page.dart b/lib/main/lockDetail/remoteControl/addRemoteControl/addRemoteControl_page.dart old mode 100755 new mode 100644 index 5145000f..2f959d73 --- a/lib/main/lockDetail/remoteControl/addRemoteControl/addRemoteControl_page.dart +++ b/lib/main/lockDetail/remoteControl/addRemoteControl/addRemoteControl_page.dart @@ -1,22 +1,14 @@ + import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; -import 'package:star_lock/tools/pickers/pickers.dart'; -import 'package:star_lock/tools/pickers/time_picker/model/date_mode.dart'; -import 'package:star_lock/tools/pickers/time_picker/model/pduration.dart'; -import '../../../../appRouters.dart'; import '../../../../app_settings/app_colors.dart'; -import '../../../../tools/CustomUnderlineTabIndicator.dart'; -import '../../../../tools/commonItem.dart'; -import '../../../../tools/dateTool.dart'; -import '../../../../tools/storage.dart'; -import '../../../../tools/submitBtn.dart'; +import '../../../../tools/appRouteObserver.dart'; import '../../../../tools/titleAppBar.dart'; -import '../../../../translations/trans_lib.dart'; import 'addRemoteControl_logic.dart'; +import 'addRemoteControl_state.dart'; class AddRemoteControlPage extends StatefulWidget { const AddRemoteControlPage({Key? key}) : super(key: key); @@ -25,472 +17,105 @@ class AddRemoteControlPage extends StatefulWidget { State createState() => _AddRemoteControlPageState(); } -class _AddRemoteControlPageState extends State - with SingleTickerProviderStateMixin { - final logic = Get.put(AddRemoteControlLoigc()); - final state = Get.find().state; - - @override - void initState() { - // TODO: implement initState - super.initState(); - - state.tabController = TabController( - vsync: this, - length: state.fromType.value == 1 - ? _itemTabs.length - : _fromCheckInTypeItemTabs.length, - initialIndex: 0); - state.tabController.addListener(() { - WidgetsBinding.instance.addPostFrameCallback((_) { - state.selectType.value = state.tabController.index.toString(); - }); - - if (state.tabController.animation!.value == state.tabController.index) { - FocusScope.of(context).requestFocus(FocusNode()); - } - }); - } +class _AddRemoteControlPageState extends State with RouteAware { + final AddRemoteControlLogic logic = Get.put(AddRemoteControlLogic()); + final AddRemoteControlState state = Get.find().state; @override Widget build(BuildContext context) { return Scaffold( backgroundColor: AppColors.mainBackgroundColor, appBar: TitleAppBar( - barTitle: - "${TranslationLoader.lanKeys!.addTip!.tr}${TranslationLoader.lanKeys!.fingerprint!.tr}", - haveBack: true, - backgroundColor: AppColors.mainColor), - body: Column( - children: [ - _tabBar(), - _pageWidget(), + barTitle: '添加遥控', + haveBack: true, + backgroundColor: AppColors.mainColor, + ), + body: ListView( + children: [ + SizedBox(height: 180.h), + Center( + child: Image.asset( + 'images/main/icon_addRemoteControl_tip.png', + width: 300.w, + height: 300.w, + fit: BoxFit.cover, + ), + ), + SizedBox(height: 90.h), + CupertinoActivityIndicator( + radius: 25.h, + ), + SizedBox(height: 120.h), + Container( + width: 1.sw, + // height: 50.h, + padding: EdgeInsets.all(10.w), + margin: EdgeInsets.only( + left: 15.w, right: 15.w, top: 10.h, bottom: 10.h), + // color: AppColors.blackColor, + decoration: BoxDecoration( + color: AppColors.blackColor, + borderRadius: BorderRadius.circular(10.w), + ), + child: Center( + child: Obx(() => Text( + state.ifConnectScuess.value + ? '已连接到锁,请按遥控'.tr + : '尝试连接设备...'.tr, + style: TextStyle(color: Colors.white, fontSize: 24.sp)))), + ), ], ), ); } - Widget indexChangeWidget() { - switch (int.parse(state.selectType.value)) { - case 0: - { - // 永久 - // return sendElectronicKeySucceed(); - return Column( - children: [ - perpetualKeyWidget( - TranslationLoader.lanKeys!.name!.tr, - TranslationLoader.lanKeys!.pleaseEnter!.tr, - state.nameController), - keyBottomWidget() - ], - ); - } - case 1: - { - // 限时 - return Column( - children: [ - perpetualKeyWidget( - TranslationLoader.lanKeys!.name!.tr, - TranslationLoader.lanKeys!.pleaseEnter!.tr, - state.nameController), - keyTimeLimitWidget(), - SizedBox(height: 10.h), - keyBottomWidget() - ], - ); - } - case 2: - { - // 循环 - return SingleChildScrollView( - child: Column( - children: [ - perpetualKeyWidget( - TranslationLoader.lanKeys!.name!.tr, - TranslationLoader.lanKeys!.pleaseEnter!.tr, - state.nameController), - keyCyclicDate(), - SizedBox(height: 10.h), - keyBottomWidget() - ], - ), - ); - } - default: - return Container(); + @override + void didChangeDependencies() { + super.didChangeDependencies(); + + /// 路由订阅 + AppRouteObserver().routeObserver.subscribe(this, ModalRoute.of(context)!); + } + + @override + void dispose() { + /// 取消路由订阅 + AppRouteObserver().routeObserver.unsubscribe(this); + super.dispose(); + } + + /// 从上级界面进入 当前界面即将出现 + @override + void didPush() { + super.didPush(); + state.ifCurrentScreen.value = true; + } + + /// 返回上一个界面 当前界面即将消失 + @override + void didPop() { + super.didPop(); + logic.cancelBlueConnetctToastTimer(); + state.ifCurrentScreen.value = false; + + if(state.ifAddState.value){ + logic.senderCancelAddRemoteControlCommand(); } } - // 密码命名输入框 - Widget perpetualKeyWidget( - String titleStr, String rightTitle, TextEditingController controller) { - return Column( - children: [ - CommonItem( - leftTitel: titleStr, - rightTitle: '', - isHaveRightWidget: true, - rightWidget: getTFWidget(rightTitle)), - Container(height: 10.h), - ], - ); + /// 从下级返回 当前界面即将出现 + @override + void didPopNext() { + super.didPopNext(); + state.ifCurrentScreen.value = true; } - // 限时顶部选择日期 - Widget keyTimeLimitWidget() { - return Column( - children: [ - Obx(() => CommonItem( - leftTitel: TranslationLoader.lanKeys!.effectiveTime!.tr, - rightTitle: state.timeLimitBeginTime.value, - isHaveLine: true, - isHaveDirection: true, - action: () async { - PDuration selectDate = PDuration.parse( - DateTime.parse(state.timeLimitBeginTime.value)); - Pickers.showDatePicker(context, - selectDate: selectDate, mode: DateMode.YMDHM, onConfirm: (p) { - state.timeLimitBeginTime.value = - DateTool().getYMDHNDateString(p, 1); - }); - })), - Obx(() => CommonItem( - leftTitel: TranslationLoader.lanKeys!.failureTime!.tr, - rightTitle: state.timeLimitEndTime.value, - isHaveDirection: true, - action: () { - PDuration selectDate = PDuration.parse( - DateTime.tryParse(state.timeLimitEndTime.value)); - Pickers.showDatePicker(context, - selectDate: selectDate, mode: DateMode.YMDHM, onConfirm: (p) { - state.timeLimitEndTime.value = - DateTool().getYMDHNDateString(p, 1); - }); - })), - Container(height: 10.h), - ], - ); - } + /// 进入下级界面 当前界面即将消失 + @override + void didPushNext() { + super.didPushNext(); + logic.cancelBlueConnetctToastTimer(); - // 循环顶部选择日期 - Widget keyCyclicDate() { - return Column( - children: [ - Obx(() => CommonItem( - leftTitel: TranslationLoader.lanKeys!.periodValidity!.tr, - rightTitle: - '${state.cycleBeginTime.value}\n${state.cycleEndTime.value}', - isHaveDirection: true, - isHaveLine: true, - action: () async { - var result = - await Get.toNamed(Routers.seletKeyCyclicDatePage, arguments: { - 'validityValue': state.weekdaysList.value, - 'starDate': state.cycleBeginTime.value, - 'endDate': state.cycleEndTime.value, - 'starTime': state.effectiveDateTime.value, - 'endTime': state.failureDateTime.value - }); - if (result != null && result.isNotEmpty) { - state.weekdaysList.value = result['validityValue']; - state.cycleBeginTime.value = result['starDate']; - state.cycleEndTime.value = result['endDate']; - state.effectiveDateTime.value = result['starTime']; - state.failureDateTime.value = result['endTime']; - } - })), - Obx(() => Visibility( - visible: state.weekdaysList.isNotEmpty, - child: CommonItem( - leftTitel: '有效日'.tr, - rightTitle: logic.weekDayStr.join(',').toString(), - isHaveDirection: true, - isHaveLine: true, - action: () async { - var result = await Get.toNamed(Routers.seletKeyCyclicDatePage, - arguments: { - 'validityValue': state.weekdaysList.value, - 'starDate': state.cycleBeginTime.value, - 'endDate': state.cycleEndTime.value, - 'starTime': state.effectiveDateTime.value, - 'endTime': state.failureDateTime.value - }); - if (result != null && result.isNotEmpty) { - state.weekdaysList.value = result['validityValue']; - state.cycleBeginTime.value = result['starDate']; - state.cycleEndTime.value = result['endDate']; - state.effectiveDateTime.value = result['starTime']; - state.failureDateTime.value = result['endTime']; - } - }))), - Obx(() => Visibility( - visible: state.effectiveDateTime.value.isNotEmpty, - child: CommonItem( - leftTitel: '有效时间'.tr, - rightTitle: - '${state.effectiveDateTime.value}-${state.failureDateTime.value}', - isHaveDirection: true, - action: () async { - var result = await Get.toNamed(Routers.seletKeyCyclicDatePage, - arguments: { - 'validityValue': state.weekdaysList.value, - 'starDate': state.cycleBeginTime.value, - 'endDate': state.cycleEndTime.value, - 'starTime': state.effectiveDateTime.value, - 'endTime': state.failureDateTime.value - }); - if (result != null && result.isNotEmpty) { - state.weekdaysList.value = result['validityValue']; - state.cycleBeginTime.value = result['starDate']; - state.cycleEndTime.value = result['endDate']; - state.effectiveDateTime.value = result['starTime']; - state.failureDateTime.value = result['endTime']; - } - }))), - ], - ); - } - - Widget keyBottomWidget() { - return Column( - children: [ - // CommonItem( - // leftTitel: TranslationLoader.lanKeys!.remoteControl!.tr, - // rightTitle: "", - // isTipsImg: false, - // isHaveRightWidget: true, - // rightWidget: SizedBox( - // width: 60.w, height: 50.h, child: _isStressFingerprint())), - SizedBox(height: 30.h), - SubmitBtn( - btnName: TranslationLoader.lanKeys!.next!.tr, - onClick: () async { - var isDemoMode = await Storage.getBool(ifIsDemoModeOrNot); - if (isDemoMode == false) { - if (state.nameController.text.isEmpty) { - logic.showToast('请输入姓名'); - return; - } - logic.showToast('请确保在设备附近'); - // logic.addFingerprintsData(); - } else { - // Get.toNamed(Routers.selectLockTypePage); - logic.showToast('演示模式'); - } - }), - ], - ); - } - - // 发送电子钥匙成功 - Widget sendElectronicKeySucceed() { - return Column( - children: [ - Container( - height: 300.h, - width: 1.sw, - color: Colors.white, - child: Column( - children: [ - SizedBox( - height: 30.h, - ), - Image.asset( - 'images/main/icon_main_addLock.png', - width: 150.w, - height: 150.w, - color: AppColors.mainColor, - ), - SizedBox( - height: 20.h, - ), - Text( - '操作成功,密码为', - style: TextStyle( - fontSize: 32.sp, - color: Colors.black, - fontWeight: FontWeight.w500), - ), - SizedBox( - height: 10.h, - ), - Text( - '62689876', - style: TextStyle( - fontSize: 60.sp, - color: Colors.black, - fontWeight: FontWeight.w500), - ), - ], - ), - ), - SizedBox( - height: 20.h, - ), - SubmitBtn( - btnName: '完成'.tr, - fontSize: 28.sp, - borderRadius: 20.w, - margin: EdgeInsets.only(left: 30.w, right: 30.w, top: 30.w), - padding: EdgeInsets.only(top: 25.w, bottom: 25.w), - onClick: () {}), - SubmitBtn( - btnName: '分享', - fontSize: 28.sp, - borderRadius: 20.w, - margin: EdgeInsets.only(left: 30.w, right: 30.w, top: 30.w), - padding: EdgeInsets.only(top: 25.w, bottom: 25.w), - onClick: () {}), - SubmitBtn( - btnName: '标记为:已入住', - fontSize: 28.sp, - borderRadius: 20.w, - margin: EdgeInsets.only(left: 30.w, right: 30.w, top: 30.w), - padding: EdgeInsets.only(top: 25.w, bottom: 25.w), - onClick: () {}), - ], - ); - } - - // 接受者信息输入框 - Widget getTFWidget(String tfStr) { - return Container( - // color: Colors.red, - height: 65.h, - width: 300.w, - padding: EdgeInsets.only(top: 5.h), - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Expanded( - child: TextField( - //输入框一行 - maxLines: 1, - inputFormatters: [ - FilteringTextInputFormatter.deny('\n'), - LengthLimitingTextInputFormatter(18), - ], - style: TextStyle( - fontSize: 22.sp, color: AppColors.darkGrayTextColor), - controller: state.nameController, - autofocus: false, - textAlign: TextAlign.end, - decoration: InputDecoration( - //输入里面输入文字内边距设置 - // contentPadding: const EdgeInsets.only(top: 12.0, bottom: 8.0), - hintText: tfStr, - hintStyle: TextStyle(fontSize: 22.sp), - focusedBorder: const OutlineInputBorder( - borderSide: - BorderSide(width: 0, color: Colors.transparent)), - disabledBorder: const OutlineInputBorder( - borderSide: - BorderSide(width: 0, color: Colors.transparent)), - enabledBorder: const OutlineInputBorder( - borderSide: - BorderSide(width: 0, color: Colors.transparent)), - border: const OutlineInputBorder( - borderSide: - BorderSide(width: 0, color: Colors.transparent)), - contentPadding: const EdgeInsets.symmetric(vertical: 0), - ), - ), - ), - SizedBox( - width: 10.w, - ), - ], - ), - ); - } - - //isStressFingerprint false:不是胁迫指纹 ture:胁迫指纹 - CupertinoSwitch _isStressFingerprint() { - return CupertinoSwitch( - activeColor: CupertinoColors.activeBlue, - trackColor: CupertinoColors.systemGrey5, - thumbColor: CupertinoColors.white, - value: true, - onChanged: (value) { - setState(() { - // state.isStressFingerprint.value = value; - }); - }, - ); - } - - final List _itemTabs = [ - ItemView(title: TranslationLoader.lanKeys!.permanent!.tr, selectType: '0'), - ItemView(title: TranslationLoader.lanKeys!.timeLimit!.tr, selectType: '1'), - ItemView( - title: TranslationLoader.lanKeys!.circulation!.tr, selectType: '2'), - ]; - - final List _fromCheckInTypeItemTabs = [ - ItemView(title: TranslationLoader.lanKeys!.permanent!.tr, selectType: '0'), - ItemView(title: TranslationLoader.lanKeys!.timeLimit!.tr, selectType: '1'), - ]; - - TabBar _tabBar() { - return TabBar( - controller: state.tabController, - onTap: (index) { - FocusScope.of(context).requestFocus(FocusNode()); - }, - tabs: state.fromType.value == 1 - ? _itemTabs.map((ItemView item) => _tab(item)).toList() - : _fromCheckInTypeItemTabs - .map((ItemView item) => _tab(item)) - .toList(), - isScrollable: true, - indicatorColor: Colors.red, - unselectedLabelColor: Colors.black, - unselectedLabelStyle: TextStyle( - color: AppColors.mainColor, - fontSize: 24.sp, - ), - automaticIndicatorColorAdjustment: true, - labelColor: AppColors.mainColor, - labelStyle: TextStyle( - color: AppColors.mainColor, - fontSize: 24.sp, - fontWeight: FontWeight.w600), - indicator: CustomUnderlineTabIndicator( - borderSide: BorderSide(color: AppColors.mainColor, width: 4.w), - strokeCap: StrokeCap.round, - width: 30.w), - ); - } - - Tab _tab(ItemView item) { - return Tab( - child: SizedBox( - width: 1.sw / 5, - child: Text(item.title, textAlign: TextAlign.center))); - } - - Widget _pageWidget() { - return Expanded( - child: TabBarView( - controller: state.tabController, - children: state.fromType.value == 1 - ? _itemTabs - .map((ItemView item) => Obx(() => indexChangeWidget())) - .toList() - : _fromCheckInTypeItemTabs - .map((ItemView item) => Obx(() => indexChangeWidget())) - .toList(), - ), - ); + state.ifCurrentScreen.value = false; } } - -class ItemView { - const ItemView({required this.title, required this.selectType}); - - final String title; - final String selectType; -} diff --git a/lib/main/lockDetail/remoteControl/addRemoteControl/addRemoteControl_state.dart b/lib/main/lockDetail/remoteControl/addRemoteControl/addRemoteControl_state.dart old mode 100755 new mode 100644 index 6f7ba940..8d46925f --- a/lib/main/lockDetail/remoteControl/addRemoteControl/addRemoteControl_state.dart +++ b/lib/main/lockDetail/remoteControl/addRemoteControl/addRemoteControl_state.dart @@ -1,40 +1,50 @@ -import 'package:flutter/material.dart'; + import 'package:get/get.dart'; -import '../../../../tools/dateTool.dart'; +import '../../../../app_settings/app_settings.dart'; +import '../../../../tools/commonDataManage.dart'; class AddRemoteControlState{ - final lockId = 0.obs; - final selectType = "0".obs;// 0永久 1显示 2循环 - final fromType = 1.obs; // // 1从添加钥匙列表进入 2从考勤添加员工入口进入 - final isStressFingerprint = false.obs; - final isAdministrator = false.obs;// 是否是管理员 - - var timeLimitBeginTime = DateTool().dateToYMDHNString(DateTime.now().millisecondsSinceEpoch.toString()).obs;// 限时开始时间 - var timeLimitEndTime = DateTool().dateToYMDHNString(DateTime.now().millisecondsSinceEpoch.toString()).obs;// 限时结束时间 - var cycleBeginTime = "".obs;// 循环开始时间 - var cycleEndTime = "".obs;// 循环结束时间 - var effectiveDateTime = "".obs;// 生效时间 - var failureDateTime = "".obs;// 失效时间 - var weekdaysList = [].obs; - var fromTypeTwoStaffName = "".obs; // 从添加员工进入 传入员工名字 - - final TextEditingController nameController = TextEditingController(); - late TabController tabController; AddRemoteControlState() { - Map map = Get.arguments; - if(map["lockId"]!=null){ - lockId.value = map["lockId"]; - } - - if(map["fromType"]!=null){ - fromType.value = map["fromType"]; - // 1从添加钥匙列表进入 2从考勤添加员工入口进入 - if(fromType.value == 2){ - fromTypeTwoStaffName.value = map["fromTypeTwoStaffName"]; // 从添加员工进入 传入员工名字 - } + final Map map = Get.arguments; + lockId.value = map['lockId']; + addType.value = map['addType']; + remoteControlName.value = map['remoteControlName']; + remoteControlNumber.value = map['remoteControlNumber']; + remoteControlType.value = map['remoteControlType']; + isCoerced.value = map['isCoerced']; + startDate.value = map['startDate']; + weekDay.value = map['weekDay']; + // AppLog.log('1111-isCoerced.value:${isCoerced.value}'); + isAdministrator.value = map['isAdministrator']; + effectiveDateTime.value = map['effectiveTime']; + failureDateTime.value = map['failureTime']; + selectType.value = map['selectType']; + //循环类型下,结束时间加一天 + if (selectType.value == '2') { + endDate.value = + "${int.parse(map["endDate"]) + CommonDataManage().dayLatestTime}"; + } else { + endDate.value = map['endDate']; } } + RxBool ifConnectScuess = false.obs; + RxBool ifCurrentScreen = true.obs; // 是否是当前界面,用于判断是否需要针对当前界面进行展示 + RxBool ifAddState = false.obs;// 是否是添加状态,如果是添加状态,返回上级界面发送取消添加指令 + RxInt addFingerprintProcessNumber = 0.obs; + final RxInt lockId = 0.obs; + final RxString endDate = ''.obs; + final RxString addType = ''.obs; + final RxString remoteControlName = ''.obs; + final RxString remoteControlNumber = ''.obs; + final RxString remoteControlType = ''.obs; + final RxString isCoerced = ''.obs; + final RxString isAdministrator = ''.obs; + final RxString startDate = ''.obs; + final RxList weekDay = [].obs; + final RxString effectiveDateTime = ''.obs; // 生效时间 + final RxString failureDateTime = ''.obs; // 失效时间 + final RxString selectType = '0'.obs; } \ No newline at end of file diff --git a/lib/main/lockDetail/remoteControl/addRemoteControlType/addRemoteControlType_logic.dart b/lib/main/lockDetail/remoteControl/addRemoteControlType/addRemoteControlType_logic.dart new file mode 100755 index 00000000..28f89d64 --- /dev/null +++ b/lib/main/lockDetail/remoteControl/addRemoteControlType/addRemoteControlType_logic.dart @@ -0,0 +1,98 @@ + +import 'package:get/get.dart'; +import 'package:star_lock/tools/baseGetXController.dart'; +import 'package:star_lock/tools/pickers/time_picker/time_utils.dart'; + +import '../../../../appRouters.dart'; +import '../../../../login/login/entity/LoginEntity.dart'; +import '../../../../network/api_repository.dart'; +import '../../../../tools/dateTool.dart'; +import 'addRemoteControlType_state.dart'; + +class AddRemoteControlTypeLoigc extends BaseGetXController{ + AddRemoteControlTypeState state = AddRemoteControlTypeState(); + + List get weekDayStr { + return state.weekdaysList.map((e) => TimeUtils.translateWeekday(e)).toList(); + } + + // 添加卡数据 + Future addRemoteControlData() async { + int carType = 0; // 永久:1;限时2,单次3,循环:4 + String startDate = ''; + String endDate = ''; + String startTime = ''; + String endTime = ''; + if (state.selectType.value == '0') { + carType = 1; + startDate = '0'; + endDate = '0'; + startTime = '0'; + endTime = '0'; + } else if (state.selectType.value == '1') { + carType = 2; + startDate = DateTool().dateToTimestamp(state.timeLimitBeginTime.value, 1).toString(); + endDate = DateTool().dateToTimestamp(state.timeLimitEndTime.value, 1).toString(); + startTime = '0'; + endTime = '0'; + + if (startDate.isEmpty) { + showToast('请选择开始时间'.tr); + return; + } + if (endDate.isEmpty) { + showToast('请选择结束时间'.tr); + return; + } + + // if(DateTime.now().millisecondsSinceEpoch > int.parse(state.beginTimeTimestamp.value)){ + // Toast.show(msg: "生效时间要大于当前时间"); + // return; + // } + + if (int.parse(startDate) >= int.parse(endDate)) { + showToast('失效时间要大于生效时间'.tr); + return; + } + // AppLog.log("state.timeLimitBeginTime.value:${state.timeLimitBeginTime.value} startDate:$startDate"); + // AppLog.log("state.timeLimitEndTime.value:${state.timeLimitEndTime.value} endDate:$endDate"); + } else if (state.selectType.value == '2') { + if (state.cycleBeginTime.value.isEmpty) { + showToast('请选择有效期'.tr); + return; + } + startDate = DateTool().dateToTimestamp(state.cycleBeginTime.value, 1).toString(); + endDate = DateTool().dateToTimestamp(state.cycleEndTime.value, 1).toString(); + startTime = DateTool().dateToTimestamp(state.effectiveDateTime.value, 0).toString(); + endTime = DateTool().dateToTimestamp(state.failureDateTime.value, 0).toString(); + carType = 4; + } + + Get.toNamed(Routers.addRemoteControlPage, arguments: { + 'lockId': state.lockId.value, + 'addType': '1', + 'remoteControlName': state.nameController.text, + 'remoteControlNumber': '123456', + 'remoteControlType': carType.toString(), + 'isCoerced': state.isStressFingerprint.value == false ? '2' : '1', + 'startDate': startDate, + 'weekDay': state.weekdaysList.value, + 'isAdministrator': state.isAdministrator.value == false ? '1' : '2', // 1:不是管理员 2:是管理员 + 'effectiveTime': startTime, + 'failureTime': endTime, + 'selectType': state.selectType.value, + 'endDate': endDate, + }); + } + + // 校验卡名字是否重复 + Future checkRemoteControlNameDuplicatedData(String remoteName) async{ + final LoginEntity entity = await ApiRepository.to.checkRemoteControlNameDuplicatedData( + lockId: state.lockId.value.toString(), + remoteName: remoteName, + ); + if(entity.errorCode!.codeIsSuccessful){ + addRemoteControlData(); + } + } +} \ No newline at end of file diff --git a/lib/main/lockDetail/remoteControl/addRemoteControlType/addRemoteControlType_page.dart b/lib/main/lockDetail/remoteControl/addRemoteControlType/addRemoteControlType_page.dart new file mode 100755 index 00000000..30332b5c --- /dev/null +++ b/lib/main/lockDetail/remoteControl/addRemoteControlType/addRemoteControlType_page.dart @@ -0,0 +1,444 @@ + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.dart'; +import 'package:star_lock/tools/pickers/pickers.dart'; +import 'package:star_lock/tools/pickers/time_picker/model/date_mode.dart'; +import 'package:star_lock/tools/pickers/time_picker/model/pduration.dart'; + +import '../../../../appRouters.dart'; +import '../../../../app_settings/app_colors.dart'; +import '../../../../tools/CustomUnderlineTabIndicator.dart'; +import '../../../../tools/commonDataManage.dart'; +import '../../../../tools/commonItem.dart'; +import '../../../../tools/dateTool.dart'; +import '../../../../tools/storage.dart'; +import '../../../../tools/submitBtn.dart'; +import '../../../../tools/titleAppBar.dart'; +import '../../../../translations/trans_lib.dart'; +import 'addRemoteControlType_logic.dart'; +import 'addRemoteControlType_state.dart'; + +class AddRemoteControlTypePage extends StatefulWidget { + const AddRemoteControlTypePage({Key? key}) : super(key: key); + + @override + State createState() => _AddRemoteControlTypePageState(); +} + +class _AddRemoteControlTypePageState extends State with SingleTickerProviderStateMixin { + final AddRemoteControlTypeLoigc logic = Get.put(AddRemoteControlTypeLoigc()); + final AddRemoteControlTypeState state = Get.find().state; + + @override + void initState() { + super.initState(); + + state.tabController = TabController( + vsync: this, + length: _itemTabs.length, + initialIndex: 0); + state.tabController.addListener(() { + WidgetsBinding.instance.addPostFrameCallback((_) { + state.selectType.value = state.tabController.index.toString(); + }); + + if (state.tabController.animation!.value == state.tabController.index) { + FocusScope.of(context).requestFocus(FocusNode()); + } + }); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: AppColors.mainBackgroundColor, + appBar: TitleAppBar( + barTitle: + '添加遥控', + haveBack: true, + backgroundColor: AppColors.mainColor), + body: Column( + children: [ + _tabBar(), + _pageWidget(), + ], + ), + ); + } + + Widget indexChangeWidget() { + switch (int.parse(state.selectType.value)) { + case 0: + { + // 永久 + return SingleChildScrollView( + child: Column( + children: [ + perpetualKeyWidget( + TranslationLoader.lanKeys!.name!.tr, + TranslationLoader.lanKeys!.pleaseEnter!.tr, + state.nameController), + keyBottomWidget() + ], + ), + ); + } + case 1: + { + // 限时 + return SingleChildScrollView( + child: Column( + children: [ + perpetualKeyWidget( + TranslationLoader.lanKeys!.name!.tr, + TranslationLoader.lanKeys!.pleaseEnter!.tr, + state.nameController), + keyTimeLimitWidget(), + // SizedBox(height: 10.h), + keyBottomWidget() + ], + ), + ); + } + case 2: + { + // 循环 + return SingleChildScrollView( + child: Column( + children: [ + perpetualKeyWidget( + TranslationLoader.lanKeys!.name!.tr, + TranslationLoader.lanKeys!.pleaseEnter!.tr, + state.nameController), + keyCyclicDate(), + SizedBox(height: 10.h), + keyBottomWidget() + ], + ), + ); + } + default: + return Container(); + } + } + + // 密码命名输入框 + Widget perpetualKeyWidget( + String titleStr, String rightTitle, TextEditingController controller) { + return Column( + children: [ + CommonItem( + leftTitel: titleStr, + rightTitle: '', + isHaveRightWidget: true, + rightWidget: getTFWidget(rightTitle)), + Container(height: 10.h), + ], + ); + } + + // 限时顶部选择日期 + Widget keyTimeLimitWidget() { + return Column( + children: [ + Obx(() => CommonItem( + leftTitel: TranslationLoader.lanKeys!.effectiveTime!.tr, + rightTitle: state.timeLimitBeginTime.value, + isHaveLine: true, + isHaveDirection: true, + action: () async { + final PDuration selectDate = PDuration.parse( + DateTime.parse(state.timeLimitBeginTime.value)); + Pickers.showDatePicker(context, + selectDate: selectDate, mode: DateMode.YMDHM, onConfirm: (PDuration p) { + state.timeLimitBeginTime.value = + DateTool().getYMDHNDateString(p, 1); + }); + })), + Obx(() => CommonItem( + leftTitel: TranslationLoader.lanKeys!.failureTime!.tr, + rightTitle: state.timeLimitEndTime.value, + isHaveDirection: true, + action: () { + final PDuration selectDate = + PDuration.parse(DateTime.tryParse(state.timeLimitEndTime.value)); + Pickers.showDatePicker(context, + selectDate: selectDate, mode: DateMode.YMDHM, onConfirm: (PDuration p) { + state.timeLimitEndTime.value = + DateTool().getYMDHNDateString(p, 1); + }); + })), + Container(height: 10.h), + ], + ); + } + + // 循环顶部选择日期 + Widget keyCyclicDate() { + return Column( + children: [ + Obx(() => CommonItem( + leftTitel: TranslationLoader.lanKeys!.periodValidity!.tr, + rightTitle: + '${state.cycleBeginTime.value}\n${state.cycleEndTime.value}', + isHaveDirection: true, + isHaveLine: true, + action: () async { + final result = + await Get.toNamed(Routers.seletKeyCyclicDatePage, arguments: { + 'validityValue': state.weekdaysList.value, + 'starDate': state.cycleBeginTime.value, + 'endDate': state.cycleEndTime.value, + 'starTime': state.effectiveDateTime.value, + 'endTime': state.failureDateTime.value + }); + if (result != null && result.isNotEmpty) { + state.weekdaysList.value = result['validityValue']; + state.cycleBeginTime.value = result['starDate']; + state.cycleEndTime.value = result['endDate']; + state.effectiveDateTime.value = result['starTime']; + state.failureDateTime.value = result['endTime']; + } + })), + Obx(() => Visibility( + visible: state.weekdaysList.isNotEmpty, + child: CommonItem( + leftTitel: '有效日'.tr, + rightTitle: logic.weekDayStr.join(',').toString(), + isHaveDirection: true, + isHaveLine: true, + action: () async { + final result = await Get.toNamed(Routers.seletKeyCyclicDatePage, + arguments: { + 'validityValue': state.weekdaysList.value, + 'starDate': state.cycleBeginTime.value, + 'endDate': state.cycleEndTime.value, + 'starTime': state.effectiveDateTime.value, + 'endTime': state.failureDateTime.value + }); + if (result != null && result.isNotEmpty) { + state.weekdaysList.value = result['validityValue']; + state.cycleBeginTime.value = result['starDate']; + state.cycleEndTime.value = result['endDate']; + state.effectiveDateTime.value = result['starTime']; + state.failureDateTime.value = result['endTime']; + } + }))), + Obx(() => Visibility( + visible: state.effectiveDateTime.value.isNotEmpty, + child: CommonItem( + leftTitel: '有效时间'.tr, + rightTitle: '${state.effectiveDateTime.value}-${state.failureDateTime.value}', + isHaveDirection: true, + action: () async { + final result = await Get.toNamed(Routers.seletKeyCyclicDatePage, + arguments: { + 'validityValue': state.weekdaysList.value, + 'starDate': state.cycleBeginTime.value, + 'endDate': state.cycleEndTime.value, + 'starTime': state.effectiveDateTime.value, + 'endTime': state.failureDateTime.value + }); + if (result != null && result.isNotEmpty) { + state.weekdaysList.value = result['validityValue']; + state.cycleBeginTime.value = result['starDate']; + state.cycleEndTime.value = result['endDate']; + state.effectiveDateTime.value = result['starTime']; + state.failureDateTime.value = result['endTime']; + } + }))), + ], + ); + } + + Widget keyBottomWidget() { + return Column( + children: [ + // Obx(() => Visibility( + // visible: CommonDataManage().currentKeyInfo.isLockOwner == 1, + // child: CommonItem( + // leftTitel: '是否为管理员'.tr, + // rightTitle: '', + // isTipsImg: false, + // isHaveRightWidget: true, + // rightWidget: + // SizedBox(width: 60.w, height: 50.h, child: _isAdmin())))), + // SizedBox(height: 10.h), + // Obx(() => CommonItem( + // leftTitel: TranslationLoader.lanKeys!.stressCard!.tr, + // rightTitle: '', + // isTipsImg: false, + // isHaveRightWidget: true, + // rightWidget: SizedBox( + // width: 60.w, height: 50.h, child: _isStressFingerprint()))), + // Container( + // color: Colors.white, + // padding: EdgeInsets.only(left: 20.w, right: 20.w, bottom: 20.h), + // child: Text( + // "${"当被胁迫要求强行开锁时,使用胁迫卡会触发报警,报警信息会推送给管理员,该功能需要锁联网。".tr}\n${"请不要将胁迫卡用于日常开锁".tr}", + // style: TextStyle( + // fontSize: 22.sp, color: AppColors.darkGrayTextColor), + // )), + SizedBox(height: 30.h), + SubmitBtn( + btnName: TranslationLoader.lanKeys!.next!.tr, + onClick: () async { + final bool? isDemoMode = await Storage.getBool(ifIsDemoModeOrNot); + if (isDemoMode == false) { + if (state.nameController.text.isEmpty) { + logic.showToast('请输入姓名'.tr); + return; + } + + logic.checkRemoteControlNameDuplicatedData(state.nameController.text); + } else { + // Get.toNamed(Routers.selectLockTypePage); + logic.showToast('演示模式'.tr); + } + }), + ], + ); + } + + // 接受者信息输入框 + Widget getTFWidget(String tfStr) { + return Container( + // color: Colors.red, + height: 65.h, + width: 300.w, + padding: EdgeInsets.only(top: 5.h), + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Expanded( + child: TextField( + //输入框一行 + maxLines: 1, + inputFormatters: [ + FilteringTextInputFormatter.deny('\n'), + LengthLimitingTextInputFormatter(50), + ], + style: TextStyle( + fontSize: 22.sp, color: AppColors.darkGrayTextColor), + controller: state.nameController, + autofocus: false, + textAlign: TextAlign.end, + decoration: InputDecoration( + //输入里面输入文字内边距设置 + // contentPadding: const EdgeInsets.only(top: 12.0, bottom: 8.0), + hintText: tfStr, + hintStyle: TextStyle(fontSize: 22.sp), + focusedBorder: const OutlineInputBorder( + borderSide: + BorderSide(width: 0, color: Colors.transparent)), + disabledBorder: const OutlineInputBorder( + borderSide: + BorderSide(width: 0, color: Colors.transparent)), + enabledBorder: const OutlineInputBorder( + borderSide: + BorderSide(width: 0, color: Colors.transparent)), + border: const OutlineInputBorder( + borderSide: + BorderSide(width: 0, color: Colors.transparent)), + contentPadding: const EdgeInsets.symmetric(vertical: 0), + ), + ), + ), + SizedBox( + width: 10.w, + ), + ], + ), + ); + } + + //isStressFingerprint false:不是胁迫指纹 ture:胁迫指纹 + CupertinoSwitch _isStressFingerprint() { + return CupertinoSwitch( + activeColor: CupertinoColors.activeBlue, + trackColor: CupertinoColors.systemGrey5, + thumbColor: CupertinoColors.white, + value: state.isStressFingerprint.value, + onChanged: (bool value) { + state.isStressFingerprint.value = value; + }, + ); + } + + // 是否为管理员 + CupertinoSwitch _isAdmin() { + return CupertinoSwitch( + activeColor: CupertinoColors.activeBlue, + trackColor: CupertinoColors.systemGrey5, + thumbColor: CupertinoColors.white, + value: state.isAdministrator.value, + onChanged: (bool value) { + state.isAdministrator.value = value; + }, + ); + } + + final List _itemTabs = [ + ItemView(title: TranslationLoader.lanKeys!.permanent!.tr, selectType: '0'), + ItemView(title: TranslationLoader.lanKeys!.timeLimit!.tr, selectType: '1'), + ItemView( + title: TranslationLoader.lanKeys!.circulation!.tr, selectType: '2'), + ]; + + + TabBar _tabBar() { + return TabBar( + controller: state.tabController, + onTap: (int index) { + FocusScope.of(context).requestFocus(FocusNode()); + }, + tabs: _itemTabs.map(_tab).toList(), + isScrollable: true, + indicatorColor: Colors.red, + unselectedLabelColor: Colors.black, + unselectedLabelStyle: TextStyle( + color: AppColors.mainColor, + fontSize: 24.sp, + ), + automaticIndicatorColorAdjustment: true, + labelColor: AppColors.mainColor, + labelStyle: TextStyle( + color: AppColors.mainColor, + fontSize: 24.sp, + fontWeight: FontWeight.w600), + indicator: CustomUnderlineTabIndicator( + borderSide: BorderSide(color: AppColors.mainColor, width: 4.w), + strokeCap: StrokeCap.round, + width: 30.w), + ); + } + + Tab _tab(ItemView item) { + return Tab( + child: SizedBox( + width: 1.sw / 5, + child: Text(item.title, textAlign: TextAlign.center))); + } + + Widget _pageWidget() { + return Expanded( + child: TabBarView( + controller: state.tabController, + children: _itemTabs + .map((ItemView item) => Obx(indexChangeWidget)) + .toList(), + ), + ); + } +} + +class ItemView { + const ItemView({required this.title, required this.selectType}); + + final String title; + final String selectType; +} diff --git a/lib/main/lockDetail/remoteControl/addRemoteControlType/addRemoteControlType_state.dart b/lib/main/lockDetail/remoteControl/addRemoteControlType/addRemoteControlType_state.dart new file mode 100755 index 00000000..90cbbf5d --- /dev/null +++ b/lib/main/lockDetail/remoteControl/addRemoteControlType/addRemoteControlType_state.dart @@ -0,0 +1,32 @@ + +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; + +import '../../../../tools/dateTool.dart'; + +class AddRemoteControlTypeState{ + AddRemoteControlTypeState() { + Map map = Get.arguments; + if(map['lockId']!=null){ + lockId.value = map['lockId']; + } + } + + final RxInt lockId = 0.obs; + final RxString selectType = '0'.obs;// 0永久 1显示 2循环 + final RxBool isStressFingerprint = false.obs; + final RxBool isAdministrator = false.obs;// 是否是管理员 + + RxString timeLimitBeginTime = DateTool().dateToYMDHNString(DateTime.now().millisecondsSinceEpoch.toString()).obs;// 限时开始时间 + RxString timeLimitEndTime = DateTool().dateToYMDHNString(DateTime.now().millisecondsSinceEpoch.toString()).obs;// 限时结束时间 + RxString cycleBeginTime = ''.obs;// 循环开始时间 + RxString cycleEndTime = ''.obs;// 循环结束时间 + RxString effectiveDateTime = ''.obs;// 生效时间 + RxString failureDateTime = ''.obs;// 失效时间 + RxList weekdaysList = [].obs; + RxString fromTypeTwoStaffName = ''.obs; // 从添加员工进入 传入员工名字 + + final TextEditingController nameController = TextEditingController(); + late TabController tabController; + +} \ No newline at end of file diff --git a/lib/main/lockDetail/remoteControl/remoteControlDetail/remoteControlDetail_logic.dart b/lib/main/lockDetail/remoteControl/remoteControlDetail/remoteControlDetail_logic.dart new file mode 100644 index 00000000..d40339c5 --- /dev/null +++ b/lib/main/lockDetail/remoteControl/remoteControlDetail/remoteControlDetail_logic.dart @@ -0,0 +1,226 @@ + +import 'dart:async'; + +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; +import 'package:get/get.dart'; +import 'package:star_lock/tools/baseGetXController.dart'; + +import '../../../../blue/blue_manage.dart'; +import '../../../../blue/io_protocol/io_addRemoteControlWithTimeCycleCoercion.dart'; +import '../../../../blue/io_reply.dart'; +import '../../../../blue/io_tool/io_tool.dart'; +import '../../../../blue/io_tool/manager_event_bus.dart'; +import '../../../../blue/sender_manage.dart'; +import '../../../../login/login/entity/LoginEntity.dart'; +import '../../../../network/api_repository.dart'; +import '../../../../tools/dateTool.dart'; +import '../../../../tools/eventBusEventManage.dart'; +import '../../../../tools/pickers/time_picker/time_utils.dart'; +import '../../../../tools/storage.dart'; +import 'remoteControlDetail_state.dart'; + +class RemoteControlDetailLogic extends BaseGetXController { + RemoteControlDetailState state = RemoteControlDetailState(); + + List get weekDayStr { + return state.weekDay.map((e) => TimeUtils.translateWeekday(e)).toList(); + } + + // 监听设备返回的数据 + late StreamSubscription _replySubscription; + + void _initReplySubscription() { + _replySubscription = + EventBusManager().eventBus!.on().listen((Reply reply) async { + // 添加卡片开始(重置锁里面所有卡) + if ((reply is SenderAddRemoteControlWithTimeCycleCoercionReply) && (state.ifCurrentScreen.value == true)) { + _replyAddRemoteControlBegin(reply); + } + }); + } + + // 添加卡片开始(此处用作删除卡片) + Future _replyAddRemoteControlBegin(Reply reply) async { + final int status = reply.data[2]; + + switch (status) { + case 0x00: + //成功 + cancelBlueConnetctToastTimer(); + dismissEasyLoading(); + if (state.isDeletRemoteControl.value == true) { + deletRemoteControlData(); + } else { + editRemoteControlData(); + } + 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.senderAddRemoteControlWithTimeCycleCoercionCommand( + keyID: state.keyId.value.toString(), + userID: await Storage.getUid(), + remoteControlNo: int.parse(state.typeNumber.value), + useCountLimit: 0xffff, + operate: state.isDeletRemoteControl.value ? 2 : 1, + // 0:注册 1:修改 2:删除 3:删除全部 + // isAdmin: state.isAdministrator.value == true ? 1 : 0, + // isForce: state.isStressCard.value == true ? 1 : 0, // 是否是胁迫 + isAdmin: 0, + isForce: 0, // 是否是胁迫 + isRound: state.keyType.value == 4 ? 1 : 0, // 是否是循环 + weekRound: DateTool().accordingTheCycleIntoTheCorrespondingNumber(state.weekDay.value), // 周循环 + startDate: int.parse(state.startDate.value) ~/ 1000, + endDate: int.parse(state.endDate.value) ~/ 1000, + startTime: DateTool().dateToHNString(state.starTime.value), + endTime: DateTool().dateToHNString(state.endTime.value), + needAuthor: 1, + signKey: signKeyDataList, + privateKey: getPrivateKeyList, + token: token, + isBeforeAddUser: false); + break; + default: + //失败 + break; + } + } + + // 添加卡片 + Future senderAddICCard() async { + if (state.sureBtnState.value == 1) { + return; + } + state.sureBtnState.value = 1; + + showEasyLoading(); + showBlueConnetctToastTimer(action: () { + dismissEasyLoading(); + state.sureBtnState.value = 0; + }); + BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected) { + 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? token = await Storage.getStringList(saveBlueToken); + final List getTokenList = changeStringListToIntList(token!); + + IoSenderManage.senderAddRemoteControlWithTimeCycleCoercionCommand( + keyID: state.keyId.value.toString(), + userID: await Storage.getUid(), + remoteControlNo: int.parse(state.typeNumber.value), + useCountLimit: 0xffff, + operate: state.isDeletRemoteControl.value ? 2 : 1, + // 0:注册 1:修改 2:删除 3:删除全部 + // isAdmin: state.isAdministrator.value == true ? 1 : 0, + // isForce: state.isStressCard.value == true ? 1 : 0, // 是否是胁迫 + isAdmin: 0, + isForce: 0, // 是否是胁迫 + isRound: state.keyType.value == 4 ? 1 : 0, // 是否是循环 + weekRound: DateTool().accordingTheCycleIntoTheCorrespondingNumber(state.weekDay.value), // 周循环 + startDate: int.parse(state.startDate.value) ~/ 1000, + endDate: int.parse(state.endDate.value) ~/ 1000, + startTime: DateTool().dateToHNString(state.starTime.value), + endTime: DateTool().dateToHNString(state.endTime.value), + needAuthor: 1, + signKey: signKeyDataList, + privateKey: getPrivateKeyList, + token: getTokenList, + isBeforeAddUser: false); + } else if (deviceConnectionState == + BluetoothConnectionState.disconnected) { + dismissEasyLoading(); + cancelBlueConnetctToastTimer(); + state.sureBtnState.value = 0; + if (state.ifCurrentScreen.value == true) { + showBlueConnetctToast(); + } + } + }); + } + + // 编辑遥控 + Future editRemoteControlData() async { + final LoginEntity entity = await ApiRepository.to.editRemoteControlData( + lockId: state.fingerprintItemData.value.lockId ?? 0, + remoteId: state.keyId.value, + startDate: int.parse(state.startDate.value), + endDate: int.parse(state.endDate.value), + startTime: int.parse(state.starTime.value), + endTime: int.parse(state.endTime.value), + remoteType: state.keyType.value, + weekDay: state.weekDay.value, + remoteName: state.changeNameController.text, + addType: 1, + isCoerced: 2, + remoteRight: 2, + ); + if (entity.errorCode!.codeIsSuccessful) { + state.fingerprintItemData.value.cardName = state.changeNameController.text; + // state.fingerprintItemData.value.isCoerced = state.isStressCard.value ? 1 : 2; + // state.fingerprintItemData.value.cardRight = state.isAdministrator.value ? 1 : 0; + showToast('修改成功'.tr, something: () { + eventBus.fire(OtherTypeRefreshListEvent()); + }); + } + } + + // 删除遥控 + Future deletRemoteControlData() async { + final LoginEntity entity = await ApiRepository.to.deletRemoteControlData( + remoteId: state.fingerprintItemData.value.remoteId ?? 0, + ); + if (entity.errorCode!.codeIsSuccessful) { + showToast('删除成功'.tr, something: () { + Get.back(result: 'addScuess'); + }); + } + } + + String getKeyTypeShowDateTime() { + String useDateStr = ''; + if (state.keyType.value == 1) { + useDateStr = '永久'.tr; + } else if (state.keyType.value == 2) { + useDateStr = + '${DateTool().dateToYMDHNString(state.startDate.value)}\n${DateTool().dateToYMDHNString(state.endDate.value)}'; + } else if (state.keyType.value == 4) { + useDateStr = + '${DateTool().dateToYMDString(state.startDate.value)}\n${DateTool().dateToYMDString(state.endDate.value)}'; + } + return useDateStr; + } + + @override + void onReady() { + super.onReady(); + + _initReplySubscription(); + } + + @override + void onClose() { + super.onClose(); + + _replySubscription.cancel(); + } +} \ No newline at end of file diff --git a/lib/main/lockDetail/remoteControl/remoteControlDetail/remoteControlDetail_page.dart b/lib/main/lockDetail/remoteControl/remoteControlDetail/remoteControlDetail_page.dart index e69de29b..dcc396db 100755 --- a/lib/main/lockDetail/remoteControl/remoteControlDetail/remoteControlDetail_page.dart +++ b/lib/main/lockDetail/remoteControl/remoteControlDetail/remoteControlDetail_page.dart @@ -0,0 +1,354 @@ + +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.dart'; + +import '../../../../appRouters.dart'; +import '../../../../app_settings/app_colors.dart'; +import '../../../../tools/appRouteObserver.dart'; +import '../../../../tools/commonItem.dart'; +import '../../../../tools/dateTool.dart'; +import '../../../../tools/showTipView.dart'; +import '../../../../tools/submitBtn.dart'; +import '../../../../tools/titleAppBar.dart'; +import '../../../../translations/trans_lib.dart'; +import '../../../lockMian/lockMain/lockMain_logic.dart'; +import 'remoteControlDetail_logic.dart'; +import 'remoteControlDetail_state.dart'; + +class RemoteControlDetailPage extends StatefulWidget { + const RemoteControlDetailPage({Key? key}) : super(key: key); + + @override + State createState() => _RemoteControlDetailPageState(); +} + +class _RemoteControlDetailPageState extends State with RouteAware { + final RemoteControlDetailLogic logic = Get.put(RemoteControlDetailLogic()); + final RemoteControlDetailState state = Get.find().state; + + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: AppColors.mainBackgroundColor, + appBar: TitleAppBar( + barTitle: '遥控详情'.tr, + haveBack: true, + backgroundColor: AppColors.mainColor, + ), + body: ListView( + children: [ + Obx(() => CommonItem( + leftTitel: '遥控号', + rightTitle: state.typeNumber.value, + isHaveDirection: false, + isHaveLine: true)), + Obx(() => lockDataListItem( + TranslationLoader.lanKeys!.name!.tr, state.typeName.value, + () { + ShowTipView().showTFViewAlertDialog( + state.changeNameController, + '${TranslationLoader.lanKeys!.amend!.tr}${TranslationLoader.lanKeys!.name!.tr}', + '', () { + if (state.changeNameController.text.isEmpty) { + logic.showToast('请输入姓名'.tr); + return; + } + Get.back(); + state.typeName.value = state.changeNameController.text; + logic.editRemoteControlData(); + }, inputFormatters: [ + FilteringTextInputFormatter.deny('\n'), + LengthLimitingTextInputFormatter(50), + ]); + })), + Obx(() => Visibility( + visible: state.keyType.value == 4 || + state.keyType.value == 2 || + state.keyType.value == 1, + child: CommonItem( + leftTitel: TranslationLoader.lanKeys!.periodValidity!.tr, + allHeight: 70.h, + rightTitle: logic.getKeyTypeShowDateTime(), + isHaveDirection: true, + isHaveLine: true, + action: () async { + if (state.keyType.value == 2 || state.keyType.value == 1) { + // 限时 + var data = await Get.toNamed( + Routers.otherTypeKeyChangeDatePage, + arguments: { + 'pushType': 2, + 'fingerprintItemData': + state.fingerprintItemData.value, + }); + if (data != null) { + setState(() { + state.startDate.value = data['beginTimeTimestamp']; + state.endDate.value = data['endTimeTimestamp']; + state.keyType.value = 2; + }); + } + } else if (state.keyType.value == 4) { + // 循环 + var data = await Get.toNamed( + Routers.otherTypeKeyChangeValidityDatePage, + arguments: { + 'pushType': 2, + 'fingerprintItemData': + state.fingerprintItemData.value, + }); + if (data != null) { + setState(() { + state.startDate.value = data['starDate']; + state.endDate.value = data['endDate']; + state.starTime.value = data['starTime']; + state.endTime.value = data['endTime']; + state.weekDay.value = data['weekDay']; + }); + } + } + }))), + Obx(() => Visibility( + visible: state.keyType.value == 4, + child: Obx(() => CommonItem( + leftTitel: TranslationLoader.lanKeys!.effectiveDay!.tr, + rightTitle: logic.weekDayStr.join(','), + isHaveDirection: true, + isHaveLine: true, + action: () async { + var data = await Get.toNamed( + Routers.otherTypeKeyChangeValidityDatePage, + arguments: { + 'pushType': 0, + 'fingerprintItemData': + state.fingerprintItemData.value, + }); + if (data != null) { + setState(() { + state.startDate.value = data['starDate']; + state.endDate.value = data['endDate']; + state.starTime.value = data['starTime']; + state.endTime.value = data['endTime']; + state.weekDay.value = data['weekDay']; + }); + } + })))), + Obx(() => Visibility( + visible: state.keyType.value == 4, + child: Obx(() => CommonItem( + leftTitel: '有效时间'.tr, + rightTitle: + '${DateTool().dateToHNString(state.starTime.value)}-${DateTool().dateToHNString(state.endTime.value)}', + isHaveDirection: true, + action: () async { + var data = await Get.toNamed( + Routers.otherTypeKeyChangeValidityDatePage, + arguments: { + 'pushType': 0, + 'fingerprintItemData': + state.fingerprintItemData.value, + }); + if (data != null) { + setState(() { + state.startDate.value = data['starDate']; + state.endDate.value = data['endDate']; + state.starTime.value = data['starTime']; + state.endTime.value = data['endTime']; + state.weekDay.value = data['validityValue']; + }); + } + })))), + Container(height: 10.h), + Obx(() => CommonItem( + leftTitel: TranslationLoader.lanKeys!.additive!.tr, + isHaveLine: true, + rightTitle: state.adder.value, + )), + Obx(() => CommonItem( + leftTitel: TranslationLoader.lanKeys!.addTime!.tr, + rightTitle: DateTool() + .dateToYMDHNString(state.addTime.value.toString()), + )), + SizedBox(height: 10.h), + // Obx(() => CommonItem( + // leftTitel: TranslationLoader.lanKeys!.stressCard!.tr, + // rightTitle: '', + // isTipsImg: false, + // isHaveLine: true, + // isHaveRightWidget: true, + // rightWidget: SizedBox( + // width: 60.w, height: 50.h, child: _isStressFingerprint()))), + // Obx(() => CommonItem( + // leftTitel: '是否为管理员'.tr, + // rightTitle: '', + // isTipsImg: false, + // isHaveRightWidget: true, + // rightWidget: + // SizedBox(width: 60.w, height: 50.h, child: _isAdmin()))), + // Container(height: 10.h), + CommonItem( + leftTitel: TranslationLoader.lanKeys!.operatingRecord!.tr, + rightTitle: '', + isHaveDirection: true, + action: () { + Get.toNamed(Routers.lockOperatingRecordPage, + arguments: { + 'type': 2, + 'id': state.fingerprintItemData.value.cardId.toString(), + 'recordName': state.fingerprintItemData.value.cardName + }); + }), + // SizedBox(height: 40.h), + // addControlsBtn(type), + SizedBox(height: 30.h), + SubmitBtn( + btnName: TranslationLoader.lanKeys!.delete!.tr, + isDelete: true, + borderRadius: 20.w, + margin: EdgeInsets.only( + left: 30.w, right: 30.w, top: 30.w, bottom: 30.w), + padding: EdgeInsets.only(top: 25.w, bottom: 25.w), + onClick: () async { + final bool isNetWork = + await LockMainLogic.to()?.judgeTheNetwork() ?? false; + if (!isNetWork) { + return; + } + + ShowTipView().showIosTipWithContentDialog('确定要删除吗?'.tr, + () async { + state.isDeletRemoteControl.value = true; + logic.senderAddICCard(); + }); + }), + ], + ), + ); + } + + Widget lockDataListItem( + String leftTitle, String conentStr, Function()? action) { + return GestureDetector( + onTap: action, + child: Container( + // height: 70.h, + padding: + EdgeInsets.only(left: 20.w, right: 10.w, top: 15.h, bottom: 15.h), + decoration: BoxDecoration( + color: Colors.white, + border: Border( + bottom: BorderSide( + color: AppColors.greyLineColor, // 设置边框颜色 + width: 2.0.h, // 设置边框宽度 + ), + )), + child: Row( + children: [ + Text(leftTitle, style: TextStyle(fontSize: 22.sp)), + SizedBox(width: 10.w), + Expanded( + child: Text(conentStr, + textAlign: TextAlign.end, + style: TextStyle( + fontSize: 22.sp, + ))), + SizedBox(width: 10.w), + Image.asset( + 'images/icon_right_grey.png', + width: 12.w, + height: 21.w, + ) + ], + ), + ), + ); + } + + //isStressFingerprint false:不是胁迫指纹 ture:胁迫指纹 + // CupertinoSwitch _isStressFingerprint() { + // return CupertinoSwitch( + // activeColor: CupertinoColors.activeBlue, + // trackColor: CupertinoColors.systemGrey5, + // thumbColor: CupertinoColors.white, + // value: state.isStressCard.value, + // onChanged: (bool value) { + // setState(() { + // state.isStressCard.value = value; + // state.isDeletCard.value = false; + // logic.senderAddICCard(); + // }); + // }, + // ); + // } + + // 是否为管理员 + // CupertinoSwitch _isAdmin() { + // return CupertinoSwitch( + // activeColor: CupertinoColors.activeBlue, + // trackColor: CupertinoColors.systemGrey5, + // thumbColor: CupertinoColors.white, + // value: state.isAdministrator.value, + // onChanged: (bool value) { + // // state.isAdministrator.value = value; + // // state.isDeletCard.value = false; + // // logic.senderAddICCard(); + // }, + // ); + // } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + + /// 路由订阅 + AppRouteObserver().routeObserver.subscribe(this, ModalRoute.of(context)!); + } + + @override + void dispose() { + /// 取消路由订阅 + AppRouteObserver().routeObserver.unsubscribe(this); + super.dispose(); + } + + /// 从上级界面进入 当前界面即将出现 + @override + void didPush() { + super.didPush(); + state.ifCurrentScreen.value = true; + } + + /// 返回上一个界面 当前界面即将消失 + @override + void didPop() { + super.didPop(); + logic.cancelBlueConnetctToastTimer(); + if (EasyLoading.isShow) { + EasyLoading.dismiss(animation: true); + } + state.ifCurrentScreen.value = false; + state.sureBtnState.value = 0; + } + + /// 从下级返回 当前界面即将出现 + @override + void didPopNext() { + super.didPopNext(); + state.ifCurrentScreen.value = true; + } + + /// 进入下级界面 当前界面即将消失 + @override + void didPushNext() { + super.didPushNext(); + logic.cancelBlueConnetctToastTimer(); + if (EasyLoading.isShow) { + EasyLoading.dismiss(animation: true); + } + state.ifCurrentScreen.value = false; + state.sureBtnState.value = 0; + } +} diff --git a/lib/main/lockDetail/remoteControl/remoteControlDetail/remoteControlDetail_state.dart b/lib/main/lockDetail/remoteControl/remoteControlDetail/remoteControlDetail_state.dart new file mode 100644 index 00000000..78b5fa73 --- /dev/null +++ b/lib/main/lockDetail/remoteControl/remoteControlDetail/remoteControlDetail_state.dart @@ -0,0 +1,49 @@ + +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; + +import '../../fingerprint/fingerprintList/fingerprintListData_entity.dart'; + +class RemoteControlDetailState{ + RemoteControlDetailState() { + Map map = Get.arguments; + if (map['fingerprintItemData'] != null) { + fingerprintItemData.value = map['fingerprintItemData']; + keyId.value = fingerprintItemData.value.remoteId!; + typeNumber.value = fingerprintItemData.value.remoteNumber!; + typeName.value = fingerprintItemData.value.remoteName!; + changeNameController.text = typeName.value; + startDate.value = fingerprintItemData.value.startDate!.toString(); + endDate.value = fingerprintItemData.value.endDate!.toString(); + starTime.value = fingerprintItemData.value.startDate!.toString(); + endTime.value = fingerprintItemData.value.endDate!.toString(); + keyType.value = fingerprintItemData.value.remoteType!; + adder.value = fingerprintItemData.value.senderUsername!; + addTime.value = fingerprintItemData.value.createDate!; + // isStressCard.value = fingerprintItemData.value.isCoerced! == 1; + weekDay.value = fingerprintItemData.value.weekDay!; + // isAdministrator.value = fingerprintItemData.value.remoteRight! == 1; + } + } + final Rx fingerprintItemData = FingerprintItemData().obs; + + final TextEditingController changeNameController = TextEditingController(); + + RxBool ifCurrentScreen = true.obs; // 是否是当前界面,用于判断是否需要针对当前界面进行展示 + RxInt sureBtnState = 0.obs; // 0普通状态(可用) 1连接中(不可用) + RxBool isDeletRemoteControl = true.obs; // 是否删除卡 + // RxBool isStressCard = false.obs; // 是否胁迫 + // RxBool isAdministrator = false.obs; // 是否为管理员 + + final RxString typeNumber = ''.obs; // 指纹号 + final RxString typeName = ''.obs; // 指纹名字 + RxString startDate = ''.obs; // 开始时间 + RxString endDate = ''.obs; // 结束时间 + RxString starTime = ''.obs; // 生效时间 + RxString endTime = ''.obs; // 失效时间 + final RxInt keyType = 0.obs; // 永久:1;限时2,单次3,循环:4 + RxList weekDay = [].obs; // 有效日 + RxString adder = ''.obs; // 添加者 + RxInt addTime = 0.obs; // 添加时间 + RxInt keyId = 0.obs; // 卡id +} \ No newline at end of file diff --git a/lib/main/lockDetail/remoteControl/remoteControlList/remoteControlList_logic.dart b/lib/main/lockDetail/remoteControl/remoteControlList/remoteControlList_logic.dart index ecb67297..e531054f 100755 --- a/lib/main/lockDetail/remoteControl/remoteControlList/remoteControlList_logic.dart +++ b/lib/main/lockDetail/remoteControl/remoteControlList/remoteControlList_logic.dart @@ -1,20 +1,253 @@ +import 'dart:async'; +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; +import 'package:get/get.dart'; import 'package:star_lock/tools/baseGetXController.dart'; +import '../../../../blue/blue_manage.dart'; +import '../../../../blue/io_protocol/io_addRemoteControlWithTimeCycleCoercion.dart'; +import '../../../../blue/io_reply.dart'; +import '../../../../blue/io_tool/io_tool.dart'; +import '../../../../blue/io_tool/manager_event_bus.dart'; +import '../../../../blue/sender_manage.dart'; +import '../../../../login/login/entity/LoginEntity.dart'; +import '../../../../network/api_repository.dart'; +import '../../../../tools/dateTool.dart'; +import '../../../../tools/eventBusEventManage.dart'; +import '../../../../tools/storage.dart'; +import '../../fingerprint/fingerprintList/fingerprintListData_entity.dart'; import 'remoteControlList_state.dart'; class RemoteControlListLogic extends BaseGetXController{ RemoteControlListState state = RemoteControlListState(); + // 获取解析后的数据 + late StreamSubscription _replySubscription; + void _initReplySubscription() { + _replySubscription = + EventBusManager().eventBus!.on().listen((Reply reply) { + // 添加卡片开始(重置锁里面所有卡) + if ((reply is SenderAddRemoteControlWithTimeCycleCoercionReply) && (state.ifCurrentScreen.value == true)) { + _replyAddRemoteControlBegin(reply); + } + }); + } + + // 添加卡片开始(此处用作删除卡片) + Future _replyAddRemoteControlBegin(Reply reply) async { + final int status = reply.data[2]; + + switch (status) { + case 0x00: + //成功 + cancelBlueConnetctToastTimer(); + if(state.isDeletAll == true){ + resetRemoteControlData(); + }else{ + deletRemoteControlData(); + } + 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.senderAddRemoteControlWithTimeCycleCoercionCommand( + keyID: state.deletKeyID, + userID: (await Storage.getUid())!, + remoteControlNo: state.deletRemoteControlNo, + useCountLimit: 0xffff, + operate: state.isDeletAll == true ? 3 : 2, // 0:注册 1:修改 2:删除 3:删除全部 + isAdmin: 0, + isForce: 0, // 是否是胁迫 + isRound: 0, // 是否是循环 + weekRound: 0, // 周循环 + startDate: 0x11223344, + endDate: 0x11223344, + startTime: '0', + endTime: '0', + needAuthor: 1, + signKey: signKeyDataList, + privateKey: getPrivateKeyList, + token: token, + isBeforeAddUser: false); + break; + default: + //失败 + break; + } + } + + // 删除卡片 + Future senderAddRemoteControl() async { + showEasyLoading(); + showBlueConnetctToastTimer(action: () { + dismissEasyLoading(); + }); + BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected) { + 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? token = await Storage.getStringList(saveBlueToken); + final List getTokenList = changeStringListToIntList(token!); + + IoSenderManage.senderAddRemoteControlWithTimeCycleCoercionCommand( + keyID: state.deletKeyID, + userID: (await Storage.getUid())!, + remoteControlNo: state.deletRemoteControlNo, + useCountLimit: 0xffff, + operate: state.isDeletAll == true ? 3 : 2, // 0:注册 1:修改 2:删除 3:删除全部 + isAdmin: 0, + isForce: 0, // 是否是胁迫 + isRound: 0, // 是否是循环 + weekRound: 0, // 周循环 + startDate: 0x11223344, + endDate: 0x11223344, + startTime: '0', + endTime: '0', + needAuthor: 1, + signKey: signKeyDataList, + privateKey: getPrivateKeyList, + token: getTokenList, + isBeforeAddUser: false); + } else if (deviceConnectionState == + BluetoothConnectionState.disconnected) { + dismissEasyLoading(); + cancelBlueConnetctToastTimer(); + if (state.ifCurrentScreen.value == true) { + showBlueConnetctToast(); + } + } + }); + } + + // 获取IC卡列表 + Future getRemoteControlListData( + {required bool isRefresh}) async { + // 如果是下拉刷新,清空已有数据 + if (isRefresh) { + state.fingerprintItemListData.clear(); + pageNo = 1; + } + final FingerprintListDataEntity entity = await ApiRepository.to.getRemoteControlListData( + lockId: state.lockId.value.toString(), + pageNo: pageNo.toString(), + pageSize: pageSize, + searchStr: state.searchController.text, + ); + if (entity.errorCode!.codeIsSuccessful) { + // 更新数据列表 + state.fingerprintItemListData.addAll(entity.data!.list!); + // 更新页码 + pageNo++; + } + return entity; + } + + // 删除所有IC卡 + Future resetRemoteControlData() async { + final LoginEntity entity = await ApiRepository.to.resetRemoteControlData( + lockId: state.lockId.value + ); + if (entity.errorCode!.codeIsSuccessful) { + showToast('重置成功'.tr, something: () { + getRemoteControlListData(isRefresh: true); + }); + } + } + + // 删除遥控 + Future deletRemoteControlData() async { + final LoginEntity entity = await ApiRepository.to.deletRemoteControlData( + remoteId: int.parse(state.deletKeyID), + ); + if (entity.errorCode!.codeIsSuccessful) { + showToast('删除成功'.tr, something: () { + Get.back(result: 'addScuess'); + }); + } + } + + // 监听修改完详情之后刷新列表 + late StreamSubscription _teamEvent; + void _initRefreshAction() { + _teamEvent = eventBus.on().listen((OtherTypeRefreshListEvent event) { + getRemoteControlListData(isRefresh: true); + }); + } + + String getKeyType(FingerprintItemData fingerprintItemData) { + String keyTypeStr = ''; // + if (fingerprintItemData.remoteStatus == 1) { + if (fingerprintItemData.startDate! > + DateTime.now().millisecondsSinceEpoch) { + keyTypeStr = '未生效'.tr; + } + } else if (fingerprintItemData.remoteStatus == 2) { + keyTypeStr = '已失效'.tr; + } + return keyTypeStr; + } + + String getKeyDateType(FingerprintItemData fingerprintItemData) { + String keyDateTypeStr = ''; // 永久:1;限时2,单次3,循环:4 + if (fingerprintItemData.remoteType! == 1) { + keyDateTypeStr = + '${DateTool().dateToYMDHNString((fingerprintItemData.createDate ?? 0).toString())} 永久'; + } else if (fingerprintItemData.remoteType! == 2) { + keyDateTypeStr = + '${DateTool().dateToYMDHNString(fingerprintItemData.startDate.toString())} - ${DateTool().dateToYMDHNString(fingerprintItemData.endDate.toString())} 限时'; + } else if (fingerprintItemData.remoteType! == 4) { + keyDateTypeStr = + '${DateTool().dateToYMDString(fingerprintItemData.startDate.toString())}-${DateTool().dateToYMDString(fingerprintItemData.endDate.toString())} 循环'; + } + return keyDateTypeStr; + } + @override - void onInit() { + Future onReady() async { + super.onReady(); + + // 获取是否是演示模式 演示模式不获取接口 + final bool? isDemoMode = await Storage.getBool(ifIsDemoModeOrNot); + if (isDemoMode == false) { + _initReplySubscription(); + + _initRefreshAction(); + } + } + + @override + Future onInit() async { super.onInit(); } @override - void onClose() { + Future onClose() async { super.onClose(); - } + final bool? isDemoMode = await Storage.getBool(ifIsDemoModeOrNot); + if (isDemoMode == false) { + _replySubscription.cancel(); + _teamEvent.cancel(); + } + } } \ No newline at end of file diff --git a/lib/main/lockDetail/remoteControl/remoteControlList/remoteControlList_page.dart b/lib/main/lockDetail/remoteControl/remoteControlList/remoteControlList_page.dart index 6ab01f50..15991d6a 100755 --- a/lib/main/lockDetail/remoteControl/remoteControlList/remoteControlList_page.dart +++ b/lib/main/lockDetail/remoteControl/remoteControlList/remoteControlList_page.dart @@ -1,21 +1,25 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:flutter_slidable/flutter_slidable.dart'; import 'package:get/get.dart'; import 'package:star_lock/main/lockMian/lockMain/lockMain_logic.dart'; import '../../../../appRouters.dart'; import '../../../../app_settings/app_colors.dart'; -import '../../../../tools/commonDataManage.dart'; +import '../../../../tools/EasyRefreshTool.dart'; +import '../../../../tools/appRouteObserver.dart'; import '../../../../tools/keySearchWidget.dart'; import '../../../../tools/noData.dart'; -import '../../../../tools/showIosTipView.dart'; +import '../../../../tools/showTipView.dart'; import '../../../../tools/storage.dart'; import '../../../../tools/submitBtn.dart'; import '../../../../tools/titleAppBar.dart'; import '../../../../translations/trans_lib.dart'; +import '../../fingerprint/fingerprintList/fingerprintListData_entity.dart'; import 'remoteControlList_logic.dart'; +import 'remoteControlList_state.dart'; class RemoteControlListPage extends StatefulWidget { const RemoteControlListPage({Key? key}) : super(key: key); @@ -24,185 +28,238 @@ class RemoteControlListPage extends StatefulWidget { State createState() => _RemoteControlListPageState(); } -class _RemoteControlListPageState extends State { - final logic = Get.put(RemoteControlListLogic()); - final state = Get.find().state; +class _RemoteControlListPageState extends State with RouteAware { + final RemoteControlListLogic logic = Get.put(RemoteControlListLogic()); + final RemoteControlListState state = Get.find().state; + + Future getHttpData({required bool isRefresh}) async { + final bool? isDemoMode = await Storage.getBool(ifIsDemoModeOrNot); + if (isDemoMode == false) { + logic.getRemoteControlListData(isRefresh: isRefresh).then((FingerprintListDataEntity value) { + if (mounted) { + setState(() {}); + } + }); + } + } + + @override + void initState() { + super.initState(); + + getHttpData(isRefresh: true); + } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: AppColors.mainBackgroundColor, + resizeToAvoidBottomInset: false, appBar: TitleAppBar( - barTitle: TranslationLoader.lanKeys!.remoteControl!.tr, + barTitle: '遥控', haveBack: true, backgroundColor: AppColors.mainColor, - actionsList: [ + actionsList: [ TextButton( child: Text( TranslationLoader.lanKeys!.reset!.tr, style: TextStyle(color: Colors.white, fontSize: 24.sp), ), onPressed: () async { - var isDemoMode = await Storage.getBool(ifIsDemoModeOrNot); + final bool? isDemoMode = await Storage.getBool(ifIsDemoModeOrNot); if (isDemoMode == false) { final bool isNetWork = await LockMainLogic.to()?.judgeTheNetwork() ?? false; if (!isNetWork) { return; } - showDeletAlertDialog(context); + + ShowTipView().showIosTipWithContentDialog( + '重置后,该锁的遥控都将被删除哦,确认要重置吗?'.tr, () async { + state.isDeletAll = true; + state.deletKeyID = '0'; + state.deletRemoteControlNo = 0; + logic.senderAddRemoteControl(); + }); + // showDeletAlertDialog(context); } else { - // Get.toNamed(Routers.selectLockTypePage); - logic.showToast("演示模式"); + logic.showToast('演示模式'.tr); } }, ), ], ), - body: Column( - children: [ - KeySearchWidget( - editingController: state.searchController, - onSubmittedAction: () { - - }, - ), - SizedBox( - height: 20.h, - ), - Expanded(child: _buildMainUI()), - AddBottomWhiteBtn( - btnName: - '${TranslationLoader.lanKeys!.add!.tr}${TranslationLoader.lanKeys!.remoteControl!.tr}', - onClick: () async { - var data = - await Get.toNamed(Routers.addRemoteControlPage, arguments: { - "lockId": CommonDataManage().currentLockSetInfoData.lockId, - "fromType": 1 // 1从添加钥匙列表进入 2从考勤添加员工入口进入 - }); - if (data != null) { - // 遥控添加 - - } - }, - ), - SizedBox( - height: 64.h, - ) - ], - ), - ); - } - - // String getAppBarTitle(int type) { - // String title = ""; - // switch (type) { - // case 0: - // title = TranslationLoader.lanKeys!.card!.tr; - // break; - // case 1: - // title = TranslationLoader.lanKeys!.fingerprint!.tr; - // break; - // case 2: - // title = TranslationLoader.lanKeys!.remoteControl!.tr; - // break; - // case 3: - // title = TranslationLoader.lanKeys!.face!.tr; - // break; - // default: - // break; - // } - // return title; - // } - - Widget _buildMainUI() { - String typeImgName = 'images/icon_card.png'; - - return NoData(noDataHeight: 1.sh - ScreenUtil().statusBarHeight - ScreenUtil().bottomBarHeight - 190.h - 64.h); - } - - Widget _buildDeleteBtn(String idStr) { - return GestureDetector( - onTap: () { - // 省略: 弹出是否删除的确认对话框。 - showIosTipViewDialog(context, idStr); - }, - child: Container( - width: 60, - color: const Color(0xFFF20101), - alignment: Alignment.center, - child: const Text( - '删除', - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w500, - color: Colors.white, - height: 1, - ), + body: EasyRefreshTool( + onRefresh: () { + getHttpData(isRefresh: true); + }, + onLoad: () { + getHttpData(isRefresh: false); + }, + child: Column( + children: [ + KeySearchWidget( + editingController: state.searchController, + onSubmittedAction: () { + getHttpData(isRefresh: true); + }, + ), + SizedBox(height: 20.h), + Expanded(child: _buildMainUI()), + AddBottomWhiteBtn( + btnName: + '添加遥控', + onClick: () async { + final data = await Get.toNamed(Routers.addRemoteControlTypePage, + arguments: { + 'lockId': state.lockId.value, + 'fromType': 1 // 1从添加钥匙列表进入 2从考勤添加员工入口进入 + }); + if (data != null) { + getHttpData(isRefresh: true); + } + }, + ), + SizedBox( + height: 64.h, + ) + ], ), ), ); } - void showIosTipViewDialog(BuildContext context, String keyId) { - showDialog( - context: context, - builder: (BuildContext context) { - return ShowIosTipView( - title: "提示", - tipTitle: "确定要删除吗?", - sureClick: () async { - // 遥控删除 + Widget _buildMainUI() { + return Obx(() => state.fingerprintItemListData.value.isNotEmpty + ? SlidableAutoCloseBehavior( + child: ListView.separated( + itemCount: state.fingerprintItemListData.value.length, + itemBuilder: (BuildContext c, int index) { + final FingerprintItemData fingerprintItemData = + state.fingerprintItemListData.value[index]; + return Slidable( + key: ValueKey(fingerprintItemData.fingerprintId), + endActionPane: ActionPane( + extentRatio: 0.2, + motion: const ScrollMotion(), + children: [ + SlidableAction( + onPressed: (BuildContext context) async { + final bool isNetWork = + await LockMainLogic.to()?.judgeTheNetwork() ?? + false; + if (!isNetWork) { + return; + } - }, - cancelClick: () { - Get.back(); - }, - ); - }, - ); + ShowTipView().showIosTipWithContentDialog( + '确定要删除吗?'.tr, () async { + state.isDeletAll = false; + state.deletKeyID = fingerprintItemData.remoteId.toString(); + state.deletRemoteControlNo = int.parse(fingerprintItemData.remoteNumber!); + logic.senderAddRemoteControl(); + }); + }, + backgroundColor: Colors.red, + foregroundColor: Colors.white, + label: '删除'.tr, + padding: EdgeInsets.only(left: 5.w, right: 5.w), + ), + ], + ), + child: _keyItem( + 'images/icon_remoteControl.png', + fingerprintItemData.remoteName!, + logic.getKeyType(fingerprintItemData), + logic.getKeyDateType(fingerprintItemData), () async { + final data = await Get.toNamed(Routers.remoteControlDetailPage, + arguments: { + 'fingerprintItemData': fingerprintItemData, + }); + if (data != null) { + getHttpData(isRefresh: true); + } + }), + ); + }, + separatorBuilder: (BuildContext context, int index) { + return const Divider( + height: 1, + color: AppColors.greyLineColor, + ); + }, + ), + ) + : NoData( + noDataHeight: 1.sh - + ScreenUtil().statusBarHeight - + ScreenUtil().bottomBarHeight - + 190.h - + 64.h)); } - Widget _keyItem(String lockTypeIcon, String lockTypeTitle, String showTime, - Function() action) { + Widget _keyItem(String lockTypeIcon, String lockTypeTitle, + String ifInvalidation, String showTime, Function() action) { return GestureDetector( onTap: action, child: Container( height: 90.h, // margin: EdgeInsets.only(left: 20.w, right: 20.w, top: 20.w), color: Colors.white, - // decoration: BoxDecoration( - // color: Colors.white, - // // borderRadius: BorderRadius.circular(10.w), - // ), child: Row( - children: [ + children: [ SizedBox(width: 30.w), - Image.asset(lockTypeIcon, width: 60.w, height: 60.w), + Container( + width: 60.w, + height: 60.w, + padding: EdgeInsets.all(20.w), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(30.w), + color: AppColors.mainColor, + ), + child: Image.asset(lockTypeIcon, ) + ), SizedBox(width: 20.w), Expanded( child: Column( mainAxisAlignment: MainAxisAlignment.center, - children: [ + children: [ Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Text(lockTypeTitle, - style: TextStyle( - fontSize: 24.sp, color: AppColors.blackColor)), + // mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + SizedBox( + width: 1.sw - 110.w - 100.w, + child: Row( + children: [ + Flexible( + child: Text(lockTypeTitle, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 24.sp, + color: AppColors.blackColor)), + ), + ], + ), + ), + Text(ifInvalidation, + style: TextStyle(fontSize: 22.sp, color: Colors.red)), + SizedBox(width: 10.w), ], ), SizedBox(height: 5.h), - Container( - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Text(showTime, + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Flexible( + child: Text(showTime, + maxLines: 1, + overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 18.sp, color: AppColors.placeholderTextColor)), - ], - ), + ), + ], ), SizedBox(width: 20.h), ], @@ -215,32 +272,54 @@ class _RemoteControlListPageState extends State { ); } - void showDeletAlertDialog( - BuildContext context, - ) { - showCupertinoDialog( - context: context, - builder: (context) { - return CupertinoAlertDialog( - title: const Text("提示"), - content: const Text('重置后遥控信息都会清除哦,确认要重置吗?'), - actions: [ - CupertinoDialogAction( - child: Text(TranslationLoader.lanKeys!.cancel!.tr), - onPressed: () { - Navigator.pop(context); - }, - ), - CupertinoDialogAction( - child: Text(TranslationLoader.lanKeys!.sure!.tr), - onPressed: () { - // 遥控重置 + @override + void didChangeDependencies() { + super.didChangeDependencies(); - }, - ), - ], - ); - }, - ); + /// 路由订阅 + AppRouteObserver().routeObserver.subscribe(this, ModalRoute.of(context)!); + } + + @override + void dispose() { + /// 取消路由订阅 + AppRouteObserver().routeObserver.unsubscribe(this); + super.dispose(); + } + + /// 从上级界面进入 当前界面即将出现 + @override + void didPush() { + super.didPush(); + state.ifCurrentScreen.value = true; + } + + /// 返回上一个界面 当前界面即将消失 + @override + void didPop() { + super.didPop(); + logic.cancelBlueConnetctToastTimer(); + if (EasyLoading.isShow) { + EasyLoading.dismiss(animation: true); + } + state.ifCurrentScreen.value = false; + } + + /// 从下级返回 当前界面即将出现 + @override + void didPopNext() { + super.didPopNext(); + state.ifCurrentScreen.value = true; + } + + /// 进入下级界面 当前界面即将消失 + @override + void didPushNext() { + super.didPushNext(); + logic.cancelBlueConnetctToastTimer(); + if (EasyLoading.isShow) { + EasyLoading.dismiss(animation: true); + } + state.ifCurrentScreen.value = false; } } diff --git a/lib/main/lockDetail/remoteControl/remoteControlList/remoteControlList_state.dart b/lib/main/lockDetail/remoteControl/remoteControlList/remoteControlList_state.dart index 42112431..8806bc0f 100755 --- a/lib/main/lockDetail/remoteControl/remoteControlList/remoteControlList_state.dart +++ b/lib/main/lockDetail/remoteControl/remoteControlList/remoteControlList_state.dart @@ -1,7 +1,24 @@ import 'package:flutter/material.dart'; +import 'package:get/get.dart'; + +import '../../fingerprint/fingerprintList/fingerprintListData_entity.dart'; class RemoteControlListState{ + RemoteControlListState() { + Map map = Get.arguments; + lockId.value = map['lockId']; + } + final RxInt lockId = 0.obs; + + // 因为删除跟添加指纹用的同一个协议 所以这里用做判断 + bool isDeletAll = false; + String deletKeyID = '0'; + int deletRemoteControlNo = 0; + + final RxList fingerprintItemListData = [].obs; final TextEditingController searchController = TextEditingController(); + RxBool ifCurrentScreen = true.obs;// 是否是当前界面,用于判断是否需要针对当前界面进行展示 + } \ No newline at end of file diff --git a/lib/main/lockMian/lockList/lockList_logic.dart b/lib/main/lockMian/lockList/lockList_logic.dart index 57247151..0ce3d0d1 100755 --- a/lib/main/lockMian/lockList/lockList_logic.dart +++ b/lib/main/lockMian/lockList/lockList_logic.dart @@ -5,6 +5,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; +import 'package:star_lock/app_settings/app_settings.dart'; import 'package:star_lock/tools/baseGetXController.dart'; import '../../../blue/blue_manage.dart'; @@ -31,6 +32,7 @@ class LockListLogic extends BaseGetXController { LockListInfoGroupEntity? entity; List get groupDataList { + final List list = _groupDataList.map((GroupList e) => e.copy()).toList(); if (state.searchStr.value != '' && state.showSearch.value) { @@ -39,6 +41,7 @@ class LockListLogic extends BaseGetXController { !(element.lockAlias?.contains(state.searchStr.value) ?? true)); }); } + AppLog.log('lockList!.length:${_groupDataList[0].lockList!.length}'); return list; } @@ -49,6 +52,7 @@ class LockListLogic extends BaseGetXController { _groupDataList = []; } _groupDataList.addAll(entity.groupList!); + AppLog.log('_groupDataList[0].lockList!.length:${_groupDataList[0].lockList!.length}'); update(); } @@ -315,6 +319,7 @@ class LockListLogic extends BaseGetXController { @override void onInit() { super.onInit(); + AppLog.log('onInit调用了 setLockListInfoGroupEntity'); setLockListInfoGroupEntity(entity!); } diff --git a/lib/main/lockMian/lockList/lockList_xhj_page.dart b/lib/main/lockMian/lockList/lockList_xhj_page.dart index 47d6fce9..d9a24696 100755 --- a/lib/main/lockMian/lockList/lockList_xhj_page.dart +++ b/lib/main/lockMian/lockList/lockList_xhj_page.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_slidable/flutter_slidable.dart'; import 'package:get/get.dart'; +import 'package:star_lock/app_settings/app_settings.dart'; import 'package:star_lock/main/lockMian/lockList/lockList_state.dart'; import '../../../appRouters.dart'; @@ -125,8 +126,9 @@ class _LockListXHJPageState extends State with RouteAware { ), Expanded( child: Obx(() { + AppLog.log('logic.groupDataList[0].lockList!.length:${logic.groupDataList[0].lockList!.length}'); return ListView.builder( - itemCount: logic.groupDataList.length, + itemCount: logic.groupDataList.length ?? 0, itemBuilder: (BuildContext context, int index) { final GroupList itemData = logic.groupDataList[index]; return _buildLockExpandedList(context, index, itemData); @@ -143,10 +145,9 @@ class _LockListXHJPageState extends State with RouteAware { } //设备多层级列表 - Widget _buildLockExpandedList( - BuildContext context, int index, GroupList itemData) { - final List lockItemList = - itemData.lockList ?? []; + Widget _buildLockExpandedList(BuildContext context, int index, GroupList itemData) { + final List lockItemList = itemData.lockList ?? []; + AppLog.log('lockItemList[0].lockAlias:${lockItemList[0].lockAlias}'); final List list = forItems(lockItemList); return LockListGroupView( onTap: () { diff --git a/lib/main/lockMian/lockMain/lockMain_logic.dart b/lib/main/lockMian/lockMain/lockMain_logic.dart index 32852a77..3add80b7 100755 --- a/lib/main/lockMian/lockMain/lockMain_logic.dart +++ b/lib/main/lockMian/lockMain/lockMain_logic.dart @@ -36,6 +36,7 @@ class LockMainLogic extends BaseGetXController { isUnShowLoading: isUnShowLoading, ); if (entity.errorCode!.codeIsSuccessful) { + AppLog.log('请求列表调用 loadMainDataLogic'); await loadMainDataLogic(entity.data!); } return entity; @@ -58,15 +59,18 @@ class LockMainLogic extends BaseGetXController { state.dataLength.value = 2; } state.lockListInfoGroupEntity.value = entity; + AppLog.log('entity:$entity state.lockListInfoGroupEntity.value.groupList!.length:${state.lockListInfoGroupEntity.value.groupList![0].lockList!.length}'); //检测控制器是否存在 if (Get.isRegistered()) { //设置控制器数据并刷新 + AppLog.log('检测控制器是否存 调用了 setLockListInfoGroupEntity'); Get.find().setLockListInfoGroupEntity(entity); } else { //延迟加载 Future.delayed(200.milliseconds, () { if (Get.isRegistered()) { //设置控制器数据并刷新 + AppLog.log('检测控制器是否存 延迟调用了 setLockListInfoGroupEntity'); Get.find().setLockListInfoGroupEntity(entity); } }); @@ -157,6 +161,7 @@ class LockMainLogic extends BaseGetXController { //刷新锁设备 Future flushedStarLockInfo(int keyId, int lockId) async { + AppLog.log('刷新锁设备: keyId:$keyId lockId:$lockId'); final LockListInfoEntity entity = await ApiRepository.to.getStarLockInfo( keyId: keyId, ); @@ -201,6 +206,7 @@ class LockMainLogic extends BaseGetXController { state.lockListInfoGroupEntity.value.groupList!.insert(0, list); } state.lockListInfoGroupEntity.refresh(); + AppLog.log('刷新调用 loadMainDataLogic'); loadMainDataLogic(state.lockListInfoGroupEntity.value); } update(); @@ -214,6 +220,7 @@ class LockMainLogic extends BaseGetXController { ?.removeWhere((LockListInfoItemEntity lock) => lock.keyId == keyId); }); state.lockListInfoGroupEntity.refresh(); + AppLog.log('删除调用 loadMainDataLogic'); loadMainDataLogic(state.lockListInfoGroupEntity.value); if (Get.isRegistered()) { final bool isKey = diff --git a/lib/mine/message/messageList/messageList_xhj_page.dart b/lib/mine/message/messageList/messageList_xhj_page.dart index ecd5d31f..ace80c85 100755 --- a/lib/mine/message/messageList/messageList_xhj_page.dart +++ b/lib/mine/message/messageList/messageList_xhj_page.dart @@ -31,7 +31,9 @@ class _MessageListXHJPageState extends State void getHttpData() { logic.messageListDataRequest().then((MessageListEntity value) { - setState(() {}); + if (mounted) { + setState(() {}); + } }); } diff --git a/lib/network/api.dart b/lib/network/api.dart index 65b57f2c..53c9e081 100755 --- a/lib/network/api.dart +++ b/lib/network/api.dart @@ -129,6 +129,15 @@ abstract class Api { final String checkCardNameURL = '/identityCard/checkIdentityCardName'; // 校验卡名字是否存在 + final String getRemoteControlListURL = '/remote/list'; // 遥控列表 + final String addRemoteControlURL = '/remote/add'; // 添加遥控 + final String updateRemoteUserNoURL = '/remote/updateRemoteUserNo'; // 更新遥控用户序号 + final String editRemoteControlURL = '/remote/update'; // 编辑遥控 + final String deleteRemoteControlURL = '/remote/delete'; // 删除遥控 + final String clearRemoteControlURL = '/remote/clear'; // 清空遥控 + final String checkRemoteControlNameURL = + '/remote/checkRemoteName'; // 校验遥控名字是否存在 + final String transferLockListURL = '/room/listForTransfer'; // 转移锁锁列表 final String transferLockConfirmURL = '/room/transferLockConfirm'; // 转移智能锁确认 final String transferLockURL = '/room/transfer'; // 转移智能锁 diff --git a/lib/network/api_provider.dart b/lib/network/api_provider.dart index d576225e..c0df687b 100755 --- a/lib/network/api_provider.dart +++ b/lib/network/api_provider.dart @@ -1462,9 +1462,119 @@ class ApiProvider extends BaseProvider { post(checkCardNameURL.toUrl, jsonEncode({'lockId': lockId, 'cardName': cardName})); + // 获取遥控列表 + Future getRemoteControlListData( + String lockId, String pageNo, String pageSize, String searchStr) => + post( + getRemoteControlListURL.toUrl, + jsonEncode({ + 'lockId': lockId, + 'pageNo': pageNo, + 'pageSize': pageSize, + 'searchStr': searchStr, + })); + + // 添加遥控 + Future addRemoteControlData( + String lockId, + String remoteName, + String remoteNumber, + int remoteType, + int startDate, + int endDate, + int addType, + List weekDay, + int startTime, + int endTime, + int remoteRight, + // String mac, + // int electricQuantity, + // List firmwareInfo + ) => + post( + addRemoteControlURL.toUrl, + jsonEncode({ + 'lockId': lockId, + 'remoteName': remoteName, + 'remoteNumber': remoteNumber, + 'remoteType': remoteType, + 'startDate': startDate, + 'endDate': endDate, + 'addType': addType, + 'weekDay': weekDay, + 'startTime': startTime, + 'endTime': endTime, + 'remoteRight': remoteRight, + // 'mac': '', + // 'electricQuantity': electricQuantity, + // 'firmwareInfo': firmwareInfo, + })); + + // 更新遥控序号 + Future updateRemoteUserNoLoadData( + int lockId, int remoteId, String remoteUserNo) => + post( + updateRemoteUserNoURL.toUrl, + jsonEncode( + {'lockId': lockId, 'remoteId': remoteId, 'remoteUserNo': remoteUserNo})); + + // 编辑遥控 + Future editRemoteControlData( + int lockId, + int remoteId, + int startDate, + int endDate, + int startTime, + int endTime, + int remoteType, + List weekDay, + String remoteName, + int addType, + int isCoerced, + int remoteRight, + ) => + post( + editRemoteControlURL.toUrl, + jsonEncode({ + 'lockId': lockId, + 'remoteId': remoteId, + 'startDate': startDate, + 'endDate': endDate, + 'startTime': startTime, + 'endTime': endTime, + 'remoteType': remoteType, + 'weekDay': weekDay, + 'remoteName': remoteName, + 'addType': addType, + 'isCoerced': isCoerced, + 'remoteRight': remoteRight + })); + + // 删除遥控 + Future deletRemoteControlData(int remoteId) => + post( + deleteRemoteControlURL.toUrl, + jsonEncode({ + 'remoteId': remoteId, + })); + + // 删除遥控 + Future resetRemoteControlData(int lockId) => + post( + clearRemoteControlURL.toUrl, + jsonEncode({ + 'lockId': lockId, + })); + + // 校验遥控名字是否重复 + Future checkRemoteControlNameDuplicatedData( + String lockId, String remoteName) => + post(checkRemoteControlNameURL.toUrl, + jsonEncode({'lockId': lockId, 'remoteName': remoteName})); + // 获取转移锁锁列表 Future getTransferLockListData(String searchStr) => - post(transferLockListURL.toUrl, jsonEncode({"searchStr": searchStr})); + post(transferLockListURL.toUrl, jsonEncode({'searchStr': searchStr})); // 转移智能锁确认 Future transferLockConfirmInfoData( diff --git a/lib/network/api_repository.dart b/lib/network/api_repository.dart index 6fc0036f..43f72529 100755 --- a/lib/network/api_repository.dart +++ b/lib/network/api_repository.dart @@ -43,6 +43,7 @@ import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/ import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_entity.dart'; import 'package:star_lock/tools/aliyunRealNameAuth/realNameVertify_entity.dart'; import 'package:star_lock/tools/aliyunRealNameAuth/serviceAuthResult_entity.dart'; + import '../common/safetyVerification/entity/CheckSafetyVerificationEntity.dart'; import '../common/safetyVerification/entity/SafetyVerificationEntity.dart'; import '../login/login/entity/LoginEntity.dart'; @@ -59,15 +60,16 @@ import '../main/lockDetail/checkingIn/checkingInStaff/checkingInSetAddStaff/chec import '../main/lockDetail/checkingIn/checkingInStaff/checkingInSetStaffList/checkingInStaffList_entity.dart'; import '../main/lockDetail/fingerprint/addFingerprint/addFingerprint_entity.dart'; import '../main/lockDetail/fingerprint/fingerprintList/fingerprintListData_entity.dart'; +import '../main/lockDetail/lockDetail/lockNetToken_entity.dart'; import '../main/lockDetail/lockOperatingRecord/keyOperationRecord_entity.dart'; +import '../main/lockDetail/lockOperatingRecord/lockOperatingRecordGetLastRecordTime_entity.dart'; import '../main/lockDetail/lockSet/basicInformation/uploadElectricQuantity/uploadElectricQuantity_entity.dart'; import '../main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifiEntity.dart'; import '../main/lockDetail/lockSet/lockSet/checkingInInfoData_entity.dart'; import '../main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart'; import '../main/lockDetail/lockSet/lockTime/getServerDatetime_entity.dart'; -import '../main/lockDetail/lockDetail/lockNetToken_entity.dart'; -import '../main/lockDetail/lockOperatingRecord/lockOperatingRecordGetLastRecordTime_entity.dart'; import '../main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_entity.dart'; +import '../main/lockDetail/remoteControl/addRemoteControl/addRemoteControl_entity.dart'; import '../main/lockMian/entity/lockListInfo_entity.dart'; import '../mine/addLock/saveLock/entity/SaveLockEntity.dart'; import '../mine/message/messageList/messageList_entity.dart'; @@ -1647,6 +1649,107 @@ class ApiRepository { return LoginEntity.fromJson(res.body); } + // 获取遥控列表 + Future getRemoteControlListData({ + required String lockId, + required String pageNo, + required String pageSize, + required String searchStr, + }) async { + final res = await apiProvider.getRemoteControlListData( + lockId, pageNo, pageSize, searchStr); + return FingerprintListDataEntity.fromJson(res.body); + } + + // 添加遥控 + Future addRemoteControlData({ + required String lockId, + required String remoteName, + required String remoteNumber, + required int remoteType, + required int startDate, + required int endDate, + required int addType, + required List weekDay, + required int startTime, + required int endTime, + required int remoteRight, + }) async { + final res = await apiProvider.addRemoteControlData( + lockId, + remoteName, + remoteNumber, + remoteType, + startDate, + endDate, + addType, + weekDay, + startTime, + endTime, + remoteRight); + return AddRemoteControlEntity.fromJson(res.body); + } + + // 更新ICCard用户序号 + Future updateRemoteUserNoLoadData( + {required int lockId, + required int remoteId, + required String remoteUserNo}) async { + final res = await apiProvider.updateRemoteUserNoLoadData( + lockId, remoteId, remoteUserNo); + return LoginEntity.fromJson(res.body); + } + + // 编辑遥控 + Future editRemoteControlData({ + required int lockId, + required int remoteId, + required int startDate, + required int endDate, + required int startTime, + required int endTime, + required int remoteType, + required List weekDay, + required String remoteName, + required int addType, + required int isCoerced, + required int remoteRight, + }) async { + final res = await apiProvider.editRemoteControlData( + lockId, + remoteId, + startDate, + endDate, + startTime, + endTime, + remoteType, + weekDay, + remoteName, + addType, + isCoerced, + remoteRight); + return LoginEntity.fromJson(res.body); + } + + // 删除遥控 + Future deletRemoteControlData({required int remoteId}) async { + final res = await apiProvider.deletRemoteControlData(remoteId); + return LoginEntity.fromJson(res.body); + } + + // 重置遥控 + Future resetRemoteControlData({required int lockId}) async { + final res = await apiProvider.resetRemoteControlData(lockId); + return LoginEntity.fromJson(res.body); + } + + // 校验遥控名字是否重复 + Future checkRemoteControlNameDuplicatedData( + {required String lockId, required String remoteName}) async { + final res = await apiProvider.checkRemoteControlNameDuplicatedData(lockId, remoteName); + return LoginEntity.fromJson(res.body); + } + // 退出登录 Future userLogout({required String deviceld}) async { final res = await apiProvider.userLogout(deviceld);