更新100J代码

This commit is contained in:
微微一笑
2026-03-24 16:18:17 +08:00
parent 4eb118b42c
commit 1598065457
3 changed files with 83 additions and 571 deletions

View File

@ -469,15 +469,23 @@
const eventChannel = this.getOpenerEventChannel();
var these = this;
this.$watch("deviceInfo.batteryPercentage", (newVal, oldVal) => {
if (newVal <= 20) {
// 低电量提示同一百分比不重复弹MQTT/蓝牙反复上报时避免刷屏);恢复高于 20% 后再次降低可再提示
this._lastBatteryLowToastPct = null;
this.$watch("deviceInfo.batteryPercentage", (newVal) => {
const n = Number(newVal);
if (!Number.isFinite(n)) return;
if (n > 20) {
this._lastBatteryLowToastPct = null;
return;
}
if (n <= 20 && this._lastBatteryLowToastPct !== n) {
this._lastBatteryLowToastPct = n;
uni.showToast({
title: '设备电量低',
icon: 'none',
duration: 2000
});
}
});
eventChannel.on('detailData', function(data) {
var device = data.data;
@ -626,6 +634,14 @@
});
this.createThrottledFunctions();
// 系统蓝牙开关:与 BleHelper 状态对齐(测试项「关蓝牙后状态空白」)
this._hby100jBleAdapterHandler = () => {
this.$nextTick(() => this.sync100JBleUiFromHelper && this.sync100JBleUiFromHelper());
};
if (typeof uni.onBluetoothAdapterStateChange === 'function') {
uni.onBluetoothAdapterStateChange(this._hby100jBleAdapterHandler);
}
// 注册蓝牙相关事件(必须 bind(this),否则 BleHelper 直接调用回调时 this 丢失,蓝牙状态不更新)
bleTool.addReceiveCallback(this.bleValueNotify.bind(this), "HBY100J");
bleTool.addDisposeCallback(this.bleStateBreak.bind(this), "HBY100J");
@ -640,6 +656,10 @@
this.Status.pageHide = true;
},
onUnload() {
if (this._hby100jBleAdapterHandler && typeof uni.offBluetoothAdapterStateChange === 'function') {
uni.offBluetoothAdapterStateChange(this._hby100jBleAdapterHandler);
this._hby100jBleAdapterHandler = null;
}
// 移除蓝牙事件监听
bleTool.removeReceiveCallback("HBY100J");
bleTool.removeDisposeCallback("HBY100J");
@ -754,6 +774,7 @@
);
Object.assign(this.formData, validData);
that.deviceInfo = res.data;
that.$nextTick(() => that.sync100JBleUiFromHelper && that.sync100JBleUiFromHelper());
const strobeEnable = res.data.strobeEnable ?? 0; // 0=关闭1=开启
const strobeMode = res.data.strobeMode ?? 0; // 0=红闪、1=蓝闪、3=红色顺时针...
if (strobeEnable === 1) {
@ -1052,15 +1073,15 @@
showCancel: true,
buttonCancelText: '取消',
okCallback: () => {
this.deviceInfo.voiceStrobeAlarm = isClose ? 0 : 1; //强制报警,报警中 0是强制报警,1是报警中
const data = {
deviceIds: [this.deviceInfo.deviceId],
// 声光报警开关关闭传0开启传1
voiceStrobeAlarm: isClose ? 0 : 1,
mode: this.formData.sta_VoiceType
};
deviceForceAlarmActivation(data).then((res) => {
if (res.code === 200) {
// 与 MQTT / bleValueNotify 一致:报警中=1解除=-1勿在请求前乐观改 UI失败会导致按钮文案错乱
this.$set(this.deviceInfo, 'voiceStrobeAlarm', isClose ? -1 : 1);
uni.showToast({
title: isClose ? '声光报警已解除' : '强制报警已开启',
icon: 'none'
@ -1074,7 +1095,12 @@
icon: 'none'
});
}
}).catch((err) => {});
}).catch(() => {
uni.showToast({
title: '网络或蓝牙异常,请重试',
icon: 'none'
});
});
}
};
},