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

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>
@ -147,7 +147,7 @@
</view>
<view style="padding-bottom: 20rpx;">
<view style="padding-bottom: 20rpx;">
<view class="proinfo lamp">
@ -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,10 +533,25 @@
}
});
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: {
getLinkedCnt() {//获取在线设备的数量
getLinkedCnt() { //获取在线设备的数量
let f = this.getDevice();
// #ifdef APP-PLUS
@ -552,11 +570,11 @@
let buffer = {
ins_Quantity: "query"
};
ble.sendString(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 30).then(res=>{
setTimeout(()=>{
ble.sendString(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 30).then(res => {
setTimeout(() => {
this.getWarns();
},1500);
}).catch(()=>{
}, 1500);
}).catch(() => {
this.getWarns();
})
}
@ -591,12 +609,12 @@
uni.getStorage({
key: linkKey,
success(res) {
console.error("获取到联机数据",res);
console.error("获取到联机数据", res);
let data = res.data;
let fs = data.filter(v => {
return !v.read
});
console.error("未读联机数据",fs);
console.error("未读联机数据", fs);
succ(fs);
},
fail(ex) {
@ -609,12 +627,12 @@
let fs = [];
if (results[0].status == 'fulfilled') {
fs=fs.concat(results[0].value);
fs = fs.concat(results[0].value);
}
if (results[1].status == 'fulfilled') {
fs=fs.concat(results[1].value);
fs = fs.concat(results[1].value);
}
console.error("获取到未读消息",fs);
console.error("获取到未读消息", fs);
these.$set(these.Status.navbar.icons[0], "math", fs.length);
});
@ -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
})
@ -1031,9 +1051,9 @@ console.error("获取到未读消息",fs);
let json = recei.ReceiveData(receive, device, pagePath, recArr);
console.log("json=", json)
setTimeout(()=>{
setTimeout(() => {
this.getWarns();
},500);
}, 500);
let active = -1;
@ -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
@ -403,7 +405,7 @@ import request, { baseURL } from '@/utils/request.js';
sta_ArrowType: '', //箭头方向
warnTime: 0,
sta_Channel: 31,
sta_ArrowMode:'',
sta_ArrowMode: '',
groups: [
]
@ -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);
@ -612,8 +656,8 @@ import request, { baseURL } from '@/utils/request.js';
let str = rec.receive.payloadString;
let json = JSON.parse(str);
if('ins_channel' in json){
this.formData.sta_Channel=json.ins_channel;
if ('ins_channel' in json) {
this.formData.sta_Channel = json.ins_channel;
these.setBleFormData();
}
@ -636,8 +680,8 @@ import request, { baseURL } from '@/utils/request.js';
return false;
});
these.formData.groups = groups;
console.error("groups=",these.formData.groups);
these.formData.groups = groups;
console.error("groups=", these.formData.groups);
let checks = groups.map(item => {
return item.id
});
@ -800,7 +844,7 @@ import request, { baseURL } from '@/utils/request.js';
});
},
groupCheck() {
if (!this.permissions.includes('54') && this.Status.apiType !== 'listA') {
if (!this.permissions.includes('54') && this.Status.apiType !== 'listA') {
this.showPop({
message: '无操作权限',
@ -942,7 +986,7 @@ if (!this.permissions.includes('54') && this.Status.apiType !== 'listA') {
},
sosSetting(item, index) {
if (!this.permissions.includes('42') && this.Status.apiType !== 'listA') {
if (!this.permissions.includes('42') && this.Status.apiType !== 'listA') {
this.showPop({
message: '无操作权限',
@ -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, {
@ -1825,19 +1870,20 @@ if (!this.permissions.includes('42') && this.Status.apiType !== 'listA') {
.modeSetting .arrow .outCircle .text {
margin-top:0rpx !important;
margin-top: 0rpx !important;
}
.arrowContent .line {
width:calc(100% - 60rpx);
.arrowContent .line {
width: calc(100% - 60rpx);
height: 0rpx;
border-bottom: 1px solid #ffffff30;
margin: 30rpx;
}
height: 0rpx;
border-bottom:1px solid #ffffff30;
margin: 30rpx ;
}
.modeSetting .arrow .outCircle {
width: 120rpx;
height: 120rpx;
@ -1906,8 +1952,8 @@ if (!this.permissions.includes('42') && this.Status.apiType !== 'listA') {
}
.modeSetting .arrow.redactive .item .text,
.modeSetting .arrow.greenactive .item .text{
color:#FFFFFFde !important;
.modeSetting .arrow.greenactive .item .text {
color: #FFFFFFde !important;
}

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">
@ -219,7 +219,7 @@
icons: [{
src: '/static/images/common/shape.png',
callback: this.gotoShare,
apiType:'listA'
apiType: 'listA'
}],
title: 'BJQ6155'
@ -373,7 +373,7 @@
let device = data.data;
these.device = device;
these.Status.apiType = data.apiType;
these.Status.navbar.title=device.deviceName;
these.Status.navbar.title = device.deviceName;
if (data.apiType !== 'listA') {
Common.getdeviceShareId(data.data.id).then(res => {
if (res.code == 200) {
@ -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 = '强';
}
if (this.formData.RSSI < -30 && this.formData.RSSI >= -60) {
remark = '一般';
}
if (this.formData.RSSI < -60 && this.formData.RSSI >= -85) {
remark = '弱';
}
if (this.formData.RSSI < -85 && this.formData.RSSI >= -100) {
remark = '微弱';
}
}
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;
}
},
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,22 +378,21 @@ these.Status.apiType = data.apiType;
this.Status.pageHide = false;
},
computed: {
RSSIRemark: function() {
let remark = '极弱';
if (this.formData.RSSI <= 0 && this.formData.RSSI >= -30) {
remark = '强';
}
if (this.formData.RSSI < -30 && this.formData.RSSI >= -60) {
remark = '一般';
}
if (this.formData.RSSI < -60 && this.formData.RSSI >= -85) {
remark = '弱';
}
if (this.formData.RSSI < -85 && this.formData.RSSI >= -100) {
remark = '微弱';
}
},
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 '未连接';
},
getMode() {
let txt = "关闭";
if (this.Status.BottomMenu.type == 'fu') {
@ -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;
}
});
}