feat(home): 首页接入最新测量数据与空态
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
e69db66eab
commit
76879270ba
@@ -10,6 +10,42 @@ interface PageUserInfo {
|
||||
height: number
|
||||
}
|
||||
|
||||
/** 身体成分单项指标 */
|
||||
interface LefuBodyDatum {
|
||||
bodyParamKey: string
|
||||
currentValue: string
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
/** 测量历史详情 */
|
||||
interface MeasureHistoryVO {
|
||||
recordId?: string
|
||||
height?: number
|
||||
weight?: number
|
||||
weightChange?: number
|
||||
bmi?: number
|
||||
bmiType?: string
|
||||
fatRate?: number
|
||||
fatValue?: number
|
||||
examTime?: string
|
||||
bodyDataList?: LefuBodyDatum[]
|
||||
}
|
||||
|
||||
/** 页面展示用最近测量记录 */
|
||||
interface WeightRecord {
|
||||
weight: number
|
||||
weightDecimal: string
|
||||
date: string
|
||||
diff: number
|
||||
height: number
|
||||
bmi: number
|
||||
bmiLabel: string
|
||||
bodyFat: number
|
||||
bodyFatMass: number
|
||||
bodyWater: number
|
||||
protein: number
|
||||
}
|
||||
|
||||
/** 将体重数字拆成整数 + 小数字符串 */
|
||||
const splitWeight = (weight: number): { int: number; decimal: string } => {
|
||||
const str = weight.toFixed(2)
|
||||
@@ -17,14 +53,23 @@ const splitWeight = (weight: number): { int: number; decimal: string } => {
|
||||
return { int: Number(intPart), decimal: `.${decPart}` }
|
||||
}
|
||||
|
||||
/** 从 bodyDataList 提取指标数值 */
|
||||
const pickValue = (list: LefuBodyDatum[] = [], key: string): number => {
|
||||
const item = list.find((d) => d?.bodyParamKey === key)
|
||||
const v = parseFloat(item?.currentValue ?? '')
|
||||
return isNaN(v) ? 0 : v
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
record: null,
|
||||
hasData: false,
|
||||
record: null as WeightRecord | null,
|
||||
userInfo: null as PageUserInfo | null,
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this._loadUserInfo()
|
||||
this.loadData()
|
||||
},
|
||||
|
||||
// 从缓存回显用户信息
|
||||
@@ -41,6 +86,38 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
// 拉取最新一次测量记录
|
||||
loadData() {
|
||||
const raw = wx.getStorageSync('userInfo') as UserInfo | null
|
||||
if (!raw?.userId) return
|
||||
get<MeasureHistoryVO>('weighingScale/v3/getMeasureHistory', {
|
||||
userId: raw.userId,
|
||||
}, { loading: false })
|
||||
.then((res: any) => {
|
||||
const d: MeasureHistoryVO = res.result
|
||||
if (!d) {
|
||||
this.setData({ hasData: false, record: null })
|
||||
return
|
||||
}
|
||||
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 ?? '',
|
||||
bodyFat: d.fatRate ?? 0,
|
||||
bodyFatMass: d.fatValue ?? 0,
|
||||
bodyWater: pickValue(d.bodyDataList, 'ppWaterKg'),
|
||||
protein: pickValue(d.bodyDataList, 'ppProteinKg'),
|
||||
}
|
||||
this.setData({ hasData: true, record })
|
||||
})
|
||||
.catch(() => {})
|
||||
},
|
||||
|
||||
onShareAppMessage(): WechatMiniprogram.Page.ICustomShareContent {
|
||||
return {
|
||||
title: '智能蓝牙秤',
|
||||
|
||||
Reference in New Issue
Block a user