fix(mp): M2 设备扫描放宽名称匹配 + vibrateShort 异步 catch
1. 扫描匹配放宽:支持 M2 / VPM / VEEPOO 三种广播名前缀 2. 增加诊断日志:SDK 加载状态 + 每个扫描到的设备完整信息 3. 扫描超时从 10s 增加到 15s 4. vibrateShort 改用 .catch() 捕获异步 rejection(DevTools 不支持 type 参数)
This commit is contained in:
@@ -88,6 +88,14 @@ Page({
|
|||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
wx.setNavigationBarTitle({ title: 'M2 手环测量' });
|
wx.setNavigationBarTitle({ title: 'M2 手环测量' });
|
||||||
this._updateSelectedDisplay('heart_rate');
|
this._updateSelectedDisplay('heart_rate');
|
||||||
|
// 诊断:确认 SDK 加载状态
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
|
console.log('[veepoo-native] SDK 加载状态:', {
|
||||||
|
veepooBle: typeof veepooBle,
|
||||||
|
veepooFeature: typeof veepooFeature,
|
||||||
|
veepooLogger: typeof veepooLogger,
|
||||||
|
scanFn: typeof veepooBle.veepooWeiXinSDKStartScanDeviceAndReceiveScanningDevice,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
onUnload: function () {
|
onUnload: function () {
|
||||||
@@ -139,9 +147,11 @@ Page({
|
|||||||
var device = Array.isArray(res) ? res[0] : res;
|
var device = Array.isArray(res) ? res[0] : res;
|
||||||
if (!device) return;
|
if (!device) return;
|
||||||
var name = (device.localName || device.name || '').toUpperCase();
|
var name = (device.localName || device.name || '').toUpperCase();
|
||||||
|
var deviceId = device.deviceId || device.mac || '';
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
console.log('[veepoo-native] 扫描到:', name, device.deviceId || device.mac);
|
console.log('[veepoo-native] 扫描到:', name, deviceId, JSON.stringify(device).substring(0, 200));
|
||||||
if (name.indexOf('M2') !== -1 && !self._scanFound) {
|
// 放宽匹配:包含 M2 / VPM / VEEPOO 均视为目标设备
|
||||||
|
if (!self._scanFound && (name.indexOf('M2') !== -1 || name.indexOf('VPM') !== -1 || name.indexOf('VEEPOO') !== -1)) {
|
||||||
self._scanFound = device;
|
self._scanFound = device;
|
||||||
veepooBle.veepooWeiXinSDKStopSearchBleManager(function () {
|
veepooBle.veepooWeiXinSDKStopSearchBleManager(function () {
|
||||||
self._doConnect(device);
|
self._doConnect(device);
|
||||||
@@ -153,9 +163,9 @@ Page({
|
|||||||
if (!self._scanFound) {
|
if (!self._scanFound) {
|
||||||
veepooBle.veepooWeiXinSDKStopSearchBleManager(function () {});
|
veepooBle.veepooWeiXinSDKStopSearchBleManager(function () {});
|
||||||
self._connecting = false;
|
self._connecting = false;
|
||||||
self.setData({ phase: 'error', error: '未找到 M2 设备,请确保手环已开机' });
|
self.setData({ phase: 'error', error: '未找到 M2 设备,请确保手环已开机且蓝牙已开启' });
|
||||||
}
|
}
|
||||||
}, 10000);
|
}, 15000);
|
||||||
},
|
},
|
||||||
|
|
||||||
_doConnect: function (device) {
|
_doConnect: function (device) {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export function showToast(options: {
|
|||||||
const duration = options.duration ?? (mode === 'elder' ? 3000 : 1500);
|
const duration = options.duration ?? (mode === 'elder' ? 3000 : 1500);
|
||||||
|
|
||||||
if (mode === 'elder') {
|
if (mode === 'elder') {
|
||||||
try { Taro.vibrateShort({ type: 'light' }); } catch { /* 不支持时静默 */ }
|
Taro.vibrateShort({ type: 'light' }).catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
Taro.showToast({ ...options, duration, icon: options.icon ?? 'none' });
|
Taro.showToast({ ...options, duration, icon: options.icon ?? 'none' });
|
||||||
|
|||||||
@@ -2,21 +2,15 @@ import Taro from '@tarojs/taro';
|
|||||||
|
|
||||||
/** 轻触反馈(按钮点击) */
|
/** 轻触反馈(按钮点击) */
|
||||||
export function hapticLight(): void {
|
export function hapticLight(): void {
|
||||||
try {
|
Taro.vibrateShort({ type: 'light' }).catch(() => { /* DevTools 不支持 type 参数,真机正常 */ });
|
||||||
Taro.vibrateShort({ type: 'light' });
|
|
||||||
} catch { /* 部分设备不支持 */ }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 中等反馈(成功操作) */
|
/** 中等反馈(成功操作) */
|
||||||
export function hapticMedium(): void {
|
export function hapticMedium(): void {
|
||||||
try {
|
Taro.vibrateShort({ type: 'medium' }).catch(() => { /* ignore */ });
|
||||||
Taro.vibrateShort({ type: 'medium' });
|
|
||||||
} catch { /* ignore */ }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 重度反馈(错误/警告) */
|
/** 重度反馈(错误/警告) */
|
||||||
export function hapticHeavy(): void {
|
export function hapticHeavy(): void {
|
||||||
try {
|
Taro.vibrateShort({ type: 'heavy' }).catch(() => { /* ignore */ });
|
||||||
Taro.vibrateShort({ type: 'heavy' });
|
|
||||||
} catch { /* ignore */ }
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user