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 -1
View File
@@ -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 {