feat: 扫描报告页+手动选波长护理+光疗功效介绍页+诊断框架(占位阈值)
- services/diagnosis.js: 诊断流水线框架,阈值/PD映射为占位待标定,支持单波长降级 - auto-scan: 扫描完成改为出报告让用户选择护理(替代原自动开始治疗) - 新增 scan-report/manual-treatment/light-info 三页,全部接入 i18n - api.js: 新增 report/diagnosis-config 接口(对接后端契约)
这个提交包含在:
@@ -1,4 +1,6 @@
|
||||
var ble = require('../../services/ble')
|
||||
var api = require('../../utils/api')
|
||||
var diagnosis = require('../../services/diagnosis')
|
||||
var SCAN_TIMEOUT = 180000
|
||||
|
||||
Page({
|
||||
@@ -158,39 +160,49 @@ Page({
|
||||
getApp().globalData.lastScanPdAvg = avg
|
||||
console.log('[SCAN] PD平均值:', avg, '帧数:', count)
|
||||
|
||||
this._startTreatment()
|
||||
this._buildAndGoReport(avg)
|
||||
},
|
||||
|
||||
_startTreatment: function () {
|
||||
// Scan finished -> run the (placeholder) diagnosis, store + persist a report, and
|
||||
// navigate to the report page so the user sees their skin tendencies and chooses
|
||||
// care. This replaces the previous auto-start-treatment behavior.
|
||||
//
|
||||
// NOTE: today only single-wavelength red PD is collected, and the thresholds +
|
||||
// PD->region mapping in services/diagnosis.js are placeholders pending calibration.
|
||||
// Report + persistence work end to end regardless; the numbers get real after
|
||||
// 4-wavelength scan collection and calibration land.
|
||||
_buildAndGoReport: function (avg) {
|
||||
var self = this
|
||||
var app = getApp()
|
||||
var mask = self.data.regions || 0x1F
|
||||
var avg = self.data.pdAvg
|
||||
var params = self._calculateTreatParams(mask, avg)
|
||||
var deviceId = (app.globalData.connectedDevice && app.globalData.connectedDevice.device_id) || null
|
||||
var scannedAt = Date.now()
|
||||
|
||||
console.log('[SCAN] 自动发送治疗命令:', JSON.stringify(params))
|
||||
ble.setParams(params).then(function () {
|
||||
return ble.startTreatment(mask)
|
||||
}).then(function () {
|
||||
wx.redirectTo({
|
||||
url: '/pages/treating/treating?regions=' + mask +
|
||||
'&wavelength=2&duration=600000&mode=1'
|
||||
})
|
||||
}).catch(function (err) {
|
||||
self.setData({ error: err.error_msg || '启动治疗失败' })
|
||||
})
|
||||
},
|
||||
function proceed(config) {
|
||||
var scanData = diagnosis.fromRedScan(avg, mask, deviceId, scannedAt)
|
||||
var report = diagnosis.analyze(scanData, config || diagnosis.DEFAULT_CONFIG)
|
||||
app.globalData.lastScanReport = report
|
||||
|
||||
_calculateTreatParams: function (mask, pdAvg) {
|
||||
// TODO: 接入完整诊断算法(NR 归一化吸收率 → 匹配光谱+强度)
|
||||
// 需要 PD→区域映射确认后实现
|
||||
return {
|
||||
region_mask: mask,
|
||||
wavelength: 2,
|
||||
brightness: 200,
|
||||
duration_ms: 600000,
|
||||
mode: 1,
|
||||
control: 0x02
|
||||
// Best-effort persist (also seeds the calibration dataset via raw_pd); never blocks navigation.
|
||||
api.saveReport({
|
||||
device_id: report.device_id,
|
||||
scanned_at: report.scanned_at,
|
||||
regions: report.regions,
|
||||
overall: report.overall,
|
||||
recommend_mask: report.recommend_mask,
|
||||
recommend_plan: report.recommend_plan,
|
||||
raw_pd: report.raw_pd,
|
||||
calibrated: report.calibrated
|
||||
}).catch(function () {})
|
||||
|
||||
wx.redirectTo({ url: '/pages/scan-report/scan-report' })
|
||||
}
|
||||
|
||||
api.getDiagnosisConfig().then(function (cfg) {
|
||||
proceed(cfg && cfg.levels ? cfg : diagnosis.DEFAULT_CONFIG)
|
||||
}).catch(function () {
|
||||
proceed(diagnosis.DEFAULT_CONFIG)
|
||||
})
|
||||
},
|
||||
|
||||
onUnload: function () {
|
||||
|
||||
在新工单中引用
屏蔽一个用户