fix:调整配网逻辑
This commit is contained in:
parent
d75754e14e
commit
ea01d79bbd
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
: () {
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user