feat(data): 历史数据页接入统计与历史接口,切换用户抽屉接真实成员
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
0fcb6eebef
commit
18704cbb76
@@ -1,7 +1,8 @@
|
||||
.scrollViewContent {
|
||||
.data {
|
||||
width: 100%;
|
||||
padding: 24rpx 30rpx;
|
||||
box-sizing: border-box;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
|
||||
.data-card {
|
||||
width: 100%;
|
||||
@@ -231,74 +232,85 @@
|
||||
}
|
||||
}
|
||||
|
||||
/* 历史记录列表 */
|
||||
.data-list {
|
||||
width: 100%;
|
||||
.data-user-list {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
|
||||
.list {
|
||||
.scrollViewContent {
|
||||
width: 100%;
|
||||
margin-bottom: 30rpx;
|
||||
|
||||
>view:first-of-type {
|
||||
color: #808080;
|
||||
padding: 24rpx 30rpx;
|
||||
box-sizing: border-box;
|
||||
|
||||
/* 历史记录列表 */
|
||||
.data-list {
|
||||
width: 100%;
|
||||
height: 24rpx;
|
||||
font-size: 24rpx;
|
||||
line-height: 24rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
>view:last-of-type {
|
||||
width: 100%;
|
||||
height: 96rpx;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding-left: 30rpx;
|
||||
padding-right: 50rpx;
|
||||
box-sizing: border-box;
|
||||
flex-wrap: nowrap;
|
||||
border-radius: 16rpx;
|
||||
background-color: #FFFFFF;
|
||||
|
||||
>view {
|
||||
color: #808080;
|
||||
font-size: 26rpx;
|
||||
height: 96rpx;
|
||||
line-height: 96rpx;
|
||||
|
||||
text {
|
||||
color: #252535;
|
||||
font-weight: bold;
|
||||
|
||||
.list {
|
||||
width: 100%;
|
||||
margin-bottom: 30rpx;
|
||||
|
||||
>view:first-of-type {
|
||||
color: #808080;
|
||||
width: 100%;
|
||||
height: 24rpx;
|
||||
font-size: 24rpx;
|
||||
line-height: 24rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
>view:last-of-type {
|
||||
width: 100%;
|
||||
height: 96rpx;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding-left: 30rpx;
|
||||
padding-right: 50rpx;
|
||||
box-sizing: border-box;
|
||||
flex-wrap: nowrap;
|
||||
border-radius: 16rpx;
|
||||
background-color: #FFFFFF;
|
||||
|
||||
>view {
|
||||
color: #808080;
|
||||
font-size: 26rpx;
|
||||
height: 96rpx;
|
||||
line-height: 96rpx;
|
||||
|
||||
text {
|
||||
color: #252535;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ===== 空态 ===== */
|
||||
.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ===== 空态 ===== */
|
||||
.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+248
-15
@@ -1,27 +1,236 @@
|
||||
// pages/data/data.ts
|
||||
Page({
|
||||
import { get } from '../../utils/request/index'
|
||||
import { calcAge } from '../../utils/idCard/index'
|
||||
import type { UserInfo } from '../../api/index'
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
type RangeType = 1 | 2 | 3
|
||||
|
||||
interface RangeTab {
|
||||
key: RangeType
|
||||
label: string
|
||||
}
|
||||
|
||||
/** 页面展示用用户信息 */
|
||||
interface PageUserInfo {
|
||||
userId: string
|
||||
realname: string
|
||||
sex: number
|
||||
sex_dictText: string
|
||||
age: number
|
||||
height: number
|
||||
avatar: string | null
|
||||
birthday: string
|
||||
relationType: number | string | null
|
||||
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
|
||||
}
|
||||
|
||||
/** GET /weighingScale/v3/getMeasureHistoryPage 返回结构 */
|
||||
interface MeasureHistoryPageResult {
|
||||
records: MeasureRecord[]
|
||||
total: number
|
||||
}
|
||||
|
||||
/** 切换用户抽屉 select 事件 detail */
|
||||
interface MemberSelectDetail {
|
||||
id: string
|
||||
name: string
|
||||
gender: '男' | '女'
|
||||
age: number
|
||||
height: number
|
||||
userId?: string
|
||||
sex?: number
|
||||
birthday?: string
|
||||
relationType?: number | string | null
|
||||
avatar?: string
|
||||
}
|
||||
|
||||
/** 统计空态默认值 */
|
||||
const EMPTY_STATS: MeasureStatistics = {
|
||||
maxWeight: 0,
|
||||
minWeight: 0,
|
||||
avgWeight: 0,
|
||||
weightChange: 0,
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
activeType: 1 as RangeType,
|
||||
rangeTabs: [
|
||||
{ key: 1, label: '近7天' },
|
||||
{ key: 2, label: '近30天' },
|
||||
{ key: 3, label: '近3月' },
|
||||
] as RangeTab[],
|
||||
|
||||
userInfo: null as PageUserInfo | null,
|
||||
|
||||
stats: EMPTY_STATS as MeasureStatistics,
|
||||
|
||||
records: [] as MeasureRecord[],
|
||||
pageNo: 1,
|
||||
total: 0,
|
||||
hasMore: false,
|
||||
refresherTriggered: false,
|
||||
showSelectDrawer: false,
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad() {
|
||||
|
||||
const raw = wx.getStorageSync('userInfo') as UserInfo | null
|
||||
if (!raw?.userId) return
|
||||
this.setData({ userInfo: this._buildSelfUserInfo(raw) })
|
||||
this.loadData()
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow() {
|
||||
|
||||
/** 由缓存用户信息构建「本人」展示信息 */
|
||||
_buildSelfUserInfo(raw: UserInfo): PageUserInfo {
|
||||
return {
|
||||
userId: raw.userId,
|
||||
realname: raw.realname ?? '',
|
||||
sex: raw.sex,
|
||||
sex_dictText: raw.sex === 1 ? '男' : raw.sex === 2 ? '女' : '',
|
||||
age: calcAge(raw.birthday),
|
||||
height: raw.height ?? 0,
|
||||
avatar: raw.avatar ?? null,
|
||||
birthday: raw.birthday ?? '',
|
||||
relationType: raw.relationType ?? null,
|
||||
isSelf: true,
|
||||
}
|
||||
},
|
||||
|
||||
/** 重置分页,并行拉统计 + 第一页列表 */
|
||||
loadData() {
|
||||
const userInfo = this.data.userInfo
|
||||
if (!userInfo?.userId) return
|
||||
this.setData({ pageNo: 1, records: [] })
|
||||
|
||||
const statsReq = get<MeasureStatistics>('weighingScale/v3/getMeasureStatistics', {
|
||||
userId: userInfo.userId,
|
||||
type: this.data.activeType,
|
||||
}, { loading: false })
|
||||
|
||||
const pageReq = get<MeasureHistoryPageResult>('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]) => {
|
||||
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) => ({
|
||||
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,
|
||||
})
|
||||
})
|
||||
.catch(() => {
|
||||
this.setData({ stats: EMPTY_STATS, records: [], total: 0, hasMore: false })
|
||||
})
|
||||
.finally(() => {
|
||||
wx.hideLoading()
|
||||
this.setData({ refresherTriggered: false })
|
||||
})
|
||||
},
|
||||
|
||||
/** 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<MeasureHistoryPageResult>('weighingScale/v3/getMeasureHistoryPage', {
|
||||
userId: userInfo.userId,
|
||||
type: this.data.activeType,
|
||||
pageNo: nextPage,
|
||||
pageSize: 10,
|
||||
}, { loading: false })
|
||||
.then((res) => {
|
||||
const page = res.result ?? {}
|
||||
const newRecords: MeasureRecord[] = (page.records ?? []).map((r) => ({
|
||||
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,
|
||||
})
|
||||
})
|
||||
.catch(() => {
|
||||
wx.showToast({ title: '加载失败,请重试', icon: 'none' })
|
||||
})
|
||||
.finally(() => {
|
||||
wx.hideLoading()
|
||||
})
|
||||
},
|
||||
|
||||
/** scroll-view 下拉刷新 */
|
||||
onRefresh() {
|
||||
this.setData({ refresherTriggered: true })
|
||||
this.loadData()
|
||||
},
|
||||
|
||||
/** 切换时间范围 Tab */
|
||||
onTapRange(e: WechatMiniprogram.TouchEvent) {
|
||||
const key = Number(e.currentTarget.dataset.key) as RangeType
|
||||
if (key === this.data.activeType) return
|
||||
this.setData({ activeType: key })
|
||||
this.loadData()
|
||||
},
|
||||
|
||||
/** 点击记录行,跳转测量报告 */
|
||||
onTapRecord(e: WechatMiniprogram.TouchEvent) {
|
||||
const recordId = e.currentTarget.dataset.recordId as string
|
||||
const userId = this.data.userInfo?.userId ?? ''
|
||||
wx.navigateTo({
|
||||
url: `/pages/detailedReport/detailedReport?recordId=${recordId}&userId=${userId}`,
|
||||
})
|
||||
},
|
||||
|
||||
/** 打开切换用户抽屉 */
|
||||
onTapSwitchMember() {
|
||||
this.setData({ showSelectDrawer: true })
|
||||
},
|
||||
@@ -30,4 +239,28 @@ Page({
|
||||
onCloseDrawer() {
|
||||
this.setData({ showSelectDrawer: false })
|
||||
},
|
||||
})
|
||||
|
||||
/** 选中用户后更新 userInfo 并重新请求数据 */
|
||||
onSelectMember(e: WechatMiniprogram.CustomEvent) {
|
||||
const m = e.detail as MemberSelectDetail
|
||||
if (!m.userId) {
|
||||
wx.showToast({ title: '用户信息异常', icon: 'none' })
|
||||
return
|
||||
}
|
||||
const storedUserId = (wx.getStorageSync('userInfo') as UserInfo | null)?.userId ?? ''
|
||||
const userInfo: PageUserInfo = {
|
||||
userId: m.userId,
|
||||
realname: m.name,
|
||||
sex: m.sex ?? (m.gender === '男' ? 1 : 2),
|
||||
sex_dictText: m.gender,
|
||||
age: m.age,
|
||||
height: m.height,
|
||||
avatar: m.avatar ?? null,
|
||||
birthday: m.birthday ?? '',
|
||||
relationType: m.relationType ?? null,
|
||||
isSelf: m.userId === storedUserId,
|
||||
}
|
||||
this.setData({ showSelectDrawer: false, userInfo })
|
||||
this.loadData()
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,91 +1,87 @@
|
||||
<scroll-view
|
||||
class="scrollView"
|
||||
scroll-y
|
||||
refresher-enabled
|
||||
refresher-triggered="{{ refresherTriggered }}"
|
||||
bind:refresherrefresh="onRefresh"
|
||||
bind:scrolltolower="onScrollToLower"
|
||||
>
|
||||
<view class="scrollViewContent">
|
||||
|
||||
<!-- 数据卡(用户信息 + 时间 Tab + 统计) -->
|
||||
<view class="data-card">
|
||||
|
||||
<!-- 用户信息 -->
|
||||
<view class="userInfo">
|
||||
<view class="avatar">张</view>
|
||||
<view class="info">
|
||||
<view class="info-name-row">
|
||||
<view class="info-name">张晓敏</view>
|
||||
<view class="data">
|
||||
<!-- 数据卡(用户信息 + 时间 Tab + 统计) -->
|
||||
<view class="data-card">
|
||||
<!-- 用户信息 -->
|
||||
<view class="userInfo" wx:if="{{ userInfo }}">
|
||||
<view class="avatar">{{ userInfo.realname[0] }}</view>
|
||||
<view class="info">
|
||||
<view class="info-name-row">
|
||||
<view class="info-name">{{ userInfo.realname }}</view>
|
||||
<block wx:if="{{ userInfo.isSelf }}">
|
||||
<view class="badge-self">本人</view>
|
||||
</view>
|
||||
<view class="info-meta">
|
||||
<view class="meta-text">男·36岁</view>
|
||||
<view class="meta-divider">|</view>
|
||||
<view class="meta-text">170cm</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
<view class="info-meta">
|
||||
<view class="meta-text">{{ userInfo.sex_dictText }}</view>
|
||||
<view class="meta-divider">·</view>
|
||||
<view class="meta-text">{{ userInfo.age }}岁</view>
|
||||
<view class="meta-divider">|</view>
|
||||
<view class="meta-text">{{ userInfo.height }}cm</view>
|
||||
</view>
|
||||
<view class="btn" bind:tap="onTapSwitchMember">切换用户</view>
|
||||
</view>
|
||||
<view class="btn" bind:tap="onTapSwitchMember">切换用户</view>
|
||||
</view>
|
||||
|
||||
<view class="card-divider"></view>
|
||||
<view class="card-divider"></view>
|
||||
|
||||
<!-- 时间范围 Tab -->
|
||||
<view class="nav">
|
||||
<view class="active">近7日</view>
|
||||
<view>近30日</view>
|
||||
<view>近90日</view>
|
||||
<!-- 时间范围 Tab -->
|
||||
<view class="nav">
|
||||
<block wx:for="{{ rangeTabs }}" wx:key="key">
|
||||
<view class="{{ activeType === item.key ? 'active' : '' }}" data-key="{{ item.key }}" bind:tap="onTapRange">{{ item.label }}</view>
|
||||
</block>
|
||||
</view>
|
||||
|
||||
<!-- 统计摘要(4格) -->
|
||||
<view class="summary">
|
||||
<view class="summary-item">
|
||||
<view class="summary-label">最高体重</view>
|
||||
<view class="summary-value">{{ stats.maxWeight }}<text>kg</text></view>
|
||||
</view>
|
||||
|
||||
<!-- 统计摘要(4格) -->
|
||||
<view class="summary">
|
||||
<view class="summary-item">
|
||||
<view class="summary-label">最高体重</view>
|
||||
<view class="summary-value">89.6<text>kg</text></view>
|
||||
</view>
|
||||
<view class="summary-item">
|
||||
<view class="summary-label">最低体重</view>
|
||||
<view class="summary-value">89.6<text>kg</text></view>
|
||||
</view>
|
||||
<view class="summary-item">
|
||||
<view class="summary-label">平均体重</view>
|
||||
<view class="summary-value">89.6<text>kg</text></view>
|
||||
</view>
|
||||
<view class="summary-item">
|
||||
<view class="summary-label">体重变化</view>
|
||||
<view class="summary-value {{ stats.weightChange < 0 ? 'value-down' : 'value-up' }}">
|
||||
{{ stats.weightChange > 0 ? '+' : '' }}{{ stats.weightChange }}<text>kg</text>
|
||||
</view>
|
||||
<view class="summary-item">
|
||||
<view class="summary-label">最低体重</view>
|
||||
<view class="summary-value">{{ stats.minWeight }}<text>kg</text></view>
|
||||
</view>
|
||||
<view class="summary-item">
|
||||
<view class="summary-label">平均体重</view>
|
||||
<view class="summary-value">{{ stats.avgWeight }}<text>kg</text></view>
|
||||
</view>
|
||||
<view class="summary-item">
|
||||
<view class="summary-label">体重变化</view>
|
||||
<view class="summary-value {{ stats.weightChange < 0 ? 'value-down' : 'value-up' }}">
|
||||
{{ stats.weightChange > 0 ? '+' : '' }}{{ stats.weightChange }}<text>kg</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 有数据:记录列表 -->
|
||||
<block wx:if="{{ records.length }}">
|
||||
<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 class="data-user-list">
|
||||
<scroll-view class="scrollView" scroll-y refresher-enabled refresher-triggered="{{ refresherTriggered }}" bind:refresherrefresh="onRefresh" bind:scrolltolower="onScrollToLower">
|
||||
<view class="scrollViewContent">
|
||||
|
||||
<!-- 有数据:记录列表 -->
|
||||
<block wx:if="{{ records.length }}">
|
||||
<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:else>
|
||||
<empty-data text="暂无称重数据" />
|
||||
</block>
|
||||
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<!-- 无数据:占位 -->
|
||||
<block wx:else>
|
||||
<empty-data />
|
||||
</block>
|
||||
</scroll-view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<select-member-drawer
|
||||
show="{{ showSelectDrawer }}"
|
||||
exclude-user-id="{{ userInfo.userId }}"
|
||||
bind:select="onSelectMember"
|
||||
bind:close="onCloseDrawer"
|
||||
/>
|
||||
<select-member-drawer show="{{ showSelectDrawer }}" source="history" exclude-user-id="{{ userInfo.userId || '' }}" bind:select="onSelectMember" bind:close="onCloseDrawer" />
|
||||
@@ -199,7 +199,7 @@ Page({
|
||||
onLoad(options: Record<string, string | undefined>) {
|
||||
const recordId = options.recordId || ''
|
||||
const userInfo = (wx.getStorageSync('userInfo') || {}) as Record<string, any>
|
||||
const userId = userInfo.userId || ''
|
||||
const userId = options.userId || userInfo.userId || ''
|
||||
this.fetchHistory(userId, recordId)
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user