蓝牙设备均添加可主动断开蓝牙

This commit is contained in:
liub
2026-02-13 16:42:15 +08:00
parent 27097fecc4
commit 1aa11a7a38
9 changed files with 467 additions and 171 deletions

View File

@ -1,8 +1,5 @@
<template>
<view class="content contentBg">
<!-- <custom-navbar :title="Status.navbar.title" :showBack="Status.navbar.showBack" color="#FFFFFF"
:rightIcons="Status.navbar.icons" @icon-click="handleRightClick" backgroundColor="#121212"></custom-navbar>
-->
<uni-nav-bar :border="false" @clickLeft="prevPage" fixed="true" statusBar="true"
background-color="#121212" color="#FFFFFF" :title="Status.navbar.title">
<template v-slot:left><view>
@ -58,9 +55,9 @@
<text class="lbl">蓝牙名称</text>
<text class="value valueFont">{{device.bluetoothName}}</text>
</view>
<view class="item">
<view class="item" @click.top="bleStatuToggle">
<text class="lbl">蓝牙状态</text>
<text class="value" :class="formData.bleStatu?'green':'red'">{{formData.bleStatu?'已连接':'未连接'}}</text>
<text class="value" :class="formData.bleStatu?'green':'red'">{{getbleStatu}}</text>
</view>
<view class="item">
<text class="lbl">设备状态</text>
@ -550,7 +547,8 @@
these.formData['imei'] = these.device.deviceImei;
}
these.getDetail();
these.formData.bleStatu = false;
these.formData.bleStatu='connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
these.formData.bleStatu = true;
});
@ -567,9 +565,49 @@
ble.removeReceiveCallback(pagePath);
},
computed: {
getbleStatu(){
if(this.formData.bleStatu===true){
return '已连接';
}
if(this.formData.bleStatu==='connecting'){
return '连接中';
}
if(this.formData.bleStatu==='dicconnect'){
return '正在断开';
}
if(this.formData.bleStatu==='err'){
return '连接异常';
}
return '未连接';
}
},
methods: {
bleStatuToggle(){
let f=this.getDevice();
if(!f){
this.showBleUnConnect();
return;
}
if(this.formData.bleStatu===true){
this.formData.bleStatu='dicconnect';
ble.disconnectDevice(f.deviceId).finally(r=>{
this.formData.bleStatu=false;
});
return;
}
if(this.formData.bleStatu===false || this.formData.bleStatu==='err'){
this.formData.bleStatu='connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
these.formData.bleStatu = true;
}).catch(ex=>{
these.formData.bleStatu = 'err';
});
return;
}
},
prevPage() {
uni.navigateBack({
@ -629,6 +667,7 @@
showLoading(this, {
text: "蓝牙恢复可用,正在连接设备"
});
this.formData.bleStatu='connecting';
ble.LinkBlue(these.formData.deviceId).then(() => {
these.formData.bleStatu = true;
updateLoading(these, {