724 lines
26 KiB
Dart
724 lines
26 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/blue/io_protocol/io_deletUser.dart';
|
|
import 'package:star_lock/blue/io_type.dart';
|
|
|
|
import '../../../../appRouters.dart';
|
|
import '../../../../blue/blue_manage.dart';
|
|
import '../../../../blue/io_protocol/io_factoryDataReset.dart';
|
|
import '../../../../blue/io_protocol/io_readSupportFunctionsNoParameters.dart';
|
|
import '../../../../blue/io_protocol/io_setSupportFunctionsNoParameters.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 '../../../../network/api_repository.dart';
|
|
import '../../../../tools/baseGetXController.dart';
|
|
import '../../../../tools/eventBusEventManage.dart';
|
|
import '../../../../tools/showTFView.dart';
|
|
import '../../../../tools/storage.dart';
|
|
import '../../../../tools/toast.dart';
|
|
import '../../../../translations/trans_lib.dart';
|
|
import 'checkingInInfoData_entity.dart';
|
|
import 'lockSet_state.dart';
|
|
|
|
typedef BlockSetStateCallback = void Function();
|
|
typedef BlockSetCheckInCallback = void Function(CheckingInInfoDataEntity checkingInInfoDataEntity);
|
|
|
|
class LockSetLogic extends BaseGetXController {
|
|
final LockSetState state = LockSetState();
|
|
|
|
// 监听蓝牙协议返回结果
|
|
late StreamSubscription<Reply> _replySubscription;
|
|
void _initReplySubscription() {
|
|
_replySubscription =
|
|
EventBusManager().eventBus!.on<Reply>().listen((reply) async {
|
|
// 删除用户
|
|
if (reply is DeletUserReply) {
|
|
_replyDeletUserKey(reply);
|
|
}
|
|
|
|
// 恢复出厂设置
|
|
if (reply is FactoryDataResetReply) {
|
|
_replyFactoryDataResetKey(reply);
|
|
}
|
|
|
|
// 设置支持功能(不带参数)
|
|
if (reply is SetSupportFunctionsNoParametersReply) {
|
|
_replySetSupportFunctionsWithParameters(reply);
|
|
}
|
|
|
|
// 读取支持功能(不带参数)
|
|
if ((reply is ReadSupportFunctionsNoParametersReply) &&
|
|
(state.settingUpSupportFeatures == 56)) {
|
|
_readSupportFunctionsWithParametersReply(reply);
|
|
}
|
|
});
|
|
}
|
|
|
|
// 删除用户
|
|
Future<void> _replyDeletUserKey(Reply reply) async {
|
|
var tokenData = reply.data.sublist(2, 6);
|
|
var saveStrList = changeIntListToStringList(tokenData);
|
|
print("openDoorToken:$tokenData");
|
|
Storage.setStringList(saveBlueToken, saveStrList);
|
|
|
|
int status = reply.data[6];
|
|
print("status:$status");
|
|
switch (status) {
|
|
case 0x00:
|
|
//成功
|
|
print("${reply.commandType}解析成功");
|
|
dismissEasyLoading();
|
|
cancelBlueConnetctToastTimer();
|
|
deletKeyData();
|
|
break;
|
|
case 0x06:
|
|
//无权限
|
|
print("${reply.commandType}需要鉴权");
|
|
|
|
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
|
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
|
|
|
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
|
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
|
|
|
IoSenderManage.deletUser(
|
|
lockID: BlueManage().connectDeviceName,
|
|
authUserID: await Storage.getUid(),
|
|
keyID: "1",
|
|
delUserID: await Storage.getUid(),
|
|
needAuthor: 1,
|
|
publicKey: publicKeyDataList,
|
|
privateKey: getPrivateKeyList,
|
|
token: tokenData);
|
|
break;
|
|
case 0x07:
|
|
//无权限
|
|
print("${reply.commandType!.typeValue} 用户无权限");
|
|
dismissEasyLoading();
|
|
showToast("用户无权限");
|
|
break;
|
|
case 0x09:
|
|
// 权限校验错误
|
|
print("${reply.commandType!.typeValue} ");
|
|
dismissEasyLoading();
|
|
showToast("权限校验错误");
|
|
break;
|
|
default:
|
|
//失败
|
|
print("${reply.commandType!.typeValue} 失败");
|
|
dismissEasyLoading();
|
|
showToast("删除失败");
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 恢复出厂设置数据解析
|
|
Future<void> _replyFactoryDataResetKey(Reply reply) async {
|
|
var token = reply.data.sublist(2, 6);
|
|
var saveStrList = changeIntListToStringList(token);
|
|
print("_replyFactoryDataResetKeyToken:$token");
|
|
Storage.setStringList(saveBlueToken, saveStrList);
|
|
|
|
int status = reply.data[6];
|
|
print("status:$status");
|
|
|
|
switch (status) {
|
|
case 0x00:
|
|
//成功
|
|
print("${reply.commandType!.typeValue} 数据解析成功");
|
|
dismissEasyLoading();
|
|
cancelBlueConnetctToastTimer();
|
|
deletLockInfoData();
|
|
break;
|
|
case 0x06:
|
|
//无权限
|
|
print("${reply.commandType!.typeValue} 需要鉴权");
|
|
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!);
|
|
|
|
IoSenderManage.senderFactoryDataReset(
|
|
lockID: BlueManage().connectDeviceName,
|
|
userID: await Storage.getUid(),
|
|
keyID: "1",
|
|
needAuthor: 1,
|
|
publicKey: publicKeyDataList,
|
|
privateKey: getPrivateKeyList,
|
|
token: getTokenList);
|
|
break;
|
|
case 0x07:
|
|
//无权限
|
|
print("${reply.commandType!.typeValue} 用户无权限");
|
|
dismissEasyLoading();
|
|
showToast("用户无权限");
|
|
break;
|
|
case 0x09:
|
|
// 权限校验错误
|
|
print("${reply.commandType!.typeValue} ");
|
|
dismissEasyLoading();
|
|
showToast("权限校验错误");
|
|
break;
|
|
default:
|
|
//失败
|
|
print("${reply.commandType!.typeValue} 失败");
|
|
dismissEasyLoading();
|
|
showToast("权限校验错误");
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 读取支持功能带参数数据解析
|
|
Future<void> _readSupportFunctionsWithParametersReply(Reply reply) async {
|
|
int status = reply.data[2];
|
|
switch (status) {
|
|
case 0x00:
|
|
//成功
|
|
print("${reply.commandType}数据解析成功");
|
|
state.isOpenBlueBroadcast.value = reply.data[6];
|
|
print("isOpenBlueBroadcast:${state.isOpenBlueBroadcast.value}");
|
|
break;
|
|
case 0x06:
|
|
//无权限
|
|
print("${reply.commandType}需要鉴权");
|
|
break;
|
|
case 0x07:
|
|
//无权限
|
|
print("${reply.commandType}用户无权限");
|
|
break;
|
|
case 0x09:
|
|
// 权限校验错误
|
|
print("${reply.commandType}权限校验错误");
|
|
break;
|
|
default:
|
|
//失败
|
|
print("${reply.commandType}失败");
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 锁设置数据解析
|
|
Future<void> _replySetSupportFunctionsWithParameters(Reply reply) async {
|
|
int status = reply.data[2];
|
|
switch (status) {
|
|
case 0x00:
|
|
//成功
|
|
print("${reply.commandType}数据解析成功");
|
|
// Toast.show(msg: "操作成功");featureEnable = state.isOpenStayWarn.value == 1 ? 0 : 1;
|
|
if (state.settingUpSupportFeatures == 55) {
|
|
// APP开锁时是否需联网
|
|
// state.isOpenLockNeedOnline.value = state.isOpenLockNeedOnline.value == 1 ? 0 : 1;
|
|
// state.lockSetInfoData.value.lockSettingInfo!.appUnlockOnline = state.isOpenLockNeedOnline.value;
|
|
setLockSetOpenLockNeedOnline();
|
|
// eventBus.fire(LockSetChangeSetRefreshLockDetailWithType(0, state.lockSetInfoData.value.lockSettingInfo!.appUnlockOnline!));
|
|
} else if (state.settingUpSupportFeatures == 56) {
|
|
// 蓝牙广播
|
|
state.isOpenBlueBroadcast.value =
|
|
state.isOpenBlueBroadcast.value == 1 ? 0 : 1;
|
|
state.lockSetInfoData.value.lockSettingInfo!.bluetoothBroadcast =
|
|
state.isOpenBlueBroadcast.value;
|
|
} else if (state.settingUpSupportFeatures == 61) {
|
|
// 逗留警告
|
|
state.isOpenStayWarn.value = state.isOpenStayWarn.value == 1 ? 0 : 1;
|
|
state.lockSetInfoData.value.lockSettingInfo!.stayWarn =
|
|
state.isOpenStayWarn.value;
|
|
} else if (state.settingUpSupportFeatures == 62) {
|
|
// 异常警告
|
|
state.isOpenExceptionWarnings.value =
|
|
state.isOpenExceptionWarnings.value == 1 ? 0 : 1;
|
|
state.lockSetInfoData.value.lockSettingInfo!.abnormalWarn =
|
|
state.isOpenExceptionWarnings.value;
|
|
}
|
|
print("isOpenBlueBroadcast111:${state.isOpenBlueBroadcast.value}");
|
|
break;
|
|
case 0x06:
|
|
//无权限
|
|
print("${reply.commandType}需要鉴权");
|
|
|
|
break;
|
|
case 0x07:
|
|
//无权限
|
|
print("${reply.commandType}用户无权限");
|
|
|
|
break;
|
|
case 0x09:
|
|
// 权限校验错误
|
|
print("${reply.commandType}权限校验错误");
|
|
|
|
break;
|
|
default:
|
|
//失败
|
|
print("${reply.commandType}失败");
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 删除用户
|
|
Future<void> deletUserAction() async {
|
|
showEasyLoading();
|
|
showBlueConnetctToastTimer(isShowBlueConnetctToast: false, action: (){
|
|
dismissEasyLoading();
|
|
showDeletAlertTipDialog(Get.context!);
|
|
});
|
|
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
|
if (connectionState == DeviceConnectionState.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 = changeStringListToIntList(token!);
|
|
|
|
IoSenderManage.deletUser(
|
|
lockID: BlueManage().connectDeviceName,
|
|
authUserID: state.lockBasicInfo.value.senderUserId.toString(),
|
|
keyID: state.lockBasicInfo.value.keyId.toString(),
|
|
delUserID: await Storage.getUid(),
|
|
// authUserID: "100001",
|
|
// keyID: "1",
|
|
// delUserID: "100001",
|
|
needAuthor: 1,
|
|
publicKey: publicKeyDataList,
|
|
privateKey: getPrivateKeyList,
|
|
token: getTokenList);
|
|
} else if (connectionState == DeviceConnectionState.disconnected) {
|
|
dismissEasyLoading();
|
|
cancelBlueConnetctToastTimer();
|
|
showDeletAlertTipDialog(Get.context!);
|
|
}
|
|
});
|
|
}
|
|
|
|
// 恢复出厂设置
|
|
Future<void> factoryDataResetAction() async {
|
|
showEasyLoading();
|
|
showBlueConnetctToastTimer(isShowBlueConnetctToast: false, action: (){
|
|
dismissEasyLoading();
|
|
showDeletAlertTipDialog(Get.context!);
|
|
});
|
|
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
|
if (connectionState == DeviceConnectionState.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 = changeStringListToIntList(token!);
|
|
|
|
IoSenderManage.senderFactoryDataReset(
|
|
lockID: BlueManage().connectDeviceName,
|
|
userID: await Storage.getUid(),
|
|
keyID: "1",
|
|
needAuthor: 1,
|
|
publicKey: publicKeyDataList,
|
|
privateKey: getPrivateKeyList,
|
|
token: getTokenList);
|
|
} else if (connectionState == DeviceConnectionState.disconnected) {
|
|
dismissEasyLoading();
|
|
cancelBlueConnetctToastTimer();
|
|
showDeletAlertTipDialog(Get.context!);
|
|
}
|
|
});
|
|
}
|
|
|
|
// 读取支持功能-带参数
|
|
// Future<void> _readSupportFunctionsNoParameters(int type) async {
|
|
// BlueManage().bludSendData(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
|
// if (connectionState == DeviceConnectionState.connected) {
|
|
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
|
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
|
//
|
|
// var token = await Storage.getStringList(saveBlueToken);
|
|
// List<int> getTokenList = changeStringListToIntList(token!);
|
|
//
|
|
// var publicKey = await Storage.getStringList(saveBluePublicKey);
|
|
// List<int> getPublicKeyList = changeStringListToIntList(publicKey!);
|
|
//
|
|
// IoSenderManage.readSupportFunctionsNoParametersCommand(
|
|
// keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(),
|
|
// userID: await Storage.getUid(),
|
|
// featureBit: type,
|
|
// token: getTokenList,
|
|
// needAuthor: 1,
|
|
// publicKey: getPublicKeyList,
|
|
// privateKey: getPrivateKeyList
|
|
// );
|
|
// }
|
|
// }, isShowLoading: true);
|
|
// }
|
|
|
|
// 设置支持功能(带参数)
|
|
Future<void> sendBurglarAlarm(int type) async {
|
|
showEasyLoading();
|
|
showBlueConnetctToastTimer();
|
|
BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async {
|
|
cancelBlueConnetctToastTimer();
|
|
if (connectionState == DeviceConnectionState.connected) {
|
|
dismissEasyLoading();
|
|
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
|
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
|
|
|
var token = await Storage.getStringList(saveBlueToken);
|
|
List<int> getTokenList = changeStringListToIntList(token!);
|
|
|
|
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
|
List<int> getPublicKeyList = changeStringListToIntList(publicKey!);
|
|
|
|
state.settingUpSupportFeatures = type;
|
|
|
|
var featureEnable = 0;
|
|
if (type == 55) {
|
|
// APP开锁时是否需联网
|
|
featureEnable = state.isOpenLockNeedOnline.value == 1 ? 0 : 1;
|
|
} else if (type == 56) {
|
|
// 蓝牙广播
|
|
featureEnable = state.isOpenBlueBroadcast.value == 1 ? 0 : 1;
|
|
} else if (type == 61) {
|
|
// 逗留警告
|
|
featureEnable = state.isOpenStayWarn.value == 1 ? 0 : 1;
|
|
} else if (type == 62) {
|
|
// 异常警告
|
|
featureEnable = state.isOpenExceptionWarnings.value == 1 ? 0 : 1;
|
|
}
|
|
IoSenderManage.setSupportFunctionsNoParametersCommand(
|
|
keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(),
|
|
userID: await Storage.getUid(),
|
|
featureBit: type,
|
|
featureEnable: featureEnable,
|
|
token: getTokenList,
|
|
needAuthor: 1,
|
|
publicKey: getPublicKeyList,
|
|
privateKey: getPrivateKeyList);
|
|
} else if (connectionState == DeviceConnectionState.disconnected) {
|
|
dismissEasyLoading();
|
|
showBlueConnetctToast();
|
|
}
|
|
});
|
|
}
|
|
|
|
// 获取锁设置信息
|
|
void getLockSettingInfoData() async {
|
|
var entity = await ApiRepository.to.getLockSettingInfoData(
|
|
lockId: state.lockId.toString(),
|
|
);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
state.lockSetInfoData.value = entity.data!;
|
|
state.lockSettingInfo.value =
|
|
state.lockSetInfoData.value.lockSettingInfo!;
|
|
state.lockFeature.value = state.lockSetInfoData.value.lockFeature!;
|
|
state.lockStatus.value = state.lockSetInfoData.value.lockStatus!;
|
|
state.lockBasicInfo.value = state.lockSetInfoData.value.lockBasicInfo!;
|
|
|
|
state.isAttendance.value = state.lockSettingInfo.value.attendance!;
|
|
state.isOpenLockNeedOnline.value =
|
|
state.lockSettingInfo.value.appUnlockOnline!;
|
|
|
|
state.isOpenBlueBroadcast.value =
|
|
state.lockSettingInfo.value.bluetoothBroadcast!;
|
|
state.isOpenExceptionWarnings.value =
|
|
state.lockSettingInfo.value.bluetoothBroadcast!;
|
|
|
|
// await _readSupportFunctionsNoParameters(56);
|
|
// _readSupportFunctionsNoParameters(62);
|
|
}
|
|
}
|
|
|
|
// 当是锁拥有者的时候,删除锁
|
|
void deletLockInfoData() async {
|
|
var entity = await ApiRepository.to.deletOwnerLockData(
|
|
lockId: state.lockSetInfoData.value.lockId.toString(),
|
|
);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
BlueManage().connectDeviceMacAddress = "";
|
|
eventBus.fire(RefreshLockListInfoDataEvent());
|
|
Get.close(2);
|
|
}
|
|
}
|
|
|
|
// 当不是锁拥有者的时候,删除钥匙
|
|
void deletKeyData() async {
|
|
var entity = await ApiRepository.to.deletOwnerKeyData(
|
|
lockId: state.lockSetInfoData.value.lockId.toString(),
|
|
keyId: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(),
|
|
);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
BlueManage().connectDeviceMacAddress = "";
|
|
eventBus.fire(RefreshLockListInfoDataEvent());
|
|
Get.close(2);
|
|
// Get.offAllNamed(Routers.starLockMain);
|
|
}
|
|
}
|
|
|
|
void showDeletPasswordAlertDialog(BuildContext context) {
|
|
// 点击删除 开始扫描
|
|
BlueManage().startScan();
|
|
showDialog(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return ShowTFView(
|
|
title: "请输入登录密码",
|
|
tipTitle: "",
|
|
controller: state.passwordTF,
|
|
sureClick: () {
|
|
//发送删除锁请求
|
|
if (state.passwordTF.text.isEmpty) {
|
|
Toast.show(msg: "请输入登录密码");
|
|
return;
|
|
}
|
|
checkLoginPassword();
|
|
},
|
|
cancelClick: () {
|
|
// 取消的时候停止扫描
|
|
BlueManage().stopScan();
|
|
Get.back();
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
// 查询账户密码
|
|
void checkLoginPassword() async {
|
|
var entity = await ApiRepository.to.checkLoginPassword(
|
|
password: state.passwordTF.text,
|
|
);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
Get.back();
|
|
|
|
// if(BlueManage().deviceConnectionState == DeviceConnectionState.connected){
|
|
// // 如果是已连接状态 直接调用协议
|
|
// // 已配对 表示这把锁未被初始化,还处于被添加状态
|
|
// if (state.lockSetInfoData.value.lockBasicInfo!.isLockOwner == 1) {
|
|
// // 如果是锁拥有者直接删除锁,调用初始化协议
|
|
// factoryDataResetAction();
|
|
// } else {
|
|
// // 不是锁拥有者,调用删除钥匙协议
|
|
// deletUserAction();
|
|
// }
|
|
// return;
|
|
// }
|
|
|
|
if (state.currentDeviceUUid.value.isNotEmpty) {
|
|
// 已经扫描到了当前设备 停止扫描,直接删除锁
|
|
BlueManage().stopScan();
|
|
deletLockLogic();
|
|
} else {
|
|
// 未扫描到 然后循环5秒扫秒
|
|
var index = 0;
|
|
showEasyLoading();
|
|
state.deletWaitScanCompleter = Completer();
|
|
state.deletWaitScanTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
|
//定时任务
|
|
if(index >= 5){
|
|
// 当超过10秒的时候还是没有搜索到,完成任务,关闭扫描,取消定时器,弹窗提示
|
|
if(state.deletWaitScanTimer != null){
|
|
state.deletWaitScanTimer!.cancel();
|
|
}
|
|
if(state.deletWaitScanCompleter != null){
|
|
state.deletWaitScanCompleter!.complete();
|
|
}
|
|
BlueManage().stopScan();
|
|
dismissEasyLoading();
|
|
showDeletAlertTipDialog(Get.context!);
|
|
}else{
|
|
// 每秒判断获取是否搜到了当前设备
|
|
if (state.currentDeviceUUid.isNotEmpty) {
|
|
BlueManage().stopScan();
|
|
// 存在的时候销毁定时器,赋值
|
|
if(state.deletWaitScanTimer != null){
|
|
state.deletWaitScanTimer!.cancel();
|
|
}
|
|
if(state.deletWaitScanCompleter != null){
|
|
state.deletWaitScanCompleter!.complete();
|
|
}
|
|
dismissEasyLoading();
|
|
|
|
deletLockLogic();
|
|
} else {
|
|
// 不存在的时候返回-1 然后循环5秒
|
|
index++;
|
|
// print("index:$index");
|
|
}
|
|
}
|
|
});
|
|
// 等待Completer完成
|
|
await state.deletWaitScanCompleter!.future;
|
|
}
|
|
}
|
|
}
|
|
|
|
void deletLockLogic() {
|
|
// 当扫描的数组里面是否有当前设备
|
|
if(state.currentDeviceUUid.value[31] == "1"){
|
|
// 已配对 表示这把锁未被初始化,还处于被添加状态
|
|
if (state.lockSetInfoData.value.lockBasicInfo!.isLockOwner == 1) {
|
|
// 如果是锁拥有者直接删除锁,调用初始化协议
|
|
factoryDataResetAction();
|
|
} else {
|
|
// 不是锁拥有者,调用删除钥匙协议
|
|
deletUserAction();
|
|
}
|
|
}else if(state.currentDeviceUUid.value[31] == "0"){
|
|
// 未配对 表示这把锁已被强制初始化 处于可添加状态 直接弹窗删除即可
|
|
showDeletAlertTipDialog(Get.context!);
|
|
}
|
|
}
|
|
|
|
// 开启考勤获取是否有公司
|
|
void openCheckingInData(BlockSetCheckInCallback blockSetCheckInCallback) async {
|
|
var entity = await ApiRepository.to.openCheckingInData(
|
|
lockId: state.lockSetInfoData.value.lockId.toString(),
|
|
);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
blockSetCheckInCallback(entity);
|
|
}
|
|
}
|
|
|
|
// 设置是否打开考勤
|
|
void setLockSetGeneralSetting() async {
|
|
var entity = await ApiRepository.to.setCheckInData(
|
|
lockId: state.lockSetInfoData.value.lockId!,
|
|
attendance: state.isAttendance.value == 1 ? 0 : 1,
|
|
);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
eventBus.fire(RefreshLockListInfoDataEvent());
|
|
|
|
state.isAttendance.value = (state.isAttendance.value == 1 ? 0 : 1);
|
|
state.lockSettingInfo.value.attendance = state.isAttendance.value;
|
|
|
|
eventBus.fire(LockSetChangeSetRefreshLockDetailWithType(0, state.lockSettingInfo.value.attendance!));
|
|
print("state.lockSettingInfo.value.attendance:${state.lockSettingInfo.value.attendance}");
|
|
Toast.show(msg: "设置成功");
|
|
}
|
|
}
|
|
|
|
// 设置是否打开开锁提醒
|
|
void setLockPickingReminder() async {
|
|
var entity = await ApiRepository.to.setLockPickingReminderData(
|
|
lockId: state.lockSetInfoData.value.lockId!,
|
|
unlockReminderPush: state.isLockPickingReminder.value == 1 ? 0 : 1,
|
|
);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
eventBus.fire(RefreshLockListInfoDataEvent());
|
|
|
|
state.isLockPickingReminder.value = (state.isLockPickingReminder.value == 1 ? 0 : 1);
|
|
state.lockSettingInfo.value.unlockReminderPush = state.isLockPickingReminder.value;
|
|
Toast.show(msg: "设置成功");
|
|
} else {}
|
|
}
|
|
|
|
// 设置是否打开开锁时是否需联网
|
|
void setLockSetOpenLockNeedOnline() async {
|
|
var entity = await ApiRepository.to.setOpenLockNeedOnlineData(
|
|
lockId: state.lockSetInfoData.value.lockId!,
|
|
appUnlockOnline: state.isOpenLockNeedOnline.value == 1 ? 0 : 1,
|
|
);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
eventBus.fire(RefreshLockListInfoDataEvent());
|
|
|
|
state.isOpenLockNeedOnline.value = (state.isOpenLockNeedOnline.value == 1 ? 0 : 1);
|
|
state.lockSettingInfo.value.appUnlockOnline = state.isOpenLockNeedOnline.value;
|
|
|
|
eventBus.fire(LockSetChangeSetRefreshLockDetailWithType(0, state.lockSettingInfo.value.appUnlockOnline!));
|
|
print("state.lockSettingInfo.value.appUnlockOnline:${state.lockSettingInfo.value.appUnlockOnline}");
|
|
Toast.show(msg: "设置成功");
|
|
}
|
|
}
|
|
|
|
// 下级界面修改成功后传递数据
|
|
StreamSubscription? _passCurrentLockInformationEvent;
|
|
void initLoadDataAction(BlockSetStateCallback blockSetStateCallback) {
|
|
// 蓝牙协议通知传输跟蓝牙之外的数据传输类不一样 eventBus
|
|
_passCurrentLockInformationEvent = eventBus.on<PassCurrentLockInformationEvent>().listen((event) {
|
|
// state.lockSetInfoData.value = event.keyInfo;
|
|
blockSetStateCallback();
|
|
});
|
|
}
|
|
|
|
late StreamSubscription<List<DiscoveredDevice>>_scanListDiscoveredDeviceSubscription;
|
|
void _scanListDiscoveredDeviceSubscriptionAction() {
|
|
_scanListDiscoveredDeviceSubscription = EventBusManager().eventBus!.on<List<DiscoveredDevice>>().listen((List<DiscoveredDevice> list) {
|
|
final knownDeviceIndex = list.indexWhere((d) => d.name == BlueManage().connectDeviceName);
|
|
if (knownDeviceIndex >= 0) {
|
|
// 存在的时候赋值
|
|
state.currentDeviceUUid.value = (list[knownDeviceIndex].serviceUuids.isNotEmpty ? list[knownDeviceIndex].serviceUuids[0] : "").toString();
|
|
}
|
|
});
|
|
}
|
|
|
|
void showDeletAlertTipDialog(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: () {
|
|
Navigator.pop(context);
|
|
if (state.lockSetInfoData.value.lockBasicInfo!.isLockOwner == 1) {
|
|
// 直接调用删除锁接口
|
|
deletLockInfoData();
|
|
} else {
|
|
// 直接调用删除要是接口
|
|
deletKeyData();
|
|
}
|
|
},
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
@override
|
|
void onReady() {
|
|
// TODO: implement onReady
|
|
super.onReady();
|
|
|
|
getLockSettingInfoData();
|
|
|
|
_initReplySubscription();
|
|
_scanListDiscoveredDeviceSubscriptionAction();
|
|
}
|
|
|
|
@override
|
|
void onInit() {
|
|
// TODO: implement onInit
|
|
super.onInit();
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
// TODO: implement onClose
|
|
|
|
_replySubscription.cancel();
|
|
_passCurrentLockInformationEvent!.cancel();
|
|
_scanListDiscoveredDeviceSubscription.cancel();
|
|
}
|
|
}
|