基本信息中添加“星云服务器联通测试”和“星图服务器联通测试”

This commit is contained in:
sky.min 2026-02-05 16:51:50 +08:00
parent 7376afe9a1
commit fa134a258e
3 changed files with 255 additions and 2 deletions

View File

@ -28,6 +28,8 @@ class BasicInformationLogic extends BaseGetXController {
.on<PassCurrentLockInformationEvent>()
.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();
}
}
}

View File

@ -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<BasicInformationPage> {
),
),
),
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<BasicInformationPage> {
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<void> _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<double> _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<void> _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<double> _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<Color> 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;
}
}
}

View File

@ -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 = LockBasicInfo().obs;
RxString groupName = '未分组'.tr.obs;
}
RxString networkConnectTestResult = '点击测试'.tr.obs;
RxString starChartTestResult = '点击测试'.tr.obs;
//
Rx<Color> networkTestResultColor = Colors.black.obs;
Rx<Color> 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 ?? '';
}
}