1
0
forked from dyf/APP

Compare commits

..

4 Commits

Author SHA1 Message Date
b76a41b624 Merge remote-tracking branch 'origin/new-20250827' 2026-03-24 14:40:58 +08:00
9b6a5e095c merge upstream 2026-02-07 13:53:33 +08:00
7735abc2a1 merge upstream 2026-02-04 09:05:49 +08:00
c626f3766e merge upstream 2026-02-03 13:07:11 +08:00

View File

@ -48,7 +48,7 @@
<text class="lbl">蓝牙名称</text> <text class="lbl">蓝牙名称</text>
<text class="value valueFont">{{device.bluetoothName}}</text> <text class="value valueFont">{{device.bluetoothName}}</text>
</view> </view>
<view class="item" @click.stop="bleStatuToggle"> <view class="item" @click.top="bleStatuToggle">
<text class="lbl">蓝牙状态</text> <text class="lbl">蓝牙状态</text>
<text class="value" <text class="value"
:class="(!formData.bleStatu || formData.bleStatu==='err')?'red':'green'">{{getbleStatu}}</text> :class="(!formData.bleStatu || formData.bleStatu==='err')?'red':'green'">{{getbleStatu}}</text>
@ -251,6 +251,7 @@
} from '@/api/100J/HBY100-J.js' } from '@/api/100J/HBY100-J.js'
import BleHelper from '@/utils/BleHelper.js'; import BleHelper from '@/utils/BleHelper.js';
var bleTool = BleHelper.getBleTool(); var bleTool = BleHelper.getBleTool();
var these = null;
import Common from '@/utils/Common.js' import Common from '@/utils/Common.js'
const pagePath = "/pages/100/HBY100"; const pagePath = "/pages/100/HBY100";
export default { export default {
@ -465,6 +466,7 @@
deviceInfo: {}, deviceInfo: {},
} }
}, },
onUnload() {},
onLoad: function() { onLoad: function() {
const eventChannel = this.getOpenerEventChannel(); const eventChannel = this.getOpenerEventChannel();
var these = this; var these = this;
@ -486,17 +488,17 @@
these.Status.apiType = data.apiType; these.Status.apiType = data.apiType;
these.Status.isRightIconVisible = these.Status.apiType === 'listA'; these.Status.isRightIconVisible = these.Status.apiType === 'listA';
these.mqttClient = new MqttClient(); this.mqttClient = new MqttClient();
these.mqttClient.connect(() => { this.mqttClient.connect(() => {
// 订阅来自设备的状态更新 // 订阅来自设备的状态更新
const statusTopic = `status/894078/HBY100/${data.data.deviceImei}`; const statusTopic = `status/894078/HBY100/${data.data.deviceImei}`;
these.mqttClient.subscribe(statusTopic, (payload) => { this.mqttClient.subscribe(statusTopic, (payload) => {
try { try {
// 解析MQTT返回的payload // 解析MQTT返回的payload
const payloadObj = typeof payload === 'string' ? JSON.parse( const payloadObj = typeof payload === 'string' ? JSON.parse(
payload) : payload; payload) : payload;
// console.log(payloadObj, '这是我的数据类型么'); console.log(payloadObj, '这是我的数据类型么');
const data = payloadObj.data ?? {}; const data = payloadObj.data ?? {};
const funcType = payloadObj.funcType ?? ''; // 从顶层获取funcType const funcType = payloadObj.funcType ?? ''; // 从顶层获取funcType
const { const {
@ -601,7 +603,7 @@
} }
} }
// 报警模式相关字段 // 报警模式相关字段
// console.log('formData赋值完成', these.formData); console.log('formData赋值完成', these.formData);
} catch (e) { } catch (e) {
// 捕获异常并打印方便排查问题不要空catch // 捕获异常并打印方便排查问题不要空catch
console.log('解析MQTT payload失败', e); console.log('解析MQTT payload失败', e);
@ -613,8 +615,8 @@
if (these.Status.apiType === 'listA') { if (these.Status.apiType === 'listA') {
these.fetchDeviceDetail(data.data.id) these.fetchDeviceDetail(data.data.id)
} else { } else {
these.activePermissions = data.data.permission ? data.data.permission.split(',') : []; this.activePermissions = data.data.permission ? data.data.permission.split(',') : [];
console.log(these.activePermissions, 'activePermissions'); console.log(this.activePermissions, 'this.activePermissions');
these.fetchDeviceDetail(data.data.deviceId) these.fetchDeviceDetail(data.data.deviceId)
} }
// 尝试连接蓝牙:需先扫描获取 BLE deviceId不能直接用 MAC延迟 500ms 确保蓝牙适配器就绪 // 尝试连接蓝牙:需先扫描获取 BLE deviceId不能直接用 MAC延迟 500ms 确保蓝牙适配器就绪
@ -626,12 +628,12 @@
}); });
this.createThrottledFunctions(); this.createThrottledFunctions();
// 注册蓝牙相关事件(必须 bind(this),否则 BleHelper 直接调用回调时 this 丢失,蓝牙状态不更新) // 注册蓝牙相关事件
bleTool.addReceiveCallback(this.bleValueNotify.bind(this), "HBY100J"); bleTool.addReceiveCallback(this.bleValueNotify.bind(this), "HBY100J");
bleTool.addDisposeCallback(this.bleStateBreak.bind(this), "HBY100J"); bleTool.addDisposeCallback(this.bleStateBreak, "HBY100J");
bleTool.addRecoveryCallback(this.bleStateRecovry.bind(this), "HBY100J"); bleTool.addRecoveryCallback(this.bleStateRecovry, "HBY100J");
bleTool.addStateBreakCallback(this.bleStateBreak.bind(this), "HBY100J"); bleTool.addStateBreakCallback(this.bleStateBreak, "HBY100J");
bleTool.addStateRecoveryCallback(this.bleStateRecovry.bind(this), "HBY100J"); bleTool.addStateRecoveryCallback(this.bleStateRecovry, "HBY100J");
@ -651,8 +653,6 @@
}, },
onShow() { onShow() {
this.Status.pageHide = false; this.Status.pageHide = false;
// 从系统蓝牙开关/后台返回时,与 BleHelper.LinkedList 对齐,避免「蓝牙状态空白/不刷新」
this.$nextTick(() => this.sync100JBleUiFromHelper());
}, },
computed: { computed: {
getbleStatu() { getbleStatu() {
@ -673,45 +673,13 @@
}, },
methods: { methods: {
/** 与 BleHelper 实际连接状态对齐(系统关蓝牙再开、从后台回前台等) */
sync100JBleUiFromHelper() {
const mac = (this.device && this.device.deviceMac) || (this.deviceInfo && this.deviceInfo.deviceMac);
if (!mac || !this.deviceInfo.deviceId) return;
const macNorm = (m) => (m || '').replace(/:/g, '').toUpperCase();
const targetMacNorm = macNorm(mac);
const last6 = targetMacNorm.slice(-6);
const item = bleTool.data.LinkedList.find((v) => {
const m = macNorm(v.macAddress || '');
return m === targetMacNorm || (m.length >= 6 && m.slice(-6) === last6);
});
if (!bleTool.data.available) {
this.formData.bleStatu = false;
updateBleStatus(false, '', this.deviceInfo.deviceId);
return;
}
if (item && item.Linked) {
this.formData.bleStatu = true;
updateBleStatus(true, item.deviceId, this.deviceInfo.deviceId);
return;
}
if (this.formData.bleStatu === true || this.formData.bleStatu === 'connecting') {
this.formData.bleStatu = false;
updateBleStatus(false, '', this.deviceInfo.deviceId);
}
},
bleStatuToggle() { bleStatuToggle() {
const mac = (this.device && this.device.deviceMac) || (this.deviceInfo && this.deviceInfo.deviceMac);
if (!mac) return;
const macNorm = (m) => (m || '').replace(/:/g, '').toUpperCase();
const targetMacNorm = macNorm(mac);
const last6 = targetMacNorm.slice(-6);
let f = bleTool.data.LinkedList.find((v) => { let f = bleTool.data.LinkedList.find((v) => {
const m = macNorm(v.macAddress || ''); return v.macAddress == this.device.deviceMac;
return m === targetMacNorm || (m.length >= 6 && m.slice(-6) === last6);
}); });
if (!f) { if (!f) {
this.tryConnect100JBle(mac); this.tryConnect100JBle(this.device.deviceMac);
return; return;
} }
if (this.formData.bleStatu === true) { if (this.formData.bleStatu === true) {
@ -724,11 +692,10 @@
if (this.formData.bleStatu === false || this.formData.bleStatu === 'err') { if (this.formData.bleStatu === false || this.formData.bleStatu === 'err') {
this.formData.bleStatu = 'connecting'; this.formData.bleStatu = 'connecting';
bleTool.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(() => { bleTool.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
this.formData.bleStatu = true; these.formData.bleStatu = true;
this.bleStateRecovry({ deviceId: f.deviceId }); }).catch(ex => {
}).catch(() => { these.formData.bleStatu = 'err';
this.formData.bleStatu = 'err';
}); });
return; return;
} }
@ -763,8 +730,8 @@
// 关闭状态 // 关闭状态
that.formData.sta_LightType = '-1'; that.formData.sta_LightType = '-1';
} }
if (this.formData.sta_VoiceType === '7' || this.formData.sta_VoiceType === 7) { if (this.formData_VoiceType == 7) {
this.formData.sta_VoiceType = (res.data.voiceStrobeAlarm ?? 0) + ''; this.formData.sta_VoiceType = res.data.voiceStrobeAlarm ?? 0;
} else { } else {
this.formData.sta_VoiceType = res.data.alarmMode + '' this.formData.sta_VoiceType = res.data.alarmMode + ''
} }
@ -1196,22 +1163,7 @@
} }
}); });
}, },
_match100JBleItemByRes(res) { bleStateBreak() {
if (!res || !res.deviceId) return true;
const mac = (this.device && this.device.deviceMac) || (this.deviceInfo && this.deviceInfo.deviceMac);
if (!mac) return true;
const macNorm = (m) => (m || '').replace(/:/g, '').toUpperCase();
const target = macNorm(mac);
const last6 = target.slice(-6);
const item = bleTool.data.LinkedList.find((v) => {
const m = macNorm(v.macAddress || '');
return v.deviceId === res.deviceId && (m === target || (m.length >= 6 && m.slice(-6) === last6));
});
return !!item;
},
bleStateBreak(res) {
// 仅处理本页 100J 的断开,避免其它型号设备断连误改本页状态
if (res && res.deviceId && !this._match100JBleItemByRes(res)) return;
this.formData.bleStatu = false; this.formData.bleStatu = false;
updateBleStatus(false, '', this.deviceInfo.deviceId); updateBleStatus(false, '', this.deviceInfo.deviceId);
}, },
@ -1225,7 +1177,6 @@
} }
return; return;
} }
if (!this._match100JBleItemByRes(res)) return;
let bleDeviceId = res.deviceId; let bleDeviceId = res.deviceId;
updateBleStatus(true, bleDeviceId, this.deviceInfo.deviceId); updateBleStatus(true, bleDeviceId, this.deviceInfo.deviceId);
// 蓝牙连接成功后主动拉取电源状态、定位(优先蓝牙设备也会每1分钟主动上报) // 蓝牙连接成功后主动拉取电源状态、定位(优先蓝牙设备也会每1分钟主动上报)