1
0
forked from dyf/APP

修复蓝牙配对时多设备串数据的问题

This commit is contained in:
liub
2026-05-20 11:26:13 +08:00
parent 7f56e46ace
commit 958aa1374a
2 changed files with 42 additions and 33 deletions

View File

@ -215,7 +215,7 @@
sta_leftFan: null, sta_leftFan: null,
sta_rightFan: null, sta_rightFan: null,
sta_channel: null, sta_channel: null,
sta_Ms: null, sta_Ms: 'S',
sta_PowerPercent: null, sta_PowerPercent: null,
sta_PowerTime: null, sta_PowerTime: null,
sta_system: null, sta_system: null,
@ -1010,10 +1010,11 @@
border-width: 5rpx; border-width: 5rpx;
border-color: #00000000; border-color: #00000000;
padding: 5rpx; padding: 5rpx;
height:130rpx !important;
} }
.lampMode .type .txt { .lampMode .type .txt {
color: rgba(255, 255, 255, 0.2); color: rgba(255, 255, 255, 0.5);
background-color: #00000000; background-color: #00000000;
font-family: "PingFang SC"; font-family: "PingFang SC";
font-size: 50rpx; font-size: 50rpx;

View File

@ -35,8 +35,8 @@
</view> </view>
<view class="centertxt "> <view class="centertxt ">
<view class="name" v-text="item.name"></view> <view class="name" v-text="item.name"></view>
</view> </view>
<view class="rightIco center"> <view class="rightIco center">
<image src="/static/images/BLEAdd/linked.png" class="img" mode="aspectFit"> <image src="/static/images/BLEAdd/linked.png" class="img" mode="aspectFit">
@ -49,8 +49,8 @@
</view> </view>
<view class="lblTitle"> <view class="lblTitle">
<text>发现设备:{{EquipMents.length}} 筛选设备:{{deviceCnt}}</text> <text>发现设备:{{EquipMents.length}} 筛选设备:{{deviceCnt}}</text>
<view @click="refreshBleList()">刷新</view> <view @click="refreshBleList()">刷新</view>
</view> </view>
<view class=""> <view class="">
@ -68,7 +68,7 @@
<view class="name"> <view class="name">
<text>{{item.name?item.name:'Unnamed'}}</text> <text>{{item.name?item.name:'Unnamed'}}</text>
</view> </view>
<view class="id"> <view class="id">
<text>信号:{{item.RSSI}}dBm</text> <text>信号:{{item.RSSI}}dBm</text>
</view> </view>
@ -131,7 +131,7 @@
var ble = null; var ble = null;
var these = null; var these = null;
var eventChannel = null; var eventChannel = null;
var sortTime=null; var sortTime = null;
export default { export default {
data() { data() {
return { return {
@ -276,7 +276,7 @@
} }
console.log("处理蓝牙不可用"); console.log("处理蓝牙不可用");
hideLoading(these); hideLoading(these);
clearInterval(these.Status.intval);
these.PairEquip = []; these.PairEquip = [];
these.EquipMents = []; these.EquipMents = [];
uni.showToast({ uni.showToast({
@ -317,6 +317,7 @@
setTimeout(() => { setTimeout(() => {
hideLoading(these); hideLoading(these);
clearInterval(these.Status.intval);
}, 1500); }, 1500);
}, pagePath); }, pagePath);
@ -348,7 +349,7 @@
}); });
if (!f) { if (!f) {
if (these.device && these.device.bluetoothName && device.name) { if (these.device && these.device.bluetoothName && device.name) {
const bn = these.device.bluetoothName; const bn = these.device.bluetoothName;
if (bn === device.name || if (bn === device.name ||
@ -370,10 +371,10 @@
} }
clearTimeout(sortTime); clearTimeout(sortTime);
sortTime=setTimeout(()=>{ sortTime = setTimeout(() => {
these.EquipMents.sort((a, b) => b.RSSI - a.RSSI); these.EquipMents.sort((a, b) => b.RSSI - a.RSSI);
},500); }, 500);
}, pagePath); }, pagePath);
@ -409,23 +410,27 @@
return; return;
} }
if ((receivData.str && (receivData.str.indexOf('mac address:') > -1 || receivData.str.indexOf( if (f.deviceId == this.item.deviceId) {//只处理本次连接的设备消息
'sta_address') > -1)) || if ((receivData.str && (receivData.str.indexOf('mac address:') > -1 || receivData
(receivData.bytes && receivData.bytes[0] === 0xFC && receivData.bytes.length >= 7)) { .str.indexOf(
'sta_address') > -1)) ||
(receivData.bytes && receivData.bytes[0] === 0xFC && receivData.bytes.length >=
7)) {
if (f.macAddress && these.device) { if (f.macAddress && these.device) {
clearInterval(this.Status.intval); clearInterval(this.Status.intval);
this.Status.intval = null; this.Status.intval = null;
this.Status.time = null; this.Status.time = null;
showLoading(these, { showLoading(these, {
text: '正在验证设备' text: '正在验证设备'
}); });
setTimeout(() => { setTimeout(() => {
these.DeviceVerdict(f.deviceId); these.DeviceVerdict(f.deviceId);
}, 0); }, 0);
}
} }
} }
}, pagePath); }, pagePath);
@ -634,8 +639,8 @@
return; return;
} }
hideLoading(these); hideLoading(these);
these.device.bleId=deviceId; these.device.bleId = deviceId;
ble.updateCache(); ble.updateCache();
eventChannel.emit('BindOver', these.device); eventChannel.emit('BindOver', these.device);
uni.navigateBack(); uni.navigateBack();
@ -721,9 +726,9 @@
return false; return false;
}, },
Link: function(item) { Link: function(item) {
this.item.deviceId = item.deviceId;
showLoading(this, { showLoading(this, {
text: "正在连接:第1次" text: "正在连接..."
}); });
let index = 1; let index = 1;
@ -761,15 +766,18 @@
ble.LinkBlue(item.deviceId).then((res) => { ble.LinkBlue(item.deviceId).then((res) => {
this.tmpLink = [item]; this.tmpLink = [item];
console.log("连接成功"); console.log("连接成功");
ble.StopSearch(); these.item.deviceId = item.deviceId;
ble.StopSearch().catch(ex=>{});
resolve(res); resolve(res);
}).catch((ex) => { }).catch((ex) => {
if (index == total) { if (index == total) {
console.log("连接了N次都没连上"); console.log("连接了N次都没连上");
reject(ex); reject(ex);
updateLoading(this, { updateLoading(this, {
text: ex.msg text: ex.msg
}) });
this.item.deviceId =null;
return; return;
} }
index++; index++;