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

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

@ -57,9 +57,9 @@
<text class="lbl">蓝牙名称</text>
<text class="value">{{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>
@ -572,8 +572,11 @@
these.formData.bleStatu = false;
these.formData.deviceId = f.deviceId;
these.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';
});
these.setBleFormData();
@ -589,7 +592,21 @@
this.Status.pageHide = false;
},
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: {
handleRightClick(item, s) {
@ -1212,12 +1229,14 @@
showLoading(this, {
text: "蓝牙恢复可用,正在连接设备"
});
these.formData.bleStatu='connecting';
ble.LinkBlue(these.formData.deviceId).then(() => {
these.formData.bleStatu = true;
updateLoading(these, {
text: '连接成功'
});
}).catch(ex => {
these.formData.bleStatu='err';
updateLoading(these, {
text: ex.msg
})
@ -1305,6 +1324,33 @@
return f;
},
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;
}
},
setBleFormData() {
ble.data.LinkedList.find((v) => {

View File

@ -58,9 +58,9 @@
<text class="lbl">蓝牙名称</text>
<text class="value">{{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>
@ -489,8 +489,11 @@
these.formData.bleStatu = false;
these.formData.deviceId = f.deviceId;
these.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';
});
these.formData.sta_IntrusTime = 0;
these.formData.sta_sosadd = "";
@ -530,6 +533,21 @@
}
});
return active;
},
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: {
@ -994,12 +1012,14 @@ console.error("获取到未读消息",fs);
showLoading(this, {
text: "蓝牙恢复可用,正在连接设备"
});
this.formData.bleStatu = 'connecting';
ble.LinkBlue(these.formData.deviceId).then(() => {
these.formData.bleStatu = true;
updateLoading(these, {
text: '连接成功'
});
}).catch(ex => {
these.formData.bleStatu = 'err';
updateLoading(these, {
text: ex.msg
})
@ -1216,6 +1236,32 @@ console.error("获取到未读消息",fs);
return f;
},
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;
}
},
setBleFormData() {
ble.data.LinkedList.find((v) => {

View File

@ -54,9 +54,9 @@
<text class="lbl">蓝牙名称</text>
<text class="value">{{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">信道:{{formData.sta_Channel}}</text>
@ -295,7 +295,9 @@
hideLoading,
updateLoading
} from '@/utils/loading.js'
import request, { baseURL } from '@/utils/request.js';
import request, {
baseURL
} from '@/utils/request.js';
import Common from '@/utils/Common.js';
import {
colors as groupColors
@ -556,6 +558,7 @@ import request, { baseURL } from '@/utils/request.js';
these.formData.deviceId = f.deviceId;
these.formData.warnTime = null;
these.formData.sta_SOSType = 'sos_off';
these.formData.bleStatu = 'connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
these.formData.bleStatu = true;
});
@ -573,9 +576,50 @@ import request, { baseURL } from '@/utils/request.js';
this.Status.pageHide = false;
},
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') {
these.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;
}
},
handleRightClick(item, s) {
if (item && item.callback) {
item.callback(item, s);
@ -1076,6 +1120,7 @@ if (!this.permissions.includes('42') && this.Status.apiType !== 'listA') {
showLoading(this, {
text: "蓝牙恢复可用,正在连接设备"
});
these.formData.bleStatu = 'connecting';
ble.LinkBlue(these.formData.deviceId).then(() => {
these.formData.bleStatu = true;
updateLoading(these, {
@ -1838,6 +1883,7 @@ if (!this.permissions.includes('42') && this.Status.apiType !== 'listA') {
border-bottom: 1px solid #ffffff30;
margin: 30rpx;
}
.modeSetting .arrow .outCircle {
width: 120rpx;
height: 120rpx;

View File

@ -9,8 +9,8 @@
</view>
<view slot="right">
<view class="navbarRight center">
<view class="imgContent" :class="{'visibilityHidden':Status.apiType!=item.apiType}" @click.stop="handleRightClick(item,index)"
v-for="item,index in Status.navbar.icons">
<view class="imgContent" :class="{'visibilityHidden':Status.apiType!=item.apiType}"
@click.stop="handleRightClick(item,index)" v-for="item,index in Status.navbar.icons">
<image class="img" :src="item.src" mode="aspectFit"></image>
<view class="baber" v-if="item.math">{{item.math>9?'9+':item.math}}</view>
</view>
@ -61,9 +61,9 @@
<text class="lbl">蓝牙名称</text>
<text class="value">{{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>
<view class="lamp">
@ -410,7 +410,7 @@
these.formData.id = device.id;
these.formData.deviceId = f.deviceId;
these.formData.bleStatu = false;
these.formData.bleStatu = 'connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
these.formData.bleStatu = true;
});
@ -433,12 +433,50 @@
},
computed: {
cModeItems: function() {
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') {
these.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;
}
},
handleRightClick(item, s) {
if (item && item.callback) {
item.callback(item, s);
@ -580,6 +618,7 @@
showLoading(this, {
text: "蓝牙恢复可用,正在连接设备"
});
these.formData.bleStatu = 'connecting';
ble.LinkBlue(these.formData.deviceId).then(() => {
these.formData.bleStatu = true;
updateLoading(these, {

View File

@ -62,9 +62,9 @@
<text class="lbl">蓝牙名称</text>
<text class="value">{{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>
<view class="lamp">
@ -380,7 +380,7 @@
these.formData.id = device.id;
these.formData.deviceId = f.deviceId;
these.formData.bleStatu = false;
these.formData.bleStatu = 'connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
these.formData.bleStatu = true;
});
@ -403,25 +403,50 @@
},
computed: {
RSSIRemark: function() {
let remark = '极弱';
if (this.formData.RSSI <= 0 && this.formData.RSSI >= -30) {
remark = '强';
getbleStatu() {
if (this.formData.bleStatu === true) {
return '已连接';
}
if (this.formData.RSSI < -30 && this.formData.RSSI >= -60) {
remark = '一般';
if (this.formData.bleStatu === 'connecting') {
return '连接中';
}
if (this.formData.RSSI < -60 && this.formData.RSSI >= -85) {
remark = '弱';
if (this.formData.bleStatu === 'dicconnect') {
return '正在断开';
}
if (this.formData.RSSI < -85 && this.formData.RSSI >= -100) {
remark = '微弱';
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') {
these.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;
}
},
handleRightClick(item, s) {
if (item && item.callback) {
item.callback(item, s);
@ -574,6 +599,7 @@
showLoading(this, {
text: "蓝牙恢复可用,正在连接设备"
});
these.formData.bleStatu = 'connecting';
ble.LinkBlue(these.formData.deviceId).then(() => {
these.formData.bleStatu = true;
updateLoading(these, {

View File

@ -55,9 +55,9 @@
<text class="lbl">设备名称</text>
<text class="value">{{device.deviceName}}</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>
@ -401,6 +401,7 @@ import request, { baseURL } from '@/utils/request.js';
these.formData.bleStatu = false;
these.formData.deviceId = f.deviceId;
these.formData.bleStatu='connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
these.formData.bleStatu = true;
});
@ -419,24 +420,49 @@ import request, { baseURL } from '@/utils/request.js';
this.Status.pageHide = false;
},
computed: {
RSSIRemark: function() {
let remark = '极弱';
if (this.formData.RSSI <= 0 && this.formData.RSSI >= -30) {
remark = '强';
getbleStatu(){
if(this.formData.bleStatu===true){
return '已连接';
}
if (this.formData.RSSI < -30 && this.formData.RSSI >= -60) {
remark = '一般';
if(this.formData.bleStatu==='connecting'){
return '连接中';
}
if (this.formData.RSSI < -60 && this.formData.RSSI >= -85) {
remark = '弱';
if(this.formData.bleStatu==='dicconnect'){
return '正在断开';
}
if (this.formData.RSSI < -85 && this.formData.RSSI >= -100) {
remark = '微弱';
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;
}
},
handleRightClick(item, s) {
if (item && item.callback) {
item.callback(item, s);
@ -521,6 +547,7 @@ import request, { baseURL } from '@/utils/request.js';
showLoading(this, {
text: "蓝牙恢复可用,正在连接设备"
});
this.formData.bleStatu='connecting';
ble.LinkBlue(these.formData.deviceId).then(() => {
these.formData.bleStatu = true;
updateLoading(these, {

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, {

View File

@ -60,9 +60,9 @@
</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>
<view class="lamp">
@ -358,7 +358,7 @@ these.Status.apiType = data.apiType;
these.formData.id = device.id;
these.formData.deviceId = f.deviceId;
these.formData.bleStatu = false;
these.formData.bleStatu = 'connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
console.log("连接成功")
these.formData.bleStatu = true;
@ -378,21 +378,20 @@ these.Status.apiType = data.apiType;
this.Status.pageHide = false;
},
computed: {
RSSIRemark: function() {
let remark = '极弱';
if (this.formData.RSSI <= 0 && this.formData.RSSI >= -30) {
remark = '强';
getbleStatu(){
if(this.formData.bleStatu===true){
return '已连接';
}
if (this.formData.RSSI < -30 && this.formData.RSSI >= -60) {
remark = '一般';
if(this.formData.bleStatu==='connecting'){
return '连接中';
}
if (this.formData.RSSI < -60 && this.formData.RSSI >= -85) {
remark = '弱';
if(this.formData.bleStatu==='dicconnect'){
return '正在断开';
}
if (this.formData.RSSI < -85 && this.formData.RSSI >= -100) {
remark = '微弱';
if(this.formData.bleStatu==='err'){
return '连接异常';
}
return '未连接';
},
getMode() {
let txt = "关闭";
@ -425,6 +424,32 @@ these.Status.apiType = data.apiType;
}
},
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'){
these.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;
}
},
handleRightClick(item, s) {
if (item && item.callback) {
item.callback(item, s);
@ -513,6 +538,7 @@ these.Status.apiType = data.apiType;
showLoading(this, {
text: "蓝牙恢复可用,正在连接设备"
});
these.formData.bleStatu = 'connecting';
ble.LinkBlue(these.formData.deviceId).then(() => {
these.formData.bleStatu = true;
updateLoading(these, {

View File

@ -37,6 +37,7 @@ class BleReceive {
});
uni.setStorageSync(this.StorageKey, linkedList);
return true;
}
});
}