Merge branch 'new-20250827' of http://47.107.152.87:3000/liubiao/APP into new-20250827
This commit is contained in:
@ -37,13 +37,25 @@
|
||||
<text class="value">{{ deviceInfo.deviceName }}</text>
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="lbl">IMEI</text>
|
||||
<text class="lbl">设备IMEI</text>
|
||||
<text class="value">{{ deviceInfo.deviceImei }}</text>
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="lbl">Mac地址</text>
|
||||
<text class="value">{{device.deviceMac}}</text>
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="lbl">蓝牙名称</text>
|
||||
<text class="value valueFont">{{device.bluetoothName}}</text>
|
||||
</view>
|
||||
<view class="item" @click.top="bleStatuToggle">
|
||||
<text class="lbl">蓝牙状态</text>
|
||||
<text class="value" :class="formData.bleStatu?'green':'red'">{{device.getbleStatu}}</text>
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="lbl">设备状态</text>
|
||||
<text class="value">{{ deviceInfo.onlineStatus === 0 ? '离线' : deviceInfo.onlineStatus
|
||||
=== 2 ? '故障' : '在线' }}</text>
|
||||
<text class="value"
|
||||
:class="deviceInfo.onlineStatus===0?'red':'green'">{{ deviceInfo.onlineStatus === 0 ? '离线': '在线' }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label" style="display: flex; align-items: center;">定位信息</text>
|
||||
@ -231,7 +243,8 @@
|
||||
deviceUpdateVolume,
|
||||
deviceVoiceBroadcast,
|
||||
updateBleStatus,
|
||||
parseBleData
|
||||
parseBleData,
|
||||
fetchBlePowerStatus
|
||||
} from '@/api/100J/HBY100-J.js'
|
||||
import BleHelper from '@/utils/BleHelper.js';
|
||||
var bleTool = BleHelper.getBleTool();
|
||||
@ -440,7 +453,7 @@
|
||||
alarmStatus: null,
|
||||
detailPageUrl: "/pages/650/HBY650",
|
||||
showConfirm: false,
|
||||
deviceId:''
|
||||
deviceId: ''
|
||||
},
|
||||
permissions: [],
|
||||
audioData: {
|
||||
@ -589,30 +602,24 @@
|
||||
these.fetchDeviceDetail(data.data.id)
|
||||
} else {
|
||||
this.activePermissions = data.data.permission ? data.data.permission.split(',') : [];
|
||||
console.log(this.activePermissions,'this.activePermissions');
|
||||
console.log(this.activePermissions, 'this.activePermissions');
|
||||
these.fetchDeviceDetail(data.data.deviceId)
|
||||
}
|
||||
|
||||
// 尝试连接蓝牙:需先扫描获取 BLE deviceId,不能直接用 MAC
|
||||
if (data.data.deviceMac) {
|
||||
these.tryConnect100JBle(data.data.deviceMac);
|
||||
}
|
||||
});
|
||||
this.createThrottledFunctions();
|
||||
|
||||
|
||||
// 注册蓝牙相关事件
|
||||
bleTool.addReceiveCallback(this.bleValueNotify, "HBY100J");
|
||||
bleTool.addDisposeCallback(this.bleStateBreak, "HBY100J");
|
||||
bleTool.addRecoveryCallback(this.bleStateRecovry, "HBY100J");
|
||||
bleTool.addStateBreakCallback(this.bleStateBreak, "HBY100J");
|
||||
bleTool.addStateRecoveryCallback(this.bleStateRecovry, "HBY100J");
|
||||
|
||||
// 尝试连接蓝牙
|
||||
if (data.data.deviceMac) {
|
||||
// 假设 deviceMac 是蓝牙的 deviceId
|
||||
bleTool.LinkBlue(data.data.deviceMac).then(() => {
|
||||
console.log("100J 蓝牙连接成功");
|
||||
this.bleStateRecovry({deviceId: data.data.deviceMac});
|
||||
}).catch(err => {
|
||||
console.log("100J 蓝牙连接失败,将使用4G", err);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
},
|
||||
onHide: function() {
|
||||
@ -625,6 +632,8 @@
|
||||
bleTool.removeRecoveryCallback("HBY100J");
|
||||
bleTool.removeStateBreakCallback("HBY100J");
|
||||
bleTool.removeStateRecoveryCallback("HBY100J");
|
||||
bleTool.removeDeviceFound("HBY100J_SCAN");
|
||||
bleTool.StopSearch();
|
||||
},
|
||||
onShow() {
|
||||
this.Status.pageHide = false;
|
||||
@ -979,24 +988,124 @@
|
||||
|
||||
deviceRecovry(res) {},
|
||||
deviceDispose(res) {},
|
||||
// 100J 蓝牙连接:先查缓存/尝试直连,失败则扫描(createBLEConnection 需要扫描返回的 deviceId)
|
||||
tryConnect100JBle(deviceMac) {
|
||||
const that = this;
|
||||
const macNorm = (m) => (m || '').replace(/:/g, '').toUpperCase();
|
||||
const targetMacNorm = macNorm(deviceMac);
|
||||
const last6 = targetMacNorm.slice(-6);
|
||||
|
||||
// 1. 查缓存:之前连过且 mac 匹配
|
||||
const cached = bleTool.data.LinkedList.find(v => {
|
||||
const m = macNorm(v.macAddress);
|
||||
return m === targetMacNorm || m.slice(-6) === last6;
|
||||
});
|
||||
if (cached && cached.deviceId) {
|
||||
console.log('[100J] 使用缓存设备连接', cached.deviceId);
|
||||
bleTool.LinkBlue(cached.deviceId).then(() => {
|
||||
console.log('100J 蓝牙连接成功(缓存)');
|
||||
that.bleStateRecovry({ deviceId: cached.deviceId });
|
||||
}).catch(err => {
|
||||
console.log('100J 蓝牙连接失败(缓存),尝试扫描', err);
|
||||
that.connect100JByScan(deviceMac, last6);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 无缓存:先尝试直连(Android 上 deviceId 可能为 MAC)
|
||||
console.log('[100J] 尝试直连', deviceMac);
|
||||
bleTool.LinkBlue(deviceMac).then(() => {
|
||||
console.log('100J 蓝牙连接成功(直连)');
|
||||
that.bleStateRecovry({ deviceId: deviceMac });
|
||||
}).catch(err => {
|
||||
console.log('100J 蓝牙直连失败,开始扫描', err);
|
||||
that.connect100JByScan(deviceMac, last6);
|
||||
});
|
||||
},
|
||||
connect100JByScan(deviceMac, last6) {
|
||||
const that = this;
|
||||
let resolved = false;
|
||||
const timeout = 15000;
|
||||
const timer = setTimeout(() => {
|
||||
if (resolved) return;
|
||||
resolved = true;
|
||||
bleTool.StopSearch();
|
||||
bleTool.removeDeviceFound('HBY100J_SCAN');
|
||||
console.log('100J 蓝牙扫描超时,将使用4G');
|
||||
}, timeout);
|
||||
|
||||
bleTool.addDeviceFound((res) => {
|
||||
if (resolved) return;
|
||||
const devices = res.devices || [];
|
||||
const match = devices.find(d => {
|
||||
const name = (d.name || '').replace(/\r\n/g, '').trim();
|
||||
return name === 'HBY100J' || name.startsWith('LED-') && name.slice(-6) === last6;
|
||||
});
|
||||
if (match) {
|
||||
resolved = true;
|
||||
clearTimeout(timer);
|
||||
bleTool.StopSearch();
|
||||
bleTool.removeDeviceFound('HBY100J_SCAN');
|
||||
console.log('[100J] 扫描到目标设备', match.name, match.deviceId);
|
||||
bleTool.LinkBlue(match.deviceId).then(() => {
|
||||
console.log('100J 蓝牙连接成功(扫描)');
|
||||
that.bleStateRecovry({ deviceId: match.deviceId });
|
||||
}).catch(err => {
|
||||
console.log('100J 蓝牙连接失败,将使用4G', err);
|
||||
});
|
||||
}
|
||||
}, 'HBY100J_SCAN');
|
||||
|
||||
bleTool.StartSearch().then(() => {
|
||||
console.log('[100J] 开始扫描蓝牙,设备名 HBY100J 或 LED-' + last6);
|
||||
}).catch(err => {
|
||||
if (!resolved) {
|
||||
resolved = true;
|
||||
clearTimeout(timer);
|
||||
bleTool.removeDeviceFound('HBY100J_SCAN');
|
||||
console.log('100J 蓝牙扫描启动失败,将使用4G', err);
|
||||
}
|
||||
});
|
||||
},
|
||||
bleStateBreak() {
|
||||
updateBleStatus(false, '', this.deviceInfo.deviceId);
|
||||
},
|
||||
bleStateRecovry(res) {
|
||||
let bleDeviceId = res ? res.deviceId : '';
|
||||
// 蓝牙适配器恢复可用(关闭蓝牙后重新开启):无 deviceId,需主动重连
|
||||
if (!res || !res.deviceId) {
|
||||
const mac = (this.device && this.device.deviceMac) || (this.deviceInfo && this.deviceInfo.deviceMac);
|
||||
if (mac) {
|
||||
console.log('[100J] 蓝牙适配器已恢复,尝试重连', mac);
|
||||
this.tryConnect100JBle(mac);
|
||||
}
|
||||
return;
|
||||
}
|
||||
let bleDeviceId = res.deviceId;
|
||||
updateBleStatus(true, bleDeviceId, this.deviceInfo.deviceId);
|
||||
// 蓝牙连接成功后主动拉取电源状态(电量、续航时间)
|
||||
fetchBlePowerStatus().catch(() => {});
|
||||
},
|
||||
previewImg(img) {},
|
||||
bleValueNotify: function(receive, device, path, recArr) { //订阅消息
|
||||
// 注意:这里 receive.deviceId 是蓝牙的 MAC 地址,而 this.formData.deviceId 是 4G 的 ID
|
||||
// 所以这里需要修改判断逻辑,或者不判断直接解析
|
||||
|
||||
// 尝试解析蓝牙上报的数据
|
||||
if (receive.bytes) {
|
||||
const parsedData = parseBleData(receive.bytes);
|
||||
if (parsedData && parsedData.batteryPercentage !== undefined) {
|
||||
this.deviceInfo.batteryPercentage = parsedData.batteryPercentage;
|
||||
}
|
||||
// 解析蓝牙上报数据 (协议: FC=MAC主动上报, FB=指令响应)
|
||||
if (!receive.bytes || receive.bytes.length < 3) return;
|
||||
const parsedData = parseBleData(receive.bytes);
|
||||
if (!parsedData) return;
|
||||
|
||||
// 5.1 连接后设备主动上报 MAC 地址 (FC + 6字节 + FF)
|
||||
if (parsedData.type === 'mac' && parsedData.macAddress) {
|
||||
this.formData.macAddress = parsedData.macAddress;
|
||||
this.device.deviceMac = parsedData.macAddress;
|
||||
this.deviceInfo.deviceMac = parsedData.macAddress;
|
||||
return;
|
||||
}
|
||||
|
||||
// 5.5 获取设备电源状态 (0x04)
|
||||
if (parsedData.batteryPercentage !== undefined) {
|
||||
this.deviceInfo.batteryPercentage = parsedData.batteryPercentage;
|
||||
}
|
||||
if (parsedData.batteryRemainingTime !== undefined) {
|
||||
this.deviceInfo.batteryRemainingTime = parsedData.batteryRemainingTime;
|
||||
}
|
||||
|
||||
if (this.deviceInfo.batteryPercentage <= 20) {
|
||||
|
||||
Reference in New Issue
Block a user