diff --git a/miniprogram/pages/home/home.less b/miniprogram/pages/home/home.less
index c31e154..a154c3e 100644
--- a/miniprogram/pages/home/home.less
+++ b/miniprogram/pages/home/home.less
@@ -59,7 +59,13 @@
overflow: hidden;
border-radius: 24rpx;
margin-right: 15rpx;
- background-color: red;
+ color: #FFFFFF;
+ font-size: 40rpx;
+ font-weight: bold;
+ line-height: 88rpx;
+ text-align: center;
+ border: 5rpx solid #ffffff;
+ background-color: #1385FA;
}
.userInfo {
@@ -70,8 +76,9 @@
color: #252535;
height: 32rpx;
font-size: 32rpx;
+ font-weight: bolder;
line-height: 32rpx;
- margin-bottom: 20rpx;
+ margin-bottom: 16rpx;
}
.userSex {
diff --git a/miniprogram/pages/home/home.ts b/miniprogram/pages/home/home.ts
index 9dee101..8eb2aac 100644
--- a/miniprogram/pages/home/home.ts
+++ b/miniprogram/pages/home/home.ts
@@ -1,4 +1,14 @@
import { get } from '../../utils/request/index'
+import { calcAge } from '../../utils/idCard/index'
+import type { UserInfo } from '../../api/index'
+
+/** 页面展示用用户信息 */
+interface PageUserInfo {
+ realname: string
+ sex_dictText: string
+ age: number
+ height: number
+}
/** 将体重数字拆成整数 + 小数字符串 */
const splitWeight = (weight: number): { int: number; decimal: string } => {
@@ -10,10 +20,25 @@ const splitWeight = (weight: number): { int: number; decimal: string } => {
Page({
data: {
record: null,
+ userInfo: null as PageUserInfo | null,
},
onShow() {
-
+ this._loadUserInfo()
+ },
+
+ // 从缓存回显用户信息
+ _loadUserInfo() {
+ const raw = wx.getStorageSync('userInfo') as UserInfo | null
+ if (!raw?.userId) return
+ this.setData({
+ userInfo: {
+ realname: raw.realname ?? '',
+ sex_dictText: raw.sex === 1 ? '男' : raw.sex === 2 ? '女' : '',
+ age: calcAge(raw.birthday),
+ height: raw.height ?? 0,
+ },
+ })
},
onShareAppMessage(): WechatMiniprogram.Page.ICustomShareContent {
diff --git a/miniprogram/pages/home/home.wxml b/miniprogram/pages/home/home.wxml
index da06a59..6ea25e9 100644
--- a/miniprogram/pages/home/home.wxml
+++ b/miniprogram/pages/home/home.wxml
@@ -9,11 +9,11 @@
设备智联 · 掌握健康
-
-
+
+ {{ userInfo.realname[0] }}
- 张晓敏
- 男·36岁丨172cm
+ {{ userInfo.realname }}
+ {{ userInfo.sex_dictText }}·{{ userInfo.age }}岁丨{{ userInfo.height }}cm
diff --git a/miniprogram/pages/my/my.ts b/miniprogram/pages/my/my.ts
index d1b37db..8192164 100644
--- a/miniprogram/pages/my/my.ts
+++ b/miniprogram/pages/my/my.ts
@@ -1,3 +1,14 @@
+import { calcAge } from '../../utils/idCard/index'
+import type { UserInfo } from '../../api/index'
+
+/** 页面展示用用户信息 */
+interface PageUserInfo {
+ realname: string
+ sex_dictText: string
+ age: number
+ height: number
+}
+
// pages/my/my.ts
Page({
@@ -7,6 +18,7 @@ Page({
data: {
// 导航栏背景色,根据滚动位置动态变化
navBgColor: 'rgba(255,255,255,0)',
+ userInfo: null as PageUserInfo | null,
},
/**
@@ -44,7 +56,21 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
+ this._loadUserInfo()
+ },
+ // 从缓存回显用户信息
+ _loadUserInfo() {
+ const raw = wx.getStorageSync('userInfo') as UserInfo | null
+ if (!raw?.userId) return
+ this.setData({
+ userInfo: {
+ realname: raw.realname ?? '',
+ sex_dictText: raw.sex === 1 ? '男' : raw.sex === 2 ? '女' : '',
+ age: calcAge(raw.birthday),
+ height: raw.height ?? 0,
+ },
+ })
},
/**
diff --git a/miniprogram/pages/my/my.wxml b/miniprogram/pages/my/my.wxml
index a6467c2..bcabdde 100644
--- a/miniprogram/pages/my/my.wxml
+++ b/miniprogram/pages/my/my.wxml
@@ -6,14 +6,14 @@
-
- 张
+
+ {{ userInfo.realname[0] }}
- 陈沐辰
+ {{ userInfo.realname }}
- 男·36岁
+ {{ userInfo.sex_dictText }}·{{ userInfo.age }}岁
|
- 172cm
+ {{ userInfo.height }}cm
diff --git a/miniprogram/utils/idCard/index.ts b/miniprogram/utils/idCard/index.ts
index ce45d57..85e3d10 100644
--- a/miniprogram/utils/idCard/index.ts
+++ b/miniprogram/utils/idCard/index.ts
@@ -38,3 +38,17 @@ export const parseIdCard = (idCard: string): IdCardParsed => {
sex,
}
}
+
+/** 从生日字符串(YYYY-MM-DD)计算周岁 */
+export const calcAge = (birthday: string): number => {
+ if (!birthday) return 0
+ const parts = birthday.split('-').map(Number)
+ const [year, month, day] = parts
+ if (!year || !month || !day) return 0
+ const now = new Date()
+ let age = now.getFullYear() - year
+ const nowMonth = now.getMonth() + 1
+ const nowDay = now.getDate()
+ if (nowMonth < month || (nowMonth === month && nowDay < day)) age -= 1
+ return Math.max(0, age)
+}