蓝牙添加连接、断开、可用、不可用控制
This commit is contained in:
@ -30,6 +30,10 @@
|
||||
<text class="lbl">设备名称</text>
|
||||
<text class="value">{{formData.deviceName}}</text>
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="lbl">蓝牙状态</text>
|
||||
<text class="value" :class="formData.bleStatu?'green':'red'">{{formData.bleStatu?'已连接':'未连接'}}</text>
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="lbl">预警级别</text>
|
||||
<text class="value">{{formData.warnLevel}}</text>
|
||||
@ -180,6 +184,7 @@
|
||||
|
||||
import usrApi from '@/api/670/HBY670.js'
|
||||
const pagePath = "pages/650/HBY650";
|
||||
|
||||
var ble = null;
|
||||
var these = null;
|
||||
var recei = null;
|
||||
@ -263,7 +268,8 @@
|
||||
name: '',
|
||||
job: '',
|
||||
id: '',
|
||||
iswarn: false
|
||||
iswarn: false,
|
||||
bleStatu: false
|
||||
},
|
||||
rgb565Data: [],
|
||||
videoHexArray: [],
|
||||
@ -291,14 +297,21 @@
|
||||
|
||||
onUnload() {
|
||||
console.log("页面卸载,释放资源");
|
||||
ble.removeReceiveCallback(pagePath);
|
||||
ble.removeAllCallback(pagePath);
|
||||
},
|
||||
onLoad: function() {
|
||||
these = this;
|
||||
recei = BleReceive.getBleReceive();
|
||||
ble = BleTool.getBleTool();
|
||||
console.log("650")
|
||||
ble.addReceiveCallback(these.bleValueNotify);
|
||||
|
||||
|
||||
ble.addReceiveCallback(these.bleValueNotify, pagePath);
|
||||
ble.addStateBreakCallback(these.bleStateBreak, pagePath);
|
||||
ble.addStateRecoveryCallback(these.bleStateRecovry, pagePath);
|
||||
ble.addDisposeCallback(these.deviceDispose, pagePath);
|
||||
ble.addRecoveryCallback(these.deviceRecovry, pagePath);
|
||||
|
||||
|
||||
let eventChannel = this.getOpenerEventChannel();
|
||||
|
||||
eventChannel.on('detailData', function(data) {
|
||||
@ -332,9 +345,11 @@
|
||||
these.formData.blename = f.name ? f.name : "Unname";
|
||||
these.formData.deviceName = device.deviceName;
|
||||
these.formData.img = device.devicePic;
|
||||
these.formData.id = device.id;
|
||||
|
||||
these.formData.deviceId = f.deviceId;
|
||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
|
||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res=>{
|
||||
these.formData.bleStatu=true;
|
||||
});
|
||||
these.setBleFormData();
|
||||
these.getDetail();
|
||||
|
||||
@ -343,10 +358,10 @@
|
||||
|
||||
},
|
||||
onHide: function() {
|
||||
|
||||
this.Status.pageHide = true;
|
||||
},
|
||||
onBackPress(e) {
|
||||
ble.removeReceiveCallback(pagePath);
|
||||
onShow() {
|
||||
this.Status.pageHide = false;
|
||||
},
|
||||
computed: {
|
||||
RSSIRemark: function() {
|
||||
@ -367,13 +382,83 @@
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
previewImg(img){
|
||||
if(!img){
|
||||
deviceRecovry(res) {
|
||||
if (this.Status.pageHide) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (res.deviceId == these.formData.deviceId) {
|
||||
this.formData.bleStatu = true;
|
||||
setTimeout(() => {
|
||||
hideLoading(these, 1000);
|
||||
});
|
||||
uni.showToast({
|
||||
icon: 'success',
|
||||
title: '蓝牙连接成功'
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
deviceDispose(res) {
|
||||
if (this.Status.pageHide) {
|
||||
return;
|
||||
}
|
||||
if (res.deviceId == these.formData.deviceId) {
|
||||
this.formData.bleStatu = false;
|
||||
setTimeout(() => {
|
||||
hideLoading(these, 1000);
|
||||
});
|
||||
uni.showToast({
|
||||
icon: 'fail',
|
||||
title: '蓝牙连接已断开'
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
bleStateBreak() {
|
||||
if (this.Status.pageHide) {
|
||||
return;
|
||||
}
|
||||
//蓝牙适配器不可用
|
||||
this.formData.bleStatu = false;
|
||||
uni.showToast({
|
||||
icon: 'fail',
|
||||
title: '蓝牙已不可用'
|
||||
})
|
||||
hideLoading(this);
|
||||
},
|
||||
bleStateRecovry() {
|
||||
console.log("蓝牙可用");
|
||||
if (this.Status.pageHide) {
|
||||
return;
|
||||
}
|
||||
console.log("蓝牙可用");
|
||||
//蓝牙适配器再次可用,尝试恢复连接
|
||||
showLoading(this, {
|
||||
text: "蓝牙恢复可用,正在连接设备"
|
||||
});
|
||||
ble.LinkBlue(these.formData.deviceId).then(() => {
|
||||
these.formData.bleStatu = true;
|
||||
updateLoading(these, {
|
||||
text: '连接成功'
|
||||
});
|
||||
}).catch(ex => {
|
||||
updateLoading(these, {
|
||||
text: ex.msg
|
||||
})
|
||||
}).finally(() => {
|
||||
setTimeout(() => {
|
||||
hideLoading(these);
|
||||
}, 1000);
|
||||
|
||||
});
|
||||
},
|
||||
previewImg(img) {
|
||||
if (!img) {
|
||||
return;
|
||||
}
|
||||
|
||||
uni.previewImage({
|
||||
urls:[img]
|
||||
urls: [img]
|
||||
})
|
||||
},
|
||||
getWarnStyle(index) {
|
||||
@ -474,7 +559,7 @@
|
||||
getDetail() {
|
||||
var that = this;
|
||||
usrApi.getDetail(this.device.id).then(res => {
|
||||
|
||||
console.log("res=",res);
|
||||
if (res && res.code == 200) {
|
||||
res = res.data;
|
||||
let personnelInfo = res.personnelInfo;
|
||||
@ -599,9 +684,9 @@
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
buttonText: '去连接',
|
||||
buttonTextColor:'#FFFFFFde',
|
||||
buttonTextColor: '#FFFFFFde',
|
||||
okCallback: function() {
|
||||
|
||||
|
||||
uni.navigateTo({
|
||||
url: "/pages/common/addBLE/addEquip",
|
||||
events: {
|
||||
@ -630,7 +715,7 @@
|
||||
proParam: function() {
|
||||
|
||||
uni.navigateTo({
|
||||
url: '/pages/common/productDes/index?id=' + this.formData.id,
|
||||
url: '/pages/common/productDes/index?id=' + this.device.id,
|
||||
success(ev) {
|
||||
|
||||
}
|
||||
@ -638,7 +723,7 @@
|
||||
},
|
||||
handRemark: function() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/common/operatingInstruct/index?id=' + this.formData.id,
|
||||
url: '/pages/common/operatingInstruct/index?id=' + this.device.id,
|
||||
success(ev) {
|
||||
|
||||
}
|
||||
@ -646,7 +731,7 @@
|
||||
},
|
||||
handVideo: function() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/common/operationVideo/index?id=' + this.formData.id,
|
||||
url: '/pages/common/operationVideo/index?id=' + this.device.id,
|
||||
success(ev) {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user