[AI Generated]: feat(*): 完善数据页切换成员、首页接口对接及我的页缓存信息展示
This commit is contained in:
@@ -1,8 +1,4 @@
|
||||
import { mockLatestRecord } from '../../mock/home.mock'
|
||||
import type { WeightRecord } from '../../mock/home.mock'
|
||||
|
||||
/** 加载状态机 */
|
||||
type LoadStatus = 'idle' | 'loading' | 'loaded'
|
||||
import { get } from '../../utils/request/index'
|
||||
|
||||
/** 设备信息 */
|
||||
interface DeviceInfo {
|
||||
@@ -10,9 +6,57 @@ interface DeviceInfo {
|
||||
connected: boolean
|
||||
}
|
||||
|
||||
/** 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
|
||||
weightDecimal: string
|
||||
date: string
|
||||
diff: number
|
||||
height: number
|
||||
bmi: number
|
||||
bmiLabel: string
|
||||
stdWeight: number
|
||||
bodyFat: number
|
||||
bodyFatMass: number
|
||||
bmr: number
|
||||
}
|
||||
|
||||
/** 缓存中的用户信息 */
|
||||
interface StorageUserInfo {
|
||||
userId: string
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
/** 将体重数字拆成整数 + 小数字符串 */
|
||||
function splitWeight(weight: number): { int: number; decimal: string } {
|
||||
const str = weight.toFixed(2)
|
||||
const [intPart, decPart] = str.split('.')
|
||||
return { int: Number(intPart), decimal: `.${decPart}` }
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
status: 'idle' as LoadStatus,
|
||||
hasData: false,
|
||||
device: {
|
||||
name: '智能体重秤',
|
||||
@@ -25,13 +69,6 @@ Page({
|
||||
this.loadData()
|
||||
},
|
||||
|
||||
onReady() {},
|
||||
onShow() {},
|
||||
onHide() {},
|
||||
onUnload() {},
|
||||
onPullDownRefresh() {},
|
||||
onReachBottom() {},
|
||||
|
||||
onShareAppMessage(): WechatMiniprogram.Page.ICustomShareContent {
|
||||
return {
|
||||
title: '智能蓝牙秤',
|
||||
@@ -40,17 +77,40 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/** 加载首页数据(当前使用 mock,后续替换为真实接口) */
|
||||
/** 拉取最新一次测量记录 */
|
||||
loadData() {
|
||||
this.setData({ status: 'loading' })
|
||||
// 模拟异步加载
|
||||
setTimeout(() => {
|
||||
this.setData({
|
||||
status: 'loaded',
|
||||
hasData: true,
|
||||
record: mockLatestRecord,
|
||||
const raw = wx.getStorageSync('userInfo') as StorageUserInfo | null
|
||||
if (!raw?.userId) return
|
||||
|
||||
wx.showLoading({ title: '加载中...', mask: true })
|
||||
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 ?? '',
|
||||
stdWeight: d.standardWeight ?? 0,
|
||||
bodyFat: d.fatRate ?? 0,
|
||||
bodyFatMass: d.fatValue ?? 0,
|
||||
bmr: d.basalMetabolism ?? 0,
|
||||
}
|
||||
this.setData({ hasData: true, record })
|
||||
})
|
||||
.finally(() => {
|
||||
wx.hideLoading()
|
||||
})
|
||||
}, 300)
|
||||
},
|
||||
|
||||
/** 跳转历史数据页 */
|
||||
|
||||
@@ -139,7 +139,7 @@
|
||||
<block wx:else>
|
||||
<view class="empty-state">
|
||||
<view class="empty-icon">
|
||||
<image src="/images/home/noData.png" mode=""/>
|
||||
<image src="/images/home/noData.png" mode="aspectFit"/>
|
||||
</view>
|
||||
<view class="empty-text">暂无称重数据</view>
|
||||
</view>
|
||||
|
||||
Reference in New Issue
Block a user