This commit is contained in:
wyf
2025-06-06 09:23:23 +08:00
parent bc86cf7d78
commit 54ad7c18e6
7 changed files with 543 additions and 244 deletions

View File

@@ -61,25 +61,25 @@ class BlueteethBindController extends GetControllerEx<BlueteethBindModel> {
Timer? _statusTimer;
THapp? currentDevice;
RxInt wifiStatus = 0.obs;//wifi连接状态 0未连接 1已连接
RxInt wifiStatus = 0.obs; //wifi连接状态 0未连接 1已连接
RxList wifiList = [].obs;
RxMap connect_wifi = {}.obs;
RxString scanMac = "".obs;
RxString currentDeviceMac = "".obs;//当前选中的设备mac地址
RxString currentDeviceMac = "".obs; //当前选中的设备mac地址
RxString? cid = "".obs;
RxString search = "".obs; //搜索关键字
RxBool bluetoothStatus = false.obs;//蓝牙开启状态
RxInt connectStatus = 0.obs;//当前wifi连接状态 0未连接 1已连接
RxInt blueConnectFlag = 0.obs;//当前蓝牙连接状态 0.正在连接 1.未连接 2.已连接
RxInt netType = 0.obs;//当前网络类型 0.正在检测 1.wifi 2.4g设备 3.未知
RxInt wifiConnectStatus = 1.obs;//获取wifi状态 0.正在检测 1.已检测完
RxBool bluetoothStatus = false.obs; //蓝牙开启状态
RxInt connectStatus = 0.obs; //当前wifi连接状态 0未连接 1已连接
RxInt blueConnectFlag = 0.obs; //当前蓝牙连接状态 0.正在连接 1.未连接 2.已连接
RxInt netType = 0.obs; //当前网络类型 0.正在检测 1.wifi 2.4g设备 3.未知
RxInt wifiConnectStatus = 1.obs; //获取wifi状态 0.正在检测 1.已检测完
RxMap selectWifi = {}.obs; //正在连接wifi信息
int returnPage = 0;//0返回首页 1.返回设备列表
int returnPage = 0; //0返回首页 1.返回设备列表
// 安全展示 TopSlideNotification
void safeShowNotification(String msg) {
@@ -174,32 +174,72 @@ class BlueteethBindController extends GetControllerEx<BlueteethBindModel> {
if (response.data['data'] != null && response.data['data'] is List) {
List<dynamic> responseList = response.data['data'];
// 构建 mac -> 设备的映射
Map<String, BleDeviceData> deviceMap = {
for (var d in model.devicelist!)
if (d.mac != null) d.mac!: d
if (d.mac != null) d.mac!.toLowerCase(): d,
};
List<String> slaveMacsToRemove = [];
// 用于记录已经设置过主从关系的 mac避免重复
Set<String> processedMacs = {};
for (var item in responseList) {
String mac = item['mac'];
String? bindMac = item['bindMac'];
String mac = item['mac'].toLowerCase();
String? bindMac = item['bindMac']?.toLowerCase();
bool? bind = item['bind'];
if (deviceMap.containsKey(mac)) {
BleDeviceData currentDevice = deviceMap[mac]!;
currentDevice.bind = bind;
if (bindMac != null && deviceMap.containsKey(bindMac)) {
BleDeviceData masterDevice = deviceMap[bindMac]!;
masterDevice.slave = currentDevice;
slaveMacsToRemove.add(mac);
if (!deviceMap.containsKey(mac)) continue;
BleDeviceData currentDevice = deviceMap[mac]!;
currentDevice.bind = bind;
if (bindMac != null && deviceMap.containsKey(bindMac)) {
final isMutualBind = responseList.any((e) =>
e['mac']?.toString().toLowerCase() == bindMac &&
e['bindMac']?.toString().toLowerCase() == mac);
if (isMutualBind) {
if (processedMacs.contains(mac) ||
processedMacs.contains(bindMac)) {
continue;
}
final masterMac = (mac.compareTo(bindMac) < 0) ? mac : bindMac;
final slaveMac = (mac.compareTo(bindMac) < 0) ? bindMac : mac;
if (deviceMap.containsKey(masterMac) &&
deviceMap.containsKey(slaveMac)) {
deviceMap[masterMac]!.slave = deviceMap[slaveMac];
processedMacs.add(masterMac);
processedMacs.add(slaveMac);
}
} else {
if (!processedMacs.contains(mac)) {
BleDeviceData masterDevice = deviceMap[bindMac]!;
masterDevice.slave = currentDevice;
processedMacs.add(mac);
processedMacs.add(bindMac);
}
}
}
}
model.devicelist!
.removeWhere((device) => slaveMacsToRemove.contains(device.mac));
model.betDevicelist = model.devicelist!;
// 获取所有被作为 slave 的 mac用于排除掉
final Set<String> allSlaveMacs = {
for (var d in deviceMap.values)
if (d.slave?.mac != null) d.slave!.mac!.toLowerCase()
};
// 构造最终列表,只保留主设备和未被作为 slave 的独立设备
final List<BleDeviceData> finalList = deviceMap.values.where((d) {
final mac = d.mac?.toLowerCase();
if (mac == null) return false;
if (d.slave != null) return true; // 主设备
return !allSlaveMacs.contains(mac); // 不是别人 slave 的独立设备
}).toList();
model.betDevicelist = finalList;
} else {
model.betDevicelist = [];
}
@@ -235,6 +275,7 @@ class BlueteethBindController extends GetControllerEx<BlueteethBindModel> {
queryUrl += "?lang=$language";
}
}
//todo 双人版的话根据slave取到mac
var data = {
"deviceType": 1,
"mac": d.mac,