1
0
forked from dyf/APP

蓝牙增加断开重连、换设备后可以去再次绑定

This commit is contained in:
liub
2025-09-19 12:01:06 +08:00
parent ff5e363ccc
commit 482a47bd4f
6 changed files with 394 additions and 186 deletions

View File

@ -8,6 +8,9 @@
<view class="deviceName">
蓝牙名:{{device.name}}
</view>
<view class="deviceName">
状态:{{deviceStatu}}
</view>
<view class="deviceName">
设备名:{{device.deviceName}}
</view>
@ -40,12 +43,14 @@
var these = null;
var eventChannel = null;
var ble = null;
var timeInteval = null;
export default {
data() {
return {
Statu: {
bound: null
bound: null,
timeInteval:null,
isSearch:false
},
device: {
"deviceId": "",
@ -57,7 +62,8 @@
],
"linkStatu": false,
"macAddress": ""
"macAddress": "",
"communicationMode":""
},
serverDevice:null
}
@ -72,15 +78,36 @@
} else {
return "red";
}
},
deviceStatu:function(){
if(!this.device.name){
return "";
}
if(!this.device.macAddress){
return '等待设备上报Mac地址';
}
if(!this.device.deviceName ){
if(this.Statu.isSearch){
return "无效设备";
}else{
if(this.Statu.timeInteval===null){
return "等待查询设备"
}else{
return "正在查询设备";
}
}
}else{
return "找到有效设备"
}
return "";
}
},
onBackPress() {
console.log("返回时断开蓝牙连接,取消订阅");
ble.disconnectDevice(these.device.deviceId);
ble.removeReceiveCallback(pagePath);
},
onUnload() {
console.log("返回时断开蓝牙连接,取消订阅");
ble.disconnectDevice(these.device.deviceId);
ble.removeReceiveCallback(pagePath);
},
onLoad(option) {
@ -96,6 +123,7 @@
if (f && f.macAddress) {
these.device.macAddress = f.macAddress;
console.log("222222");
these.Statu.isSearch=false;
these.initDevice();
}
}
@ -112,9 +140,9 @@
keys.forEach((v, index) => {
these.device[v] = f[v];
})
console.log("LinkedList=", ble.data.LinkedList)
console.log("f=", f);
console.log("获取到设备", these.device);
// console.log("LinkedList=", ble.data.LinkedList)
// console.log("f=", f);
// console.log("获取到设备", these.device);
if (f.macAddress) {
these.device.macAddress = f.macAddress;
@ -130,9 +158,10 @@
methods: {
initDevice: function() {
clearTimeout(timeInteval);
clearTimeout(this.Statu.timeInteval);
timeInteval = setTimeout(() => {
this.Statu.timeInteval = setTimeout(() => {
this.Statu.isSearch=true;
showLoading(these, {
text: '正在获取设备信息'
});
@ -144,6 +173,7 @@
deviceMac: these.device.macAddress
}
}).then(res => {
console.log("获取设备信息", res);
if (res && res.code == 200) {
let data = res.data;
@ -180,6 +210,8 @@
}).catch((ex) => {
console.log("获取设备出现异常:", ex);
}).finally(() => {
this.Statu.timeInteval=null;
this.Statu.isSearch=false;
hideLoading(these);
});
@ -202,11 +234,16 @@
these.Statu.boundRemark = "设备上报Mac地址异常";
return;
}
if(!this.device.deviceName){
these.Statu.bound = false;
these.Statu.boundRemark = "设备未入库";
return;
}
these.Statu.bound = null;
these.Statu.boundRemark = "";
showLoading(these, {
text: "连接中..."
text: "绑定中..."
})
let promise = request({
url: '/app/device/bind',