feat(home,my): 首页和我的页从缓存回显用户信息

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
17792275749
2026-08-24 15:31:12 +08:00
co-authored by Claude Sonnet 4.6
parent 90f84cc7df
commit e25e797b35
6 changed files with 84 additions and 12 deletions
+26
View File
@@ -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,
},
})
},
/**
+5 -5
View File
@@ -6,14 +6,14 @@
<image src="/images/my/bg.png" mode="aspectFit" />
</view>
<view class="user">
<view class="userAvatar"></view>
<view class="user" wx:if="{{ userInfo }}">
<view class="userAvatar">{{ userInfo.realname[0] }}</view>
<view class="userInfo">
<view class="userName">陈沐辰</view>
<view class="userName">{{ userInfo.realname }}</view>
<view class="userSex">
<text class="meta-text">男·36岁</text>
<text class="meta-text">{{ userInfo.sex_dictText }}·{{ userInfo.age }}岁</text>
<text class="meta-divider">|</text>
<text class="meta-text">172cm</text>
<text class="meta-text">{{ userInfo.height }}cm</text>
</view>
</view>
</view>