2023-08-24 14:25:55 +08:00
|
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
2024-03-18 16:16:51 +08:00
|
|
|
|
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
2023-08-24 14:25:55 +08:00
|
|
|
|
import 'package:get/get.dart';
|
2025-01-10 19:19:17 +08:00
|
|
|
|
import 'package:star_lock/apm/apm_helper.dart';
|
2025-02-24 17:02:38 +08:00
|
|
|
|
import 'package:star_lock/appRouters.dart';
|
2024-06-05 09:30:04 +08:00
|
|
|
|
|
2024-05-23 18:38:02 +08:00
|
|
|
|
import 'package:star_lock/main/lockDetail/lockDetail/lockDetail_logic.dart';
|
2025-02-24 17:02:38 +08:00
|
|
|
|
import 'package:star_lock/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart';
|
2024-05-23 18:38:02 +08:00
|
|
|
|
import 'package:star_lock/mine/addLock/saveLock/entity/SaveLockEntity.dart';
|
2023-08-24 14:25:55 +08:00
|
|
|
|
|
2024-05-14 09:32:06 +08:00
|
|
|
|
import '../../../app_settings/app_settings.dart';
|
2023-08-24 14:25:55 +08:00
|
|
|
|
import '../../../blue/blue_manage.dart';
|
|
|
|
|
|
import '../../../blue/io_protocol/io_addUser.dart';
|
2023-08-31 15:56:01 +08:00
|
|
|
|
import '../../../blue/io_reply.dart';
|
2023-08-24 14:25:55 +08:00
|
|
|
|
import '../../../blue/io_tool/io_tool.dart';
|
|
|
|
|
|
import '../../../blue/io_tool/manager_event_bus.dart';
|
|
|
|
|
|
import '../../../blue/sender_manage.dart';
|
|
|
|
|
|
import '../../../network/api_repository.dart';
|
|
|
|
|
|
import '../../../tools/baseGetXController.dart';
|
2024-06-05 09:30:04 +08:00
|
|
|
|
import '../../../tools/commonDataManage.dart';
|
2024-10-19 18:26:41 +08:00
|
|
|
|
import '../../../tools/dateTool.dart';
|
2023-09-07 18:36:16 +08:00
|
|
|
|
import '../../../tools/eventBusEventManage.dart';
|
2023-08-24 14:25:55 +08:00
|
|
|
|
import '../../../tools/storage.dart';
|
|
|
|
|
|
import 'saveLock_state.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class SaveLockLogic extends BaseGetXController {
|
|
|
|
|
|
final SaveLockState state = SaveLockState();
|
|
|
|
|
|
|
|
|
|
|
|
// 获取解析后的数据
|
|
|
|
|
|
late StreamSubscription<Reply> _replySubscription;
|
2024-05-14 18:07:58 +08:00
|
|
|
|
|
2023-08-24 14:25:55 +08:00
|
|
|
|
void _initReplySubscription() {
|
2024-05-14 18:07:58 +08:00
|
|
|
|
_replySubscription =
|
2024-05-23 18:38:02 +08:00
|
|
|
|
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
|
2024-04-23 15:15:56 +08:00
|
|
|
|
if (reply is AddUserReply && state.ifCurrentScreen.value == true) {
|
2023-08-24 14:25:55 +08:00
|
|
|
|
_replyAddUserKey(reply);
|
|
|
|
|
|
}
|
2024-01-18 11:25:56 +08:00
|
|
|
|
|
2024-05-14 09:32:06 +08:00
|
|
|
|
// if (reply is SenderCustomPasswordsReply) {
|
|
|
|
|
|
// _replySenderCustomPasswords(reply);
|
|
|
|
|
|
// }
|
2024-01-18 11:25:56 +08:00
|
|
|
|
|
2024-04-25 16:17:49 +08:00
|
|
|
|
// if (reply is ChangeAdministratorPasswordReply) {
|
|
|
|
|
|
// _replyChangeAdministratorPassword(reply);
|
|
|
|
|
|
// }
|
2023-08-24 14:25:55 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-24 14:23:36 +08:00
|
|
|
|
// 添加用户
|
2023-08-24 14:25:55 +08:00
|
|
|
|
Future<void> _replyAddUserKey(Reply reply) async {
|
2024-05-23 18:38:02 +08:00
|
|
|
|
final List<int> token = reply.data.sublist(42, 46);
|
|
|
|
|
|
final List<String> strTokenList = changeIntListToStringList(token);
|
2023-08-24 14:25:55 +08:00
|
|
|
|
Storage.setStringList(saveBlueToken, strTokenList);
|
|
|
|
|
|
|
2024-05-23 18:38:02 +08:00
|
|
|
|
final int status = reply.data[46];
|
2023-12-18 10:34:53 +08:00
|
|
|
|
switch (status) {
|
2023-08-24 14:25:55 +08:00
|
|
|
|
case 0x00:
|
2024-05-14 09:32:06 +08:00
|
|
|
|
//成功 如果成功保存用户编号
|
2024-05-09 10:48:28 +08:00
|
|
|
|
state.lockUserNo = listChangInt(reply.data.sublist(47, 49));
|
2024-05-23 18:38:02 +08:00
|
|
|
|
AppLog.log('state.lockUserNo:${state.lockUserNo}');
|
2023-11-01 17:28:59 +08:00
|
|
|
|
|
2024-05-14 09:32:06 +08:00
|
|
|
|
// 关闭超时
|
2024-01-06 16:26:13 +08:00
|
|
|
|
cancelBlueConnetctToastTimer();
|
2023-08-24 14:25:55 +08:00
|
|
|
|
bindBlueAdmin();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 0x06:
|
2023-12-18 10:34:53 +08:00
|
|
|
|
//无权限
|
2024-05-23 18:38:02 +08:00
|
|
|
|
final List<String>? privateKey =
|
|
|
|
|
|
await Storage.getStringList(saveBluePrivateKey);
|
|
|
|
|
|
final List<int> getPrivateKeyList =
|
|
|
|
|
|
changeStringListToIntList(privateKey!);
|
2023-08-24 14:25:55 +08:00
|
|
|
|
|
2024-05-23 18:38:02 +08:00
|
|
|
|
final List<String>? publicKey =
|
|
|
|
|
|
await Storage.getStringList(saveBluePublicKey);
|
|
|
|
|
|
final List<int> publicKeyDataList =
|
|
|
|
|
|
changeStringListToIntList(publicKey!);
|
2023-08-24 14:25:55 +08:00
|
|
|
|
|
|
|
|
|
|
IoSenderManage.senderAddUser(
|
2023-12-13 11:54:34 +08:00
|
|
|
|
lockID: BlueManage().connectDeviceName,
|
2023-12-18 10:34:53 +08:00
|
|
|
|
authUserID: await Storage.getUid(),
|
2024-05-23 18:38:02 +08:00
|
|
|
|
keyID: '1',
|
2023-12-18 10:34:53 +08:00
|
|
|
|
userID: await Storage.getUid(),
|
|
|
|
|
|
openMode: 1,
|
|
|
|
|
|
keyType: 1,
|
|
|
|
|
|
startDate: DateTime.now().millisecondsSinceEpoch,
|
|
|
|
|
|
expireDate: 0x11223344,
|
2024-05-09 10:23:17 +08:00
|
|
|
|
useCountLimit: 0xFFFF,
|
2024-05-14 18:07:58 +08:00
|
|
|
|
isRound: 0,
|
2024-05-09 10:23:17 +08:00
|
|
|
|
weekRound: 0,
|
2024-05-14 18:07:58 +08:00
|
|
|
|
startHour: 0,
|
2024-05-09 10:23:17 +08:00
|
|
|
|
startMin: 0,
|
|
|
|
|
|
endHour: 0,
|
2024-05-14 18:07:58 +08:00
|
|
|
|
endMin: 0,
|
2023-12-18 10:34:53 +08:00
|
|
|
|
role: 255,
|
2024-05-14 09:32:06 +08:00
|
|
|
|
password: state.adminPassword,
|
2023-12-18 10:34:53 +08:00
|
|
|
|
needAuthor: 1,
|
|
|
|
|
|
publicKey: publicKeyDataList,
|
|
|
|
|
|
privateKey: getPrivateKeyList,
|
2024-04-25 11:56:13 +08:00
|
|
|
|
token: token,
|
2024-05-14 18:07:58 +08:00
|
|
|
|
isBeforeAddUser: true);
|
2023-08-24 14:25:55 +08:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2024-05-14 09:32:06 +08:00
|
|
|
|
//失败 关闭loading
|
2024-04-30 14:46:06 +08:00
|
|
|
|
state.sureBtnState.value = 0;
|
2024-01-06 16:26:13 +08:00
|
|
|
|
dismissEasyLoading();
|
2023-08-24 14:25:55 +08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-18 11:25:56 +08:00
|
|
|
|
// 添加管理员密码
|
2024-05-14 09:32:06 +08:00
|
|
|
|
// Future<void> _replySenderCustomPasswords(Reply reply) async {
|
|
|
|
|
|
// int status = reply.data[2];
|
|
|
|
|
|
//
|
|
|
|
|
|
// switch (status) {
|
|
|
|
|
|
// case 0x00:
|
|
|
|
|
|
// //成功
|
|
|
|
|
|
// state.sureBtnState.value = 0;
|
|
|
|
|
|
// dismissEasyLoading();
|
|
|
|
|
|
// addLockAdminPassword(true);
|
|
|
|
|
|
// break;
|
|
|
|
|
|
// case 0x06:
|
|
|
|
|
|
// //无权限
|
|
|
|
|
|
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
|
|
|
|
|
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
|
|
|
|
|
//
|
|
|
|
|
|
// var signKey = await Storage.getStringList(saveBlueSignKey);
|
|
|
|
|
|
// List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
|
|
|
|
|
//
|
|
|
|
|
|
// var token = reply.data.sublist(5, 9);
|
|
|
|
|
|
// var saveStrList = changeIntListToStringList(token);
|
|
|
|
|
|
// Storage.setStringList(saveBlueToken, saveStrList);
|
|
|
|
|
|
//
|
|
|
|
|
|
// IoSenderManage.senderCustomPasswordsCommand(
|
|
|
|
|
|
// keyID: "1",
|
|
|
|
|
|
// userID: await Storage.getUid(),
|
|
|
|
|
|
// pwdNo: 0,
|
|
|
|
|
|
// pwd: state.adminPassword,
|
|
|
|
|
|
// operate: 0,
|
|
|
|
|
|
// isAdmin: 1,
|
|
|
|
|
|
// useCountLimit: 0xffff,
|
|
|
|
|
|
// startTime: 0x11223344,
|
|
|
|
|
|
// endTime: 0x11223344,
|
|
|
|
|
|
// needAuthor: 1,
|
|
|
|
|
|
// isBeforeAddUser: true,
|
|
|
|
|
|
// signKey: signKeyDataList,
|
|
|
|
|
|
// privateKey: getPrivateKeyList,
|
|
|
|
|
|
// token: token);
|
|
|
|
|
|
// break;
|
|
|
|
|
|
// default:
|
|
|
|
|
|
// state.sureBtnState.value = 0;
|
|
|
|
|
|
// dismissEasyLoading();
|
|
|
|
|
|
// backAction();
|
|
|
|
|
|
// // AppLog.log("添加管理员密码失败 消失");
|
|
|
|
|
|
// break;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
2024-01-18 11:25:56 +08:00
|
|
|
|
|
|
|
|
|
|
// 修改管理员密码
|
2024-04-25 16:17:49 +08:00
|
|
|
|
// Future<void> _replyChangeAdministratorPassword(Reply reply) async {
|
|
|
|
|
|
// var token = reply.data.sublist(5, 9);
|
|
|
|
|
|
// var saveStrList = changeIntListToStringList(token);
|
|
|
|
|
|
// Storage.setStringList(saveBlueToken, saveStrList);
|
|
|
|
|
|
//
|
|
|
|
|
|
// int status = reply.data[2];
|
|
|
|
|
|
//
|
|
|
|
|
|
// switch (status) {
|
|
|
|
|
|
// case 0x00:
|
|
|
|
|
|
// //成功
|
|
|
|
|
|
// cancelBlueConnetctToastTimer();
|
|
|
|
|
|
// addLockAdminPassword(false);
|
|
|
|
|
|
// break;
|
|
|
|
|
|
// case 0x06:
|
|
|
|
|
|
// //无权限
|
|
|
|
|
|
// var signKey = await Storage.getStringList(saveBlueSignKey);
|
|
|
|
|
|
// List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
|
|
|
|
|
//
|
|
|
|
|
|
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
|
|
|
|
|
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
|
|
|
|
|
//
|
|
|
|
|
|
// IoSenderManage.changeAdministratorPasswordCommand(
|
|
|
|
|
|
// keyID: "1",
|
|
|
|
|
|
// userID: await Storage.getUid(),
|
|
|
|
|
|
// pwdNo: 254,
|
|
|
|
|
|
// pwd:state.adminPasswordTF.text,
|
|
|
|
|
|
// useCountLimit: 0xff,
|
|
|
|
|
|
// startTime: 0x11223344,
|
|
|
|
|
|
// endTime: 0x11223344,
|
|
|
|
|
|
// needAuthor: 1,
|
|
|
|
|
|
// isBeforeAddUser: true,
|
|
|
|
|
|
// signKey: signKeyDataList,
|
|
|
|
|
|
// privateKey: getPrivateKeyList,
|
|
|
|
|
|
// token: token);
|
|
|
|
|
|
// break;
|
|
|
|
|
|
// default:
|
|
|
|
|
|
// break;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
2023-08-24 14:25:55 +08:00
|
|
|
|
|
|
|
|
|
|
// 添加用户
|
|
|
|
|
|
Future<void> addUserConnectBlue() async {
|
|
|
|
|
|
// 进来之后首先连接
|
2024-05-14 18:07:58 +08:00
|
|
|
|
if (state.sureBtnState.value == 1) {
|
2024-04-30 14:46:06 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
state.sureBtnState.value = 1;
|
|
|
|
|
|
|
2024-05-14 09:32:06 +08:00
|
|
|
|
// showTitleEasyLoading("添加锁进行中 1/2");
|
|
|
|
|
|
showEasyLoading();
|
|
|
|
|
|
// 判断超时
|
2024-05-14 18:07:58 +08:00
|
|
|
|
showBlueConnetctToastTimer(action: () {
|
2024-01-06 16:26:13 +08:00
|
|
|
|
dismissEasyLoading();
|
2024-04-30 14:46:06 +08:00
|
|
|
|
state.sureBtnState.value = 0;
|
2024-05-14 18:07:58 +08:00
|
|
|
|
if (state.ifCurrentScreen.value == true) {
|
2024-05-14 09:32:06 +08:00
|
|
|
|
showBlueConnetctToast();
|
|
|
|
|
|
}
|
2024-01-06 16:26:13 +08:00
|
|
|
|
});
|
2024-05-21 15:33:06 +08:00
|
|
|
|
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
2024-05-14 18:07:58 +08:00
|
|
|
|
(BluetoothConnectionState deviceConnectionState) async {
|
|
|
|
|
|
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
2023-08-24 14:25:55 +08:00
|
|
|
|
// 私钥
|
2024-05-23 18:38:02 +08:00
|
|
|
|
final List<String>? privateKey =
|
|
|
|
|
|
await Storage.getStringList(saveBluePrivateKey);
|
|
|
|
|
|
final List<int> getPrivateKeyList =
|
|
|
|
|
|
changeStringListToIntList(privateKey!);
|
|
|
|
|
|
|
|
|
|
|
|
final List<String>? publicKey =
|
|
|
|
|
|
await Storage.getStringList(saveBluePublicKey);
|
|
|
|
|
|
final List<int> publicKeyDataList =
|
|
|
|
|
|
changeStringListToIntList(publicKey!);
|
|
|
|
|
|
|
|
|
|
|
|
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
|
|
|
|
|
List<int> getTokenList = <int>[0, 0, 0, 0];
|
2023-12-18 10:34:53 +08:00
|
|
|
|
if (token != null) {
|
2023-08-24 14:25:55 +08:00
|
|
|
|
getTokenList = changeStringListToIntList(token);
|
|
|
|
|
|
}
|
|
|
|
|
|
IoSenderManage.senderAddUser(
|
2023-08-30 10:56:18 +08:00
|
|
|
|
lockID: BlueManage().connectDeviceName,
|
2024-05-14 18:07:58 +08:00
|
|
|
|
authUserID: await Storage.getUid(),
|
2024-05-23 18:38:02 +08:00
|
|
|
|
keyID: '1',
|
2024-05-14 18:07:58 +08:00
|
|
|
|
userID: await Storage.getUid(),
|
|
|
|
|
|
openMode: 1,
|
|
|
|
|
|
keyType: 1,
|
2024-05-15 16:56:05 +08:00
|
|
|
|
startDate: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
2024-05-14 18:07:58 +08:00
|
|
|
|
expireDate: 0x11223344,
|
2024-05-09 10:23:17 +08:00
|
|
|
|
useCountLimit: 0xFFFF,
|
2024-05-14 18:07:58 +08:00
|
|
|
|
isRound: 0,
|
2024-05-09 10:23:17 +08:00
|
|
|
|
weekRound: 0,
|
2024-05-14 18:07:58 +08:00
|
|
|
|
startHour: 0,
|
2024-05-09 10:23:17 +08:00
|
|
|
|
startMin: 0,
|
|
|
|
|
|
endHour: 0,
|
2024-05-14 18:07:58 +08:00
|
|
|
|
endMin: 0,
|
|
|
|
|
|
role: 255,
|
|
|
|
|
|
password: state.adminPassword,
|
|
|
|
|
|
needAuthor: 1,
|
|
|
|
|
|
publicKey: publicKeyDataList,
|
|
|
|
|
|
privateKey: getPrivateKeyList,
|
2024-04-25 11:56:13 +08:00
|
|
|
|
token: getTokenList,
|
2024-05-14 18:07:58 +08:00
|
|
|
|
isBeforeAddUser: true);
|
|
|
|
|
|
} else if (deviceConnectionState ==
|
|
|
|
|
|
BluetoothConnectionState.disconnected) {
|
2024-01-02 18:03:50 +08:00
|
|
|
|
dismissEasyLoading();
|
2024-01-06 16:26:13 +08:00
|
|
|
|
cancelBlueConnetctToastTimer();
|
2024-04-30 14:46:06 +08:00
|
|
|
|
state.sureBtnState.value = 0;
|
2024-05-14 18:07:58 +08:00
|
|
|
|
if (state.ifCurrentScreen.value == true) {
|
2024-01-06 16:26:13 +08:00
|
|
|
|
showBlueConnetctToast();
|
|
|
|
|
|
}
|
2023-08-24 14:25:55 +08:00
|
|
|
|
}
|
2024-01-08 17:58:19 +08:00
|
|
|
|
}, isAddEquipment: true);
|
2023-08-24 14:25:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-18 11:25:56 +08:00
|
|
|
|
// 设置管理员密码(同添加自定义开锁密码,指纹/密码/卡片前5个是管理员)
|
2024-05-14 09:32:06 +08:00
|
|
|
|
// Future<void> senderCustomPasswords() async {
|
|
|
|
|
|
//
|
|
|
|
|
|
// showTitleEasyLoading("添加锁进行中 2/2");
|
|
|
|
|
|
// // showEasyLoading();
|
|
|
|
|
|
// showBlueConnetctToastTimer(isShowBlueConnetctToast: false, action: (){
|
|
|
|
|
|
// // AppLog.log("添加管理员密码超时");
|
|
|
|
|
|
// dismissEasyLoading();
|
|
|
|
|
|
// state.sureBtnState.value = 0;
|
|
|
|
|
|
// if(state.ifCurrentScreen.value == true){
|
|
|
|
|
|
// showBlueConnetctToast();
|
|
|
|
|
|
// }
|
|
|
|
|
|
// // backAction();
|
|
|
|
|
|
// });
|
|
|
|
|
|
// BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async {
|
|
|
|
|
|
// if (deviceConnectionState == BluetoothConnectionState.connected) {
|
|
|
|
|
|
// var signKey = await Storage.getStringList(saveBlueSignKey);
|
|
|
|
|
|
// List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
|
|
|
|
|
//
|
|
|
|
|
|
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
|
|
|
|
|
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
|
|
|
|
|
//
|
|
|
|
|
|
// var token = await Storage.getStringList(saveBlueToken);
|
|
|
|
|
|
// List<int> getTokenList = changeStringListToIntList(token!);
|
|
|
|
|
|
//
|
|
|
|
|
|
// IoSenderManage.senderCustomPasswordsCommand(
|
|
|
|
|
|
// keyID: "1",
|
|
|
|
|
|
// // userID: await Storage.getUid(),
|
|
|
|
|
|
// userID: "0",
|
|
|
|
|
|
// pwdNo: 0,
|
|
|
|
|
|
// pwd: state.adminPassword,
|
|
|
|
|
|
// operate: 0,
|
|
|
|
|
|
// isAdmin: 1,
|
|
|
|
|
|
// useCountLimit: 0xffff,
|
|
|
|
|
|
// startTime: 0x11223344,
|
|
|
|
|
|
// endTime: 0x11223344,
|
|
|
|
|
|
// needAuthor: 1,
|
|
|
|
|
|
// isBeforeAddUser: true,
|
|
|
|
|
|
// signKey: signKeyDataList,
|
|
|
|
|
|
// privateKey: getPrivateKeyList,
|
|
|
|
|
|
// token: getTokenList);
|
|
|
|
|
|
// } else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
|
|
|
|
|
|
// dismissEasyLoading();
|
|
|
|
|
|
// state.sureBtnState.value = 0;
|
|
|
|
|
|
// if(state.ifCurrentScreen.value == true){
|
|
|
|
|
|
// showBlueConnetctToast();
|
|
|
|
|
|
// }
|
|
|
|
|
|
// // backAction();
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }, isAddEquipment: true);
|
|
|
|
|
|
// }
|
2024-01-18 11:25:56 +08:00
|
|
|
|
|
|
|
|
|
|
// 修改管理员密码(同添加自定义开锁密码,指纹/密码/卡片前5个是管理员)
|
2024-04-25 16:17:49 +08:00
|
|
|
|
// Future<void> changeAdministratorPasswordCommand() async {
|
|
|
|
|
|
// showEasyLoading();
|
|
|
|
|
|
// showBlueConnetctToastTimer(action: (){
|
|
|
|
|
|
// dismissEasyLoading();
|
|
|
|
|
|
// });
|
|
|
|
|
|
// BlueManage().bludSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async {
|
|
|
|
|
|
// if (deviceConnectionState == BluetoothConnectionState.connected) {
|
|
|
|
|
|
// var signKey = await Storage.getStringList(saveBlueSignKey);
|
|
|
|
|
|
// List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
|
|
|
|
|
//
|
|
|
|
|
|
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
|
|
|
|
|
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
|
|
|
|
|
//
|
|
|
|
|
|
// var token = await Storage.getStringList(saveBlueToken);
|
|
|
|
|
|
// List<int> getTokenList = changeStringListToIntList(token!);
|
|
|
|
|
|
//
|
|
|
|
|
|
// IoSenderManage.changeAdministratorPasswordCommand(
|
|
|
|
|
|
// keyID: "1",
|
|
|
|
|
|
// userID: await Storage.getUid(),
|
|
|
|
|
|
// pwdNo: 254,
|
|
|
|
|
|
// pwd:state.adminPasswordTF.text,
|
|
|
|
|
|
// useCountLimit: 0xff,
|
|
|
|
|
|
// startTime: 0x11223344,
|
|
|
|
|
|
// endTime: 0x11223344,
|
|
|
|
|
|
// needAuthor: 1,
|
|
|
|
|
|
// isBeforeAddUser: true,
|
|
|
|
|
|
// signKey: signKeyDataList,
|
|
|
|
|
|
// privateKey: getPrivateKeyList,
|
|
|
|
|
|
// token: getTokenList);
|
|
|
|
|
|
// } else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
|
|
|
|
|
|
// dismissEasyLoading();
|
|
|
|
|
|
// cancelBlueConnetctToastTimer();
|
|
|
|
|
|
// state.saveBtnIsUsable.value = true;
|
|
|
|
|
|
// if(state.ifCurrentScreen.value == true){
|
|
|
|
|
|
// showBlueConnetctToast();
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }, isAddEquipment: true);
|
|
|
|
|
|
// }
|
2024-01-02 18:17:05 +08:00
|
|
|
|
|
2024-05-14 18:07:58 +08:00
|
|
|
|
void bindBlueAdmin() async {
|
2024-05-23 18:38:02 +08:00
|
|
|
|
state.lockInfo['adminPwd'] = state.adminPassword;
|
|
|
|
|
|
|
2025-05-06 19:32:13 +08:00
|
|
|
|
// final Map<String, dynamic> positionMap = <String, dynamic>{};
|
|
|
|
|
|
// positionMap['longitude'] = state.addressInfo['longitude'];
|
|
|
|
|
|
// positionMap['latitude'] = state.addressInfo['latitude'];
|
|
|
|
|
|
// positionMap['country'] = state.addressInfo['country'];
|
|
|
|
|
|
// positionMap['province'] = state.addressInfo['province'];
|
|
|
|
|
|
// positionMap['city'] = state.addressInfo['city'];
|
|
|
|
|
|
// positionMap['district'] = state.addressInfo['district'];
|
|
|
|
|
|
// positionMap['township'] = state.addressInfo['street'];
|
|
|
|
|
|
// positionMap['address'] = state.addressInfo['address'];
|
2024-05-23 18:38:02 +08:00
|
|
|
|
|
|
|
|
|
|
final Map<String, dynamic> bluetooth = <String, dynamic>{};
|
2023-08-29 11:02:52 +08:00
|
|
|
|
bluetooth['bluetoothDeviceId'] = BlueManage().connectDeviceMacAddress;
|
|
|
|
|
|
bluetooth['bluetoothDeviceName'] = BlueManage().connectDeviceName;
|
|
|
|
|
|
|
2024-05-23 18:38:02 +08:00
|
|
|
|
final List<String>? publicKey =
|
|
|
|
|
|
await Storage.getStringList(saveBluePublicKey);
|
|
|
|
|
|
final List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
2023-08-29 11:02:52 +08:00
|
|
|
|
bluetooth['publicKey'] = publicKeyDataList;
|
|
|
|
|
|
|
2024-05-23 18:38:02 +08:00
|
|
|
|
final List<String>? privateKey =
|
|
|
|
|
|
await Storage.getStringList(saveBluePrivateKey);
|
|
|
|
|
|
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
2023-08-29 11:02:52 +08:00
|
|
|
|
bluetooth['privateKey'] = getPrivateKeyList;
|
2023-08-24 14:25:55 +08:00
|
|
|
|
|
2024-05-23 18:38:02 +08:00
|
|
|
|
final List<String>? signKey = await Storage.getStringList(saveBlueSignKey);
|
|
|
|
|
|
final List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
2023-08-30 14:55:42 +08:00
|
|
|
|
bluetooth['signKey'] = signKeyDataList;
|
|
|
|
|
|
|
2024-05-23 18:38:02 +08:00
|
|
|
|
final SaveLockEntity entity = await ApiRepository.to.bindingBlueAdmin(
|
2023-12-18 10:34:53 +08:00
|
|
|
|
lockAlias: state.aliName.value,
|
2025-05-06 19:32:13 +08:00
|
|
|
|
position: {},
|
2023-12-18 10:34:53 +08:00
|
|
|
|
bluetooth: bluetooth,
|
|
|
|
|
|
lockInfo: state.lockInfo,
|
|
|
|
|
|
lockUserNo: state.lockUserNo.toString(),
|
|
|
|
|
|
pwdTimestamp: state.pwdTimestamp.value.toString(),
|
|
|
|
|
|
featureValue: state.featureValue,
|
|
|
|
|
|
featureSettingValue: state.featureSettingValue,
|
|
|
|
|
|
featureSettingParams: state.featureSettingParams,
|
2023-08-24 14:25:55 +08:00
|
|
|
|
);
|
2023-12-18 10:34:53 +08:00
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
2024-01-18 11:25:56 +08:00
|
|
|
|
state.lockId = entity.data!.lockId!;
|
2024-05-14 09:32:06 +08:00
|
|
|
|
|
2024-10-19 18:26:41 +08:00
|
|
|
|
final String getMobile = (await Storage.getMobile())!;
|
2025-01-10 19:19:17 +08:00
|
|
|
|
ApmHelper.instance.trackEvent('save_lock_result', {
|
2025-02-24 17:02:38 +08:00
|
|
|
|
'lock_name': BlueManage().connectDeviceName,
|
|
|
|
|
|
'account':
|
|
|
|
|
|
getMobile.isNotEmpty ? getMobile : (await Storage.getEmail())!,
|
|
|
|
|
|
'date': DateTool().getNowDateWithType(1),
|
|
|
|
|
|
'save_lock_result': '成功',
|
2024-10-19 18:26:41 +08:00
|
|
|
|
});
|
2024-05-14 09:32:06 +08:00
|
|
|
|
backAction();
|
|
|
|
|
|
// await senderCustomPasswords();
|
2024-01-18 11:25:56 +08:00
|
|
|
|
|
|
|
|
|
|
// BlueManage().disconnect(BlueManage().connectDeviceMacAddress);
|
|
|
|
|
|
// eventBus.fire(RefreshLockListInfoDataEvent());
|
|
|
|
|
|
// Get.close(state.isFromMap == 1 ? 5 : 6);
|
2024-05-14 18:07:58 +08:00
|
|
|
|
} else {
|
2024-04-30 14:46:06 +08:00
|
|
|
|
state.sureBtnState.value = 0;
|
2024-10-19 18:26:41 +08:00
|
|
|
|
|
|
|
|
|
|
final String getMobile = (await Storage.getMobile())!;
|
2025-01-10 19:19:17 +08:00
|
|
|
|
ApmHelper.instance.trackEvent('save_lock_result', {
|
2025-02-24 17:02:38 +08:00
|
|
|
|
'lock_name': BlueManage().connectDeviceName,
|
|
|
|
|
|
'account':
|
|
|
|
|
|
getMobile.isNotEmpty ? getMobile : (await Storage.getEmail())!,
|
|
|
|
|
|
'date': DateTool().getNowDateWithType(1),
|
|
|
|
|
|
'save_lock_result': '${entity.errorCode}--${entity.errorMsg}',
|
2024-10-19 18:26:41 +08:00
|
|
|
|
});
|
2024-01-18 11:25:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 更新管理员密码
|
2024-05-14 09:32:06 +08:00
|
|
|
|
// void addLockAdminPassword(bool isAddLockAdminPassword) async {
|
|
|
|
|
|
// var entity = await ApiRepository.to.setAdminPasswordData(
|
|
|
|
|
|
// lockId: state.lockId,
|
|
|
|
|
|
// adminPwd: state.adminPassword,
|
|
|
|
|
|
// );
|
|
|
|
|
|
// // if (entity.errorCode!.codeIsSuccessful) {
|
|
|
|
|
|
// // if(isAddLockAdminPassword == true){
|
|
|
|
|
|
// // showDeletPasswordAlertDialog();
|
|
|
|
|
|
// // }else{
|
|
|
|
|
|
// backAction();
|
|
|
|
|
|
// // }
|
|
|
|
|
|
// // }
|
|
|
|
|
|
// }
|
2023-08-24 14:25:55 +08:00
|
|
|
|
|
2024-04-25 16:17:49 +08:00
|
|
|
|
// void showDeletPasswordAlertDialog() {
|
|
|
|
|
|
// showDialog(
|
|
|
|
|
|
// context: Get.context!,
|
|
|
|
|
|
// builder: (BuildContext context) {
|
|
|
|
|
|
// return ShowTFView(
|
|
|
|
|
|
// title: "管理员密码",
|
|
|
|
|
|
// tipTitle: "如需修改,请输入新的管理员密码(6位),点击确定即可修改",
|
|
|
|
|
|
// leftBtnTitle: "确定".tr,
|
|
|
|
|
|
// rightBtnTitle: "修改",
|
|
|
|
|
|
// keyboardType: TextInputType.number,
|
|
|
|
|
|
// inputFormatters: [
|
|
|
|
|
|
// FilteringTextInputFormatter.allow(RegExp('[0-9]')),
|
|
|
|
|
|
// LengthLimitingTextInputFormatter(6),
|
|
|
|
|
|
// ],
|
|
|
|
|
|
// controller: state.adminPasswordTF,
|
|
|
|
|
|
// sureClick: () {
|
|
|
|
|
|
// if(state.adminPasswordTF.text.length < 6){
|
|
|
|
|
|
// showToast("请输入6位管理员密码".tr);
|
|
|
|
|
|
// return;
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// if(state.adminPasswordTF.text == state.adminPassword){
|
|
|
|
|
|
// showToast("请输入新的管理员密码".tr);
|
|
|
|
|
|
// return;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// changeAdministratorPasswordCommand();
|
|
|
|
|
|
// },
|
|
|
|
|
|
// cancelClick: () {
|
|
|
|
|
|
// backAction();
|
|
|
|
|
|
// },
|
|
|
|
|
|
// );
|
|
|
|
|
|
// },
|
|
|
|
|
|
// );
|
|
|
|
|
|
// }
|
2024-01-18 11:25:56 +08:00
|
|
|
|
|
2025-02-24 17:02:38 +08:00
|
|
|
|
void backAction() async {
|
2025-03-24 15:16:04 +08:00
|
|
|
|
// BlueManage().disconnect();
|
2025-02-24 17:02:38 +08:00
|
|
|
|
|
|
|
|
|
|
// 查询锁设置信息
|
|
|
|
|
|
final LockSetInfoEntity entity =
|
2025-02-26 11:35:29 +08:00
|
|
|
|
await ApiRepository.to.getLockSettingInfoData(
|
2025-02-24 17:02:38 +08:00
|
|
|
|
lockId: state.lockId.toString(),
|
|
|
|
|
|
);
|
|
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
|
|
|
|
state.lockSetInfoData.value = entity.data!;
|
|
|
|
|
|
if (state.lockSetInfoData.value.lockFeature?.wifi == 1) {
|
|
|
|
|
|
// 如果是wifi锁,需要配置WIFI
|
|
|
|
|
|
Get.toNamed(Routers.wifiListPage, arguments: {
|
|
|
|
|
|
'lockSetInfoData': state.lockSetInfoData.value,
|
|
|
|
|
|
'pageName': 'saveLock'
|
|
|
|
|
|
});
|
2025-07-18 10:40:41 +08:00
|
|
|
|
} else if (state.lockSetInfoData.value.lockFeature?.languageSpeech == 1) {
|
|
|
|
|
|
Get.toNamed(Routers.lockVoiceSettingPage, arguments: {
|
|
|
|
|
|
'lockSetInfoData': state.lockSetInfoData.value,
|
|
|
|
|
|
'pageName': 'saveLock'
|
|
|
|
|
|
});
|
2025-02-24 17:02:38 +08:00
|
|
|
|
} else {
|
2025-07-18 10:40:41 +08:00
|
|
|
|
eventBus.fire(RefreshLockListInfoDataEvent(
|
|
|
|
|
|
clearScanDevices: true, isUnShowLoading: true));
|
2025-02-24 17:02:38 +08:00
|
|
|
|
Future<void>.delayed(const Duration(seconds: 1), () {
|
2025-05-06 19:32:13 +08:00
|
|
|
|
// Get.close(state.isFromMap == 1
|
|
|
|
|
|
// ? (CommonDataManage().seletLockType == 0 ? 4 : 5)
|
|
|
|
|
|
// : (CommonDataManage().seletLockType == 0 ? 5 : 6));
|
2025-07-18 10:40:41 +08:00
|
|
|
|
Get.until((route) => route.isFirst);
|
2025-02-24 17:02:38 +08:00
|
|
|
|
});
|
|
|
|
|
|
//刚刚配对完,需要对开锁页锁死 2 秒
|
|
|
|
|
|
Future<void>.delayed(const Duration(milliseconds: 200), () {
|
|
|
|
|
|
if (Get.isRegistered<LockDetailLogic>()) {
|
|
|
|
|
|
Get.find<LockDetailLogic>()
|
|
|
|
|
|
.functionBlocker
|
|
|
|
|
|
.countdownProhibited(duration: const Duration(seconds: 2));
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2024-05-23 18:38:02 +08:00
|
|
|
|
}
|
2025-02-28 14:16:04 +08:00
|
|
|
|
} else {
|
2025-07-18 10:40:41 +08:00
|
|
|
|
eventBus.fire(RefreshLockListInfoDataEvent(
|
|
|
|
|
|
clearScanDevices: true, isUnShowLoading: true));
|
2025-02-28 14:16:04 +08:00
|
|
|
|
Future<void>.delayed(const Duration(seconds: 1), () {
|
2025-05-06 19:32:13 +08:00
|
|
|
|
// Get.close(state.isFromMap == 1
|
|
|
|
|
|
// ? (CommonDataManage().seletLockType == 0 ? 4 : 5)
|
|
|
|
|
|
// : (CommonDataManage().seletLockType == 0 ? 5 : 6));
|
|
|
|
|
|
Get.until((route) => route.isFirst);
|
2025-02-28 14:16:04 +08:00
|
|
|
|
});
|
|
|
|
|
|
//刚刚配对完,需要对开锁页锁死 2 秒
|
|
|
|
|
|
Future<void>.delayed(const Duration(milliseconds: 200), () {
|
|
|
|
|
|
if (Get.isRegistered<LockDetailLogic>()) {
|
|
|
|
|
|
Get.find<LockDetailLogic>()
|
|
|
|
|
|
.functionBlocker
|
|
|
|
|
|
.countdownProhibited(duration: const Duration(seconds: 2));
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-02-24 17:02:38 +08:00
|
|
|
|
}
|
2024-01-18 11:25:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-24 14:25:55 +08:00
|
|
|
|
@override
|
|
|
|
|
|
void onReady() {
|
|
|
|
|
|
super.onReady();
|
|
|
|
|
|
|
|
|
|
|
|
_initReplySubscription();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void onInit() {
|
|
|
|
|
|
super.onInit();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void onClose() {
|
|
|
|
|
|
_replySubscription.cancel();
|
2024-01-03 15:33:53 +08:00
|
|
|
|
super.onClose();
|
2023-08-24 14:25:55 +08:00
|
|
|
|
}
|
2023-12-18 10:34:53 +08:00
|
|
|
|
}
|