更新界面布局
This commit is contained in:
@@ -136,7 +136,128 @@ class BlueteethBindController extends GetControllerEx<BlueteethBindModel> {
|
||||
_statusTimer = null;
|
||||
}
|
||||
|
||||
Future<ApiResponse> updateDeviceStatus() async {
|
||||
// Future<ApiResponse> updateDeviceStatus() async {
|
||||
// try {
|
||||
// String serviceAddress = ServiceConstant.service_address;
|
||||
// String serviceName = ServiceConstant.server_service;
|
||||
// String serviceApi = ServiceConstant.get_bluetooth_device_status;
|
||||
// String queryUrl = "$serviceAddress$serviceName$serviceApi";
|
||||
|
||||
// if (model.devicelist != null && model.devicelist!.isNotEmpty) {
|
||||
// final macParams = model.devicelist!
|
||||
// .map((device) => "mac=${Uri.encodeQueryComponent(device.mac!)}")
|
||||
// .join("&");
|
||||
|
||||
// if (queryUrl.contains('?')) {
|
||||
// queryUrl += '&$macParams';
|
||||
// } else {
|
||||
// queryUrl += '?$macParams';
|
||||
// }
|
||||
// String? language = "";
|
||||
// if (languageController.selectLanguage != null) {
|
||||
// language = languageController.selectLanguage.value!.language_code;
|
||||
// }
|
||||
// if (language != null && language.isNotEmpty) {
|
||||
// if (queryUrl.contains("?")) {
|
||||
// queryUrl += "&lang=$language";
|
||||
// } else {
|
||||
// queryUrl += "?lang=$language";
|
||||
// }
|
||||
// }
|
||||
|
||||
// var response = await EasyDartModule.dio.get(queryUrl);
|
||||
// var responseData =
|
||||
// response.data is String ? jsonDecode(response.data) : response.data;
|
||||
// ApiResponse res =
|
||||
// ApiResponse.fromJson(responseData, (object) => object);
|
||||
// if (res.code != HttpStatusCodes.ok) return res;
|
||||
|
||||
// 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!.toLowerCase(): d,
|
||||
// };
|
||||
|
||||
// // 用于记录已经设置过主从关系的 mac,避免重复
|
||||
// Set<String> processedMacs = {};
|
||||
|
||||
// for (var item in responseList) {
|
||||
// String mac = item['mac'].toLowerCase();
|
||||
// String? bindMac = item['bindMac']?.toLowerCase();
|
||||
// bool? bind = item['bind'];
|
||||
|
||||
// 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);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 获取所有被作为 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 = [];
|
||||
// }
|
||||
|
||||
// updateAll();
|
||||
// return res;
|
||||
// }
|
||||
// } catch (e) {
|
||||
// print("获取设备状态异常: $e");
|
||||
// EasyDartModule.logger.info("获取设备状态异常: $e");
|
||||
// DailyLogUtils.writeLog("获取设备状态异常: $e");
|
||||
// return ApiResponse(code: -1, msg: "请求失败".tr);
|
||||
// }
|
||||
|
||||
// return ApiResponse(code: -1, msg: "未知错误".tr);
|
||||
// }
|
||||
|
||||
Future<ApiResponse> updateDeviceStatus() async {
|
||||
try {
|
||||
String serviceAddress = ServiceConstant.service_address;
|
||||
String serviceName = ServiceConstant.server_service;
|
||||
@@ -174,72 +295,32 @@ 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!.toLowerCase(): d,
|
||||
if (d.mac != null) d.mac!: d
|
||||
};
|
||||
|
||||
// 用于记录已经设置过主从关系的 mac,避免重复
|
||||
Set<String> processedMacs = {};
|
||||
List<String> slaveMacsToRemove = [];
|
||||
|
||||
for (var item in responseList) {
|
||||
String mac = item['mac'].toLowerCase();
|
||||
String? bindMac = item['bindMac']?.toLowerCase();
|
||||
String mac = item['mac'];
|
||||
String? bindMac = item['bindMac'];
|
||||
bool? bind = item['bind'];
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取所有被作为 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;
|
||||
model.devicelist!
|
||||
.removeWhere((device) => slaveMacsToRemove.contains(device.mac));
|
||||
model.betDevicelist = model.devicelist!;
|
||||
} else {
|
||||
model.betDevicelist = [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user