优化蓝牙订阅在首页的弹窗

This commit is contained in:
liub
2026-04-06 14:02:00 +08:00
parent 1e51023c00
commit 2b7ae4ebaa
5 changed files with 232 additions and 208 deletions

View File

@ -1,8 +1,20 @@
import Common from '@/utils/Common.js'
import { parseBleData } from '@/api/100J/HBY100-J.js'
import {
parseBleData
} from '@/api/100J/HBY100-J.js'
import {
MsgSuccess,
MsgError,
MsgClose,
MsgWarning,
showPop,
MsgClear,
MsgInfo
} from '@/utils/MsgPops.js';
class BleReceive {
constructor() {
constructor(_ref) {
this.ref = _ref;
this.StorageKey = "linkedDevices";
this.HandlerMap = {
'/pages/6155/deviceDetail': this.Receive_6155.bind(this),
@ -13,10 +25,11 @@ class BleReceive {
'/pages/4877/BJQ4877': this.Receive_4877.bind(this),
'/pages/100/HBY100': this.Receive_100.bind(this),
'/pages/102/HBY102': this.Receive_102.bind(this),
'/pages/6170/deviceControl/index':this.Receive_6170.bind(this),
'/pages/6170/deviceControl/index': this.Receive_6170.bind(this),
'/pages/100J/HBY100-J': this.Receive_100J.bind(this),
'/pages/6075J/BJQ6075J':this.Receive_6075.bind(this)
'/pages/6075J/BJQ6075J': this.Receive_6075.bind(this)
};
}
@ -63,23 +76,23 @@ class BleReceive {
return receive;
}
if (f && f.macAddress && f.device && f.device.id) {
if (fReady) {
let handler = null;
let keys = Object.keys(this.HandlerMap);
let devKey = f.device.detailPageUrl ? f.device.detailPageUrl.replace(/\//g, '').toLowerCase() : '';
for (let index = 0; index < keys.length; index++) {
let devKey = f.device.detailPageUrl ? f.device.detailPageUrl.replace(/\//g, "").toLowerCase() : '';
let key = keys[index].replace(/\//g, '').toLowerCase();
if (key == devKey) {
handler = this.HandlerMap[keys[index]];
break;
}
}
if (handler) {
let data = handler(receive, f, path, recArr);
let data = handler(receive, f, path, recArr);
this.setBleFormData(data, f);
return data;
} else {
@ -89,7 +102,7 @@ class BleReceive {
} else {
// 100J AE30 二进制帧在 f 不完整时已在上方 parseBleData此处不再误报「无法处理」
if (!is100JAe30) {
console.log("已收到该消息,但无法处理", receive, "f:", f);
console.error("已收到该消息,但无法处理", receive, "f:", f);
}
}
@ -180,40 +193,33 @@ class BleReceive {
formData.modeCurr = modeCurr;
formData.warnLevel = warn;
formData.iswarn = iswarn;
let recCnt = recArr.find(v => {
return v.key.replace(/\//g, "").toLowerCase() == f.device.detailPageUrl
.replace(/\//g, "").toLowerCase();
});
if (!recCnt) {
let msg = [];
if (f) {
if (formData.battary <= 20) {
msg.push("设备'" + f.device.deviceName + "'电量低");
}
if (iswarn) {
msg.push("设备'" + f.device.deviceName + "'环境存在漏电电源");
}
if (iswarn) {
uni.showModal({
content: "'" + f.device.deviceName + "'环境存在漏电电源",
title: "警告",
success(res) {
if (res.confirm) {
if (f) {
uni.navigateTo({
url: f.detailPageUrl,
events: {
ack: function(data) {}
},
success: (res) => {
res.eventChannel.emit('detailData', {
data: f,
deviceType: '',
apiType: 'listA'
});
}
});
}
}
if (this.ref && msg.length>0) {
if (msg.length > 0) {
msg = msg.join(',');
MsgError("'" + f.device.deviceName + "'环境存在漏电电源", '', this.ref, () => {
MsgClear(this.ref);
});
}
})
}
}
}
return formData;
} catch (error) {
@ -229,7 +235,7 @@ class BleReceive {
if (str.indexOf('mac address:') == 0) {
let formData = {};
formData.macAddress = str.split(':')[1];
return formData;
} else {
let receiveData = {
@ -348,7 +354,7 @@ class BleReceive {
receiveData.fourGStrenth = fourGStrenth;
receiveData.SOS = sosTxt;
receiveData.qzwarn = sosTxt === 'sg';
console.log("recArr=", recArr);
let recCnt = recArr.find(v => {
return v.key.replace(/\//g, "").toLowerCase() == f.device.detailPageUrl
@ -362,13 +368,22 @@ class BleReceive {
if (staticWarn) { //有静止报警
msgs.push("静止报警中");
}
if (receiveData.battary <= 20) {
msg.push("设备'" + f.device.deviceName + "'电量低");
}
if (msgs.length > 0) {
msgs = "设备'" + f.device.deviceName + msgs.join(";");
uni.showModal({
title: "警告",
content: msgs,
showCancel: false
});
msgs = msgs.join(";");
if (this.ref) {
MsgError(msgs, '', this.ref, () => {
MsgClear(this.ref);
});
}
// uni.showModal({
// title: "警告",
// content: msgs,
// showCancel: false
// });
}
}
@ -436,7 +451,7 @@ class BleReceive {
console.log('将数据转文本失败', ex);
}
}
return receiveData;
}
@ -514,12 +529,13 @@ class BleReceive {
});
if (!recCnt) {
if (batteryLevel <= 20) {
// 会弹出两个框,暂且注释掉这段代码
uni.showModal({
content: "设备'" + f.device.deviceName + "'电量低",
title: "提示"
});
if (batteryLevel <= 20 && warn == 0x00) {
if (this.ref) {
MsgError("设备'" + f.device.deviceName + "'电量低", '', this.ref, () => {
MsgClear(this.ref);
});
}
}
}
@ -613,13 +629,17 @@ class BleReceive {
});
console.log("formData=",formData)
if (!recCnt) {
if (batteryLevel <= 20) {
// 会弹出两个框,暂且注释掉这段代码
uni.showModal({
content: "设备'" + f.device.deviceName + "'电量低",
title: "提示"
});
console.log("11111");
if (formData.battary <= 20 && bytes[5] == 0x00) {
console.log("2222")
if (this.ref) {
console.log("3333333");
MsgError("设备'" + f.device.deviceName + "'电量低", '', this.ref, () => {
MsgClear(this.ref);
});
}
}
}
@ -646,11 +666,13 @@ class BleReceive {
});
if (!recCnt) {
if (receiveData.sta_PowerPercent <= 20) {
uni.showModal({
title: "提示",
content: "设备'" + f.device.deviceName + "'电量低",
showCancel: false
});
if (this.ref) {
MsgError("设备'" + f.device.deviceName + "'电量低", '', this.ref, () => {
MsgClear(this.ref);
});
}
}
}
} catch (error) {
@ -674,12 +696,16 @@ class BleReceive {
.replace(/\//g, "").toLowerCase();
});
if (!recCnt) {
if (receiveData.sta_battery <= 20) {
uni.showModal({
title: "提示",
content: "设备'" + f.device.deviceName + "'电量低",
showCancel: false
});
if (receiveData.sta_battery <= 20 && (receiveData.sta_system != '1' || receiveData.sta_system !=
'3')) {
if (this.ref) {
MsgError("设备'" + f.device.deviceName + "'电量低", '', this.ref, () => {
MsgClear(this.ref);
});
}
}
}
} catch (error) {
@ -695,19 +721,22 @@ class BleReceive {
try {
if (!receive.bytes || receive.bytes.length < 3) return receiveData;
// 与 HBY100-J 页 bleValueNotify 共用 notify避免 parseBleData 执行两次重复日志、FB05 双次 resolve、onNotify 双次
const parsed = parseBleData(receive.bytes, { skipSideEffects: true });
const parsed = parseBleData(receive.bytes, {
skipSideEffects: true
});
if (!parsed) return receiveData;
if (parsed.longitude !== undefined) receiveData.longitude = parsed.longitude;
if (parsed.latitude !== undefined) receiveData.latitude = parsed.latitude;
if (parsed.batteryPercentage !== undefined) receiveData.batteryPercentage = parsed.batteryPercentage;
if (parsed.batteryRemainingTime !== undefined) receiveData.batteryRemainingTime = parsed.batteryRemainingTime;
if (parsed.batteryRemainingTime !== undefined) receiveData.batteryRemainingTime = parsed
.batteryRemainingTime;
} catch (e) {
console.log('[100J] BleReceive 解析失败', e);
}
return receiveData;
}
Receive_6170(receive, f, path, recArr) {
Receive_6170(receive, f, path, recArr) {
let receiveData = {};
try {
@ -721,21 +750,20 @@ Receive_6170(receive, f, path, recArr) {
.replace(/\//g, "").toLowerCase();
});
if (!recCnt) {
if (receiveData.sta_PowerPercent <= 20) {
uni.showModal({
title: "提示",
content: "设备'" + f.device.deviceName + "'电量低",
showCancel: false
});
let deviceState = receiveData.state;
if (deviceState && deviceState instanceof Array) {
if (deviceState[0] == 12 && deviceState[3] <= 20 && deviceState[4] == 0) {
if (this.ref) {
MsgError("设备'" + f.device.deviceName + "'电量低", '', this.ref, () => {
MsgClear(this.ref);
});
}
}
}
}
} catch (error) {
receiveData = {};
console.error("文本解析失败", error)
@ -758,18 +786,21 @@ Receive_6170(receive, f, path, recArr) {
.replace(/\//g, "").toLowerCase();
});
if (!recCnt) {
if (receiveData.sta_PowerPercent <= 20) {
uni.showModal({
title: "提示",
content: "设备'" + f.device.deviceName + "'电量低",
showCancel: false
});
let msgs = [];
if (receiveData.sta_PowerPercent <= 20 && receiveData.sta_charge == 0) {
msgs.push("设备'" + f.device.deviceName + "'电量低");
}
if (receiveData.sta_Intrusion === 1) {
uni.showModal({
title: "提示",
content: "闯入报警中",
showCancel: false
msgs.push("设备'" + f.device.deviceName + "'闯入报警中");
}
if (this.ref && msg.length>0) {
msgs = msgs.join(",");
MsgError(msgs, '', this.ref, () => {
MsgClear(this.ref);
});
}
@ -787,7 +818,7 @@ Receive_6170(receive, f, path, recArr) {
if (receiveData.sta_tomac.indexOf(':') == -1) {
receiveData.sta_tomac = receiveData.sta_tomac.replace(/(.{2})/g, '$1:').slice(0, -
1); //mac地址自动补:
1); //mac地址自动补:
}
uni.getStorageInfo({
success: function(res) {
@ -814,9 +845,9 @@ Receive_6170(receive, f, path, recArr) {
let dev = arr.find(v => {
if (v.linkId == f.linkId) {
let vl = v.linkEqs.find(cvl => {
if(cvl.linkMac === receiveData.sta_tomac){
v.read=false;
cvl.linkTime=time;
if (cvl.linkMac === receiveData.sta_tomac) {
v.read = false;
cvl.linkTime = time;
return true;
}
return false;
@ -853,7 +884,7 @@ Receive_6170(receive, f, path, recArr) {
console.error("某个设备闯入报警");
if (receiveData.sta_sosadd.indexOf(':') == -1) {
receiveData.sta_sosadd = receiveData.sta_sosadd.replace(/(.{2})/g, '$1:').slice(0, -
1); //mac地址自动补:
1); //mac地址自动补:
}
warnArrs.push({
linkId: f.linkId,
@ -911,35 +942,33 @@ Receive_6170(receive, f, path, recArr) {
}
Receive_6075(receive,f,path,recArr){
Receive_6075(receive, f, path, recArr) {
let receiveData = {};
try {
receiveData = JSON.parse(receive.str);
let recCnt = recArr.find(v => {
return v.key.replace(/\//g, "").toLowerCase() == f.device.detailPageUrl
.replace(/\//g, "").toLowerCase();
});
if (!recCnt) {
// if (receiveData.sta_PowerPercent <= 20) {
// uni.showModal({
// title: "提示",
// content: "设备'" + f.device.deviceName + "'电量低",
// showCancel: false
// });
// }
if (!recCnt && this.ref) {
if (receiveData.sta_PowerPercent <= 20 && (receiveData.sta_system != 3 || receiveData.sta_system !=1)) {
MsgError("设备'" + f.device.deviceName + "'电量低", '', this.ref, () => {
MsgClear(this.ref);
});
}
}
} catch (error) {
receiveData = {};
console.log("文本解析失败", error)
}
return receiveData;
}
}
@ -947,10 +976,12 @@ Receive_6170(receive, f, path, recArr) {
let receiveInstance = null;
export default {
getBleReceive: function(found, receive) {
getBleReceive: function(_ref) {
console.log("_ref=",_ref);
if (!receiveInstance) {
receiveInstance = new BleReceive();
receiveInstance = new BleReceive(_ref);
}else{
console.log("使用现有实例receiveInstance")
}
return receiveInstance;
}