fix:调整配网逻辑
This commit is contained in:
parent
d75754e14e
commit
ea01d79bbd
@ -181,17 +181,28 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
|||||||
// 保存到缓存
|
// 保存到缓存
|
||||||
await Storage.saveLockNetWorkInfo(jsonMap);
|
await Storage.saveLockNetWorkInfo(jsonMap);
|
||||||
|
|
||||||
await _getUploadLockSet();
|
showToast('配网成功'.tr, something: () {
|
||||||
|
state.sureBtnState.value = 0; // 确保重置状态
|
||||||
|
if (state.pageName.value == 'lockSet') {
|
||||||
|
Get.close(2);
|
||||||
|
} else {
|
||||||
|
Get.offAllNamed(Routers.starLockMain);
|
||||||
|
}
|
||||||
|
eventBus.fire(SuccessfulDistributionNetwork());
|
||||||
|
});
|
||||||
|
|
||||||
|
// 获取锁设置
|
||||||
|
_getUploadLockSet();
|
||||||
} else {
|
} else {
|
||||||
dismissEasyLoading();
|
dismissEasyLoading();
|
||||||
showToast('网络配置失败,请重试'.tr);
|
// showToast('网络配置失败,请重试'.tr);
|
||||||
state.sureBtnState.value = 0;
|
state.sureBtnState.value = 0;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (EasyLoading.isShow) {
|
if (EasyLoading.isShow) {
|
||||||
dismissEasyLoading();
|
dismissEasyLoading();
|
||||||
}
|
}
|
||||||
showToast('解析配网信息失败,请重试'.tr);
|
// showToast('解析配网信息失败,请重试'.tr);
|
||||||
state.sureBtnState.value = 0; // 确保重置状态
|
state.sureBtnState.value = 0; // 确保重置状态
|
||||||
AppLog.log('解析配网信息失败: $e');
|
AppLog.log('解析配网信息失败: $e');
|
||||||
return; // 添加return阻止后续流程
|
return; // 添加return阻止后续流程
|
||||||
@ -203,7 +214,7 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
|||||||
if (EasyLoading.isShow) {
|
if (EasyLoading.isShow) {
|
||||||
dismissEasyLoading();
|
dismissEasyLoading();
|
||||||
}
|
}
|
||||||
showToast('WiFi密码错误,请重新输入'.tr);
|
// showToast('WiFi密码错误,请重新输入'.tr);
|
||||||
state.sureBtnState.value = 0; // 确保重置状态
|
state.sureBtnState.value = 0; // 确保重置状态
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -212,7 +223,7 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
|||||||
if (EasyLoading.isShow) {
|
if (EasyLoading.isShow) {
|
||||||
dismissEasyLoading();
|
dismissEasyLoading();
|
||||||
}
|
}
|
||||||
showToast('找不到该WiFi网络,请确认WiFi名称正确'.tr);
|
// showToast('找不到该WiFi网络,请确认WiFi名称正确'.tr);
|
||||||
state.sureBtnState.value = 0; // 确保重置状态
|
state.sureBtnState.value = 0; // 确保重置状态
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -221,7 +232,7 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
|||||||
if (EasyLoading.isShow) {
|
if (EasyLoading.isShow) {
|
||||||
dismissEasyLoading();
|
dismissEasyLoading();
|
||||||
}
|
}
|
||||||
showToast('连接WiFi超时,请确保网络信号良好'.tr);
|
// showToast('连接WiFi超时,请确保网络信号良好'.tr);
|
||||||
state.sureBtnState.value = 0; // 确保重置状态
|
state.sureBtnState.value = 0; // 确保重置状态
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -230,7 +241,7 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
|||||||
if (EasyLoading.isShow) {
|
if (EasyLoading.isShow) {
|
||||||
dismissEasyLoading();
|
dismissEasyLoading();
|
||||||
}
|
}
|
||||||
showToast('配网失败 (错误码: $status),请重试'.tr);
|
// showToast('配网失败 (错误码: $status),请重试'.tr);
|
||||||
state.sureBtnState.value = 0; // 确保重置状态
|
state.sureBtnState.value = 0; // 确保重置状态
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -315,12 +326,15 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 设置蓝牙操作超时处理
|
// 设置蓝牙操作超时处理
|
||||||
showBlueConnetctToastTimer(action: () {
|
showBlueConnetctToastTimer(
|
||||||
if (EasyLoading.isShow) {
|
action: () {
|
||||||
dismissEasyLoading();
|
if (EasyLoading.isShow) {
|
||||||
}
|
dismissEasyLoading();
|
||||||
state.sureBtnState.value = 0; // 连接超时时重置状态
|
}
|
||||||
});
|
state.sureBtnState.value = 0; // 连接超时时重置状态
|
||||||
|
},
|
||||||
|
outTimer: 30,
|
||||||
|
);
|
||||||
|
|
||||||
// 发送配网指令
|
// 发送配网指令
|
||||||
BlueManage().blueSendData(
|
BlueManage().blueSendData(
|
||||||
@ -340,7 +354,7 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
|||||||
}
|
}
|
||||||
cancelBlueConnetctToastTimer();
|
cancelBlueConnetctToastTimer();
|
||||||
state.sureBtnState.value = 0; // 发送命令失败时重置状态
|
state.sureBtnState.value = 0; // 发送命令失败时重置状态
|
||||||
showToast('发送配网指令失败:${e.toString()}'.tr);
|
// showToast('发送配网指令失败:${e.toString()}'.tr);
|
||||||
}
|
}
|
||||||
} else if (connectionState == BluetoothConnectionState.disconnected) {
|
} else if (connectionState == BluetoothConnectionState.disconnected) {
|
||||||
if (EasyLoading.isShow) {
|
if (EasyLoading.isShow) {
|
||||||
@ -474,70 +488,53 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
|||||||
default:
|
default:
|
||||||
//失败
|
//失败
|
||||||
dismissEasyLoading();
|
dismissEasyLoading();
|
||||||
showToast('获取设备状态失败'.tr);
|
// showToast('获取设备状态失败'.tr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 上传数据获取设置
|
// 上传数据获取设置
|
||||||
Future<void> _getUploadLockSet() async {
|
Future<void> _getUploadLockSet() async {
|
||||||
// 保持已有的loading状态,不再重新显示loading
|
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
||||||
showBlueConnetctToastTimer(action: () {
|
final List<int> getTokenList = changeStringListToIntList(token!);
|
||||||
if (EasyLoading.isShow) {
|
// 蓝牙获取锁设置
|
||||||
dismissEasyLoading();
|
await _uploadLockSet(getTokenList);
|
||||||
}
|
|
||||||
state.sureBtnState.value = 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
|
||||||
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
|
||||||
if (token == null || token.isEmpty) {
|
|
||||||
throw Exception('Token is empty');
|
|
||||||
}
|
|
||||||
final List<int> getTokenList = changeStringListToIntList(token);
|
|
||||||
// 蓝牙获取锁设置
|
|
||||||
await _uploadLockSet(getTokenList);
|
|
||||||
} catch (e) {
|
|
||||||
if (EasyLoading.isShow) {
|
|
||||||
dismissEasyLoading();
|
|
||||||
}
|
|
||||||
cancelBlueConnetctToastTimer();
|
|
||||||
state.sureBtnState.value = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 公共的上传锁设置
|
// 公共的上传锁设置
|
||||||
Future<void> _uploadLockSet(List<int> token) async {
|
Future<void> _uploadLockSet(List<int> token) async {
|
||||||
try {
|
final List<String>? privateKey =
|
||||||
final List<String>? privateKey =
|
await Storage.getStringList(saveBluePrivateKey);
|
||||||
await Storage.getStringList(saveBluePrivateKey);
|
if (privateKey == null || privateKey.isEmpty) {
|
||||||
if (privateKey == null || privateKey.isEmpty) {
|
throw Exception('Private key is empty');
|
||||||
throw Exception('Private key is empty');
|
}
|
||||||
}
|
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey);
|
||||||
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey);
|
|
||||||
|
|
||||||
final List<String>? signKey =
|
final List<String>? signKey = await Storage.getStringList(saveBlueSignKey);
|
||||||
await Storage.getStringList(saveBlueSignKey);
|
if (signKey == null || signKey.isEmpty) {
|
||||||
if (signKey == null || signKey.isEmpty) {
|
throw Exception('Sign key is empty');
|
||||||
throw Exception('Sign key is empty');
|
}
|
||||||
}
|
final List<int> signKeyDataList = changeStringListToIntList(signKey);
|
||||||
final List<int> signKeyDataList = changeStringListToIntList(signKey);
|
|
||||||
|
|
||||||
IoSenderManage.updataLockSetCommand(
|
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||||
|
(BluetoothConnectionState connectionState) async {
|
||||||
|
if (connectionState == BluetoothConnectionState.connected) {
|
||||||
|
IoSenderManage.updataLockSetCommand(
|
||||||
lockID: BlueManage().connectDeviceName,
|
lockID: BlueManage().connectDeviceName,
|
||||||
userID: await Storage.getUid(),
|
userID: await Storage.getUid(),
|
||||||
token: token,
|
token: token,
|
||||||
needAuthor: 1,
|
needAuthor: 1,
|
||||||
signKey: signKeyDataList,
|
signKey: signKeyDataList,
|
||||||
privateKey: getPrivateKeyList);
|
privateKey: getPrivateKeyList,
|
||||||
} catch (e) {
|
);
|
||||||
if (EasyLoading.isShow) {
|
} else if (connectionState == BluetoothConnectionState.disconnected) {
|
||||||
dismissEasyLoading();
|
dismissEasyLoading();
|
||||||
|
cancelBlueConnetctToastTimer();
|
||||||
|
if (state.ifCurrentScreen.value == true) {
|
||||||
|
showBlueConnetctToast();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cancelBlueConnetctToastTimer();
|
}, isAddEquipment: true);
|
||||||
showToast('上传设置失败:${e.toString()}'.tr);
|
|
||||||
state.sureBtnState.value = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 上传数据获取锁设置解析
|
// 上传数据获取锁设置解析
|
||||||
@ -565,7 +562,7 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
|||||||
if (EasyLoading.isShow) {
|
if (EasyLoading.isShow) {
|
||||||
dismissEasyLoading(); // 错误时关闭loading
|
dismissEasyLoading(); // 错误时关闭loading
|
||||||
}
|
}
|
||||||
showToast('获取设置权限失败:${e.toString()}'.tr);
|
// showToast('获取设置权限失败:${e.toString()}'.tr);
|
||||||
state.sureBtnState.value = 0; // 确保重置状态
|
state.sureBtnState.value = 0; // 确保重置状态
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -574,7 +571,7 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
|||||||
if (EasyLoading.isShow) {
|
if (EasyLoading.isShow) {
|
||||||
dismissEasyLoading(); // 错误时关闭loading
|
dismissEasyLoading(); // 错误时关闭loading
|
||||||
}
|
}
|
||||||
showToast('获取锁设置失败 (错误码: $status)'.tr);
|
// showToast('获取锁设置失败 (错误码: $status)'.tr);
|
||||||
state.sureBtnState.value = 0; // 确保重置状态
|
state.sureBtnState.value = 0; // 确保重置状态
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -585,43 +582,16 @@ class ConfiguringWifiLogic extends BaseGetXController {
|
|||||||
{required int uploadType,
|
{required int uploadType,
|
||||||
required int recordType,
|
required int recordType,
|
||||||
required List records}) async {
|
required List records}) async {
|
||||||
try {
|
final LoginEntity entity = await ApiRepository.to.lockDataUpload(
|
||||||
final LoginEntity entity = await ApiRepository.to.lockDataUpload(
|
lockId: state.lockBasicInfo.value.lockId ?? -1,
|
||||||
lockId: state.lockBasicInfo.value.lockId ?? -1,
|
uploadType: uploadType,
|
||||||
uploadType: uploadType,
|
recordType: recordType,
|
||||||
recordType: recordType,
|
records: records,
|
||||||
records: records,
|
isUnShowLoading: true);
|
||||||
isUnShowLoading: true);
|
|
||||||
|
|
||||||
if (entity.errorCode!.codeIsSuccessful) {
|
if (entity.errorCode!.codeIsSuccessful) {
|
||||||
if (EasyLoading.isShow) {
|
eventBus
|
||||||
dismissEasyLoading();
|
.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
|
||||||
}
|
|
||||||
showToast('配网成功'.tr, something: () {
|
|
||||||
state.sureBtnState.value = 0; // 确保重置状态
|
|
||||||
if (state.pageName.value == 'lockSet') {
|
|
||||||
Get.close(2);
|
|
||||||
} else {
|
|
||||||
Get.offAllNamed(Routers.starLockMain);
|
|
||||||
}
|
|
||||||
|
|
||||||
eventBus.fire(
|
|
||||||
PassCurrentLockInformationEvent(state.lockSetInfoData.value));
|
|
||||||
eventBus.fire(SuccessfulDistributionNetwork());
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
if (EasyLoading.isShow) {
|
|
||||||
dismissEasyLoading();
|
|
||||||
}
|
|
||||||
// showToast('数据上传失败:${entity.errorCode}'.tr);
|
|
||||||
state.sureBtnState.value = 0; // 确保重置状态
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
if (EasyLoading.isShow) {
|
|
||||||
dismissEasyLoading();
|
|
||||||
}
|
|
||||||
// showToast('数据上传异常:${e.toString()}'.tr);
|
|
||||||
state.sureBtnState.value = 0; // 确保重置状态
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,7 +51,7 @@ class _ConfiguringWifiPageState extends State<ConfiguringWifiPage>
|
|||||||
() => SubmitBtn(
|
() => SubmitBtn(
|
||||||
btnName: state.sureBtnState.value == 1 ? '配置中...'.tr : '确定'.tr,
|
btnName: state.sureBtnState.value == 1 ? '配置中...'.tr : '确定'.tr,
|
||||||
// 当sureBtnState为1时按钮不可用
|
// 当sureBtnState为1时按钮不可用
|
||||||
isDisabled: state.sureBtnState.value == 1,
|
isDisabled: state.sureBtnState.value == 0,
|
||||||
onClick: state.sureBtnState.value == 1
|
onClick: state.sureBtnState.value == 1
|
||||||
? null
|
? null
|
||||||
: () {
|
: () {
|
||||||
|
|||||||
@ -37,14 +37,14 @@ class WifiListLogic extends BaseGetXController {
|
|||||||
}, onError: (error) {
|
}, onError: (error) {
|
||||||
// 处理CRC校验失败等错误
|
// 处理CRC校验失败等错误
|
||||||
AppLog.log('WiFi列表获取过程中发生错误: $error');
|
AppLog.log('WiFi列表获取过程中发生错误: $error');
|
||||||
|
|
||||||
// 取消loading状态,显示错误提示
|
// 取消loading状态,显示错误提示
|
||||||
dismissEasyLoading();
|
dismissEasyLoading();
|
||||||
cancelBlueConnetctToastTimer();
|
cancelBlueConnetctToastTimer();
|
||||||
|
|
||||||
// 重置按钮状态,允许重新扫描
|
// 重置按钮状态,允许重新扫描
|
||||||
state.sureBtnState.value = 0;
|
state.sureBtnState.value = 0;
|
||||||
|
|
||||||
// 如果是CRC校验失败,显示特定提示
|
// 如果是CRC校验失败,显示特定提示
|
||||||
if (error.toString().contains('CRC')) {
|
if (error.toString().contains('CRC')) {
|
||||||
showToast('数据校验失败,请重新扫描'.tr);
|
showToast('数据校验失败,请重新扫描'.tr);
|
||||||
@ -91,29 +91,29 @@ class WifiListLogic extends BaseGetXController {
|
|||||||
// 把得到的数据按33位分割成数组然后处理
|
// 把得到的数据按33位分割成数组然后处理
|
||||||
final List<List<int>> getList = splitList(reply.data, 33);
|
final List<List<int>> getList = splitList(reply.data, 33);
|
||||||
final List<Map<String, String>> uploadList = <Map<String, String>>[];
|
final List<Map<String, String>> uploadList = <Map<String, String>>[];
|
||||||
|
|
||||||
for (int i = 0; i < getList.length; i++) {
|
for (int i = 0; i < getList.length; i++) {
|
||||||
final List<int> indexList = getList[i];
|
final List<int> indexList = getList[i];
|
||||||
final Map<String, String> indexMap = <String, String>{};
|
final Map<String, String> indexMap = <String, String>{};
|
||||||
final List<int> wifiName = indexList.sublist(0, 32);
|
final List<int> wifiName = indexList.sublist(0, 32);
|
||||||
final String wifiNameStr = utf8String(wifiName).trim();
|
final String wifiNameStr = utf8String(wifiName).trim();
|
||||||
|
|
||||||
// 过滤掉空的WiFi名称
|
// 过滤掉空的WiFi名称
|
||||||
if (wifiNameStr.isEmpty) {
|
if (wifiNameStr.isEmpty) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
indexMap['wifiName'] = wifiNameStr;
|
indexMap['wifiName'] = wifiNameStr;
|
||||||
indexMap['rssi'] = (indexList.last - 255).toString();
|
indexMap['rssi'] = (indexList.last - 255).toString();
|
||||||
uploadList.add(indexMap);
|
uploadList.add(indexMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按信号强度排序WiFi列表 (从强到弱)
|
// 按信号强度排序WiFi列表 (从强到弱)
|
||||||
uploadList.sort((a, b) =>
|
uploadList.sort(
|
||||||
int.parse(b['rssi']!).compareTo(int.parse(a['rssi']!)));
|
(a, b) => int.parse(b['rssi']!).compareTo(int.parse(a['rssi']!)));
|
||||||
|
|
||||||
state.wifiNameDataList.value = uploadList;
|
state.wifiNameDataList.value = uploadList;
|
||||||
|
|
||||||
if (uploadList.isEmpty) {
|
if (uploadList.isEmpty) {
|
||||||
showToast('未检测到可用的WiFi网络'.tr);
|
showToast('未检测到可用的WiFi网络'.tr);
|
||||||
}
|
}
|
||||||
@ -144,7 +144,7 @@ class WifiListLogic extends BaseGetXController {
|
|||||||
showBlueConnetctToastTimer(action: () {
|
showBlueConnetctToastTimer(action: () {
|
||||||
state.sureBtnState.value = 0;
|
state.sureBtnState.value = 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||||
(BluetoothConnectionState connectionState) async {
|
(BluetoothConnectionState connectionState) async {
|
||||||
if (connectionState == BluetoothConnectionState.connected) {
|
if (connectionState == BluetoothConnectionState.connected) {
|
||||||
@ -172,6 +172,7 @@ class WifiListLogic extends BaseGetXController {
|
|||||||
super.onReady();
|
super.onReady();
|
||||||
_initReplySubscription();
|
_initReplySubscription();
|
||||||
await senderGetWifiListWifiAction();
|
await senderGetWifiListWifiAction();
|
||||||
|
dismissEasyLoading();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user