This commit is contained in:
wyf
2025-05-21 09:53:32 +08:00
parent 0a8cffa4c6
commit 489e907e00
26 changed files with 516 additions and 853 deletions

View File

@@ -90,7 +90,7 @@ class _CalibrationPageState extends State<CalibrationPage> {
borderRadius: 20.rpx,
onTap: () async {
// Get.toNamed("/personPage");
Get.toNamed("/bindDeviceSuccess");
Get.toNamed("/bindDeviceSuccess");
},
colors: [
themeController.currentColor.sc1,
@@ -490,110 +490,6 @@ class _CalibrationPageState extends State<CalibrationPage> {
child: CustomCard(
borderRadius:
AppConstants().button_container_radius, // 圆角半径
// onTap: () async {
// BlueteethBindController blueteethBindController =
// Get.find();
// String serviceAddress = "http://192.168.1.80:8086";
// String serviceApi = ServiceConstant.start_calibration;
// String queryUrl = "${serviceAddress}${serviceApi}";
// requestWithLog(
// logTitle: "设备校准",
// method: MyHttpMethod.post,
// queryUrl: queryUrl,
// data: {
// "macA": blueteethBindController.currentDeviceMac,
// if (blueteethBindController.cid!.value.isNotEmpty)
// "id": blueteethBindController.cid!.value,
// },
// onSuccess: (res) {
// String cid = res.rawResponse.data['cid'];
// blueteethBindController.cid!.value = cid;
// final ValueNotifier<double> progressNotifier =
// ValueNotifier<double>(0.0);
// final ValueNotifier<bool> failureNotifier =
// ValueNotifier<bool>(false);
// Timer? pollingTimer;
// // 定义请求函数
// void requestCalibrationProgress() {
// String serviceAddress =
// "http://192.168.1.80:8086";
// String serviceApi =
// ServiceConstant.calibration_process;
// String queryUrl =
// "${serviceAddress}${serviceApi}?id=$cid";
// requestWithLog(
// logTitle: "设备校准进度",
// method: MyHttpMethod.get,
// queryUrl: queryUrl,
// onSuccess: (res) {
// print(res);
// deviceCalibrationController.tips.value =
// res.data['statusText'];
// if (res.data['per'] == 100) {
// TopSlideNotification.show(context,
// text: deviceCalibrationController
// .tips.value);
// }
// double process =
// (res.data['per'] ?? 0).toDouble();
// progressNotifier.value = process;
// if (process >= 100) {
// if (deviceCalibrationController
// .process.value ==
// 0) {
// deviceCalibrationController
// .bed_calibration.value = 1;
// deviceCalibrationController.updateAll();
// }
// if (deviceCalibrationController
// .process.value ==
// 1) {
// deviceCalibrationController
// .position_calibration.value = 1;
// deviceCalibrationController.updateAll();
// }
// deviceCalibrationController
// .process.value = 1;
// deviceCalibrationController.updateAll();
// pollingTimer?.cancel();
// }
// },
// onFailure: (res) {
// pollingTimer?.cancel();
// failureNotifier.value = true;
// TopSlideNotification.show(
// context,
// text: res.msg ?? "服务器.失败".tr,
// textColor:
// themeController.currentColor.sc9,
// );
// },
// );
// }
// // 启动轮询
// pollingTimer =
// Timer.periodic(Duration(seconds: 2), (timer) {
// requestCalibrationProgress();
// });
// // 初始调用一次
// requestCalibrationProgress();
// // 显示进度弹窗
// showProgressDialog(
// context, progressNotifier, failureNotifier);
// },
// onFailure: (res) {
// TopSlideNotification.show(
// context,
// text: res.msg ?? "服务器.失败".tr,
// textColor: themeController.currentColor.sc9,
// );
// },
// );
// },
onTap: () async {
if (deviceCalibrationController.complete) {
showConfirmDialog(
@@ -608,139 +504,279 @@ class _CalibrationPageState extends State<CalibrationPage> {
.position_calibration.value = 0;
blueteethBindController.cid!.value = "";
deviceCalibrationController.complete = false;
}, onCancel: () {});
}
String serviceAddress =
"https://caibration.he-info.cn";
String calibrationApi =
ServiceConstant.start_calibration;
String progressApi =
ServiceConstant.calibration_process;
BlueteethBindController blueteethBindController =
Get.find();
String serviceAddress = "https://caibration.he-info.cn/";
String calibrationApi =
ServiceConstant.start_calibration;
String progressApi =
ServiceConstant.calibration_process;
String queryUrl =
"$serviceAddress$calibrationApi";
String queryUrl = "$serviceAddress$calibrationApi";
final ValueNotifier<double> progressNotifier =
ValueNotifier<double>(0.0);
final ValueNotifier<bool> failureNotifier =
ValueNotifier<bool>(false);
Timer? pollingTimer;
final ValueNotifier<double> progressNotifier =
ValueNotifier<double>(0.0);
final ValueNotifier<bool> failureNotifier =
ValueNotifier<bool>(false);
Timer? pollingTimer;
Map<String, dynamic> data = {
"macA": blueteethBindController
.currentDeviceMac!.value,
};
Map<String, dynamic> data = {
"macA": blueteethBindController.currentDeviceMac,
};
// 是否是二次点击有cid表示进行第二阶段
bool isSecondStep =
blueteethBindController.cid?.value.isNotEmpty ??
// 是否是二次点击有cid表示进行第二阶段
bool isSecondStep = blueteethBindController
.cid?.value.isNotEmpty ??
false;
if (isSecondStep) {
data["id"] = blueteethBindController.cid!.value;
}
// 发起校准请求
requestWithLog(
logTitle: "设备校准",
method: MyHttpMethod.post,
queryUrl: queryUrl,
data: data,
onSuccess: (res) {
if (!isSecondStep) {
// 保存第一次获取的 cid
String cid = res.rawResponse.data['cid'];
blueteethBindController.cid!.value = cid;
if (isSecondStep) {
data["id"] = blueteethBindController.cid!.value;
}
void requestCalibrationProgress() {
String cid = blueteethBindController.cid!.value;
String progressUrl =
"$serviceAddress$progressApi?id=$cid";
requestWithLog(
logTitle: "设备校准进度",
method: MyHttpMethod.get,
queryUrl: progressUrl,
onSuccess: (res) {
final data = res.data;
double per = (data['per'] ?? 0).toDouble();
int currStep = data['currStep'] ?? -1;
bool status = data['status'] ?? false;
String tips = data['statusText'] ?? '';
// 发起校准请求
requestWithLog(
logTitle: "设备校准",
method: MyHttpMethod.post,
queryUrl: queryUrl,
data: data,
onSuccess: (res) {
if (!isSecondStep) {
// 保存第一次获取的 cid
String cid = res.rawResponse.data['cid'];
blueteethBindController.cid!.value = cid;
}
deviceCalibrationController.tips.value =
tips;
// progressNotifier.value =
// (res.data['per'] ?? 0) / 100.0;
progressNotifier.value = per;
void requestCalibrationProgress() {
String cid =
blueteethBindController.cid!.value;
String progressUrl =
"$serviceAddress$progressApi?id=$cid";
requestWithLog(
logTitle: "设备校准进度",
method: MyHttpMethod.get,
queryUrl: progressUrl,
onSuccess: (res) {
final data = res.data;
double per =
(data['per'] ?? 0).toDouble();
int currStep = data['currStep'] ?? -1;
bool status = data['status'] ?? false;
String tips = data['statusText'] ?? '';
if (!isSecondStep && per >= 100) {
// 第一步完成:仅 per >= 100
pollingTimer?.cancel();
TopSlideNotification.show(context,
text: tips);
deviceCalibrationController
.process.value = 1;
deviceCalibrationController
.bed_calibration.value = 1;
deviceCalibrationController.tips.value =
tips;
deviceCalibrationController.updateAll();
}
progressNotifier.value = per;
if (!isSecondStep && per >= 20) {
progressNotifier.value = 100;
// 第一步完成:仅 per >= 100
pollingTimer?.cancel();
TopSlideNotification.show(context,
text: tips);
deviceCalibrationController
.process.value = 1;
deviceCalibrationController
.bed_calibration.value = 1;
if (isSecondStep &&
per >= 100 &&
currStep == 5 &&
status == true) {
// 第二步完成per >= 100 && currStep == 5 && status == true
pollingTimer?.cancel();
TopSlideNotification.show(context,
text: "设备校准完成".tr);
// 可在这里执行校准完成后的业务逻辑更新
deviceCalibrationController
.bed_calibration.value = 1;
deviceCalibrationController
.position_calibration.value = 1;
deviceCalibrationController
.process.value = 1;
deviceCalibrationController.complete =
true;
deviceCalibrationController.updateAll();
}
},
onFailure: (res) {
pollingTimer?.cancel();
failureNotifier.value = true;
TopSlideNotification.show(
context,
text: res.msg ?? "服务器.失败".tr,
textColor:
themeController.currentColor.sc9,
deviceCalibrationController
.updateAll();
}
if (isSecondStep &&
per >= 100 &&
currStep == 5 &&
status == true) {
// 第二步完成per >= 100 && currStep == 5 && status == true
pollingTimer?.cancel();
TopSlideNotification.show(context,
text: "设备校准完成".tr);
// 可在这里执行校准完成后的业务逻辑更新
deviceCalibrationController
.bed_calibration.value = 1;
deviceCalibrationController
.position_calibration.value = 1;
deviceCalibrationController
.process.value = 1;
deviceCalibrationController.complete =
true;
deviceCalibrationController
.updateAll();
}
},
onFailure: (res) {
pollingTimer?.cancel();
failureNotifier.value = true;
TopSlideNotification.show(
context,
text: res.msg ?? "服务器.失败".tr,
textColor:
themeController.currentColor.sc9,
);
},
);
},
);
}
}
// 初始调用一次
requestCalibrationProgress();
// 初始调用一次
requestCalibrationProgress();
// 开始轮询
pollingTimer =
Timer.periodic(Duration(seconds: 2), (_) {
requestCalibrationProgress();
});
// 开始轮询
pollingTimer =
Timer.periodic(Duration(seconds: 2), (_) {
requestCalibrationProgress();
});
// 显示进度弹窗
showProgressDialog(
context, progressNotifier, failureNotifier);
},
onFailure: (res) {
TopSlideNotification.show(
context,
text: res.msg ?? "服务器.失败".tr,
textColor: themeController.currentColor.sc9,
// 显示进度弹窗
showProgressDialog(context, progressNotifier,
failureNotifier);
},
onFailure: (res) {
TopSlideNotification.show(
context,
text: res.msg ?? "服务器.失败".tr,
textColor: themeController.currentColor.sc9,
);
},
);
},
);
}, onCancel: () {
return;
});
} else {
BlueteethBindController blueteethBindController =
Get.find();
String serviceAddress =
"https://caibration.he-info.cn";
String calibrationApi =
ServiceConstant.start_calibration;
String progressApi =
ServiceConstant.calibration_process;
String queryUrl = "$serviceAddress$calibrationApi";
final ValueNotifier<double> progressNotifier =
ValueNotifier<double>(0.0);
final ValueNotifier<bool> failureNotifier =
ValueNotifier<bool>(false);
Timer? pollingTimer;
Map<String, dynamic> data = {
"macA": blueteethBindController
.currentDeviceMac!.value,
};
// 是否是二次点击有cid表示进行第二阶段
bool isSecondStep =
blueteethBindController.cid?.value.isNotEmpty ??
false;
if (isSecondStep) {
data["id"] = blueteethBindController.cid!.value;
}
// 发起校准请求
requestWithLog(
logTitle: "设备校准",
method: MyHttpMethod.post,
queryUrl: queryUrl,
data: data,
onSuccess: (res) {
if (!isSecondStep) {
// 保存第一次获取的 cid
String cid = res.rawResponse.data['cid'];
blueteethBindController.cid!.value = cid;
}
void requestCalibrationProgress() {
String cid =
blueteethBindController.cid!.value;
String progressUrl =
"$serviceAddress$progressApi?id=$cid";
requestWithLog(
logTitle: "设备校准进度",
method: MyHttpMethod.get,
queryUrl: progressUrl,
onSuccess: (res) {
final data = res.data;
double per =
(data['per'] ?? 0).toDouble();
int currStep = data['currStep'] ?? -1;
bool status = data['status'] ?? false;
String tips = data['statusText'] ?? '';
deviceCalibrationController.tips.value =
tips;
progressNotifier.value = per;
if (!isSecondStep && per >= 20) {
progressNotifier.value = 100;
// 第一步完成:仅 per >= 100
pollingTimer?.cancel();
TopSlideNotification.show(context,
text: tips);
deviceCalibrationController
.process.value = 1;
deviceCalibrationController
.bed_calibration.value = 1;
deviceCalibrationController.updateAll();
}
if (isSecondStep &&
per >= 100 &&
currStep == 5 &&
status == true) {
// 第二步完成per >= 100 && currStep == 5 && status == true
pollingTimer?.cancel();
TopSlideNotification.show(context,
text: "设备校准完成".tr);
// 可在这里执行校准完成后的业务逻辑更新
deviceCalibrationController
.bed_calibration.value = 1;
deviceCalibrationController
.position_calibration.value = 1;
deviceCalibrationController
.process.value = 1;
deviceCalibrationController.complete =
true;
deviceCalibrationController.updateAll();
}
},
onFailure: (res) {
pollingTimer?.cancel();
failureNotifier.value = true;
TopSlideNotification.show(
context,
text: res.msg ?? "服务器.失败".tr,
textColor:
themeController.currentColor.sc9,
);
},
);
}
// 初始调用一次
requestCalibrationProgress();
// 开始轮询
pollingTimer =
Timer.periodic(Duration(seconds: 2), (_) {
requestCalibrationProgress();
});
// 显示进度弹窗
showProgressDialog(
context, progressNotifier, failureNotifier);
},
onFailure: (res) {
TopSlideNotification.show(
context,
text: res.msg ?? "服务器.失败".tr,
textColor: themeController.currentColor.sc9,
);
},
);
}
},
colors: [