蓝牙小优化,App隐藏时断开设备连接
This commit is contained in:
@ -331,7 +331,7 @@
|
||||
var ble = null;
|
||||
var rec = null;
|
||||
|
||||
var pagePath = "pages/6170/BJQ6170";
|
||||
var pagePath = "/pages/6170/deviceControl/index";
|
||||
|
||||
export default {
|
||||
components: {
|
||||
@ -498,9 +498,12 @@
|
||||
if (receive.deviceId !== this.formData.deviceId) {
|
||||
return;
|
||||
}
|
||||
let data = recei.ReceiveData(receive, device, pagePath, recArr);
|
||||
let data = rec.ReceiveData(receive, device, pagePath, recArr);
|
||||
console.log("蓝牙收到消息", data)
|
||||
this.receivData(data);
|
||||
},
|
||||
receivData(data) {
|
||||
|
||||
},
|
||||
bleStateBreak() {
|
||||
if (this.Status.pageHide) {
|
||||
@ -542,9 +545,9 @@
|
||||
});
|
||||
},
|
||||
deviceDispose(res) {
|
||||
if (this.Status.pageHide) {
|
||||
return;
|
||||
}
|
||||
// if (this.Status.pageHide) {
|
||||
// return;
|
||||
// }
|
||||
if (res.deviceId == these.formData.deviceId) {
|
||||
if (res.device) {
|
||||
these.formData.bleStatu = 'connecting';
|
||||
@ -856,20 +859,26 @@
|
||||
})
|
||||
uni.hideLoading();
|
||||
}
|
||||
}).catch(ex => {
|
||||
console.error("ex=", ex);
|
||||
});
|
||||
}
|
||||
|
||||
if (ble && this.itemInfo.deviceMac) {
|
||||
console.log("111111")
|
||||
let f = this.getDevice();
|
||||
if (f) {
|
||||
console.log("222222");
|
||||
let json = {
|
||||
instruct: [1, 0, 0, 0, 0]
|
||||
};
|
||||
json.instruct[1] = parseInt(selectedItem.instructValue);
|
||||
|
||||
ble.sendString(f.deviceId, json).then(res => {
|
||||
|
||||
console.log("ble send success")
|
||||
this.lightModeA = false;
|
||||
}).catch(ex => {
|
||||
console.error("ble send fail,mqsending....")
|
||||
mqSend();
|
||||
});
|
||||
} else {
|
||||
@ -979,7 +988,7 @@
|
||||
}
|
||||
let that = this;
|
||||
uni.navigateTo({
|
||||
url: "/pages/ImgCrop/ImgCrop",
|
||||
url: "/pages/common/ImgCrop/ImgCrop",
|
||||
events: {
|
||||
ImgCutOver: function(data) {
|
||||
that.selectedImage = data.picPath;
|
||||
@ -990,6 +999,9 @@
|
||||
ev.eventChannel.emit('checkImg', {
|
||||
data: res.tempFiles[0].path,
|
||||
});
|
||||
},
|
||||
fail(ex) {
|
||||
console.error("跳转失败", ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1797,7 +1809,7 @@
|
||||
onLoad(options) {
|
||||
these = this;
|
||||
|
||||
|
||||
rec = BleReceive.getBleReceive();
|
||||
const eventChannel = this.getOpenerEventChannel();
|
||||
// 监听 'detailData' 事件,获取传过来的数据
|
||||
uni.showLoading({
|
||||
@ -1815,7 +1827,7 @@
|
||||
// 根据 apiType 设置右图标的显示状态
|
||||
this.isRightIconVisible = this.apiType === 'listA';
|
||||
|
||||
this.initBle();
|
||||
|
||||
// 初始化并连接MQTT
|
||||
this.mqttClient = new MqttClient();
|
||||
this.mqttClient.connect(() => {
|
||||
@ -1896,6 +1908,9 @@
|
||||
rec = BleReceive.getBleReceive();
|
||||
ble = BleTool.getBleTool();
|
||||
|
||||
this.initBle();
|
||||
|
||||
console.log("ble=", ble);
|
||||
let f = ble.data.LinkedList.find((v) => {
|
||||
if (v.macAddress == this.itemInfo.deviceMac) {
|
||||
console.log("找到设备了", v);
|
||||
@ -1908,9 +1923,9 @@
|
||||
if (f) {
|
||||
these.formData.bleStatu = 'connecting';
|
||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(
|
||||
res => {
|
||||
these.formData.bleStatu = true;
|
||||
});
|
||||
res => {
|
||||
these.formData.bleStatu = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -1922,6 +1937,16 @@
|
||||
})
|
||||
|
||||
},
|
||||
onShow() {
|
||||
let f = this.getDevice();
|
||||
if (f) {
|
||||
these.formData.bleStatu = 'connecting';
|
||||
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
|
||||
console.log("连接成功")
|
||||
these.formData.bleStatu = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
onUnload() {
|
||||
// 页面卸载时断开MQTT连接
|
||||
if (this.mqttClient) {
|
||||
|
||||
Reference in New Issue
Block a user