|
|
@@ -70,6 +70,7 @@ import WifiListComponent from './components/wifi-list.vue'
|
|
|
import SuccessPage from './components/success-page.vue'
|
|
|
import APPConfig from '@/config/index'
|
|
|
import { AppTypeEnum } from '@/enum/index'
|
|
|
+import { getBeaconInfo } from '@/utils/template';
|
|
|
|
|
|
// 定义步骤状态:0=开始, 1=扫描蓝牙, 2=选择WiFi, 3=完成
|
|
|
const currentStep = ref<number>(0);
|
|
|
@@ -180,7 +181,6 @@ const goDevicesPage = () => {
|
|
|
const startScan = () => {
|
|
|
// 故事机 扫描二维码 获取蓝牙信息 进行链接
|
|
|
// 小逗AI 扫描物理设备蓝牙 进行链接
|
|
|
- console.log('APPConfig.appType:', APPConfig.appType);
|
|
|
uni.openBluetoothAdapter({
|
|
|
success: (res) => {
|
|
|
if (APPConfig.appType === AppTypeEnum.StoryMachine) {
|
|
|
@@ -190,7 +190,12 @@ const startScan = () => {
|
|
|
success: (res) => {
|
|
|
loadingBluetoothConnect.value = true
|
|
|
console.log("扫码结果:", res);
|
|
|
- const mac = res.result
|
|
|
+
|
|
|
+ // 二维码格式: https://luojigou.vip/g/98A34635D252
|
|
|
+ // 提取 MAC 地址(URL 最后一段)
|
|
|
+ const urlParts = res.result.split('/')
|
|
|
+ const mac = urlParts[urlParts.length - 1].toUpperCase()
|
|
|
+ console.log("提取的MAC:", mac);
|
|
|
|
|
|
const isIOS = uni.getSystemInfoSync().platform === 'ios'
|
|
|
|
|
|
@@ -200,32 +205,26 @@ const startScan = () => {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // iOS 不支持 MAC 直连,需要先扫描,从广播数据中匹配目标设备
|
|
|
- const targetMac = mac.toUpperCase().replace(/:/g, '')
|
|
|
-
|
|
|
+ // iOS 不支持 MAC 直连,需要扫描并通过设备名称匹配
|
|
|
+ // 设备名称格式: XDS_ + MAC (如 XDS_98A34635D252)
|
|
|
+ const targetDeviceName = `XDS_${mac}`
|
|
|
currentStep.value = 1
|
|
|
|
|
|
uni.startBluetoothDevicesDiscovery({
|
|
|
allowDuplicatesKey: false,
|
|
|
success: () => {
|
|
|
- console.log('iOS: 开始扫描,目标MAC:', targetMac)
|
|
|
+ console.log('iOS: 开始扫描,目标设备名:', targetDeviceName)
|
|
|
const scanTimeout = setTimeout(() => {
|
|
|
uni.stopBluetoothDevicesDiscovery({})
|
|
|
uni.offBluetoothDeviceFound()
|
|
|
+ loadingBluetoothConnect.value = false
|
|
|
uni.showToast({ title: '未找到设备,请靠近后重试', icon: 'none' })
|
|
|
}, 15000)
|
|
|
|
|
|
uni.onBluetoothDeviceFound((foundRes) => {
|
|
|
for (const device of foundRes.devices) {
|
|
|
- // iOS deviceId 是 UUID,从广播数据里匹配 MAC
|
|
|
- let macInAdvert = ''
|
|
|
- if (device.advertisData) {
|
|
|
-
|
|
|
- const bytes = new Uint8Array(device.advertisData)
|
|
|
- macInAdvert = Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('').toUpperCase()
|
|
|
- console.log('当前蓝牙设备的广播数据段中的 ManufacturerData 数据段备:', macInAdvert)
|
|
|
- }
|
|
|
- if (macInAdvert.includes(targetMac)) {
|
|
|
+ console.log('扫描到设备:', device.name, device.deviceId)
|
|
|
+ if (device.name === targetDeviceName) {
|
|
|
clearTimeout(scanTimeout)
|
|
|
uni.stopBluetoothDevicesDiscovery({})
|
|
|
uni.offBluetoothDeviceFound()
|