From cd41dd4ccf8e1b25872267799bd3479df09bb8d6 Mon Sep 17 00:00:00 2001 From: liyi Date: Thu, 10 Apr 2025 16:54:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=B0=83=E6=95=B4=E9=85=8D=E7=BD=91loading?= =?UTF-8?q?=E5=8D=A1=E4=B8=BB=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configuringWifi_logic.dart | 156 +++++++----------- .../addLock/nearbyLock/nearbyLock_logic.dart | 4 +- 2 files changed, 61 insertions(+), 99 deletions(-) diff --git a/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_logic.dart b/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_logic.dart index 9b25bf55..25c8e43d 100755 --- a/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_logic.dart +++ b/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_logic.dart @@ -62,17 +62,15 @@ class ConfiguringWifiLogic extends BaseGetXController { peerId: peerId, ); if (entity.errorCode!.codeIsSuccessful) { + // 设置锁的peerID + StartChartManage().lockNetworkInfo = DeviceNetworkInfo( + wifiName: wifiName, + networkMac: networkMac, + secretKey: secretKey, + peerId: peerId, + ); - showToast('配网成功'.tr, something: () async { - // 设置锁的peerID - StartChartManage().lockNetworkInfo = DeviceNetworkInfo( - wifiName: wifiName, - networkMac: networkMac, - secretKey: secretKey, - peerId: peerId, - ); - }); - _getUploadLockSet(); + await _getUploadLockSet(); } } @@ -106,8 +104,11 @@ class ConfiguringWifiLogic extends BaseGetXController { // WIFI配网结果 Future _replySenderConfiguringWifiResult(Reply reply) async { final int status = reply.data[2]; - state.sureBtnState.value = 0; - state.isLoading.value = false; + // state.sureBtnState.value = 0; + + // 取消loading超时定时器 + state.loadingTimer?.cancel(); + state.loadingTimer = null; switch (status) { case 0x00: @@ -140,15 +141,17 @@ class ConfiguringWifiLogic extends BaseGetXController { secretKey: secretKey ?? '', deviceMac: deviceMac ?? '', networkMac: networkMac ?? ''); + break; default: //失败 - dismissEasyLoading(); + dismissEasyLoading(); // 关闭loading + cancelBlueConnetctToastTimer(); if (state.loadingTimer != null) { state.loadingTimer!.cancel(); state.loadingTimer = null; } - cancelBlueConnetctToastTimer(); + showToast('配网失败'.tr); state.isLoading.value = false; break; @@ -164,7 +167,7 @@ class ConfiguringWifiLogic extends BaseGetXController { // 点击配置wifi Future senderConfiguringWifiAction() async { AppLog.log('开始配网${EasyLoading.isShow}'); - EasyLoading.show(); + if (state.isLoading.isTrue) { AppLog.log('正在配网中请勿重复点击'); return; @@ -178,10 +181,10 @@ class ConfiguringWifiLogic extends BaseGetXController { showToast('请输入WiFi密码'.tr); return; } - if (state.sureBtnState.value == 1) { - return; - } - state.sureBtnState.value = 1; + // if (state.sureBtnState.value == 1) { + // return; + // } + // state.sureBtnState.value = 1; final GetGatewayConfigurationEntity entity = await ApiRepository.to.getGatewayConfigurationNotLoading(timeout: 60); @@ -218,9 +221,13 @@ class ConfiguringWifiLogic extends BaseGetXController { // 如果为空,则直接赋值 state.getGatewayConfigurationStr = "{\"userPeerld\": \"$appPeerId\"}"; } + showEasyLoading(); + showBlueConnetctToastTimer(action: () { + dismissEasyLoading(); + state.isLoading.value = false; + }); - AppLog.log('获取到配网信息===开始发送蓝牙指令${EasyLoading.isShow}'); - + // 发送配网指令 BlueManage().blueSendData( BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { @@ -233,35 +240,16 @@ class ConfiguringWifiLogic extends BaseGetXController { } else if (connectionState == BluetoothConnectionState.disconnected) { dismissEasyLoading(); cancelBlueConnetctToastTimer(); - state.sureBtnState.value = 0; + state.isLoading.value = false; + // state.sureBtnState.value = 0; if (state.ifCurrentScreen.value == true) { showBlueConnetctToast(); } } }, - isAddEquipment: true, + isAddEquipment: false, ); - state.loadingTimer ??= Timer.periodic(Duration(milliseconds: 100), (timer) { - if (!EasyLoading.isShow) { - EasyLoading.show(); - } - }); - state.isLoading.value = true; - // 添加15秒超时检查 - Future.delayed(const Duration(seconds: 15), () { - if (state.isLoading.isTrue) { - EasyLoading.dismiss(); - state.isLoading.value = false; - state.sureBtnState.value = 0; - if (state.loadingTimer != null) { - state.loadingTimer!.cancel(); - state.loadingTimer = null; - } - showToast('配网失败'.tr); - } - }); - AppLog.log('发送方法执行完毕${EasyLoading.isShow}'); } // 获取设备状态 @@ -320,7 +308,7 @@ class ConfiguringWifiLogic extends BaseGetXController { getWifiLockServiceIpAndPort(); _initReplySubscription(); - getDevicesStatusAction(); + // getDevicesStatusAction(); } @override @@ -336,13 +324,13 @@ class ConfiguringWifiLogic extends BaseGetXController { void _replyGatewayGetStatusReply(GatewayGetStatusReply reply) { final int status = reply.data[2]; - + //成功 + dismissEasyLoading(); + cancelBlueConnetctToastTimer(); switch (status) { case 0x00: //成功 - // state.sureBtnState.value = 0; - cancelBlueConnetctToastTimer(); - dismissEasyLoading(); + // state.sureBtnState.value = 0; final GetGatewayInfoModel gatewayModel = GetGatewayInfoModel(); // 网关MAC地址 @@ -393,28 +381,17 @@ class ConfiguringWifiLogic extends BaseGetXController { } } - void _replyStatusInfo(reply) {} - // 上传数据获取设置 Future _getUploadLockSet() async { - // showEasyLoading(); - // showBlueConnetctToastTimer(action: () { - // dismissEasyLoading(); - // }); - BlueManage().blueSendData(BlueManage().connectDeviceName, - (BluetoothConnectionState connectionState) async { - if (connectionState == BluetoothConnectionState.connected) { - final List? token = await Storage.getStringList(saveBlueToken); - final List getTokenList = changeStringListToIntList(token!); - - _uploadLockSet(getTokenList); - } else if (connectionState == BluetoothConnectionState.disconnected) { - cancelBlueConnetctToastTimer(); - if (state.ifCurrentScreen.value == true) { - showBlueConnetctToast(); - } - } + showEasyLoading(); + showBlueConnetctToastTimer(action: () { + dismissEasyLoading(); }); + + final List? token = await Storage.getStringList(saveBlueToken); + final List getTokenList = changeStringListToIntList(token!); + + await _uploadLockSet(getTokenList); } // 公共的上传锁设置 @@ -438,15 +415,15 @@ class ConfiguringWifiLogic extends BaseGetXController { // 上传数据获取锁设置解析 Future _replyUpdataLockSetReply(Reply reply) async { final int status = reply.data[2]; + dismissEasyLoading(); // 关闭loading + cancelBlueConnetctToastTimer(); switch (status) { case 0x00: - //成功 - dismissEasyLoading(); - cancelBlueConnetctToastTimer(); - _lockDataUpload( + await _lockDataUpload( uploadType: 1, recordType: 0, records: reply.data.sublist(7, reply.data.length)); + break; case 0x06: //无权限 @@ -475,33 +452,18 @@ class ConfiguringWifiLogic extends BaseGetXController { records: records, isUnShowLoading: true); if (entity.errorCode!.codeIsSuccessful) { - await Future.delayed((Duration(seconds: 1))); - if (state.pageName.value == 'lockSet') { - Get.close(2); - } else { - Get.offAllNamed(Routers.starLockMain); - } - dismissEasyLoading(); - eventBus - .fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value)); - eventBus - .fire(SuccessfulDistributionNetwork()); - if (state.loadingTimer != null) { - state.loadingTimer!.cancel(); - state.loadingTimer = null; - } - } - } + showToast('配网成功'.tr, something: () { + state.isLoading.value = false; + if (state.pageName.value == 'lockSet') { + Get.close(2); + } else { + Get.offAllNamed(Routers.starLockMain); + } - @override - void dispose() { - dismissEasyLoading(); - // TODO: implement dispose - super.dispose(); - state.isLoading.value = false; - if (state.loadingTimer != null) { - state.loadingTimer!.cancel(); - state.loadingTimer = null; + eventBus + .fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value)); + eventBus.fire(SuccessfulDistributionNetwork()); + }); } } } diff --git a/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart b/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart index 77872c3c..05b499f0 100755 --- a/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart +++ b/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart @@ -93,7 +93,6 @@ class NearbyLockLogic extends BaseGetXController { showToast('固件升级完成'.tr); closeOTADAta(); } - dismissEasyLoading(); }); } @@ -160,6 +159,7 @@ class NearbyLockLogic extends BaseGetXController { // 获取星锁状态 Future _replyGetStarLockStatusInfo(Reply reply) async { final int status = reply.data[2]; + dismissEasyLoading(); switch (status) { case 0x00: //成功 @@ -743,8 +743,8 @@ class NearbyLockLogic extends BaseGetXController { @override void onClose() { - super.onClose(); _replySubscription?.cancel(); + super.onClose(); } Future getNearByLimits() async {