diff --git a/miniprogram/pages/home/home.less b/miniprogram/pages/home/home.less index a154c3e..15bb053 100644 --- a/miniprogram/pages/home/home.less +++ b/miniprogram/pages/home/home.less @@ -211,6 +211,14 @@ font-weight: bolder; line-height: 48rpx; margin-right: 10rpx; + + &.diff-up { + color: #FF4D4F; + } + + &.diff-neutral { + color: #252535; + } } > view:nth-of-type(2) { @@ -315,6 +323,32 @@ } } + .empty-state { + width: 100%; + display: flex; + flex-direction: column; + align-items: center; + padding-top: 160rpx; + + .empty-icon { + width: 193rpx; + height: 138rpx; + margin-bottom: 40rpx; + + image { + width: 100%; + height: 100%; + } + } + + .empty-text { + color: #808080; + height: 30rpx; + font-size: 30rpx; + line-height: 30rpx; + } + } + .detailedData { width: 100%; border-radius: 24rpx; diff --git a/miniprogram/pages/home/home.ts b/miniprogram/pages/home/home.ts index 8eb2aac..af8116a 100644 --- a/miniprogram/pages/home/home.ts +++ b/miniprogram/pages/home/home.ts @@ -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('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: '智能蓝牙秤', diff --git a/miniprogram/pages/home/home.wxml b/miniprogram/pages/home/home.wxml index 6ea25e9..3a81128 100644 --- a/miniprogram/pages/home/home.wxml +++ b/miniprogram/pages/home/home.wxml @@ -17,76 +17,82 @@ - - - - 最近测量 - 详细报告 - - - - - - 68 - .20 - kg - - 07-22 09:30 - - - - 2.6 + + + + + 最近测量 + 详细报告 + + + + - + {{ record.weight }} + {{ record.weightDecimal }} kg + {{ record.date }} + + + + {{ record.diff < 0 ? -record.diff : record.diff }} + + {{ record.diff < 0 ? '↓' : (record.diff > 0 ? '↑' : '') }} + kg + + + {{ record.diff < 0 ? '体重较上次减轻' : (record.diff > 0 ? '体重较上次增加' : '与上次持平') }} - 体重较上次减轻 - - - - - 身高 - 172cm - - - BMI标准 - 22.4 - - - 体脂率 - 22.1% + + + + 身高 + {{ record.height }}cm + + + BMI{{ record.bmiLabel }} + {{ record.bmi }} + + + 体脂率 + {{ record.bodyFat }}% + - - - - + + + + - - - - - 详细数据 - - - - 体脂肪量 - 16.0kg + + + + 详细数据 - - 体水分量 - 39.8kg - - - 蛋白质量 - 1680kcal + + + 体脂肪量 + {{ record.bodyFatMass }}kg + + + 体水分量 + {{ record.bodyWater }}kg + + + 蛋白质量 + {{ record.protein }}kg + - + + + + + - \ No newline at end of file +