[AI Generated]: feat(*): 完善数据页切换成员、首页接口对接及我的页缓存信息展示

This commit is contained in:
17792275749
2026-05-15 14:30:30 +08:00
parent e0573857e0
commit fbef06b5c2
11 changed files with 316 additions and 88 deletions
+44 -3
View File
@@ -1,7 +1,48 @@
Page({
data: {},
/** 缓存中的用户信息 */
interface StorageUserInfo {
userId: string
realname: string
sex: number
height: number
birthday: string
[key: string]: any
}
onLoad() {},
/** 页面展示用用户信息 */
interface PageUserInfo {
realname: string
sex_dictText: '男' | '女' | ''
age: number
height: number
}
/** 从生日字符串(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: {
userInfo: null as PageUserInfo | null,
},
onLoad() {
const raw = wx.getStorageSync('userInfo') as StorageUserInfo | null
if (!raw?.userId) return
const userInfo: PageUserInfo = {
realname: raw.realname ?? '',
sex_dictText: raw.sex === 1 ? '男' : raw.sex === 2 ? '女' : '',
age: calcAge(raw.birthday),
height: raw.height ?? 0,
}
this.setData({ userInfo })
},
onShareAppMessage(): WechatMiniprogram.Page.ICustomShareContent {
return {