fix:调整配网逻辑

This commit is contained in:
liyi 2025-04-28 09:20:25 +08:00
parent d75754e14e
commit ea01d79bbd
3 changed files with 81 additions and 110 deletions

View File

@ -181,17 +181,28 @@ class ConfiguringWifiLogic extends BaseGetXController {
//
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 {
dismissEasyLoading();
showToast('网络配置失败,请重试'.tr);
// showToast('网络配置失败,请重试'.tr);
state.sureBtnState.value = 0;
}
} catch (e) {
if (EasyLoading.isShow) {
dismissEasyLoading();
}
showToast('解析配网信息失败,请重试'.tr);
// showToast('解析配网信息失败,请重试'.tr);
state.sureBtnState.value = 0; //
AppLog.log('解析配网信息失败: $e');
return; // return阻止后续流程
@ -203,7 +214,7 @@ class ConfiguringWifiLogic extends BaseGetXController {
if (EasyLoading.isShow) {
dismissEasyLoading();
}
showToast('WiFi密码错误请重新输入'.tr);
// showToast('WiFi密码错误请重新输入'.tr);
state.sureBtnState.value = 0; //
break;
@ -212,7 +223,7 @@ class ConfiguringWifiLogic extends BaseGetXController {
if (EasyLoading.isShow) {
dismissEasyLoading();
}
showToast('找不到该WiFi网络请确认WiFi名称正确'.tr);
// showToast('找不到该WiFi网络请确认WiFi名称正确'.tr);
state.sureBtnState.value = 0; //
break;
@ -221,7 +232,7 @@ class ConfiguringWifiLogic extends BaseGetXController {
if (EasyLoading.isShow) {
dismissEasyLoading();
}
showToast('连接WiFi超时请确保网络信号良好'.tr);
// showToast('连接WiFi超时请确保网络信号良好'.tr);
state.sureBtnState.value = 0; //
break;
@ -230,7 +241,7 @@ class ConfiguringWifiLogic extends BaseGetXController {
if (EasyLoading.isShow) {
dismissEasyLoading();
}
showToast('配网失败 (错误码: $status),请重试'.tr);
// showToast('配网失败 (错误码: $status),请重试'.tr);
state.sureBtnState.value = 0; //
break;
}
@ -315,12 +326,15 @@ class ConfiguringWifiLogic extends BaseGetXController {
}
//
showBlueConnetctToastTimer(action: () {
if (EasyLoading.isShow) {
dismissEasyLoading();
}
state.sureBtnState.value = 0; //
});
showBlueConnetctToastTimer(
action: () {
if (EasyLoading.isShow) {
dismissEasyLoading();
}
state.sureBtnState.value = 0; //
},
outTimer: 30,
);
//
BlueManage().blueSendData(
@ -340,7 +354,7 @@ class ConfiguringWifiLogic extends BaseGetXController {
}
cancelBlueConnetctToastTimer();
state.sureBtnState.value = 0; //
showToast('发送配网指令失败:${e.toString()}'.tr);
// showToast('发送配网指令失败:${e.toString()}'.tr);
}
} else if (connectionState == BluetoothConnectionState.disconnected) {
if (EasyLoading.isShow) {
@ -474,70 +488,53 @@ class ConfiguringWifiLogic extends BaseGetXController {
default:
//
dismissEasyLoading();
showToast('获取设备状态失败'.tr);
// showToast('获取设备状态失败'.tr);
break;
}
}
//
Future<void> _getUploadLockSet() async {
// loading状态loading
showBlueConnetctToastTimer(action: () {
if (EasyLoading.isShow) {
dismissEasyLoading();
}
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;
}
final List<String>? token = await Storage.getStringList(saveBlueToken);
final List<int> getTokenList = changeStringListToIntList(token!);
//
await _uploadLockSet(getTokenList);
}
//
Future<void> _uploadLockSet(List<int> token) async {
try {
final List<String>? privateKey =
await Storage.getStringList(saveBluePrivateKey);
if (privateKey == null || privateKey.isEmpty) {
throw Exception('Private key is empty');
}
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey);
final List<String>? privateKey =
await Storage.getStringList(saveBluePrivateKey);
if (privateKey == null || privateKey.isEmpty) {
throw Exception('Private key is empty');
}
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey);
final List<String>? signKey =
await Storage.getStringList(saveBlueSignKey);
if (signKey == null || signKey.isEmpty) {
throw Exception('Sign key is empty');
}
final List<int> signKeyDataList = changeStringListToIntList(signKey);
final List<String>? signKey = await Storage.getStringList(saveBlueSignKey);
if (signKey == null || signKey.isEmpty) {
throw Exception('Sign key is empty');
}
final List<int> signKeyDataList = changeStringListToIntList(signKey);
IoSenderManage.updataLockSetCommand(
BlueManage().blueSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState connectionState) async {
if (connectionState == BluetoothConnectionState.connected) {
IoSenderManage.updataLockSetCommand(
lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(),
token: token,
needAuthor: 1,
signKey: signKeyDataList,
privateKey: getPrivateKeyList);
} catch (e) {
if (EasyLoading.isShow) {
privateKey: getPrivateKeyList,
);
} else if (connectionState == BluetoothConnectionState.disconnected) {
dismissEasyLoading();
cancelBlueConnetctToastTimer();
if (state.ifCurrentScreen.value == true) {
showBlueConnetctToast();
}
}
cancelBlueConnetctToastTimer();
showToast('上传设置失败:${e.toString()}'.tr);
state.sureBtnState.value = 0;
}
}, isAddEquipment: true);
}
//
@ -565,7 +562,7 @@ class ConfiguringWifiLogic extends BaseGetXController {
if (EasyLoading.isShow) {
dismissEasyLoading(); // loading
}
showToast('获取设置权限失败:${e.toString()}'.tr);
// showToast('获取设置权限失败:${e.toString()}'.tr);
state.sureBtnState.value = 0; //
}
break;
@ -574,7 +571,7 @@ class ConfiguringWifiLogic extends BaseGetXController {
if (EasyLoading.isShow) {
dismissEasyLoading(); // loading
}
showToast('获取锁设置失败 (错误码: $status)'.tr);
// showToast('获取锁设置失败 (错误码: $status)'.tr);
state.sureBtnState.value = 0; //
break;
}
@ -585,43 +582,16 @@ class ConfiguringWifiLogic extends BaseGetXController {
{required int uploadType,
required int recordType,
required List records}) async {
try {
final LoginEntity entity = await ApiRepository.to.lockDataUpload(
lockId: state.lockBasicInfo.value.lockId ?? -1,
uploadType: uploadType,
recordType: recordType,
records: records,
isUnShowLoading: true);
final LoginEntity entity = await ApiRepository.to.lockDataUpload(
lockId: state.lockBasicInfo.value.lockId ?? -1,
uploadType: uploadType,
recordType: recordType,
records: records,
isUnShowLoading: true);
if (entity.errorCode!.codeIsSuccessful) {
if (EasyLoading.isShow) {
dismissEasyLoading();
}
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; //
if (entity.errorCode!.codeIsSuccessful) {
eventBus
.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
}
}
}

View File

@ -51,7 +51,7 @@ class _ConfiguringWifiPageState extends State<ConfiguringWifiPage>
() => SubmitBtn(
btnName: state.sureBtnState.value == 1 ? '配置中...'.tr : '确定'.tr,
// sureBtnState为1时按钮不可用
isDisabled: state.sureBtnState.value == 1,
isDisabled: state.sureBtnState.value == 0,
onClick: state.sureBtnState.value == 1
? null
: () {

View File

@ -37,14 +37,14 @@ class WifiListLogic extends BaseGetXController {
}, onError: (error) {
// CRC校验失败等错误
AppLog.log('WiFi列表获取过程中发生错误: $error');
// loading状态
dismissEasyLoading();
cancelBlueConnetctToastTimer();
//
state.sureBtnState.value = 0;
// CRC校验失败
if (error.toString().contains('CRC')) {
showToast('数据校验失败,请重新扫描'.tr);
@ -91,29 +91,29 @@ class WifiListLogic extends BaseGetXController {
// 33
final List<List<int>> getList = splitList(reply.data, 33);
final List<Map<String, String>> uploadList = <Map<String, String>>[];
for (int i = 0; i < getList.length; i++) {
final List<int> indexList = getList[i];
final Map<String, String> indexMap = <String, String>{};
final List<int> wifiName = indexList.sublist(0, 32);
final String wifiNameStr = utf8String(wifiName).trim();
// WiFi名称
if (wifiNameStr.isEmpty) {
continue;
}
indexMap['wifiName'] = wifiNameStr;
indexMap['rssi'] = (indexList.last - 255).toString();
uploadList.add(indexMap);
}
// WiFi列表 ()
uploadList.sort((a, b) =>
int.parse(b['rssi']!).compareTo(int.parse(a['rssi']!)));
uploadList.sort(
(a, b) => int.parse(b['rssi']!).compareTo(int.parse(a['rssi']!)));
state.wifiNameDataList.value = uploadList;
if (uploadList.isEmpty) {
showToast('未检测到可用的WiFi网络'.tr);
}
@ -144,7 +144,7 @@ class WifiListLogic extends BaseGetXController {
showBlueConnetctToastTimer(action: () {
state.sureBtnState.value = 0;
});
BlueManage().blueSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState connectionState) async {
if (connectionState == BluetoothConnectionState.connected) {
@ -172,6 +172,7 @@ class WifiListLogic extends BaseGetXController {
super.onReady();
_initReplySubscription();
await senderGetWifiListWifiAction();
dismissEasyLoading();
}
@override