修复102时间加减异常

This commit is contained in:
liub
2026-03-24 12:00:27 +08:00
parent 5163491ea3
commit c286660a10
7 changed files with 234 additions and 48 deletions

View File

@ -50,7 +50,8 @@
</view>
<view class="item" @click.top="bleStatuToggle">
<text class="lbl">蓝牙状态</text>
<text class="value" :class="formData.bleStatu?'green':'red'">{{device.getbleStatu}}</text>
<text class="value"
:class="(!formData.bleStatu || formData.bleStatu==='err')?'red':'green'">{{getbleStatu}}</text>
</view>
<view class="item">
<text class="lbl">设备状态</text>
@ -469,6 +470,17 @@
onLoad: function() {
const eventChannel = this.getOpenerEventChannel();
var these = this;
this.$watch("deviceInfo.batteryPercentage", (newVal, oldVal) => {
if (newVal <= 20) {
uni.showToast({
title: '设备电量低',
icon: 'none',
duration: 2000
});
}
});
eventChannel.on('detailData', function(data) {
var device = data.data;
these.device = device;
@ -609,7 +621,9 @@
}
// 尝试连接蓝牙:需先扫描获取 BLE deviceId不能直接用 MAC延迟 500ms 确保蓝牙适配器就绪
if (data.data.deviceMac) {
setTimeout(() => { these.tryConnect100JBle(data.data.deviceMac); }, 500);
setTimeout(() => {
these.tryConnect100JBle(data.data.deviceMac);
}, 500);
}
});
this.createThrottledFunctions();
@ -641,10 +655,53 @@
this.Status.pageHide = false;
},
computed: {
getbleStatu() {
if (this.formData.bleStatu === true) {
return '已连接';
}
if (this.formData.bleStatu === 'connecting') {
return '连接中';
}
if (this.formData.bleStatu === 'dicconnect') {
return '正在断开';
}
if (this.formData.bleStatu === 'err') {
return '连接异常';
}
return '未连接';
}
},
methods: {
bleStatuToggle() {
let f = bleTool.data.LinkedList.find((v) => {
return v.macAddress == this.device.deviceMac;
});
if (!f) {
this.tryConnect100JBle(this.device.deviceMac);
return;
}
if (this.formData.bleStatu === true) {
this.formData.bleStatu = 'dicconnect';
bleTool.disconnectDevice(f.deviceId).finally(r => {
this.formData.bleStatu = false;
});
return;
}
if (this.formData.bleStatu === false || this.formData.bleStatu === 'err') {
this.formData.bleStatu = 'connecting';
bleTool.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
these.formData.bleStatu = true;
}).catch(ex => {
these.formData.bleStatu = 'err';
});
return;
}
},
createThrottledFunctions() {
// 创建节流函数
this.throttledBrightnessChange = this.throttle(this.handleBrightnessChange, 500);
@ -1014,20 +1071,31 @@
const NOTIFY = '0000AE02-0000-1000-8000-00805F9B34FB';
if (cached && cached.deviceId) {
console.log('[100J] 使用缓存设备连接', cached.deviceId);
that.formData.bleStatu = 'connecting';
bleTool.LinkBlue(cached.deviceId, SVC, WRITE, NOTIFY, 2).then(() => {
console.log('100J 蓝牙连接成功(缓存)');
that.bleStateRecovry({ deviceId: cached.deviceId });
that.formData.bleStatu = true;
that.bleStateRecovry({
deviceId: cached.deviceId
});
}).catch(err => {
console.log('100J 蓝牙连接失败(缓存),尝试扫描', err);
that.formData.bleStatu = 'err';
that.connect100JByScan(deviceMac, last6);
});
return;
}
// 2. 无缓存先尝试直连。Android 上 deviceId 多为 MAC 反序(11:22:33:44:55:02->02:55:44:33:22:11)
that.formData.bleStatu = 'connecting';
const tryDirect = (id) => bleTool.LinkBlue(id, SVC, WRITE, NOTIFY, 2).then(() => {
console.log('100J 蓝牙连接成功(直连)', id);
that.bleStateRecovry({ deviceId: id });
that.formData.bleStatu = true;
that.bleStateRecovry({
deviceId: id
});
}).catch(ex => {
that.formData.bleStatu = 'err';
});
const deviceIdReversed = macToDeviceId(deviceMac);
console.log('[100J] 尝试直连', deviceIdReversed, '(MAC反序)');
@ -1070,11 +1138,16 @@
bleTool.StopSearch();
bleTool.removeDeviceFound('HBY100J_SCAN');
console.log('[100J] 扫描到目标设备', match.name, match.deviceId);
that.formData.bleStatu = 'connecting';
bleTool.LinkBlue(match.deviceId, SVC, WRITE, NOTIFY, 2).then(() => {
console.log('100J 蓝牙连接成功(扫描)');
that.bleStateRecovry({ deviceId: match.deviceId });
that.formData.bleStatu = true;
that.bleStateRecovry({
deviceId: match.deviceId
});
}).catch(err => {
console.log('100J 蓝牙连接失败将使用4G', err);
that.formData.bleStatu = 'err';
});
}
}, 'HBY100J_SCAN');
@ -1091,6 +1164,7 @@
});
},
bleStateBreak() {
this.formData.bleStatu = false;
updateBleStatus(false, '', this.deviceInfo.deviceId);
},
bleStateRecovry(res) {
@ -1115,7 +1189,8 @@
previewImg(img) {},
bleValueNotify: function(receive, device, path, recArr) { //订阅消息
// 仅处理当前设备的数据device 为 LinkedList 中匹配 receive.deviceId 的项)
if (device && device.device && this.deviceInfo.deviceId && device.device.id != this.deviceInfo.deviceId) return;
if (device && device.device && this.deviceInfo.deviceId && device.device.id != this.deviceInfo
.deviceId) return;
// 解析蓝牙上报数据 (协议: FC=MAC主动上报, FB=指令响应)
if (!receive.bytes || receive.bytes.length < 3) return;
const parsedData = parseBleData(receive.bytes);
@ -1144,9 +1219,7 @@
this.$set(this.deviceInfo, 'batteryRemainingTime', parsedData.batteryRemainingTime);
}
if (this.deviceInfo.batteryPercentage <= 20) {
uni.showToast({ title: '设备电量低', icon: 'none', duration: 2000 });
}
// 设备物理按键切换:蓝牙响应同步到 APP 页面(与 4G MQTT 逻辑一致)
const fc = parsedData.funcCode;
@ -1191,13 +1264,17 @@
else if (this.formData.sta_VoiceType === '7') this.formData.sta_VoiceType = '-1';
}
if (parsedData.volume !== undefined) this.formData.volume = parsedData.volume;
if (parsedData.strobeFrequency !== undefined) this.formData.strobeFrequency = parsedData.strobeFrequency;
if (parsedData.redBrightness !== undefined) this.formData.lightBrightness = parsedData.redBrightness;
if (parsedData.strobeFrequency !== undefined) this.formData.strobeFrequency = parsedData
.strobeFrequency;
if (parsedData.redBrightness !== undefined) this.formData.lightBrightness = parsedData
.redBrightness;
}
// 0x09 音量、0x0D 亮度:单独响应时同步
if (fc === 0x09 && parsedData.volume !== undefined) this.formData.volume = parsedData.volume;
if (fc === 0x0B && parsedData.strobeFrequency !== undefined) this.formData.strobeFrequency = parsedData.strobeFrequency;
if (fc === 0x0D && parsedData.redBrightness !== undefined) this.formData.lightBrightness = parsedData.redBrightness;
if (fc === 0x0B && parsedData.strobeFrequency !== undefined) this.formData.strobeFrequency = parsedData
.strobeFrequency;
if (fc === 0x0D && parsedData.redBrightness !== undefined) this.formData.lightBrightness = parsedData
.redBrightness;
},
showBleUnConnect() {},