1
0
forked from dyf/APP

修复100J

This commit is contained in:
微微一笑
2026-03-26 15:39:50 +08:00
parent a18b2b81e8
commit e7b40dbed6
3 changed files with 90 additions and 16 deletions

View File

@ -684,10 +684,20 @@ export function deviceUpdateVolume(data) {
); );
} }
// 语音播放 /** 蓝牙侧语音播报:自定义音(mode=7)部分固件需先 0x0C 带模式再 0x06否则无声音 */
function bleVoiceBroadcastChain(data) {
const on = Number(data.voiceBroadcast) === 1;
const mode = data.mode != null ? String(data.mode) : '';
if (on && mode === '7') {
return protocolInstance.setForceAlarm(0, 7).then(() => protocolInstance.setVoiceBroadcast(1));
}
return protocolInstance.setVoiceBroadcast(on ? 1 : 0);
}
// 语音播放HTTP 透传 data便于后端识别 mode
export function deviceVoiceBroadcast(data) { export function deviceVoiceBroadcast(data) {
return execWithBleFirst( return execWithBleFirst(
() => protocolInstance.setVoiceBroadcast(data.voiceBroadcast).then(() => ({ code: 200, msg: '操作成功(蓝牙)' })), () => bleVoiceBroadcastChain(data).then(() => ({ code: 200, msg: '操作成功(蓝牙)' })),
() => request({ url: `/app/hby100j/device/voiceBroadcast`, method: 'post', data }), () => request({ url: `/app/hby100j/device/voiceBroadcast`, method: 'post', data }),
'语音播报' '语音播报'
); );

View File

@ -469,23 +469,41 @@
const eventChannel = this.getOpenerEventChannel(); const eventChannel = this.getOpenerEventChannel();
var these = this; var these = this;
// 低电量提示同一百分比不重复弹MQTT/蓝牙反复上报时避免刷屏);恢复高于 20% 后再次降低可再提示 // 低电量:语音上传/蓝牙分包时电量字段易抖动,防抖 + 上传中不弹,避免「发送中频繁低电量」误报
this._lastBatteryLowToastPct = null; this._lastBatteryLowToastPct = null;
this.$watch("deviceInfo.batteryPercentage", (newVal) => { this._batteryLowDebounceTimer = null;
const n = Number(newVal); this.$watch("deviceInfo.batteryPercentage", () => {
if (bleTool.isVoiceUploading && bleTool.isVoiceUploading()) {
if (this._batteryLowDebounceTimer) {
clearTimeout(this._batteryLowDebounceTimer);
this._batteryLowDebounceTimer = null;
}
return;
}
const n = Math.round(Number(this.deviceInfo.batteryPercentage));
if (!Number.isFinite(n)) return; if (!Number.isFinite(n)) return;
if (n > 20) { if (n > 20) {
this._lastBatteryLowToastPct = null; this._lastBatteryLowToastPct = null;
if (this._batteryLowDebounceTimer) {
clearTimeout(this._batteryLowDebounceTimer);
this._batteryLowDebounceTimer = null;
}
return; return;
} }
if (n <= 20 && this._lastBatteryLowToastPct !== n) { if (this._batteryLowDebounceTimer) clearTimeout(this._batteryLowDebounceTimer);
this._lastBatteryLowToastPct = n; this._batteryLowDebounceTimer = setTimeout(() => {
this._batteryLowDebounceTimer = null;
if (bleTool.isVoiceUploading && bleTool.isVoiceUploading()) return;
const cur = Math.round(Number(this.deviceInfo.batteryPercentage));
if (!Number.isFinite(cur) || cur > 20) return;
if (this._lastBatteryLowToastPct === cur) return;
this._lastBatteryLowToastPct = cur;
uni.showToast({ uni.showToast({
title: '设备电量低', title: '设备电量低',
icon: 'none', icon: 'none',
duration: 2000 duration: 2000
}); });
} }, 800);
}); });
eventChannel.on('detailData', function(data) { eventChannel.on('detailData', function(data) {
var device = data.data; var device = data.data;
@ -656,6 +674,10 @@
this.Status.pageHide = true; this.Status.pageHide = true;
}, },
onUnload() { onUnload() {
if (this._batteryLowDebounceTimer) {
clearTimeout(this._batteryLowDebounceTimer);
this._batteryLowDebounceTimer = null;
}
if (this._hby100jBleAdapterHandler && typeof uni.offBluetoothAdapterStateChange === 'function') { if (this._hby100jBleAdapterHandler && typeof uni.offBluetoothAdapterStateChange === 'function') {
uni.offBluetoothAdapterStateChange(this._hby100jBleAdapterHandler); uni.offBluetoothAdapterStateChange(this._hby100jBleAdapterHandler);
this._hby100jBleAdapterHandler = null; this._hby100jBleAdapterHandler = null;
@ -1035,11 +1057,11 @@
} }
}) })
} else if (isVoiceOperate) { } else if (isVoiceOperate) {
console.log('我是谁'); const data = {
let data = {
deviceId: this.deviceInfo.deviceId, deviceId: this.deviceInfo.deviceId,
voiceBroadcast: Number(this.formData.sta_VoiceType) === -1 ? 0 : 1 voiceBroadcast: Number(this.formData.sta_VoiceType) === -1 ? 0 : 1,
} mode: this.formData.sta_VoiceType
};
deviceVoiceBroadcast(data).then((res) => { deviceVoiceBroadcast(data).then((res) => {
if (res.code == 200) { if (res.code == 200) {
uni.showToast({ uni.showToast({
@ -1052,7 +1074,25 @@
icon: 'none' icon: 'none'
}); });
} }
}) }).catch(() => {
uni.showToast({ title: '下发失败,请检查蓝牙或网络', icon: 'none' });
});
} else {
// 非强制报警态下选择内置音色:原先仅改 UI 未下发,设备无播报
const data = {
deviceIds: [this.deviceInfo.deviceId],
voiceStrobeAlarm: 0,
mode: val
};
deviceForceAlarmActivation(data).then((res) => {
if (res.code === 200) {
uni.showToast({ title: res.msg || '已切换', icon: 'none' });
} else {
uni.showToast({ title: res.msg || '操作失败', icon: 'none' });
}
}).catch(() => {
uni.showToast({ title: '下发失败,请检查蓝牙或网络', icon: 'none' });
});
} }
}, },
// 报警模式 // 报警模式

View File

@ -29,8 +29,8 @@
</view> </view>
<view class="itemRight "> <view class="itemRight ">
<view class="btn" @click.stop="Apply(item, index)" <view class="btn" @click.stop="Apply(item, index)"
:class="{ 'active': item.useStatus, 'btn-default': !item.useStatus }"> :class="{ 'active': isVoiceInUse(item), 'btn-default': !isVoiceInUse(item) }">
{{ item.useStatus == 1 ? '使用中' : '使用' }} {{ isVoiceInUse(item) ? '使用中' : '使用' }}
</view> </view>
</view> </view>
<view class="clear"></view> <view class="clear"></view>
@ -266,7 +266,8 @@
this.total = res.total; this.total = res.total;
const list = (res.data || []).map(item => ({ const list = (res.data || []).map(item => ({
...item, ...item,
createTime: item.createTime || Common.DateFormat(new Date(), "yyyy年MM月dd日") createTime: item.createTime || Common.DateFormat(new Date(), "yyyy年MM月dd日"),
useStatus: Number(item.useStatus) === 1 ? 1 : 0
})); }));
this.dataListA = mergeLocal(list); this.dataListA = mergeLocal(list);
if (this.mescroll) this.mescroll.endBySize(this.dataListA.length, this.total + (this.dataListA.length - list.length)); if (this.mescroll) this.mescroll.endBySize(this.dataListA.length, this.total + (this.dataListA.length - list.length));
@ -496,6 +497,27 @@
this.checkList.push(item.Id); this.checkList.push(item.Id);
} }
}, },
/** 与后端约定:仅 1 为使用中(避免字符串 "0" 在 class 里仍为 truthy */
isVoiceInUse(item) {
return Number(item && item.useStatus) === 1;
},
/** 切换「使用」后同步整表:仅当前项为 1其余为 0避免第一项永远显示使用中 */
syncVoiceListUseStatus(activeItem) {
const pickId = (o) => {
if (!o) return '';
const v = o.id ?? o.fileId ?? o.Id;
return v != null && v !== '' ? String(v) : '';
};
const aid = pickId(activeItem);
if (!aid) return;
this.dataListA.forEach((row, i) => {
const rid = pickId(row);
const use = rid === aid ? 1 : 0;
if (Number(row.useStatus) !== use) {
this.$set(this.dataListA, i, { ...row, useStatus: use });
}
});
},
Apply(item, index) { Apply(item, index) {
this.updateProgress = 0; this.updateProgress = 0;
this.isUpdating = true; this.isUpdating = true;
@ -530,6 +552,7 @@
if (RES.code == 200) { if (RES.code == 200) {
// 蓝牙上传:进度已由 onProgress 更新,直接完成 // 蓝牙上传:进度已由 onProgress 更新,直接完成
if (RES._channel === 'ble') { if (RES._channel === 'ble') {
this.syncVoiceListUseStatus(item);
uni.showToast({ title: '音频上传成功', icon: 'success', duration: 2000 }); uni.showToast({ title: '音频上传成功', icon: 'success', duration: 2000 });
this.isUpdating = false; this.isUpdating = false;
setTimeout(() => { uni.navigateBack(); }, 1500); setTimeout(() => { uni.navigateBack(); }, 1500);
@ -554,6 +577,7 @@
this.updateProgress = progress; this.updateProgress = progress;
if (progress === 100) { if (progress === 100) {
clearTimeout(this.upgradeTimer); clearTimeout(this.upgradeTimer);
this.syncVoiceListUseStatus(item);
uni.showToast({ title: '音频上传成功', icon: 'success', duration: 2000 }); uni.showToast({ title: '音频上传成功', icon: 'success', duration: 2000 });
this.isUpdating = false; this.isUpdating = false;
setTimeout(() => { uni.navigateBack(); }, 1500); setTimeout(() => { uni.navigateBack(); }, 1500);