From 31e3105c288f156bb62e4d1ca7cd4d203e24d654 Mon Sep 17 00:00:00 2001 From: fdp <1286779656@qq.com> Date: Tue, 22 Jul 2025 21:44:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=89=88=E5=AE=9A=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E5=BE=85=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vercel/project.json | 1 + ios/Podfile.lock | 4 +- lib/data/models/user_Info.dart | 9 +-- .../controllers/pairing_controller.dart | 70 ++++++++++++++----- .../yunqiinnovation/ble_service/BleService.kt | 27 +++++-- .../Sources/ble_service/BleService.swift | 9 ++- 6 files changed, 90 insertions(+), 30 deletions(-) create mode 100644 .vercel/project.json diff --git a/.vercel/project.json b/.vercel/project.json new file mode 100644 index 000000000..10e684870 --- /dev/null +++ b/.vercel/project.json @@ -0,0 +1 @@ +{"projectName":"trae_deep_voice_k3cu"} \ No newline at end of file diff --git a/ios/Podfile.lock b/ios/Podfile.lock index ad056d922..cc533b2d6 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -80,7 +80,7 @@ PODS: - SDWebImage/Core (~> 5.17) - spotify_sdk (0.0.1): - Flutter - - tencentcloud_cos_sdk_plugin (1.2.4): + - tencentcloud_cos_sdk_plugin (1.2.3): - Flutter - QCloudCOSXML (= 6.4.7) - WechatOpenSDK-XCFramework (2.0.4) @@ -192,7 +192,7 @@ SPEC CHECKSUMS: SDWebImage: f84b0feeb08d2d11e6a9b843cb06d75ebf5b8868 SDWebImageWebPCoder: e38c0a70396191361d60c092933e22c20d5b1380 spotify_sdk: a48400bb29f70c4fe251ebfdc9135c37097ac5ca - tencentcloud_cos_sdk_plugin: 7bed564dbe72df23e7b5cacb1e51b1a20cb1639c + tencentcloud_cos_sdk_plugin: c3d78b2c3bae42b5a20009dc047f3f1621e6272b WechatOpenSDK-XCFramework: 36fb2bea0754266c17184adf4963d7e6ff98b69f wifi_iot: f645260a2be8608517b2a9bf4c39b98e97003acc diff --git a/lib/data/models/user_Info.dart b/lib/data/models/user_Info.dart index 04fa89610..e5efa62ec 100644 --- a/lib/data/models/user_Info.dart +++ b/lib/data/models/user_Info.dart @@ -23,6 +23,7 @@ class User { String phonemac; String password; int viplv = 0; //添加会员等级字段,0表示普通用户 + List devices; // 私有构造函数 @@ -43,7 +44,7 @@ class User { factory User.fromJson(Map json) { // 修复1:安全获取嵌套的 user 字段 final userData = json['user'] as Map?; // 允许空值 - final devicesData = json['devices'] as Map?; // 允许空值 + final devicesData = json['devices'] as List?; // 允许空值 //final token = json['data']['token'] as String? ?? ''; //final token = ''; // 更新单例实例 @@ -61,7 +62,7 @@ class User { phonemac: (userData?['phonemac'] as String?) ?? '', password: (userData?['password'] as String?) ?? '', viplv: (userData?['viplv'] as int?) ?? 0, // 提供默认值 - devices: (devicesData as List?) + devices: devicesData ?.map((e) => UserDevice.fromJson(e as Map)) .toList() ?? [], // 处理设备列表 @@ -70,7 +71,7 @@ class User { factory User.fronTokenJson(Map json) { // 修复1:安全获取嵌套的 user 字段 final userData = json['user'] as Map?; // 允许空值 - final devicesData = json['devices'] as Map?; // 允许空值 + final devicesData = json['devices'] as List?; // 允许空值 print("数据获取fronTokenJson${userData} ${devicesData}"); // 更新单例实例 return _instance = User._( @@ -86,7 +87,7 @@ class User { password: (userData?['password'] as String?) ?? '', viplv: (userData?['viplv'] as int?) ?? 0, // 提供默认值 devices: devicesData != null - ? (devicesData as List) + ? (devicesData) .map((e) => UserDevice.fromJson(e as Map)) .toList() : [], // 处理设备列表 diff --git a/lib/modules/pairing/controllers/pairing_controller.dart b/lib/modules/pairing/controllers/pairing_controller.dart index 39bb9d47a..090dd9d6f 100644 --- a/lib/modules/pairing/controllers/pairing_controller.dart +++ b/lib/modules/pairing/controllers/pairing_controller.dart @@ -76,6 +76,9 @@ class PairingController extends GetxController { bool isShowSkipButton = false; //是否显示跳过按钮 + final availableDevices = [].obs; // 可用设备列表 + final selectedDevice = Rx(null); // 用户选中的设备 + // ========== 监听器管理 ========== final List _workers = []; Timer? _bleTimeoutTimer; @@ -601,13 +604,23 @@ class PairingController extends GetxController { } } - //自动绑定设备 0 未合作商 1 合作商 2,已绑定 + //自动绑定设备 0 未合作商 1 合作商 9经典蓝牙已绑定 10,ble蓝牙已绑定 Future authbindingDevice(BluetoothDevice device) async { - // if (User.instance.earphoneauthcode != "" && - // User.instance.earphonemac == device.address) { - // // 已经绑定 - // return 9; - // } + // 检查是否已有绑定的设备 + final existingDevice = User.instance.devices.firstWhere( + (d) => d.devicetype == 0 && d.devicemac == device.address, + orElse: () => UserDevice( + id: -1, + uid: '', + devicetype: -1, + devicename: '', + devicemac: '', + license: ''), + ); + if (existingDevice.id != -1) { + // 已经绑定 + return 9; + } // 检查设备名称是否包含 DeepSound 或 DeapSound final deviceName = device.name; @@ -663,14 +676,26 @@ class PairingController extends GetxController { _bleManager.stopScan(); deviceCode.value = code; _verifiedDeviceAddress = device.address; - // 检查是否已经绑定 - // if (User.instance.earphonelicense != "" && - // User.instance.earphonemac == device.address) { - // // 已经绑定 - // return 10; - // } else { - return 1; - // } + //检查是否已经绑定 + final existingDevice = User.instance.devices.firstWhere( + (d) => + d.devicetype == 2 && + d.license != "" && + d.devicemac == device.address, + orElse: () => UserDevice( + id: -1, + uid: '', + devicetype: -1, + devicename: '', + devicemac: '', + license: ''), + ); + if (existingDevice.id != -1) { + // 已经绑定 + return 10; + } else { + return 1; + } } } else { break; @@ -681,9 +706,13 @@ class PairingController extends GetxController { } await Future.delayed(Duration(seconds: 1)); } + return 0; - } else { - return 0; + } + + //可以跳转1 + else { + return 1; } } @@ -919,4 +948,13 @@ class PairingController extends GetxController { Logger.e(_tag, '清除设备关联失败: $e'); } } + + // 用户选择设备后调用 + void onDeviceSelected(BluetoothDevice device) { + Logger.i(_tag, '用户选择了设备: ${device.name} (${device.address})'); + selectedDevice.value = device; + _currentClassicDevice = device; + _transition(PairingState.verifying); + _verifyDevice(device); + } } diff --git a/local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleService.kt b/local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleService.kt index 497968ed0..c538dc027 100644 --- a/local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleService.kt +++ b/local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleService.kt @@ -357,17 +357,34 @@ object BleService { } return null; } - fun getDeviceInfos(deviceName: String): List>? { + fun getDeviceInfos(deviceName: String): List> { // 更新缓存 val matchedResults = scanResults.filter { it.device.name == deviceName } Log.d(TAG, "找到 ${matchedResults.size} 个名称为 $deviceName 的设备") - - if (matchedResults.isEmpty()) { - return emptyList() + + val ret = mutableListOf>() + + // 如果找到匹配设备名的结果,返回匹配设备的信息 + if (matchedResults.isNotEmpty()) { + for (result in matchedResults) { + val info = printDeviceInfo(result) + if (info != null) { + ret.add(info) + } + } + } else { + // 如果没找到匹配设备名的结果,返回所有扫描到的设备信息 + for (result in scanResults) { + val info = printDeviceInfo(result) + if (info != null) { + ret.add(info) + } + } } - return null; + + return ret } /** * 打印设备信息和服务UUID diff --git a/local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift b/local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift index 5c10e0399..b36c9c997 100644 --- a/local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift +++ b/local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift @@ -230,11 +230,14 @@ private var cmdReplyType: UInt8 = 0 isScanning = true // 移除服务UUID过滤,扫描所有设备 - manager.scanForPeripherals(withServices: nil, options: [ + // manager.scanForPeripherals(withServices: nil, options: [ + // CBCentralManagerScanOptionAllowDuplicatesKey: true // 允许重复以获取更新的广播数据 + // ]) + let serviceUUIDs = [BleConst.SERVICE_UUID] + manager.scanForPeripherals(withServices: serviceUUIDs, options: [ CBCentralManagerScanOptionAllowDuplicatesKey: true // 允许重复以获取更新的广播数据 ]) - - os_log("🔍 开始扫描所有BLE设备(无过滤),超时时间: %.1f秒", log: logger, type: .info, timeout) + // os_log("🔍 开始扫描所有BLE设备(无过滤),超时时间: %.1f秒", log: logger, type: .info, timeout) // 设置扫描超时 scanTimer?.invalidate()