[AI Generated]: feat(*): 完善数据页切换成员、首页接口对接及我的页缓存信息展示
This commit is contained in:
@@ -20,10 +20,16 @@
|
||||
.user-avatar {
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
border-radius: 16rpx;
|
||||
margin-right: 30rpx;
|
||||
border-radius: 24rpx;
|
||||
color: #FFFFFF;
|
||||
font-size: 48rpx;
|
||||
font-weight: bold;
|
||||
line-height: 110rpx;
|
||||
text-align: center;
|
||||
box-sizing: border-box;
|
||||
border: 5rpx solid #ffffff;
|
||||
background-color: #1385FA;
|
||||
}
|
||||
|
||||
.user-info {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -4,15 +4,15 @@
|
||||
</view>
|
||||
|
||||
<view class="user">
|
||||
<view class="user-avatar"></view>
|
||||
<view class="user-avatar">{{ userInfo.realname[0] }}</view>
|
||||
<view class="user-info">
|
||||
<view class="user-name">陈知夏</view>
|
||||
<view class="user-name">{{ userInfo.realname }}</view>
|
||||
<view class="user-meta">
|
||||
<text class="meta-text">男</text>
|
||||
<text class="meta-text">{{ userInfo.sex_dictText }}</text>
|
||||
<text class="meta-divider">·</text>
|
||||
<text class="meta-text">56岁</text>
|
||||
<text class="meta-text">{{ userInfo.age }}岁</text>
|
||||
<text class="meta-divider">|</text>
|
||||
<text class="meta-text">182cm</text>
|
||||
<text class="meta-text">{{ userInfo.height }}cm</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
Reference in New Issue
Block a user