修复用户第一次进行蓝牙协议交互,添加用户问题
This commit is contained in:
parent
9e31a73a81
commit
fc7b487f8a
@ -48,7 +48,7 @@ abstract class Reply{
|
||||
case 0x06:
|
||||
// 需要鉴权
|
||||
Get.log("${commandType!.typeName}需要鉴权");
|
||||
showErrorMessage("需要鉴权");
|
||||
// showErrorMessage("需要鉴权");
|
||||
break;
|
||||
case 0x07:
|
||||
// 无权限
|
||||
|
||||
158
star_lock/lib/blue/sender_beforeDataManage.dart
Normal file
158
star_lock/lib/blue/sender_beforeDataManage.dart
Normal file
@ -0,0 +1,158 @@
|
||||
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:star_lock/blue/sender_manage.dart';
|
||||
import 'package:star_lock/tools/baseGetXController.dart';
|
||||
import 'package:star_lock/tools/eventBusEventManage.dart';
|
||||
|
||||
import '../main/lockDetail/lockDetail/lockNetToken_entity.dart';
|
||||
import '../network/api_repository.dart';
|
||||
import '../tools/commonDataManage.dart';
|
||||
import '../tools/storage.dart';
|
||||
import 'blue_manage.dart';
|
||||
import 'io_protocol/io_addUser.dart';
|
||||
import 'io_reply.dart';
|
||||
import 'io_tool/io_tool.dart';
|
||||
import 'io_tool/manager_event_bus.dart';
|
||||
|
||||
class SenderBeforeDataManage {
|
||||
static SenderBeforeDataManage? _manager;
|
||||
SenderBeforeDataManage._init();
|
||||
|
||||
static SenderBeforeDataManage? shareManager() {
|
||||
_manager ??= SenderBeforeDataManage._init();
|
||||
_manager!._init();
|
||||
return _manager;
|
||||
}
|
||||
|
||||
factory SenderBeforeDataManage() => shareManager()!;
|
||||
SenderBeforeDataManage? get manager => shareManager();
|
||||
|
||||
void _init() {
|
||||
_initReplySubscription();
|
||||
}
|
||||
|
||||
// 监听设备返回的数据
|
||||
StreamSubscription<Reply>? _replySubscription;
|
||||
void _initReplySubscription() {
|
||||
_replySubscription ??= EventBusManager().eventBus!.on<Reply>().listen((reply) async {
|
||||
|
||||
// 添加用户
|
||||
if ((reply is AddUserReply)) {
|
||||
_replyAddUserKey(reply);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 添加用户
|
||||
Future<void> _replyAddUserKey(Reply reply) async {
|
||||
// var lockId = reply.data.sublist(2, 42);
|
||||
// print("lockId:$lockId");
|
||||
|
||||
int status = reply.data[46];
|
||||
// print("status:$status reply.data:${reply.data}");
|
||||
|
||||
print("status:$status");
|
||||
switch (status) {
|
||||
case 0x00:
|
||||
//成功
|
||||
CommonDataManage().currentLockUserNo = reply.data[47];
|
||||
CommonDataManage().currentKeyInfo.lockUserNo = CommonDataManage().currentLockUserNo;
|
||||
_updateLockUserNo();
|
||||
break;
|
||||
case 0x06:
|
||||
//无权限
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
|
||||
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
||||
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
||||
|
||||
var token = reply.data.sublist(42, 46);
|
||||
List<String> strTokenList = changeIntListToStringList(token);
|
||||
Storage.setStringList(saveBlueToken, strTokenList);
|
||||
// print("token:$token");
|
||||
|
||||
// IoSenderManage.senderAddUser(
|
||||
// lockID: BlueManage().connectDeviceName,
|
||||
// authUserID: CommonDataManage().currentKeyInfo.senderUserId!.toString(),
|
||||
// keyID: CommonDataManage().currentKeyInfo.keyId.toString(),
|
||||
// userID: await Storage.getUid(),
|
||||
// openMode: 1,
|
||||
// keyType: 0,
|
||||
// startDate: CommonDataManage().currentKeyInfo.startDate!~/10000,
|
||||
// expireDate: CommonDataManage().currentKeyInfo.endDate!~/10000,
|
||||
// role: CommonDataManage().currentKeyInfo.keyRight == 1 ? 1 : 0,
|
||||
// password: "123456",
|
||||
// needAuthor: 1,
|
||||
// publicKey: publicKeyDataList,
|
||||
// privateKey: getPrivateKeyList,
|
||||
// token: token);
|
||||
var addUserData = AddUserCommand(
|
||||
lockID: BlueManage().connectDeviceName,
|
||||
authUserID: CommonDataManage().currentKeyInfo.senderUserId!.toString(),
|
||||
keyID: CommonDataManage().currentKeyInfo.keyId.toString(),
|
||||
userID: await Storage.getUid(),
|
||||
openMode: 1,
|
||||
keyType: 0,
|
||||
startDate: CommonDataManage().currentKeyInfo.startDate!~/10000,
|
||||
expireDate: CommonDataManage().currentKeyInfo.endDate!~/10000,
|
||||
role: CommonDataManage().currentKeyInfo.keyRight == 1 ? 1 : 0,
|
||||
password: "123456",
|
||||
needAuthor: 1,
|
||||
publicKey: publicKeyDataList,
|
||||
privateKey: getPrivateKeyList,
|
||||
token: token);
|
||||
eventBus.fire(LockAddUserSucceedEvent(addUserData.packageData(), 1));
|
||||
break;
|
||||
default:
|
||||
//失败
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<int>> getAddUserKeyData() async {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
|
||||
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
||||
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
||||
|
||||
var token = await Storage.getStringList(saveBlueToken);
|
||||
List<int> getTokenList = changeStringListToIntList(token!);
|
||||
|
||||
var addUserData = AddUserCommand(
|
||||
lockID: BlueManage().connectDeviceName,
|
||||
authUserID: CommonDataManage().currentKeyInfo.senderUserId!.toString(),
|
||||
keyID: CommonDataManage().currentKeyInfo.keyId.toString(),
|
||||
userID: await Storage.getUid(),
|
||||
openMode: 1,
|
||||
keyType: 0,
|
||||
startDate: CommonDataManage().currentKeyInfo.startDate!~/10000,
|
||||
expireDate: CommonDataManage().currentKeyInfo.endDate!~/10000,
|
||||
role: CommonDataManage().currentKeyInfo.keyRight == 1 ? 1 : 0,
|
||||
password: "123456",
|
||||
needAuthor: 1,
|
||||
publicKey: publicKeyDataList,
|
||||
privateKey: getPrivateKeyList,
|
||||
token: getTokenList);
|
||||
return addUserData.packageData();
|
||||
}
|
||||
|
||||
// 普通用户接收电子钥匙之后 更新锁用户NO
|
||||
void _updateLockUserNo() async {
|
||||
LockNetTokenEntity entity = await ApiRepository.to.updateLockUserNo(
|
||||
keyId: CommonDataManage().currentKeyInfo.keyId.toString(),
|
||||
lockUserNo: CommonDataManage().currentKeyInfo.lockUserNo.toString()
|
||||
);
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
eventBus.fire(LockAddUserSucceedEvent([0], 0));
|
||||
}
|
||||
}
|
||||
|
||||
dispose() {
|
||||
_replySubscription!.cancel();
|
||||
}
|
||||
}
|
||||
@ -1,15 +1,19 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import '../app_settings/app_settings.dart';
|
||||
import '../tools/commonDataManage.dart';
|
||||
import '../tools/eventBusEventManage.dart';
|
||||
import 'io_sender.dart';
|
||||
import 'io_type.dart';
|
||||
import 'io_tool/io_model.dart';
|
||||
import 'io_tool/manager_event_bus.dart';
|
||||
import 'sender_beforeDataManage.dart';
|
||||
|
||||
typedef CommandSendCallBack = void Function(ErrorType errorType);
|
||||
class CommandSenderManager {
|
||||
|
||||
static final CommandSenderManager _manager = CommandSenderManager
|
||||
._init();
|
||||
static final CommandSenderManager _manager = CommandSenderManager._init();
|
||||
factory CommandSenderManager()=>_manager;
|
||||
static CommandSenderManager getInstance()=>_manager;
|
||||
CommandSenderManager._init(){
|
||||
@ -17,7 +21,21 @@ class CommandSenderManager {
|
||||
}
|
||||
|
||||
init(){
|
||||
initLockAddUserSucceedEvent();
|
||||
}
|
||||
|
||||
// 下级界面修改成功后传递数据
|
||||
StreamSubscription? _passCurrentLockInformationEvent;
|
||||
List<int> dataBeforeAddTheUser = [];
|
||||
void initLockAddUserSucceedEvent() {
|
||||
// 蓝牙协议通知传输跟蓝牙之外的数据传输类不一样 eventBus
|
||||
_passCurrentLockInformationEvent = eventBus.on<LockAddUserSucceedEvent>().listen((event) {
|
||||
if(event.type == 0){
|
||||
_sendNormalData(dataBeforeAddTheUser);
|
||||
}else{
|
||||
_sendNormalData(event.dataList);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// CommandType lastCommandType = CommandType.readLockStatusInfo;
|
||||
@ -37,8 +55,17 @@ class CommandSenderManager {
|
||||
}
|
||||
|
||||
List<int> value = command.packageData();
|
||||
// print("sendData:${value}");
|
||||
_sendNormalData(value);
|
||||
print("CommonDataManage().currentLockUserNo:${CommonDataManage().currentLockUserNo}");
|
||||
if(CommonDataManage().currentLockUserNo == 0){
|
||||
// 先添加用户
|
||||
var entity = await SenderBeforeDataManage().getAddUserKeyData();
|
||||
_sendNormalData(entity);
|
||||
dataBeforeAddTheUser = value;
|
||||
return;
|
||||
}else{
|
||||
print("继续发送数据了继续发送数据了继续发送数据了");
|
||||
_sendNormalData(value);
|
||||
}
|
||||
}
|
||||
|
||||
void _sendNormalData(List<int> data) async {
|
||||
@ -102,4 +129,7 @@ class CommandSenderManager {
|
||||
// bufferList = [];
|
||||
// }
|
||||
|
||||
dispose() {
|
||||
_passCurrentLockInformationEvent?.cancel();
|
||||
}
|
||||
}
|
||||
@ -57,9 +57,9 @@ class LockDetailLogic extends BaseGetXController {
|
||||
}
|
||||
|
||||
// 添加用户
|
||||
if ((reply is AddUserReply) && (state.ifCurrentScreen.value == true)) {
|
||||
_replyAddUserKey(reply);
|
||||
}
|
||||
// if ((reply is AddUserReply) && (state.ifCurrentScreen.value == true)) {
|
||||
// _replyAddUserKey(reply);
|
||||
// }
|
||||
});
|
||||
}
|
||||
|
||||
@ -297,126 +297,126 @@ class LockDetailLogic extends BaseGetXController {
|
||||
}
|
||||
}
|
||||
|
||||
// 添加用户
|
||||
Future<void> _replyAddUserKey(Reply reply) async {
|
||||
var lockId = reply.data.sublist(2, 42);
|
||||
// print("lockId:$lockId");
|
||||
|
||||
var token = reply.data.sublist(42, 46);
|
||||
List<String> strTokenList = changeIntListToStringList(token);
|
||||
Storage.setStringList(saveBlueToken, strTokenList);
|
||||
// print("token:$token");
|
||||
|
||||
int status = reply.data[46];
|
||||
// print("status:$status reply.data:${reply.data}");
|
||||
|
||||
print("status:$status");
|
||||
switch (status) {
|
||||
case 0x00:
|
||||
//成功
|
||||
Get.log("添加用户数据解析成功");
|
||||
cancelBlueConnetctToastTimer();
|
||||
state.lockUserNo = reply.data[47];
|
||||
_updateLockUserNo();
|
||||
|
||||
break;
|
||||
case 0x06:
|
||||
//无权限
|
||||
Get.log("需要鉴权");
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
|
||||
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
||||
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
||||
|
||||
IoSenderManage.senderAddUser(
|
||||
lockID: BlueManage().connectDeviceName,
|
||||
authUserID: state.senderUserId.toString(),
|
||||
keyID: state.keyInfos.value.keyId.toString(),
|
||||
userID: await Storage.getUid(),
|
||||
openMode: 1,
|
||||
keyType: 0,
|
||||
startDate: state.keyInfos.value.startDate!~/10000,
|
||||
expireDate: state.keyInfos.value.endDate!~/10000,
|
||||
role: state.keyInfos.value.keyRight == 1 ? 1 : 0,
|
||||
password: "123456",
|
||||
needAuthor: 1,
|
||||
publicKey: publicKeyDataList,
|
||||
privateKey: getPrivateKeyList,
|
||||
token: token);
|
||||
break;
|
||||
default:
|
||||
//失败
|
||||
Get.log("领锁失败");
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
// // 添加用户
|
||||
// Future<void> _replyAddUserKey(Reply reply) async {
|
||||
// var lockId = reply.data.sublist(2, 42);
|
||||
// // print("lockId:$lockId");
|
||||
//
|
||||
// var token = reply.data.sublist(42, 46);
|
||||
// List<String> strTokenList = changeIntListToStringList(token);
|
||||
// Storage.setStringList(saveBlueToken, strTokenList);
|
||||
// // print("token:$token");
|
||||
//
|
||||
// int status = reply.data[46];
|
||||
// // print("status:$status reply.data:${reply.data}");
|
||||
//
|
||||
// print("status:$status");
|
||||
// switch (status) {
|
||||
// case 0x00:
|
||||
// //成功
|
||||
// Get.log("添加用户数据解析成功");
|
||||
// cancelBlueConnetctToastTimer();
|
||||
// state.lockUserNo = reply.data[47];
|
||||
// _updateLockUserNo();
|
||||
//
|
||||
// break;
|
||||
// case 0x06:
|
||||
// //无权限
|
||||
// Get.log("需要鉴权");
|
||||
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
//
|
||||
// var publicKey = await Storage.getStringList(saveBluePublicKey);
|
||||
// List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
||||
//
|
||||
// IoSenderManage.senderAddUser(
|
||||
// lockID: BlueManage().connectDeviceName,
|
||||
// authUserID: state.senderUserId.toString(),
|
||||
// keyID: state.keyInfos.value.keyId.toString(),
|
||||
// userID: await Storage.getUid(),
|
||||
// openMode: 1,
|
||||
// keyType: 0,
|
||||
// startDate: state.keyInfos.value.startDate!~/10000,
|
||||
// expireDate: state.keyInfos.value.endDate!~/10000,
|
||||
// role: state.keyInfos.value.keyRight == 1 ? 1 : 0,
|
||||
// password: "123456",
|
||||
// needAuthor: 1,
|
||||
// publicKey: publicKeyDataList,
|
||||
// privateKey: getPrivateKeyList,
|
||||
// token: token);
|
||||
// break;
|
||||
// default:
|
||||
// //失败
|
||||
// Get.log("领锁失败");
|
||||
//
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// 添加用户(普通用户接收电子钥匙)
|
||||
Future<void> addUserConnectBlue() async {
|
||||
showBlueConnetctToastTimer(action: () {
|
||||
state.openLockBtnState.value = 0;
|
||||
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
||||
});
|
||||
|
||||
// var listData = AddUserCommand(
|
||||
// lockID: BlueManage().connectDeviceName,
|
||||
// authUserID: state.senderUserId.toString(),
|
||||
// keyID: state.keyInfos.value.keyId.toString(),
|
||||
// userID: await Storage.getUid(),
|
||||
// openMode: 1,
|
||||
// keyType: 0,
|
||||
// startDate: state.keyInfos.value.startDate!~/10000,
|
||||
// expireDate: state.keyInfos.value.endDate!~/10000,
|
||||
// role: state.keyInfos.value.keyRight == 1 ? 1 : 0,
|
||||
// password: "123456",
|
||||
// needAuthor: 1,
|
||||
// publicKey: publicKeyDataList,
|
||||
// privateKey: getPrivateKeyList,
|
||||
// token: getTokenList).packageData();
|
||||
BlueManage().bludSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!, (BluetoothConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||||
// 私钥
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
|
||||
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
||||
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
||||
|
||||
var token = await Storage.getStringList(saveBlueToken);
|
||||
List<int> getTokenList = [0, 0, 0, 0];
|
||||
if (token != null) {
|
||||
getTokenList = changeStringListToIntList(token);
|
||||
}
|
||||
|
||||
Get.log("BlueManage().connectDeviceName:${BlueManage().connectDeviceName} authUserID:${state.senderUserId.toString()} keyID:${state.keyInfos.value.keyId.toString()} userID:${await Storage.getUid()}");
|
||||
IoSenderManage.senderAddUser(
|
||||
lockID: BlueManage().connectDeviceName,
|
||||
authUserID: state.senderUserId.toString(),
|
||||
keyID: state.keyInfos.value.keyId.toString(),
|
||||
userID: await Storage.getUid(),
|
||||
openMode: 1,
|
||||
keyType: 0,
|
||||
startDate: state.keyInfos.value.startDate!~/10000,
|
||||
expireDate: state.keyInfos.value.endDate!~/10000,
|
||||
role: state.keyInfos.value.keyRight == 1 ? 1 : 0,
|
||||
password: "123456",
|
||||
needAuthor: 1,
|
||||
publicKey: publicKeyDataList,
|
||||
privateKey: getPrivateKeyList,
|
||||
token: getTokenList);
|
||||
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
|
||||
cancelBlueConnetctToastTimer();
|
||||
if (state.ifCurrentScreen.value == true) {
|
||||
showBlueConnetctToast();
|
||||
}
|
||||
|
||||
state.openLockBtnState.value = 0;
|
||||
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
||||
}
|
||||
});
|
||||
}
|
||||
// Future<void> addUserConnectBlue() async {
|
||||
// showBlueConnetctToastTimer(action: () {
|
||||
// state.openLockBtnState.value = 0;
|
||||
// eventBus.fire(RefreshLockDetailInfoDataEvent());
|
||||
// });
|
||||
//
|
||||
// // var listData = AddUserCommand(
|
||||
// // lockID: BlueManage().connectDeviceName,
|
||||
// // authUserID: state.senderUserId.toString(),
|
||||
// // keyID: state.keyInfos.value.keyId.toString(),
|
||||
// // userID: await Storage.getUid(),
|
||||
// // openMode: 1,
|
||||
// // keyType: 0,
|
||||
// // startDate: state.keyInfos.value.startDate!~/10000,
|
||||
// // expireDate: state.keyInfos.value.endDate!~/10000,
|
||||
// // role: state.keyInfos.value.keyRight == 1 ? 1 : 0,
|
||||
// // password: "123456",
|
||||
// // needAuthor: 1,
|
||||
// // publicKey: publicKeyDataList,
|
||||
// // privateKey: getPrivateKeyList,
|
||||
// // token: getTokenList).packageData();
|
||||
// BlueManage().bludSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!, (BluetoothConnectionState deviceConnectionState) async {
|
||||
// if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||||
// // 私钥
|
||||
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
//
|
||||
// var publicKey = await Storage.getStringList(saveBluePublicKey);
|
||||
// List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
||||
//
|
||||
// var token = await Storage.getStringList(saveBlueToken);
|
||||
// List<int> getTokenList = [0, 0, 0, 0];
|
||||
// if (token != null) {
|
||||
// getTokenList = changeStringListToIntList(token);
|
||||
// }
|
||||
//
|
||||
// Get.log("BlueManage().connectDeviceName:${BlueManage().connectDeviceName} authUserID:${state.senderUserId.toString()} keyID:${state.keyInfos.value.keyId.toString()} userID:${await Storage.getUid()}");
|
||||
// IoSenderManage.senderAddUser(
|
||||
// lockID: BlueManage().connectDeviceName,
|
||||
// authUserID: state.senderUserId.toString(),
|
||||
// keyID: state.keyInfos.value.keyId.toString(),
|
||||
// userID: await Storage.getUid(),
|
||||
// openMode: 1,
|
||||
// keyType: 0,
|
||||
// startDate: state.keyInfos.value.startDate!~/10000,
|
||||
// expireDate: state.keyInfos.value.endDate!~/10000,
|
||||
// role: state.keyInfos.value.keyRight == 1 ? 1 : 0,
|
||||
// password: "123456",
|
||||
// needAuthor: 1,
|
||||
// publicKey: publicKeyDataList,
|
||||
// privateKey: getPrivateKeyList,
|
||||
// token: getTokenList);
|
||||
// } else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
|
||||
// cancelBlueConnetctToastTimer();
|
||||
// if (state.ifCurrentScreen.value == true) {
|
||||
// showBlueConnetctToast();
|
||||
// }
|
||||
//
|
||||
// state.openLockBtnState.value = 0;
|
||||
// eventBus.fire(RefreshLockDetailInfoDataEvent());
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// 点击开门事件
|
||||
Future<void> openDoorAction() async {
|
||||
@ -508,23 +508,23 @@ class LockDetailLogic extends BaseGetXController {
|
||||
}
|
||||
|
||||
// 普通用户接收电子钥匙之后 更新锁用户NO
|
||||
void _updateLockUserNo() async {
|
||||
LockNetTokenEntity entity = await ApiRepository.to.updateLockUserNo(
|
||||
keyId: state.keyInfos.value.keyId.toString(),
|
||||
lockUserNo: state.lockUserNo.toString()
|
||||
);
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
eventBus.fire(RefreshLockDetailInfoDataEvent());
|
||||
SchedulerBinding.instance.addPostFrameCallback((_) {
|
||||
eventBus.fire(RefreshLockListInfoDataEvent());
|
||||
});
|
||||
if (state.isOpenLockNeedOnline.value == 0) {
|
||||
openDoorAction();
|
||||
} else {
|
||||
getLockNetToken();
|
||||
}
|
||||
}
|
||||
}
|
||||
// void _updateLockUserNo() async {
|
||||
// LockNetTokenEntity entity = await ApiRepository.to.updateLockUserNo(
|
||||
// keyId: state.keyInfos.value.keyId.toString(),
|
||||
// lockUserNo: state.lockUserNo.toString()
|
||||
// );
|
||||
// if (entity.errorCode!.codeIsSuccessful) {
|
||||
// eventBus.fire(RefreshLockDetailInfoDataEvent());
|
||||
// SchedulerBinding.instance.addPostFrameCallback((_) {
|
||||
// eventBus.fire(RefreshLockListInfoDataEvent());
|
||||
// });
|
||||
// if (state.isOpenLockNeedOnline.value == 0) {
|
||||
// openDoorAction();
|
||||
// } else {
|
||||
// getLockNetToken();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// 查询锁记录最后时间
|
||||
void getLockRecordLastUploadDataTime() async {
|
||||
|
||||
@ -17,6 +17,7 @@ import '../../../blue/blue_manage.dart';
|
||||
import '../../../blue/io_tool/io_tool.dart';
|
||||
import '../../../common/XSConstantMacro/XSConstantMacro.dart';
|
||||
import '../../../tools/appRouteObserver.dart';
|
||||
import '../../../tools/commonDataManage.dart';
|
||||
import '../../../tools/dateTool.dart';
|
||||
import '../../../tools/eventBusEventManage.dart';
|
||||
import '../../../tools/storage.dart';
|
||||
@ -48,7 +49,6 @@ class _LockDetailPageState extends State<LockDetailPage>
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
Get.log("LockDetailPage initState1111");
|
||||
|
||||
// logic.startScanAction();
|
||||
|
||||
@ -66,7 +66,6 @@ class _LockDetailPageState extends State<LockDetailPage>
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
Get.log("LockDetailPage didChangeDependencies2222");
|
||||
|
||||
/// 路由订阅
|
||||
AppRouteObserver().routeObserver.subscribe(this, ModalRoute.of(context)!);
|
||||
@ -84,12 +83,15 @@ class _LockDetailPageState extends State<LockDetailPage>
|
||||
|
||||
void loadData() {
|
||||
state.keyInfos.value = widget.lockListInfoItemEntity;
|
||||
CommonDataManage().currentLockUserNo = state.keyInfos.value.lockUserNo!;
|
||||
CommonDataManage().currentKeyInfo = state.keyInfos.value;
|
||||
|
||||
state.lockUserNo = state.keyInfos.value.lockUserNo!;
|
||||
if (state.lockUserNo == 0) {
|
||||
state.bottomBtnisEable.value = false;
|
||||
} else {
|
||||
state.bottomBtnisEable.value = true;
|
||||
}
|
||||
// if (state.lockUserNo == 0) {
|
||||
// state.bottomBtnisEable.value = false;
|
||||
// } else {
|
||||
// state.bottomBtnisEable.value = true;
|
||||
// }
|
||||
// print("state.keyInfos.value.keyStatus:${state.keyInfos.value.keyStatus}");
|
||||
if (state.keyInfos.value.keyStatus ==
|
||||
XSConstantMacro.keyStatusWaitIneffective ||
|
||||
@ -989,10 +991,10 @@ class _LockDetailPageState extends State<LockDetailPage>
|
||||
state.openLockBtnState.value = 1;
|
||||
// state.animationController!.forward();
|
||||
|
||||
if (state.lockUserNo == 0) {
|
||||
// 电子钥匙lockUserNo为0 要先添加用户
|
||||
logic.addUserConnectBlue();
|
||||
} else {
|
||||
// if (state.lockUserNo == 0) {
|
||||
// // 电子钥匙lockUserNo为0 要先添加用户
|
||||
// logic.addUserConnectBlue();
|
||||
// } else {
|
||||
// print("state.isOpenLockNeedOnline.value:${state.isOpenLockNeedOnline.value}");
|
||||
if (state.isOpenLockNeedOnline.value == 0) {
|
||||
// 不需要联网
|
||||
@ -1002,7 +1004,7 @@ class _LockDetailPageState extends State<LockDetailPage>
|
||||
// 需要联网
|
||||
logic.getLockNetToken();
|
||||
}
|
||||
}
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
@ -1015,13 +1017,13 @@ class _LockDetailPageState extends State<LockDetailPage>
|
||||
state.openLockBtnState.value = 1;
|
||||
state.animationController!.forward();
|
||||
|
||||
if (state.lockUserNo == 0) {
|
||||
// 电子钥匙lockUserNo为0 要先添加用户
|
||||
logic.addUserConnectBlue();
|
||||
} else {
|
||||
// if (state.lockUserNo == 0) {
|
||||
// // 电子钥匙lockUserNo为0 要先添加用户
|
||||
// logic.addUserConnectBlue();
|
||||
// } else {
|
||||
state.openDoorModel = 32;
|
||||
logic.openDoorAction();
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
@override
|
||||
@ -1029,7 +1031,6 @@ class _LockDetailPageState extends State<LockDetailPage>
|
||||
// TODO: implement dispose
|
||||
|
||||
/// 取消路由订阅
|
||||
Get.log("LockDetailPage===dispose");
|
||||
AppRouteObserver().routeObserver.unsubscribe(this);
|
||||
state.closedUnlockSuccessfulTimer?.cancel();
|
||||
_lockRefreshLockDetailInfoDataEvent?.cancel();
|
||||
@ -1048,7 +1049,6 @@ class _LockDetailPageState extends State<LockDetailPage>
|
||||
@override
|
||||
void didPush() {
|
||||
super.didPush();
|
||||
Get.log("LockDetailPage===didPush");
|
||||
state.ifCurrentScreen.value = true;
|
||||
}
|
||||
|
||||
@ -1056,7 +1056,6 @@ class _LockDetailPageState extends State<LockDetailPage>
|
||||
@override
|
||||
void didPop() {
|
||||
super.didPop();
|
||||
Get.log("LockDetailPage===didPop");
|
||||
state.ifCurrentScreen.value = false;
|
||||
logic.cancelBlueConnetctToastTimer();
|
||||
BlueManage().stopScan();
|
||||
@ -1069,14 +1068,12 @@ class _LockDetailPageState extends State<LockDetailPage>
|
||||
void didPopNext() {
|
||||
super.didPopNext();
|
||||
state.ifCurrentScreen.value = true;
|
||||
Get.log("LockDetailPage===didPopNext");
|
||||
}
|
||||
|
||||
/// 进入下级界面 当前界面即将消失
|
||||
@override
|
||||
void didPushNext() {
|
||||
super.didPushNext();
|
||||
Get.log("LockDetailPage===didPushNext");
|
||||
state.ifCurrentScreen.value = false;
|
||||
logic.cancelBlueConnetctToastTimer();
|
||||
BlueManage().stopScan();
|
||||
|
||||
@ -16,6 +16,7 @@ import '../../../../blue/io_tool/manager_event_bus.dart';
|
||||
import '../../../../blue/sender_manage.dart';
|
||||
import '../../../../network/api_repository.dart';
|
||||
import '../../../../tools/baseGetXController.dart';
|
||||
import '../../../../tools/commonDataManage.dart';
|
||||
import '../../../../tools/eventBusEventManage.dart';
|
||||
import '../../../../tools/storage.dart';
|
||||
import 'checkingInInfoData_entity.dart';
|
||||
@ -406,6 +407,8 @@ class LockSetLogic extends BaseGetXController {
|
||||
);
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
state.lockSetInfoData.value = entity.data!;
|
||||
CommonDataManage().currentLockSetInfoData = entity.data!;
|
||||
|
||||
state.lockSettingInfo.value = state.lockSetInfoData.value.lockSettingInfo!;
|
||||
state.lockFeature.value = state.lockSetInfoData.value.lockFeature!;
|
||||
state.lockStatus.value = state.lockSetInfoData.value.lockStatus!;
|
||||
|
||||
@ -1,15 +1,10 @@
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
// import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../../../appRouters.dart';
|
||||
import '../../../app_settings/app_colors.dart';
|
||||
import '../../../blue/blue_manage.dart';
|
||||
import '../../../tools/appRouteObserver.dart';
|
||||
|
||||
@ -30,7 +30,7 @@ class SaveLockLogic extends BaseGetXController {
|
||||
late StreamSubscription<Reply> _replySubscription;
|
||||
void _initReplySubscription() {
|
||||
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((reply) {
|
||||
if (reply is AddUserReply) {
|
||||
if (reply is AddUserReply && state.ifCurrentScreen.value == true) {
|
||||
_replyAddUserKey(reply);
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,9 @@
|
||||
// 实现一个CommonDataManage的单例,用来管理项目中使用的一些公共数据
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart';
|
||||
import '../main/lockMian/entity/lockListInfo_entity.dart';
|
||||
|
||||
class CommonDataManage {
|
||||
static CommonDataManage? _manager;
|
||||
CommonDataManage._init();
|
||||
@ -20,12 +23,15 @@ class CommonDataManage {
|
||||
set setMainLockCount(int v) => _mainLockCount.value = v;
|
||||
get getMainLockCount => _mainLockCount;
|
||||
|
||||
// 锁信息
|
||||
LockListInfoItemEntity currentKeyInfo = LockListInfoItemEntity();
|
||||
|
||||
// 当前锁的用户编号
|
||||
int currentLockUserNo = 0;
|
||||
// set setCurrentLockUserNo(int v) => _currentLockUserNo = v;
|
||||
// get getCurrentLockUserNo => _currentLockUserNo;
|
||||
|
||||
|
||||
LockSetInfoData currentLockSetInfoData = LockSetInfoData();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -10,6 +10,13 @@ class RefreshLockListInfoDataEvent {
|
||||
RefreshLockListInfoDataEvent();
|
||||
}
|
||||
|
||||
/// 蓝牙添加用户成功
|
||||
class LockAddUserSucceedEvent {
|
||||
int type; // 0用户号更新成功 1token失效
|
||||
List<int> dataList;
|
||||
LockAddUserSucceedEvent(this.dataList, this.type);
|
||||
}
|
||||
|
||||
/// 刷新锁详情数据
|
||||
class RefreshLockDetailInfoDataEvent {
|
||||
RefreshLockDetailInfoDataEvent();
|
||||
|
||||
@ -207,7 +207,7 @@ class Storage {
|
||||
if (data != null && data.isNotEmpty) {
|
||||
lockListInfoGroupEntity = LockListInfoGroupEntity.fromJson(jsonDecode(data));
|
||||
}
|
||||
print("lockListInfoEntity:$lockListInfoGroupEntity");
|
||||
return lockListInfoGroupEntity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user