修改蓝牙接收数据处理逻辑,改成配置式,避免if无限增多
This commit is contained in:
@ -1,7 +1,12 @@
|
||||
class BleReceive {
|
||||
constructor() {
|
||||
this.StorageKey = "linkedDevices";
|
||||
|
||||
this.HandlerMap = {
|
||||
'/pages/6155/deviceDetail': this.Receive_6155.bind(this),
|
||||
'/pages/7305/BJQ7305': this.Receive_6155.bind(this),
|
||||
'/pages/650/HBY650': this.Receive_650.bind(this),
|
||||
'/pages/670/HBY670': this.Receive_670.bind(this)
|
||||
};
|
||||
}
|
||||
|
||||
getCurrentPagePath() {
|
||||
@ -48,23 +53,15 @@ class BleReceive {
|
||||
|
||||
|
||||
ReceiveData(receive,f,path,recArr) {
|
||||
if(f && f.macAddress && f.device && f.device.id){
|
||||
let data={};
|
||||
if(f.device.detailPageUrl=='/pages/6155/deviceDetail' || f.device.detailPageUrl=='/pages/7305/BJQ7305'){
|
||||
// console.log("该设备是6155");
|
||||
data= this.Receive_6155(receive,f,path,recArr);
|
||||
if(f && f.macAddress && f.device && f.device.id){
|
||||
let handler = this.HandlerMap[f.device.detailPageUrl];
|
||||
if(handler){
|
||||
let data=handler(receive, f, path, recArr);
|
||||
return data;
|
||||
}else{
|
||||
console.log("已收到消息,但无指定处理程序",receive);
|
||||
}
|
||||
|
||||
if(f.device.detailPageUrl=='/pages/650/HBY650'){
|
||||
// console.log("该设备是650");
|
||||
data= this.Receive_650(receive,f,path,recArr);
|
||||
}
|
||||
if(f.device.detailPageUrl=='/pages/670/HBY670'){
|
||||
// console.log("该设备是670");
|
||||
data= this.Receive_670(receive,f,path,recArr);
|
||||
}
|
||||
// console.log("收到数据并处理完毕,",data);
|
||||
return data;
|
||||
}else{
|
||||
console.log("已收到该消息,但无法处理",receive);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user