diff --git a/lib/main/lockDetail/lockSet/basicInformation/basicInformation/basicInformation_logic.dart b/lib/main/lockDetail/lockSet/basicInformation/basicInformation/basicInformation_logic.dart index 38643a53..1046f5ee 100755 --- a/lib/main/lockDetail/lockSet/basicInformation/basicInformation/basicInformation_logic.dart +++ b/lib/main/lockDetail/lockSet/basicInformation/basicInformation/basicInformation_logic.dart @@ -28,6 +28,8 @@ class BasicInformationLogic extends BaseGetXController { .on() .listen((PassCurrentLockInformationEvent event) { state.lockSetInfoData.value = event.lockSetInfoData; + // 更新响应式变量 + _updateReactiveVariables(); blockSetStateCallback(); }); @@ -45,12 +47,25 @@ class BasicInformationLogic extends BaseGetXController { }); } + // 更新响应式变量的方法 + void _updateReactiveVariables() { + final lockFeature = state.lockSetInfoData.value.lockFeature; + final networkInfo = state.lockSetInfoData.value.lockBasicInfo?.networkInfo; + + state.updateWifiFeature(lockFeature?.wifi ?? 0); + state.updateRssiValue(networkInfo?.rssi); + state.updateTimezoneName(state.lockSetInfoData.value.lockBasicInfo?.timezoneName); + } + @override void onReady() { super.onReady(); // AppLog.log( // '厂商 vendor:${state.lockBasicInfo.value.vendor} 型号 model:${state.lockBasicInfo.value.model}'); + + // 初始化响应式变量 + _updateReactiveVariables(); } @override @@ -59,4 +74,4 @@ class BasicInformationLogic extends BaseGetXController { _passCurrentLockInformationEvent?.cancel(); lockSetChangeSetRefreshLockDetailWithTypeSubscription?.cancel(); } -} +} \ No newline at end of file diff --git a/lib/main/lockDetail/lockSet/basicInformation/basicInformation/basicInformation_page.dart b/lib/main/lockDetail/lockSet/basicInformation/basicInformation/basicInformation_page.dart index 3fbb60d0..c59b6067 100755 --- a/lib/main/lockDetail/lockSet/basicInformation/basicInformation/basicInformation_page.dart +++ b/lib/main/lockDetail/lockSet/basicInformation/basicInformation/basicInformation_page.dart @@ -4,6 +4,8 @@ import 'package:get/get.dart'; import 'package:star_lock/main/lockDetail/lockSet/basicInformation/basicInformation/basicInformation_state.dart'; import 'package:star_lock/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart'; import 'package:star_lock/tools/dateTool.dart'; +import 'package:star_lock/network/api_repository.dart'; +import 'package:star_lock/network/start_chart_api.dart'; import '../../../../../appRouters.dart'; import '../../../../../app_settings/app_colors.dart'; @@ -159,6 +161,22 @@ class _BasicInformationPageState extends State { ), ), ), + Obx(() => _buildNetworkTestItem( + title: '星云服务器联通测试'.tr, + result: state.networkConnectTestResult.value, + color: state.networkTestResultColor.value, + onTap: () async { + await _performNetworkTest(); + }, + )), + Obx(() => _buildNetworkTestItem( + title: '星图服务器联通测试'.tr, + result: state.starChartTestResult.value, + color: state.starChartTestResultColor.value, + onTap: () async { + await _performStarChartNetworkTest(); + }, + )), // Obx(() => CommonItem( // leftTitel: '位置信息'.tr, // // rightTitle: state.lockBasicInfo.value.address ?? "-", @@ -352,4 +370,197 @@ class _BasicInformationPageState extends State { return timezoneMap[timezoneName] ?? timezoneName; } + + // 带颜色的网络测试结果 + Widget _buildNetworkTestItem({ + required String title, + required String result, + required Color color, + required Function() onTap, + }) { + return GestureDetector( + onTap: onTap, + child: Container( + height: 65.h, + padding: EdgeInsets.only(left: 20.w, right: 10.w), + decoration: BoxDecoration( + color: Colors.white, + border: Border( + bottom: BorderSide( + color: AppColors.greyLineColor, + width: 2.0.h, + ), + ), + ), + child: Row( + children: [ + Text(title, style: TextStyle(fontSize: 22.sp)), + const SizedBox(width: 10), + Expanded( + child: Text( + result, + textAlign: TextAlign.end, + style: TextStyle( + fontSize: 22.sp, + color: color, + fontWeight: FontWeight.w500, + ), + ), + ), + const SizedBox(width: 10), + Image.asset( + 'images/icon_right_grey.png', + width: 12.w, + height: 21.w, + ), + ], + ), + ), + ); + } + + // 星云网络测试 + Future _performNetworkTest() async { + try { + // 显示加载状态为黑色文字 + state.networkConnectTestResult.value = '测试中...'.tr; + state.networkTestResultColor.value = Colors.black; + + // 直接测试星云服务器连接 + final double responseTime = await _testStarCloudServerConnection(); + + // 测试完成后更新星云测试结果显示 + _updateTestResult( + responseTime: responseTime, + resultText: state.networkConnectTestResult, + resultColor: state.networkTestResultColor, + testType: '星云网络'.tr, + ); + + } catch (e) { + state.networkConnectTestResult.value = '测试失败'.tr; + state.networkTestResultColor.value = AppColors.networkFailedColor; + print('星云网络测试执行失败: $e'); + } + } + + // 测试星云服务器连接 + Future _testStarCloudServerConnection() async { + try { + final stopwatch = Stopwatch()..start(); + + // 尝试访问锁列表API + try { + // 调用内部API:/lock/list + final response = await ApiRepository.to.getStarLockListInfo( + pageNo: 1, + pageSize: 10, + isUnShowLoading: true, + ); + + stopwatch.stop(); + final responseTime = stopwatch.elapsedMilliseconds / 1000.0; + return responseTime; + } catch (e) { + // 如果API请求失败 + stopwatch.stop(); + return 9.999; + } + } catch (e) { + return 9.999; + } + } + + // 执行星图网络测试 + Future _performStarChartNetworkTest() async { + try { + // 显示测试中状态为黑色文字 + state.starChartTestResult.value = '测试中...'.tr; + state.starChartTestResultColor.value = Colors.black; + + // 直接测试星图服务器连接 + final double responseTime = await _testStarChartServerConnection(); + + // 根据响应时间更新显示 + _updateTestResult( + responseTime: responseTime, + resultText: state.starChartTestResult, + resultColor: state.starChartTestResultColor, + testType: '星图网络'.tr, + ); + + } catch (e) { + // 显示错误提示并更新显示状态 + state.starChartTestResult.value = '测试失败'.tr; + state.starChartTestResultColor.value = AppColors.networkFailedColor; + print('星图网络测试执行失败: $e'); + } + } + + // 测试星图服务器连接 + Future _testStarChartServerConnection() async { + try { + final stopwatch = Stopwatch()..start(); + + try { + // 尝试连接StartChartApi服务器 - 通过调用注册节点API来测试连接 + final response = await StartChartApi.to.starChartRegisterNode( + product: 'TEST', + model: 'TEST_MODEL', + name: 'TEST_NAME', + unique: 'TEST_UNIQUE_${DateTime.now().millisecondsSinceEpoch}', + ); + + stopwatch.stop(); + final responseTime = stopwatch.elapsedMilliseconds / 1000.0; + return responseTime; + } catch (e) { + // 如果StartChartApi请求失败 + stopwatch.stop(); + return 9.999; + } + } catch (e) { + return 9.999; + } + } + + // 更新网络测试结果显示 + void _updateTestResult({ + required double responseTime, + required RxString resultText, + required Rx resultColor, + String testType = '网络', + }) { + try { + String displayText; + Color displayColor; + + if (responseTime == 9.999) { + displayText = '连接失败'.tr; + displayColor = AppColors.networkFailedColor; + } else if (responseTime > 0 && responseTime < 0.1) { + displayText = '${'连接良好'.tr} ${(responseTime * 1000).round()}ms'; + displayColor = AppColors.networkGoodColor; + } else if (responseTime >= 0.1 && responseTime < 0.3) { + displayText = '${'连接正常'.tr} ${(responseTime * 1000).round()}ms'; + displayColor = AppColors.networkNormalColor; + } else if (responseTime >= 0.3) { + displayText = '${'连接较慢'.tr} ${(responseTime * 1000).round()}ms'; + displayColor = AppColors.networkSlowColor; + } else { + displayText = '点击测试'.tr; + displayColor = Colors.black; // 点击测试时显示黑色 + } + + // 更新文本和颜色 + resultText.value = displayText; + resultColor.value = displayColor; + + print('${testType}测试完成,响应时间: ${responseTime}s, 显示: $displayText'); + } catch (e) { + print('更新${testType}测试结果显示出错: $e'); + resultText.value = '测试失败'.tr; + resultColor.value = AppColors.networkFailedColor; + } + } } diff --git a/lib/main/lockDetail/lockSet/basicInformation/basicInformation/basicInformation_state.dart b/lib/main/lockDetail/lockSet/basicInformation/basicInformation/basicInformation_state.dart index a52b8582..7fddf57f 100755 --- a/lib/main/lockDetail/lockSet/basicInformation/basicInformation/basicInformation_state.dart +++ b/lib/main/lockDetail/lockSet/basicInformation/basicInformation/basicInformation_state.dart @@ -1,5 +1,8 @@ +import 'dart:ui'; +import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:star_lock/app_settings/app_colors.dart'; import '../../lockSet/lockSetInfo_entity.dart'; @@ -18,4 +21,28 @@ class BasicInformationState { Rx lockBasicInfo = LockBasicInfo().obs; RxString groupName = '未分组'.tr.obs; -} + RxString networkConnectTestResult = '点击测试'.tr.obs; + RxString starChartTestResult = '点击测试'.tr.obs; + + // 网络状态颜色 + Rx networkTestResultColor = Colors.black.obs; + Rx starChartTestResultColor = Colors.black.obs; + + // 添加响应式变量来处理深层嵌套的数据访问 + RxInt wifiFeature = RxInt(0); + RxInt rssiValue = RxInt(0); + RxString timezoneNameValue = RxString(''); + + // 更新响应式变量的方法 + void updateWifiFeature(int feature) { + wifiFeature.value = feature; + } + + void updateRssiValue(int? rssi) { + rssiValue.value = rssi ?? 0; + } + + void updateTimezoneName(String? timezone) { + timezoneNameValue.value = timezone ?? ''; + } +} \ No newline at end of file