[AI Generated]: feat(*): 对接数据页/测量报告真实接口,完善成员管理、蓝牙连接及成员选择抽屉逻辑
This commit is contained in:
@@ -34,13 +34,18 @@
|
||||
align-items: center;
|
||||
margin-bottom: 30rpx;
|
||||
|
||||
/* 头像色块 */
|
||||
/* 头像色块(展示姓名首字) */
|
||||
.avatar {
|
||||
width: 90rpx;
|
||||
height: 90rpx;
|
||||
margin-right: 24rpx;
|
||||
border-radius: 18rpx;
|
||||
background: var(--avatar-bg);
|
||||
color: #FFFFFF;
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
line-height: 90rpx;
|
||||
text-align: center;
|
||||
background-color: #1385FA;
|
||||
}
|
||||
|
||||
/* 姓名 + meta */
|
||||
@@ -269,4 +274,31 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ===== 空态 ===== */
|
||||
.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+184
-37
@@ -1,72 +1,219 @@
|
||||
import { getMockRecords, calcStats } from '../../mock/data.mock'
|
||||
import type { TimeRange, RecordItem, StatsData } from '../../mock/data.mock'
|
||||
import type { MemberItem } from '../../mock/member.mock'
|
||||
import { mockMembers } from '../../mock/member.mock'
|
||||
import { get } from '../../utils/request/index'
|
||||
|
||||
/** 加载状态机 */
|
||||
type LoadStatus = 'idle' | 'loading' | 'loaded'
|
||||
|
||||
/** 接口 type 参数:0=全部 1=近7天 2=近30天 3=近3月 */
|
||||
type RangeType = 0 | 1 | 2 | 3
|
||||
|
||||
/** 时间范围 Tab 项 */
|
||||
interface RangeTab {
|
||||
key: TimeRange
|
||||
key: RangeType
|
||||
label: string
|
||||
}
|
||||
|
||||
/** 缓存中的用户信息 */
|
||||
interface StorageUserInfo {
|
||||
userId: string
|
||||
realname: string
|
||||
sex: number
|
||||
height: number
|
||||
birthday: string
|
||||
avatar: string | null
|
||||
relationType: number | string | null
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
/** 页面展示用用户信息 */
|
||||
interface PageUserInfo extends StorageUserInfo {
|
||||
sex_dictText: '男' | '女' | ''
|
||||
age: number
|
||||
isSelf: boolean
|
||||
}
|
||||
|
||||
/** GET /weighingScale/v3/getMeasureStatistics 返回结构 */
|
||||
interface MeasureStatistics {
|
||||
maxWeight: number
|
||||
minWeight: number
|
||||
avgWeight: number
|
||||
weightChange: number
|
||||
}
|
||||
|
||||
/** GET /weighingScale/v3/getMeasureHistoryPage records 单条 */
|
||||
interface MeasureRecord {
|
||||
recordId: string
|
||||
examTime: string
|
||||
weight: number
|
||||
bmi: number
|
||||
fatRate: number
|
||||
}
|
||||
|
||||
/** 统计空态默认值 */
|
||||
const EMPTY_STATS: MeasureStatistics = {
|
||||
maxWeight: 0,
|
||||
minWeight: 0,
|
||||
avgWeight: 0,
|
||||
weightChange: 0,
|
||||
}
|
||||
|
||||
/** 从生日字符串(YYYY-MM-DD)计算周岁 */
|
||||
function calcAge(birthday: string): number {
|
||||
if (!birthday) return 0
|
||||
const [year, month, day] = birthday.split('-').map(Number)
|
||||
if (!year || !month || !day) return 0
|
||||
const now = new Date()
|
||||
let age = now.getFullYear() - year
|
||||
if (now.getMonth() + 1 < month || (now.getMonth() + 1 === month && now.getDate() < day)) age -= 1
|
||||
return Math.max(0, age)
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
status: 'idle' as LoadStatus,
|
||||
activeRange: '7d' as TimeRange,
|
||||
activeType: 1 as RangeType,
|
||||
rangeTabs: [
|
||||
{ key: '7d', label: '近7天' },
|
||||
{ key: '30d', label: '近30天' },
|
||||
{ key: '3m', label: '近3月' },
|
||||
{ key: 1, label: '近7天' },
|
||||
{ key: 2, label: '近30天' },
|
||||
{ key: 3, label: '近3月' },
|
||||
] as RangeTab[],
|
||||
|
||||
/** 当前查看的成员(默认本人) */
|
||||
currentMember: null as MemberItem | null,
|
||||
userInfo: null as PageUserInfo | null,
|
||||
|
||||
stats: null as StatsData | null,
|
||||
recordList: [] as RecordItem[],
|
||||
stats: EMPTY_STATS as MeasureStatistics,
|
||||
|
||||
records: [] as MeasureRecord[],
|
||||
pageNo: 1,
|
||||
total: 0,
|
||||
hasMore: false,
|
||||
hasData: false,
|
||||
refresherTriggered: false,
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
// 默认选本人(isSelf=true),后备取第一个
|
||||
const members: MemberItem[] = wx.getStorageSync('memberList') || mockMembers
|
||||
const self = members.find(m => m.isSelf) || members[0] || null
|
||||
this.setData({ currentMember: self })
|
||||
const raw = wx.getStorageSync('userInfo') as StorageUserInfo | null
|
||||
if (!raw?.userId) return
|
||||
const userInfo: PageUserInfo = {
|
||||
...raw,
|
||||
sex_dictText: raw.sex === 1 ? '男' : raw.sex === 2 ? '女' : '',
|
||||
age: calcAge(raw.birthday),
|
||||
isSelf: String(raw.relationType ?? '') === '1',
|
||||
}
|
||||
this.setData({ userInfo })
|
||||
this.loadData()
|
||||
},
|
||||
|
||||
onReady() {},
|
||||
onShow() {},
|
||||
onHide() {},
|
||||
onUnload() {},
|
||||
onPullDownRefresh() {},
|
||||
onReachBottom() {},
|
||||
/** 重置分页,并行拉统计 + 第一页列表 */
|
||||
loadData() {
|
||||
const userInfo = this.data.userInfo
|
||||
if (!userInfo?.userId) return
|
||||
this.setData({ status: 'loading', pageNo: 1, records: [] })
|
||||
|
||||
onShareAppMessage(): WechatMiniprogram.Page.ICustomShareContent {
|
||||
return {}
|
||||
const statsReq = get<MeasureStatistics>('weighingScale/v3/getMeasureStatistics', {
|
||||
userId: userInfo.userId,
|
||||
type: this.data.activeType,
|
||||
}, { loading: false })
|
||||
|
||||
const pageReq = get('weighingScale/v3/getMeasureHistoryPage', {
|
||||
userId: userInfo.userId,
|
||||
type: this.data.activeType,
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
}, { loading: false })
|
||||
|
||||
wx.showLoading({ title: '加载中...', mask: true })
|
||||
Promise.all([statsReq, pageReq])
|
||||
.then(([statsRes, pageRes]: any[]) => {
|
||||
const rawStats = statsRes.result
|
||||
const stats: MeasureStatistics = rawStats ? {
|
||||
maxWeight: rawStats.maxWeight ?? 0,
|
||||
minWeight: rawStats.minWeight ?? 0,
|
||||
avgWeight: rawStats.avgWeight ?? 0,
|
||||
weightChange: rawStats.weightChange ?? 0,
|
||||
} : EMPTY_STATS
|
||||
|
||||
const page = pageRes.result ?? {}
|
||||
const records: MeasureRecord[] = (page.records ?? []).map((r: any) => ({
|
||||
recordId: r.recordId ?? '',
|
||||
examTime: r.examTime ?? '',
|
||||
weight: r.weight ?? 0,
|
||||
bmi: r.bmi ?? 0,
|
||||
fatRate: r.fatRate ?? 0,
|
||||
}))
|
||||
const total = page.total ?? 0
|
||||
|
||||
this.setData({
|
||||
stats,
|
||||
records,
|
||||
total,
|
||||
hasMore: records.length < total,
|
||||
hasData: records.length > 0,
|
||||
})
|
||||
})
|
||||
.finally(() => {
|
||||
wx.hideLoading()
|
||||
this.setData({ status: 'loaded', refresherTriggered: false })
|
||||
})
|
||||
},
|
||||
|
||||
/** 加载数据(切 Tab / 切成员 复用同一入口) */
|
||||
loadData() {
|
||||
this.setData({ status: 'loading' })
|
||||
setTimeout(() => {
|
||||
const records = getMockRecords(this.data.activeRange)
|
||||
const stats = calcStats(records)
|
||||
this.setData({ recordList: records, stats, status: 'loaded' })
|
||||
}, 300)
|
||||
/** scroll-view 触底,加载下一页 */
|
||||
onScrollToLower() {
|
||||
if (!this.data.hasMore) return
|
||||
const userInfo = this.data.userInfo
|
||||
if (!userInfo?.userId) return
|
||||
const nextPage = this.data.pageNo + 1
|
||||
|
||||
wx.showLoading({ title: '加载中...', mask: true })
|
||||
get('weighingScale/v3/getMeasureHistoryPage', {
|
||||
userId: userInfo.userId,
|
||||
type: this.data.activeType,
|
||||
pageNo: nextPage,
|
||||
pageSize: 10,
|
||||
}, { loading: false })
|
||||
.then((res: any) => {
|
||||
const page = res.result ?? {}
|
||||
const newRecords: MeasureRecord[] = (page.records ?? []).map((r: any) => ({
|
||||
recordId: r.recordId ?? '',
|
||||
examTime: r.examTime ?? '',
|
||||
weight: r.weight ?? 0,
|
||||
bmi: r.bmi ?? 0,
|
||||
fatRate: r.fatRate ?? 0,
|
||||
}))
|
||||
const allRecords = [...this.data.records, ...newRecords]
|
||||
this.setData({
|
||||
records: allRecords,
|
||||
pageNo: nextPage,
|
||||
hasMore: allRecords.length < this.data.total,
|
||||
})
|
||||
})
|
||||
.finally(() => {
|
||||
wx.hideLoading()
|
||||
})
|
||||
},
|
||||
|
||||
/** scroll-view 下拉刷新 */
|
||||
onRefresh() {
|
||||
this.setData({ refresherTriggered: true })
|
||||
this.loadData()
|
||||
},
|
||||
|
||||
/** 切换时间范围 Tab */
|
||||
onTapRange(e: WechatMiniprogram.TouchEvent) {
|
||||
const key = e.currentTarget.dataset.key as TimeRange
|
||||
if (key === this.data.activeRange) return
|
||||
this.setData({ activeRange: key })
|
||||
const key = Number(e.currentTarget.dataset.key) as RangeType
|
||||
if (key === this.data.activeType) return
|
||||
this.setData({ activeType: key })
|
||||
this.loadData()
|
||||
},
|
||||
|
||||
/** 切换成员 */
|
||||
/** 点击记录行,携带 recordId + userId 跳转测量报告 */
|
||||
onTapRecord(e: WechatMiniprogram.TouchEvent) {
|
||||
const recordId = e.currentTarget.dataset.recordId as string
|
||||
const userId = this.data.userInfo?.userId ?? ''
|
||||
wx.navigateTo({
|
||||
url: `/pages/measurementReport/measurementReport?recordId=${recordId}&userId=${userId}`,
|
||||
})
|
||||
},
|
||||
|
||||
/** 切换成员占位 */
|
||||
onTapSwitchMember() {
|
||||
wx.showToast({ title: '切换成员', icon: 'none' })
|
||||
},
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
<scroll-view class="scrollView" scroll-y>
|
||||
<scroll-view
|
||||
class="scrollView"
|
||||
scroll-y
|
||||
refresher-enabled
|
||||
refresher-triggered="{{ refresherTriggered }}"
|
||||
bind:refresherrefresh="onRefresh"
|
||||
bind:scrolltolower="onScrollToLower"
|
||||
>
|
||||
<view class="scrollViewContent">
|
||||
|
||||
<!-- 数据卡(成员信息 + 时间 Tab + 统计) -->
|
||||
@@ -6,20 +13,20 @@
|
||||
|
||||
<!-- 成员信息 -->
|
||||
<view class="userInfo">
|
||||
<view class="avatar" style="--avatar-bg: {{ currentMember.avatar }};"></view>
|
||||
<view class="avatar">{{ userInfo.realname[0] }}</view>
|
||||
<view class="info">
|
||||
<view class="info-name-row">
|
||||
<view class="info-name">{{ currentMember.name }}</view>
|
||||
<block wx:if="{{ currentMember.isSelf }}">
|
||||
<view class="info-name">{{ userInfo.realname }}</view>
|
||||
<block wx:if="{{ userInfo.isSelf }}">
|
||||
<view class="badge-self">本人</view>
|
||||
</block>
|
||||
</view>
|
||||
<view class="info-meta">
|
||||
<view class="meta-text">{{ currentMember.gender }}</view>
|
||||
<view class="meta-text">{{ userInfo.sex_dictText }}</view>
|
||||
<view class="meta-divider">·</view>
|
||||
<view class="meta-text">{{ currentMember.age }}岁</view>
|
||||
<view class="meta-text">{{ userInfo.age }}岁</view>
|
||||
<view class="meta-divider">|</view>
|
||||
<view class="meta-text">{{ currentMember.height }}cm</view>
|
||||
<view class="meta-text">{{ userInfo.height }}cm</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="btn" bind:tap="onTapSwitchMember">切换成员</view>
|
||||
@@ -31,7 +38,7 @@
|
||||
<view class="nav">
|
||||
<block wx:for="{{ rangeTabs }}" wx:key="key">
|
||||
<view
|
||||
class="{{ activeRange === item.key ? 'active' : '' }}"
|
||||
class="{{ activeType === item.key ? 'active' : '' }}"
|
||||
data-key="{{ item.key }}"
|
||||
bind:tap="onTapRange"
|
||||
>{{ item.label }}</view>
|
||||
@@ -54,26 +61,38 @@
|
||||
</view>
|
||||
<view class="summary-item">
|
||||
<view class="summary-label">体重变化</view>
|
||||
<view class="summary-value {{ stats.weightDiff < 0 ? 'value-down' : 'value-up' }}">
|
||||
{{ stats.weightDiff > 0 ? '+' : '' }}{{ stats.weightDiff }}<text>kg</text>
|
||||
<view class="summary-value {{ stats.weightChange < 0 ? 'value-down' : 'value-up' }}">
|
||||
{{ stats.weightChange > 0 ? '+' : '' }}{{ stats.weightChange }}<text>kg</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 历史记录列表 -->
|
||||
<view class="data-list">
|
||||
<block wx:for="{{ recordList }}" wx:key="id">
|
||||
<view class="list">
|
||||
<view>{{ item.time }}</view>
|
||||
<view class="arrow">
|
||||
<view>体重:<text>{{ item.weight }}kg</text></view>
|
||||
<view>BMI:<text>{{ item.bmi }}</text></view>
|
||||
<view>体脂率:<text>{{ item.bodyFat }}%</text></view>
|
||||
<!-- 有数据:记录列表 -->
|
||||
<block wx:if="{{ hasData }}">
|
||||
<view class="data-list">
|
||||
<block wx:for="{{ records }}" wx:key="recordId">
|
||||
<view class="list" bind:tap="onTapRecord" data-record-id="{{ item.recordId }}">
|
||||
<view>{{ item.examTime }}</view>
|
||||
<view class="arrow">
|
||||
<view>体重:<text>{{ item.weight }}kg</text></view>
|
||||
<view>BMI:<text>{{ item.bmi }}</text></view>
|
||||
<view>体脂率:<text>{{ item.fatRate }}%</text></view>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<!-- 无数据:占位 -->
|
||||
<block wx:elif="{{ status === 'loaded' }}">
|
||||
<view class="empty-state">
|
||||
<view class="empty-icon">
|
||||
<image src="/images/home/noData.png" mode="aspectFit"/>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
<view class="empty-text">暂无称重数据</view>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
Reference in New Issue
Block a user