[AI Generated]: feat(*): 对接数据页/测量报告真实接口,完善成员管理、蓝牙连接及成员选择抽屉逻辑

This commit is contained in:
17792275749
2026-05-15 14:10:27 +08:00
parent 5f9232572f
commit e0573857e0
16 changed files with 612 additions and 283 deletions
@@ -1,70 +1,122 @@
/** 测量报告数据 */
import { get } from '../../utils/request/index'
/** GET /weighingScale/v3/getMeasureHistory result 结构 */
interface MeasureHistoryVO {
recordId: string
height: number
weight: number
weightChange: number
bmi: number
bmiType: string
standardWeight: number
fatRate: number
fatValue: number
basalMetabolism: number
examTime: string
sn: string
userInfo: {
realname: string
sex: number
[key: string]: any
} | null
}
/** 页面渲染用测量记录 */
interface WeightRecord {
/** 体重整数部分 */
weight: number
/** 体重小数部分,含小数点,如 ".20" */
weightDecimal: string
/** 测量时间显示,如 "今日 07:30" */
date: string
/** 与上次相比差值(负=减轻,正=增重) */
diff: number
/** 身高(cm) */
height: number
/** BMI 值 */
bmi: number
/** BMI 评级标签,如 "标准" */
bmiLabel: string
/** 标准体重(kg) */
stdWeight: number
/** 体脂率(%) */
bodyFat: number
/** 体脂肪(kg) */
bodyFatMass: number
/** 基础代谢(kcal) */
bmr: number
/** 体重整数部分 */
weight: number
/** 体重小数部分含小数点如 ".20" */
weightDecimal: string
/** 测量时间 */
date: string
/** 与上次体重差值负=减轻正=增重 */
diff: number
/** 身高(cm) */
height: number
/** BMI 值 */
bmi: number
/** BMI 评级文本(来自接口 bmiType */
bmiLabel: string
/** 标准体重(kg) */
stdWeight: number
/** 体脂率(%) */
bodyFat: number
/** 体脂肪(kg) */
bodyFatMass: number
/** 基础代谢(kcal) */
bmr: number
}
/** 空态默认值,避免页面展示 null */
const EMPTY_RECORD: WeightRecord = {
weight: 0,
weightDecimal: '',
date: '',
diff: 0,
height: 0,
bmi: 0,
bmiLabel: '',
stdWeight: 0,
bodyFat: 0,
bodyFatMass: 0,
bmr: 0,
}
/** 将体重数字拆成整数 + 小数字符串 */
function splitWeight(weight: number): { int: number; decimal: string } {
const str = weight.toFixed(2)
const [intPart, decPart] = str.split('.')
return { int: Number(intPart), decimal: `.${decPart}` }
}
/**
* 测量报告页
* 展示单次测量的详细数据报告
* URL 参数:recordId(记录 ID)、userId(用户 ID
*/
Page({
data: {
// 报告数据
record: {
weight: 68,
weightDecimal: '.20',
date: '今日 07:30',
diff: -0.3,
height: 176,
bmi: 22.4,
bmiLabel: '标准',
stdWeight: 67.2,
bodyFat: 22.3,
bodyFatMass: 52.1,
bmr: 1652
} as WeightRecord
},
data: {
record: EMPTY_RECORD as WeightRecord,
/** 被查看用户的姓名(来自接口 userInfo.realname */
realname: '',
},
onLoad(options) {
// TODO: 根据 options.id 获取报告详情
},
onLoad(options: Record<string, string>) {
const { recordId, userId } = options
if (!recordId || !userId) return
onReady() {},
get<MeasureHistoryVO>('weighingScale/v3/getMeasureHistory', {
userId,
recordId,
}, { loading: true })
.then((res: any) => {
const d: MeasureHistoryVO = res.result
if (!d) return
onShow() {},
const { int, decimal } = splitWeight(d.weight ?? 0)
const record: WeightRecord = {
weight: int,
weightDecimal: decimal,
date: d.examTime ?? '',
diff: d.weightChange ?? 0,
height: d.height ?? 0,
bmi: d.bmi ?? 0,
bmiLabel: d.bmiType ?? '',
stdWeight: d.standardWeight ?? 0,
bodyFat: d.fatRate ?? 0,
bodyFatMass: d.fatValue ?? 0,
bmr: d.basalMetabolism ?? 0,
}
this.setData({
record,
realname: d.userInfo?.realname ?? '',
})
})
},
onHide() {},
onUnload() {},
/**
* 分享报告
*/
onShareAppMessage(): WechatMiniprogram.Page.ICustomShareContent {
return {
title: `${this.data.report.userName}的测量报告`,
path: '/pages/measurementReport/measurementReport'
}
}
onShareAppMessage(): WechatMiniprogram.Page.ICustomShareContent {
return {
title: `${this.data.realname}的测量报告`,
path: '/pages/measurementReport/measurementReport',
}
},
})