优化蓝牙连接7305同步状态

This commit is contained in:
微微一笑
2025-11-05 10:22:17 +08:00
parent 9313ec0106
commit a0c883f4e3

View File

@ -333,6 +333,13 @@
console.log("连接成功"); console.log("连接成功");
these.formData.bleStatu = true; these.formData.bleStatu = true;
// 连接成功后同步BleHelper中的连接状态
if (f) {
f.Linked = true;
ble.updateCache();
console.log("页面初始化连接成功同步BleHelper连接状态为已连接");
}
// 确保订阅消息已开启 // 确保订阅消息已开启
let linkedDevice = ble.data.LinkedList.find(v => v.deviceId == f.deviceId); let linkedDevice = ble.data.LinkedList.find(v => v.deviceId == f.deviceId);
if (linkedDevice && !linkedDevice.notifyState) { if (linkedDevice && !linkedDevice.notifyState) {
@ -413,8 +420,15 @@
if (res.deviceId == these.formData.deviceId) { if (res.deviceId == these.formData.deviceId) {
this.formData.bleStatu = true; this.formData.bleStatu = true;
// 连接恢复后,确保重新订阅消息以接收设备上报的数据 // 连接恢复后,同步BleHelper中的连接状态
let f = this.getDevice(); let f = this.getDevice();
if (f) {
f.Linked = true;
ble.updateCache();
console.log("设备连接恢复同步BleHelper连接状态为已连接");
}
// 连接恢复后,确保重新订阅消息以接收设备上报的数据
if (f && (f.notifyServiceid || f.notifyCharactId)) { if (f && (f.notifyServiceid || f.notifyCharactId)) {
console.log("连接恢复,重新订阅消息"); console.log("连接恢复,重新订阅消息");
ble.subScribe(res.deviceId, true).then(() => { ble.subScribe(res.deviceId, true).then(() => {
@ -474,6 +488,13 @@
}); });
ble.LinkBlue(these.formData.deviceId).then(() => { ble.LinkBlue(these.formData.deviceId).then(() => {
these.formData.bleStatu = true; these.formData.bleStatu = true;
// 连接成功后同步BleHelper中的连接状态
let f = this.getDevice();
if (f) {
f.Linked = true;
ble.updateCache();
console.log("蓝牙状态恢复后连接成功同步BleHelper连接状态为已连接");
}
updateLoading(these, { updateLoading(these, {
text: '连接成功' text: '连接成功'
}); });
@ -982,6 +1003,13 @@
return; return;
} }
// 发送前确保连接状态同步:如果页面显示已连接,同步更新 BleHelper 中的 Linked 状态
if (this.formData.bleStatu && f) {
f.Linked = true;
ble.updateCache();
console.log("发送模式指令前同步连接状态为已连接");
}
showLoading(these, { showLoading(these, {
text: "请稍候..." text: "请稍候..."
}); });
@ -1113,6 +1141,14 @@
text: "请稍候..." text: "请稍候..."
}); });
this.setBleFormData(); this.setBleFormData();
// 发送前确保连接状态同步:如果页面显示已连接,同步更新 BleHelper 中的 Linked 状态
if (this.formData.bleStatu && f) {
f.Linked = true;
ble.updateCache();
console.log("发送人员信息前同步连接状态为已连接");
}
let task = async () => { let task = async () => {
var sendTxtPackge = (rgbdata, type, str, lineIndex) => { var sendTxtPackge = (rgbdata, type, str, lineIndex) => {
@ -1320,6 +1356,13 @@
let f = this.getDevice(); let f = this.getDevice();
if (f) { if (f) {
// 发送前确保连接状态同步:如果页面显示已连接,同步更新 BleHelper 中的 Linked 状态
if (this.formData.bleStatu && f) {
f.Linked = true;
ble.updateCache();
console.log("发送亮度指令前同步连接状态为已连接");
}
// 发送数据 // 发送数据
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 100).catch(ex => { ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 100).catch(ex => {
@ -1369,6 +1412,13 @@
dataView.setUint8(3, '9C41'); // 数据长度 dataView.setUint8(3, '9C41'); // 数据长度
let f = this.getDevice(); let f = this.getDevice();
if (f) { if (f) {
// 发送前确保连接状态同步:如果页面显示已连接,同步更新 BleHelper 中的 Linked 状态
if (this.formData.bleStatu && f) {
f.Linked = true;
ble.updateCache();
console.log("发送命令前同步连接状态为已连接");
}
// 发送数据 // 发送数据
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 100).catch(ex => { ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 100).catch(ex => {