添加全局消息监听
This commit is contained in:
@ -128,8 +128,8 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//设置发现新设备的回调
|
//设置发现新设备的回调
|
||||||
addDeviceFound(callback) {
|
addDeviceFound(callback,currKey) {
|
||||||
let key = this.getCurrentPagePath();
|
let key =currKey?currKey:this.getCurrentPagePath();
|
||||||
if (!key) {
|
if (!key) {
|
||||||
key = new Date().getTime();
|
key = new Date().getTime();
|
||||||
}
|
}
|
||||||
@ -150,8 +150,8 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//移除发现新设备的回调
|
//移除发现新设备的回调
|
||||||
removeDeviceFound() {
|
removeDeviceFound(currKey) {
|
||||||
let key = this.getCurrentPagePath();
|
let key =currKey?currKey: this.getCurrentPagePath();
|
||||||
|
|
||||||
if (key) {
|
if (key) {
|
||||||
console.log("key=" + key);
|
console.log("key=" + key);
|
||||||
@ -170,8 +170,8 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//添加接收到数据的回调
|
//添加接收到数据的回调
|
||||||
addReceiveCallback(callback) {
|
addReceiveCallback(callback,currKey) {
|
||||||
let key = this.getCurrentPagePath();
|
let key =currKey?currKey: this.getCurrentPagePath();
|
||||||
if (!key) {
|
if (!key) {
|
||||||
key = new Date().getTime();
|
key = new Date().getTime();
|
||||||
}
|
}
|
||||||
@ -193,8 +193,8 @@ class BleHelper {
|
|||||||
|
|
||||||
|
|
||||||
//设置接收到数据的回调
|
//设置接收到数据的回调
|
||||||
removeReceiveCallback(ev) {
|
removeReceiveCallback(ev,currKey) {
|
||||||
let key = this.getCurrentPagePath();
|
let key =currKey?currKey: this.getCurrentPagePath();
|
||||||
if (key) {
|
if (key) {
|
||||||
console.log("key=" + key);
|
console.log("key=" + key);
|
||||||
let f = this.cfg.receivDataCallback.findIndex((v) => {
|
let f = this.cfg.receivDataCallback.findIndex((v) => {
|
||||||
|
21
utils/BleReceive.js
Normal file
21
utils/BleReceive.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
class BleReceive {
|
||||||
|
constructor() {
|
||||||
|
this.StorageKey = "linkedDevices";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let instance = null;
|
||||||
|
export default {
|
||||||
|
getBleReceive: function(found, receive) {
|
||||||
|
if (!instance) {
|
||||||
|
instance = new BleReceive();
|
||||||
|
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user