This commit is contained in:
lik
2026-09-03 11:35:21 +08:00
parent f8f7afceb8
commit b4c8bf0add
45 changed files with 2989 additions and 426 deletions
+77
View File
@@ -0,0 +1,77 @@
// pages/me/index.js
// 性别映射
const SEX_MAP = {
male: '男',
female: '女'
}
Page({
data: {
user: {}
},
onShow() {
this.loadUser()
},
/**
* 加载当前登录用户信息
*/
loadUser() {
const app = getApp()
app.ensureLogin()
.then(user => {
this.setUser(user)
})
.catch(() => {
wx.showToast({ title: '获取用户信息失败', icon: 'none' })
})
},
/**
* 处理并展示用户信息
*/
setUser(user) {
if (!user) return
const profile = user.profile || {}
const location = user.location || {}
const meta = user.meta || {}
const name = profile.name || '微信用户'
const locationText = [location.province, location.city, location.district]
.filter(Boolean).join(' ')
this.setData({
user: {
avatar: profile.avatar || '',
avatarText: name[0],
name,
mobile: profile.mobile || '',
sexLabel: SEX_MAP[profile.sex] || '未知',
birthText: this.formatDate(profile.birth),
email: profile.email || '',
idnumber: profile.idnumber || '',
locationText,
createText: this.formatDate(meta.createtime)
}
})
},
/**
* 格式化日期为 yyyy-MM-dd
*/
formatDate(dateStr) {
if (!dateStr) return ''
const date = new Date(dateStr)
if (isNaN(date.getTime())) return ''
const pad = (n) => String(n).padStart(2, '0')
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
},
onShareAppMessage() {
return {
title: '个人中心',
path: '/pages/me/index'
}
}
})
+5
View File
@@ -0,0 +1,5 @@
{
"usingComponents": {
"t-icon": "tdesign-miniprogram/icon/icon"
}
}
+106
View File
@@ -0,0 +1,106 @@
/* pages/me/index.less */
page {
background-color: #f5f6fa;
color: #1a1a2e;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}
.page {
min-height: 100vh;
background: #f5f6fa;
box-sizing: border-box;
padding: 24rpx;
}
/* === 用户信息卡 === */
.header-card {
background: linear-gradient(135deg, #2dd36f, #17c3a5);
border-radius: 24rpx;
padding: 40rpx 32rpx;
display: flex;
align-items: center;
color: #ffffff;
box-shadow: 0 8rpx 24rpx rgba(23, 195, 165, 0.25);
}
.avatar {
width: 112rpx;
height: 112rpx;
border-radius: 50%;
background-color: rgba(255, 255, 255, 0.25);
border: 2rpx solid rgba(255, 255, 255, 0.4);
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
flex-shrink: 0;
}
.avatar-img {
width: 100%;
height: 100%;
}
.avatar-text {
font-size: 44rpx;
font-weight: 600;
color: #ffffff;
}
.user-info {
margin-left: 28rpx;
display: flex;
flex-direction: column;
}
.user-name {
font-size: 36rpx;
font-weight: 600;
}
.user-mobile {
margin-top: 10rpx;
font-size: 26rpx;
opacity: 0.9;
}
/* === 详细信息卡 === */
.info-card {
margin-top: 24rpx;
background: #ffffff;
border-radius: 24rpx;
padding: 8rpx 28rpx;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
}
.info-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 28rpx 0;
& + .info-item {
border-top: 1rpx solid #f0f1f5;
}
}
.info-left {
display: flex;
align-items: center;
}
.info-label {
margin-left: 16rpx;
font-size: 28rpx;
color: #6b7280;
}
.info-value {
font-size: 28rpx;
color: #1a1a2e;
max-width: 400rpx;
text-align: right;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
+60
View File
@@ -0,0 +1,60 @@
<!--pages/me/index.wxml-->
<view class="page">
<!-- 用户信息卡 -->
<view class="header-card">
<view class="avatar">
<image wx:if="{{user.avatar}}" class="avatar-img" src="{{user.avatar}}" mode="aspectFill" />
<text wx:else class="avatar-text">{{user.avatarText}}</text>
</view>
<view class="user-info">
<text class="user-name">{{user.name}}</text>
<text class="user-mobile">{{user.mobile || '暂未绑定手机号'}}</text>
</view>
</view>
<!-- 详细信息 -->
<view class="info-card">
<view class="info-item">
<view class="info-left">
<t-icon name="user" size="36rpx" color="#1abc9c" />
<text class="info-label">性别</text>
</view>
<text class="info-value">{{user.sexLabel}}</text>
</view>
<view class="info-item">
<view class="info-left">
<t-icon name="calendar" size="36rpx" color="#1abc9c" />
<text class="info-label">出生日期</text>
</view>
<text class="info-value">{{user.birthText || '未填写'}}</text>
</view>
<view class="info-item">
<view class="info-left">
<t-icon name="mail" size="36rpx" color="#1abc9c" />
<text class="info-label">邮箱</text>
</view>
<text class="info-value">{{user.email || '未填写'}}</text>
</view>
<view class="info-item">
<view class="info-left">
<t-icon name="id-card" size="36rpx" color="#1abc9c" />
<text class="info-label">身份证号</text>
</view>
<text class="info-value">{{user.idnumber || '未填写'}}</text>
</view>
<view class="info-item">
<view class="info-left">
<t-icon name="location" size="36rpx" color="#1abc9c" />
<text class="info-label">所在地区</text>
</view>
<text class="info-value">{{user.locationText || '未填写'}}</text>
</view>
<view class="info-item">
<view class="info-left">
<t-icon name="time" size="36rpx" color="#1abc9c" />
<text class="info-label">注册时间</text>
</view>
<text class="info-value">{{user.createText || '未知'}}</text>
</view>
</view>
</view>