feat(mp): 连接M2手环后自动测量5项指标 + 修复仪表盘数值不可见
- 连接认证成功后自动依次测量心率→血氧→血压→体温→压力 - 列表式进度UI展示每项指标状态(等待/测量中/完成/跳过) - 总进度条百分比实时更新 - 测量完成后保存结果并显示'查看结果并返回'按钮 - 支持取消自动测量,已测得的数据不丢失 - 修复仪表盘中心区域缺少背景色导致数值与底色混淆不可见
This commit is contained in:
@@ -71,6 +71,12 @@ Page({
|
||||
measureError: '',
|
||||
results: {},
|
||||
hasResults: false,
|
||||
// 自动测量状态
|
||||
autoMeasuring: false,
|
||||
autoMeasureDone: false,
|
||||
autoMeasureStatus: {},
|
||||
autoMeasureValues: {},
|
||||
autoMeasureProgress: 0,
|
||||
},
|
||||
|
||||
_authTimer: null,
|
||||
@@ -84,6 +90,8 @@ Page({
|
||||
_eventChannel: null,
|
||||
_connecting: false,
|
||||
_listenersRegistered: false,
|
||||
_autoQueue: null,
|
||||
_autoQueueIndex: 0,
|
||||
|
||||
// ── 生命周期 ──
|
||||
|
||||
@@ -278,6 +286,9 @@ Page({
|
||||
// 认证成功后自动读取 3 天睡眠数据 + 开启自动测量
|
||||
this._readSleepData();
|
||||
this._enableAutoMeasurement();
|
||||
|
||||
// 自动依次测量所有指标(面向中老年人,减少操作)
|
||||
this._startAutoMeasureQueue();
|
||||
},
|
||||
|
||||
// ── SDK 事件路由 ──
|
||||
@@ -415,6 +426,13 @@ Page({
|
||||
// ── 测量事件处理 ──
|
||||
|
||||
_handleMeasureEvent: function (type, data) {
|
||||
// 自动测量模式下,路由到自动测量处理器
|
||||
if (this.data.autoMeasuring) {
|
||||
this._handleAutoMeasureEvent(type, data);
|
||||
return;
|
||||
}
|
||||
|
||||
// 手动测量模式
|
||||
if (this.data.selectedType !== type || this.data.measurePhase !== 'measuring') return;
|
||||
|
||||
var content = data.content || {};
|
||||
@@ -634,4 +652,212 @@ Page({
|
||||
console.warn('[veepoo-native] 开启体温自动监测失败:', e);
|
||||
}
|
||||
},
|
||||
|
||||
// ── 自动测量队列 ──
|
||||
|
||||
_startAutoMeasureQueue: function () {
|
||||
var types = [];
|
||||
var status = {};
|
||||
for (var i = 0; i < MEASURE_TYPES.length; i++) {
|
||||
types.push(MEASURE_TYPES[i].type);
|
||||
status[MEASURE_TYPES[i].type] = 'pending';
|
||||
}
|
||||
|
||||
this._autoQueue = types;
|
||||
this._autoQueueIndex = 0;
|
||||
|
||||
this.setData({
|
||||
autoMeasuring: true,
|
||||
autoMeasureDone: false,
|
||||
autoMeasureStatus: status,
|
||||
autoMeasureValues: {},
|
||||
autoMeasureProgress: 0,
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
console.log('[veepoo-native] 启动自动测量队列,共 ' + types.length + ' 项');
|
||||
|
||||
var self = this;
|
||||
setTimeout(function () {
|
||||
self._startNextAutoMeasure();
|
||||
}, 800);
|
||||
},
|
||||
|
||||
_startNextAutoMeasure: function () {
|
||||
if (!this._autoQueue || this._autoQueueIndex >= this._autoQueue.length) {
|
||||
this._onAutoMeasureComplete();
|
||||
return;
|
||||
}
|
||||
|
||||
var type = this._autoQueue[this._autoQueueIndex];
|
||||
this._updateSelectedDisplay(type);
|
||||
|
||||
var status = Object.assign({}, this.data.autoMeasureStatus);
|
||||
status[type] = 'measuring';
|
||||
this.setData({
|
||||
autoMeasureStatus: status,
|
||||
measurePhase: 'measuring',
|
||||
measureProgress: 0,
|
||||
measureDisplayValue: '',
|
||||
measureError: '',
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
console.log('[veepoo-native] 自动测量 [' + (this._autoQueueIndex + 1) + '/' + this._autoQueue.length + ']: ' + type);
|
||||
|
||||
this._lastValues = null;
|
||||
this._sendMeasureCommand(type, true);
|
||||
|
||||
var self = this;
|
||||
var timeout = MEASURE_TIMEOUTS[type] || 60000;
|
||||
this._measureTimer = setTimeout(function () {
|
||||
// eslint-disable-next-line no-undef
|
||||
console.warn('[veepoo-native] 自动测量超时: ' + type);
|
||||
self._onAutoMeasureError(type, '测量超时');
|
||||
}, timeout);
|
||||
},
|
||||
|
||||
_handleAutoMeasureEvent: function (type, data) {
|
||||
if (!this._autoQueue || this._autoQueueIndex >= this._autoQueue.length) return;
|
||||
if (type !== this._autoQueue[this._autoQueueIndex]) return;
|
||||
|
||||
var content = data.content || {};
|
||||
var self = this;
|
||||
|
||||
if (content.deviceBusy === true) { self._onAutoMeasureError(type, '设备正忙'); return; }
|
||||
if (content.notWear === true || data.state === 6) { self._onAutoMeasureError(type, '未佩戴'); return; }
|
||||
if (data.state === 7) { self._onAutoMeasureError(type, '设备充电中'); return; }
|
||||
if (data.state === 8) { self._onAutoMeasureError(type, '电量不足'); return; }
|
||||
if (type === 'pressure' && data.ack === 2) { self._onAutoMeasureError(type, '电量不足'); return; }
|
||||
if (type === 'pressure' && data.ack === 3) { self._onAutoMeasureError(type, '设备正忙'); return; }
|
||||
if (type === 'pressure' && data.ack === 4) { self._onAutoMeasureError(type, '未佩戴'); return; }
|
||||
|
||||
var values = self._extractValues(type, content);
|
||||
if (!values) return;
|
||||
|
||||
self._lastValues = values;
|
||||
|
||||
var progress = data.Progress !== undefined ? data.Progress : 0;
|
||||
self.setData({ measureProgress: Math.max(progress, 0) });
|
||||
|
||||
if (progress >= 100) {
|
||||
self._onAutoMeasureSuccess(type, values);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!self._settleTimer) {
|
||||
self._settleTimer = setTimeout(function () {
|
||||
if (self._lastValues && self.data.autoMeasuring) {
|
||||
self._onAutoMeasureSuccess(type, self._lastValues);
|
||||
}
|
||||
}, MEASURE_SETTLE_DELAY);
|
||||
}
|
||||
},
|
||||
|
||||
_onAutoMeasureSuccess: function (type, values) {
|
||||
this._cancelPendingMeasure();
|
||||
|
||||
var result = { type: type, values: values, measuredAt: Date.now() };
|
||||
var newResults = Object.assign({}, this.data.results);
|
||||
newResults[type] = result;
|
||||
|
||||
var status = Object.assign({}, this.data.autoMeasureStatus);
|
||||
status[type] = 'done';
|
||||
|
||||
var newValues = Object.assign({}, this.data.autoMeasureValues);
|
||||
newValues[type] = this._formatValues(type, values);
|
||||
|
||||
var doneCount = 0;
|
||||
var keys = Object.keys(status);
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
if (status[keys[i]] === 'done' || status[keys[i]] === 'error') doneCount++;
|
||||
}
|
||||
var progress = Math.round((doneCount / this._autoQueue.length) * 100);
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
console.log('[veepoo-native] 自动测量完成: ' + type + ' = ' + newValues[type] + ' (' + progress + '%)');
|
||||
|
||||
this.setData({
|
||||
results: newResults,
|
||||
hasResults: true,
|
||||
autoMeasureStatus: status,
|
||||
autoMeasureValues: newValues,
|
||||
autoMeasureProgress: progress,
|
||||
measurePhase: 'idle',
|
||||
});
|
||||
|
||||
this._autoQueueIndex++;
|
||||
var self = this;
|
||||
setTimeout(function () {
|
||||
self._startNextAutoMeasure();
|
||||
}, 800);
|
||||
},
|
||||
|
||||
_onAutoMeasureError: function (type, msg) {
|
||||
this._cancelPendingMeasure();
|
||||
|
||||
var status = Object.assign({}, this.data.autoMeasureStatus);
|
||||
status[type] = 'error';
|
||||
|
||||
var doneCount = 0;
|
||||
var keys = Object.keys(status);
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
if (status[keys[i]] === 'done' || status[keys[i]] === 'error') doneCount++;
|
||||
}
|
||||
var progress = Math.round((doneCount / this._autoQueue.length) * 100);
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
console.warn('[veepoo-native] 自动测量失败: ' + type + ' - ' + msg + ' (' + progress + '%)');
|
||||
|
||||
this.setData({
|
||||
autoMeasureStatus: status,
|
||||
autoMeasureProgress: progress,
|
||||
measurePhase: 'idle',
|
||||
});
|
||||
|
||||
this._autoQueueIndex++;
|
||||
var self = this;
|
||||
setTimeout(function () {
|
||||
self._startNextAutoMeasure();
|
||||
}, 500);
|
||||
},
|
||||
|
||||
_onAutoMeasureComplete: function () {
|
||||
// eslint-disable-next-line no-undef
|
||||
console.log('[veepoo-native] 自动测量全部完成');
|
||||
|
||||
var results = this.data.results;
|
||||
if (Object.keys(results).length > 0) {
|
||||
try {
|
||||
// eslint-disable-next-line no-undef
|
||||
wx.setStorageSync('hms:veepoo_measure_results', JSON.stringify(results));
|
||||
} catch (_) { /* ignore */ }
|
||||
}
|
||||
|
||||
this.setData({
|
||||
autoMeasureDone: true,
|
||||
autoMeasuring: false,
|
||||
autoMeasureProgress: 100,
|
||||
measurePhase: 'idle',
|
||||
});
|
||||
},
|
||||
|
||||
handleCancelAutoMeasure: function () {
|
||||
this._cancelPendingMeasure();
|
||||
this._autoQueue = null;
|
||||
|
||||
var results = this.data.results;
|
||||
if (Object.keys(results).length > 0) {
|
||||
try {
|
||||
// eslint-disable-next-line no-undef
|
||||
wx.setStorageSync('hms:veepoo_measure_results', JSON.stringify(results));
|
||||
} catch (_) { /* ignore */ }
|
||||
}
|
||||
|
||||
this.setData({
|
||||
autoMeasuring: false,
|
||||
autoMeasureDone: false,
|
||||
measurePhase: 'idle',
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user