[AI Generated]: feat(*): 完善数据页切换成员、首页接口对接及我的页缓存信息展示
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user