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 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; //
} }
} }
} }

View File

@ -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
: () { : () {

View File

@ -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