This commit is contained in:
wyf
2025-05-23 14:51:09 +08:00
parent 8a418c9c98
commit c650bad8b1
36 changed files with 1297 additions and 892 deletions

View File

@@ -24,10 +24,25 @@ class _DeviceShareInfoWidgetState extends State<DeviceShareInfoWidget> {
@override
Widget build(BuildContext context) {
bool selected = false;
final key = deviceShareListController.model.accountKey;
final matchedValues = [];
for (final item in widget.data) {
if (item is Map && item.containsKey(key)) {
final value = item[key];
if (value != null) {
final strValue = value.toString();
if (strValue.isNotEmpty) {
matchedValues.add(strValue);
break;
}
}
}
}
return ClickableContainer(
backgroundColor: themeController.currentColor.sc5,
highlightColor: themeController.currentColor.sc3,
highlightColor: themeController.currentColor.sc4,
borderRadius: 20.rpx,
padding: EdgeInsetsDirectional.fromSTEB(0.rpx, 33.rpx, 0.rpx, 33.rpx),
onTap: () {},
@@ -35,6 +50,11 @@ class _DeviceShareInfoWidgetState extends State<DeviceShareInfoWidget> {
mainAxisSize: MainAxisSize.max,
children: [
Obx(() {
// 判断当前项是否被选中
var aa = deviceShareListController.selectedShareInfo;
print(aa);
final isSelected = matchedValues.any((v) =>
deviceShareListController.selectedShareInfo.value.contains(v));
return Theme(
data: ThemeData(
checkboxTheme: CheckboxThemeData(
@@ -47,18 +67,52 @@ class _DeviceShareInfoWidgetState extends State<DeviceShareInfoWidget> {
unselectedWidgetColor: Color(0xFFD3D3D3),
),
child: Checkbox(
value: deviceShareListController.selectedShareInfo.value
.contains(widget.data[0]['k']),
value: isSelected,
onChanged: (newValue) async {
if (newValue != null) {
if (newValue == true) {
deviceShareListController.selectedShareInfo.value
.add(widget.data[0]['k']);
} else {
deviceShareListController.selectedShareInfo.value
.remove(widget.data[0]['k']);
final key = deviceShareListController.model.accountKey;
// 提取包含指定 key 的 value
final List<String> matchedValues = [];
for (final item in widget.data) {
if (item is Map && item.containsKey(key)) {
final value = item[key];
if (value != null) {
final strValue = value.toString();
if (strValue.isNotEmpty) {
matchedValues.add(strValue);
break;
}
}
}
}
if (newValue == true) {
// 添加匹配值到已选列表中(避免重复)
for (final v in matchedValues) {
if (!deviceShareListController.selectedShareInfo.value
.contains(v)) {
deviceShareListController.selectedShareInfo.value
.add(v);
}
}
} else {
// 从已选列表中移除匹配值
deviceShareListController.selectedShareInfo.value
.removeWhere((v) => matchedValues.contains(v));
}
// 刷新 UI 和全选状态
final selectedCount =
deviceShareListController.selectedShareInfo.length;
final totalCount =
deviceShareListController.shareInfoList.length;
deviceShareListController.model.all =
(selectedCount == totalCount) ? 1 : 0;
deviceShareListController.selectedShareInfo.refresh();
deviceShareListController.updateAll();
}
final selectedCount =
deviceShareListController.selectedShareInfo.length;
final totalCount =
@@ -66,8 +120,7 @@ class _DeviceShareInfoWidgetState extends State<DeviceShareInfoWidget> {
deviceShareListController.model.all =
(selectedCount == totalCount) ? 1 : 0;
deviceShareListController.selectedShareInfo
.refresh(); // ✅ 关键代码
deviceShareListController.selectedShareInfo.refresh();
deviceShareListController.updateAll();
},
side: BorderSide(
@@ -91,22 +144,52 @@ class _DeviceShareInfoWidgetState extends State<DeviceShareInfoWidget> {
crossAxisAlignment: CrossAxisAlignment.start,
children: List.generate(widget.data.length, (index) {
final item = widget.data[index];
if (item is Map &&
item.containsKey('show') &&
item['show'] == false) {
return Container();
}
return Container(
constraints: BoxConstraints(
minHeight: 62.rpx,
),
child: Align(
alignment: AlignmentDirectional(-1, 0),
child: Text(
"${item['k']}" + ":" + "${item['v']}",
style:
FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
fontSize: 26.rpx,
letterSpacing: 0.0,
color: themeController.currentColor.sc3,
),
),
child: Row(
children: [
SizedBox(
width: 105.rpx,
child: Align(
alignment: AlignmentDirectional(-1, 0),
child: Text(
"${item['k']}",
style: FlutterFlowTheme.of(context)
.bodyMedium
.override(
fontFamily: 'Inter',
fontSize: 26.rpx,
letterSpacing: 0.0,
color: themeController.currentColor.sc4,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
),
Text(
"${item['v']}",
style: FlutterFlowTheme.of(context)
.bodyMedium
.override(
fontFamily: 'Inter',
fontSize: 26.rpx,
letterSpacing: 0.0,
color: themeController.currentColor.sc3,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
].divide(SizedBox(
width: 34.rpx,
)),
),
);
}),

View File

@@ -8,7 +8,6 @@ import 'package:vbvs_app/common/util/DailyLogUtils.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/component/tool/ClickableContainer.dart';
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
import 'package:vbvs_app/component/tool/cmd.dart';
import 'package:vbvs_app/controller/device/blueteeth_bind_controller.dart';
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
import 'package:vbvs_app/model/BleDeviceData.dart';
@@ -86,7 +85,8 @@ class _SingleBlueteethDeviceCompoentWidgetState
TopSlideNotification.show(context, text: response.msg!);
if (response.code == HttpStatusCodes.ok) {
// showLoadingDialog(context); // 显示 loading
Get.toNamed("/personPage");
// Get.toNamed("/personPage");
Get.toNamed("/wifiPage");
THapp bledevice = THapp(device: widget.bleDevice.device);
blueteethBindController.currentDevice = bledevice;
// await bledevice.device.connect();

View File

@@ -530,9 +530,9 @@ void showConfirmDialog(
CustomCard(
borderRadius: AppConstants().button_container_radius,
onTap: () {
Get.back();
onConfirm();
// await Future.delayed(Duration(milliseconds: 300));
Get.back();
},
colors: [
themeController.currentColor.sc1,

View File

@@ -28,6 +28,7 @@ class CalibrationPage extends StatefulWidget {
class _CalibrationPageState extends State<CalibrationPage> {
DeviceCalibrationController deviceCalibrationController = Get.find();
BlueteethBindController blueteethBindController = Get.find();
int flag = 0; //默认没有开始校准过
@override
void initState() {
super.initState();
@@ -89,8 +90,32 @@ class _CalibrationPageState extends State<CalibrationPage> {
child: CustomCard(
borderRadius: 20.rpx,
onTap: () async {
// Get.toNamed("/personPage");
Get.toNamed("/bindDeviceSuccess");
if (flag != 0) {
showConfirmDialog(
context, Container(), "校准未完成提示".tr,
onConfirm: () async {
await Get.toNamed("/personPage");
print("object");
deviceCalibrationController.process.value = 0;
deviceCalibrationController
.bed_calibration.value = 0;
deviceCalibrationController
.position_calibration.value = 0;
blueteethBindController.cid!.value = "";
deviceCalibrationController.complete = false;
}, onCancel: () {});
} else {
await Get.toNamed("/personPage");
deviceCalibrationController.process.value = 0;
deviceCalibrationController
.bed_calibration.value = 0;
deviceCalibrationController
.position_calibration.value = 0;
blueteethBindController.cid!.value = "";
deviceCalibrationController.complete = false;
}
// Get.toNamed("/bindDeviceSuccess");
},
colors: [
themeController.currentColor.sc1,
@@ -491,6 +516,7 @@ class _CalibrationPageState extends State<CalibrationPage> {
borderRadius:
AppConstants().button_container_radius, // 圆角半径
onTap: () async {
flag = 1;
if (deviceCalibrationController.complete) {
showConfirmDialog(
context, Container(), "校准已经完成,是否重新开始校准?",
@@ -504,7 +530,7 @@ class _CalibrationPageState extends State<CalibrationPage> {
.position_calibration.value = 0;
blueteethBindController.cid!.value = "";
deviceCalibrationController.complete = false;
String serviceAddress =
"https://caibration.he-info.cn";
String calibrationApi =
@@ -589,6 +615,7 @@ class _CalibrationPageState extends State<CalibrationPage> {
currStep == 5 &&
status == true) {
// 第二步完成per >= 100 && currStep == 5 && status == true
flag = 0;
pollingTimer?.cancel();
TopSlideNotification.show(context,
text: "设备校准完成".tr);

View File

@@ -2,14 +2,17 @@ import 'package:ef/ef.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:flutterflow_ui/flutterflow_ui.dart';
import 'package:vbvs_app/common/color/ServiceConstant.dart';
import 'package:vbvs_app/common/color/appConstants.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/common/util/MyUtils.dart';
import 'package:vbvs_app/common/util/requestWithLog.dart';
import 'package:vbvs_app/component/NullDataComponentWidget.dart';
import 'package:vbvs_app/component/tool/ClickableContainer.dart';
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
import 'package:vbvs_app/controller/device/device_share_list_controller.dart';
import 'package:vbvs_app/model/BleDeviceData.dart';
import 'package:vbvs_app/pages/device_bind/componnet/DeviceShareInfoWidget.dart';
import 'package:vbvs_app/pages/device_bind/componnet/bind_dialog.dart';
class DeviceShareListPage extends StatefulWidget {
String device = "";
@@ -27,7 +30,10 @@ class _DeviceShareListPageState extends State<DeviceShareListPage> {
deviceShareListController.model.key = null;
deviceShareListController.shareInfoList.value = [];
deviceShareListController.selectedShareInfo.value = [];
deviceShareListController.getDeviceShareList(widget.device);
deviceShareListController.model.all = 0;
deviceShareListController.getDeviceShareList(widget.device).then((value) {
deviceShareListController.updateAll();
});
super.initState();
}
@@ -70,7 +76,6 @@ class _DeviceShareListPageState extends State<DeviceShareListPage> {
fontSize: 30.rpx,
),
),
//todo 返回刷新列表
Positioned(
left: 0,
child: returnIconButtom,
@@ -207,8 +212,8 @@ class _DeviceShareListPageState extends State<DeviceShareListPage> {
fontSize: 26.rpx,
letterSpacing: 0.0,
),
cursorColor: themeController
.currentColor.sc3,
cursorColor:
themeController.currentColor.sc3,
),
),
),
@@ -253,6 +258,10 @@ class _DeviceShareListPageState extends State<DeviceShareListPage> {
// themeController.currentColor.sc9,
// );
// }
deviceShareListController
.getDeviceShareList(widget.device,
key: deviceShareListController
.model.key);
},
padding: EdgeInsets.symmetric(
horizontal: 10.rpx, vertical: 6.rpx),
@@ -310,15 +319,40 @@ class _DeviceShareListPageState extends State<DeviceShareListPage> {
: true,
onChanged: (newValue) async {
if (newValue == true) {
// 设置为全选
deviceShareListController.model.all =
1;
deviceShareListController
.selectedShareInfo.value =
deviceShareListController
.shareInfoList
.map((e) => e['id'] as String)
.toList();
try {
deviceShareListController
.model.all = 1;
final key =
deviceShareListController
.model.accountKey;
final List<String> selectedList =
[];
final allShareInfo =
deviceShareListController
.shareInfoList;
for (final sublist
in allShareInfo) {
if (sublist is List) {
for (final item in sublist) {
if (item is Map &&
item.containsKey(key)) {
selectedList.add(item[key]);
break;
}
}
}
}
deviceShareListController
.selectedShareInfo
.value = selectedList;
print("已全选: $selectedList");
} catch (e) {
print("全选失败: $e");
}
} else {
// 取消全选
deviceShareListController.model.all =
@@ -356,19 +390,56 @@ class _DeviceShareListPageState extends State<DeviceShareListPage> {
),
ClickableContainer(
onTap: () async {
//todo 删除分享
// ApiResponse apiResponse =
// await deviceShareListController
// .deleteShareDevice();
// if (apiResponse.code == HttpStatusCodes.ok) {
// TopSlideNotification.show(context,
// text: apiResponse.msg!);
// } else {
// TopSlideNotification.show(context,
// text: apiResponse.msg!,
// textColor:
// themeController.currentColor.sc9);
// }
showConfirmDialog(context, Container(), "删除提示".tr,
onConfirm: () async {
if (deviceShareListController
.selectedShareInfo ==
null ||
deviceShareListController
.selectedShareInfo.isEmpty) {
TopSlideNotification.show(context,
text: "删除错误提示".tr,
textColor:
themeController.currentColor.sc9);
return;
}
String serviceAddress =
ServiceConstant.service_address;
String serviceName =
ServiceConstant.server_service;
String serviceApi = ServiceConstant.device_bind;
String queryUrl =
"${serviceAddress}${serviceName}${serviceApi}";
final data = {
"mac": widget.device,
"uid": deviceShareListController
.selectedShareInfo.value
.join(','),
};
await requestWithLog(
logTitle: "删除分享设备",
method: MyHttpMethod.delete,
queryUrl: queryUrl,
data: data,
onSuccess: (res) {
TopSlideNotification.show(context,
text: res.msg!);
deviceShareListController.model.all = 0;
deviceShareListController
.selectedShareInfo.value = [];
deviceShareListController
.getDeviceShareList(widget.device);
deviceShareListController.updateAll();
},
onFailure: (res) {
TopSlideNotification.show(context,
text: res.msg!,
textColor:
themeController.currentColor.sc9);
deviceShareListController.updateAll();
},
);
}, onCancel: () {});
},
padding: EdgeInsets.symmetric(
horizontal: 20.rpx, vertical: 10.rpx),
@@ -387,28 +458,27 @@ class _DeviceShareListPageState extends State<DeviceShareListPage> {
],
),
),
Expanded(
child: deviceShareListController
.shareInfoList.value.isNotEmpty
? SingleChildScrollView(
child: Obx(() {
var selected = deviceShareListController
.selectedShareInfo.value;
return Column(
children: deviceShareListController
.shareInfoList.value
Obx(() {
final list =
deviceShareListController.shareInfoList.value;
final selected =
deviceShareListController.selectedShareInfo.value;
return Expanded(
child: list.isNotEmpty
? SingleChildScrollView(
child: Column(
children: list
.map((item) =>
DeviceShareInfoWidget(data: item))
.toList()
.divide(SizedBox(height: 30.rpx))
.addToEnd(SizedBox(
height: 30.rpx,
)),
);
}),
)
: NullDataWidget(),
),
.addToEnd(SizedBox(height: 30.rpx)),
),
)
: NullDataWidget(),
);
})
].divide(SizedBox(height: 30.rpx)),
),
),
@@ -419,42 +489,3 @@ class _DeviceShareListPageState extends State<DeviceShareListPage> {
);
}
}
BleDeviceData parseBleData(List<int> data) {
if (data.length < 18) {
throw Exception('BLE广播数据长度不足18字节');
}
int type = data[0];
int sn = data[1];
// 设备唯一ID (6字节),格式化为 MAC 地址样式
String deviceId =
List.generate(6, (i) => data[2 + i].toRadixString(16).padLeft(2, '0'))
.join(":")
.toUpperCase();
int bre = data[8];
int ht = data[9];
int active = data[10];
int flag = data[11];
// version 是4字节 uint大端字节序
int version =
(data[12] << 24) | (data[13] << 16) | (data[14] << 8) | data[15];
// qsn 是2字节 ushort大端字节序
int qsn = (data[16] << 8) | data[17];
return BleDeviceData(
type: type,
sn: sn,
deviceId: deviceId,
bre: bre,
ht: ht,
active: active,
flag: flag,
version: version,
qsn: qsn,
);
}

View File

@@ -72,7 +72,7 @@ class _WifiPageState extends State<WifiPage> {
}
if (onData.status == BleEventType.ready) {
aa = await getDeviceNetVersion(
blueteethBindController.currentDevice!, 1);
blueteethBindController.currentDevice!, 2);
if (aa == "4g") {
TopSlideNotification.show(
context,
@@ -84,6 +84,12 @@ class _WifiPageState extends State<WifiPage> {
Future.delayed(const Duration(seconds: 1), () {
Get.toNamed("/calibrationPage", arguments: 1);
});
} else if (aa == 'unknown') {
TopSlideNotification.show(
context,
text: "获取设备网络类型失败".tr,
textColor: themeController.currentColor.sc9,
);
} else {
await initWifiStatusAndWifiList();
}
@@ -1020,6 +1026,7 @@ class _WifiPageState extends State<WifiPage> {
text: "4g设备配置wifi提示".tr,
textColor: themeController.currentColor.sc9,
);
Get.back();
});
return;
} else {