完善版本
This commit is contained in:
@@ -11,14 +11,12 @@
|
||||
<view class="user-header">
|
||||
<view class="header-bg"></view>
|
||||
<view class="user-avatar">
|
||||
<uni-icons type="person-filled" size="70" color="#fff"></uni-icons>
|
||||
<view class="vip-badge" v-if="isLogin">
|
||||
<text>VIP</text>
|
||||
</view>
|
||||
<image v-if="userInfo.avatar" :src="userInfo.avatar" class="avatar-image" mode="aspectFill"></image>
|
||||
<uni-icons v-else type="person-filled" size="70" color="#fff"></uni-icons>
|
||||
</view>
|
||||
<view class="user-info">
|
||||
<text class="user-name">{{ userInfo.nickname || userInfo.username || '未登录' }}</text>
|
||||
<text class="user-desc" v-if="isLogin">{{ userInfo.email || '暂无邮箱' }}</text>
|
||||
<text class="user-name">{{ userInfo.username || '未登录' }}</text>
|
||||
<text class="user-nickname" v-if="isLogin && userInfo.nickname">{{ userInfo.nickname }}</text>
|
||||
<text class="user-desc" v-else>点击登录体验更多功能</text>
|
||||
</view>
|
||||
<view class="edit-profile" @tap="handleEditProfile" v-if="isLogin">
|
||||
@@ -62,7 +60,7 @@
|
||||
</view>
|
||||
<view class="quick-item" @tap="navigateTo('/pages/account/statistics/index')">
|
||||
<view class="quick-icon" style="background: linear-gradient(135deg, #4ECDC4 0%, #44A08D 100%);">
|
||||
<uni-icons type="chart" size="24" color="#fff"></uni-icons>
|
||||
<uni-icons type="color-filled" size="24" color="#fff"></uni-icons>
|
||||
</view>
|
||||
<text class="quick-text">统计分析</text>
|
||||
</view>
|
||||
@@ -79,7 +77,7 @@
|
||||
<view class="menu-section">
|
||||
<view class="section-title">设置</view>
|
||||
<view class="menu-list">
|
||||
<view class="menu-item" @tap="navigateTo('/pages/ucenter/profile')">
|
||||
<view class="menu-item" @tap="navigateTo('/pages/ucenter/profile/index')">
|
||||
<view class="menu-left">
|
||||
<view class="menu-icon-wrapper">
|
||||
<uni-icons type="gear" size="20" color="#667eea"></uni-icons>
|
||||
@@ -91,7 +89,7 @@
|
||||
</view>
|
||||
<uni-icons type="right" size="16" color="#ccc"></uni-icons>
|
||||
</view>
|
||||
<view class="menu-item" @tap="navigateTo('/pages/ucenter/help')">
|
||||
<view class="menu-item" @tap="navigateTo('/pages/ucenter/help/index')">
|
||||
<view class="menu-left">
|
||||
<view class="menu-icon-wrapper">
|
||||
<uni-icons type="help" size="20" color="#667eea"></uni-icons>
|
||||
@@ -103,7 +101,7 @@
|
||||
</view>
|
||||
<uni-icons type="right" size="16" color="#ccc"></uni-icons>
|
||||
</view>
|
||||
<view class="menu-item" @tap="navigateTo('/pages/ucenter/about')">
|
||||
<view class="menu-item" @tap="navigateTo('/pages/ucenter/about/index')">
|
||||
<view class="menu-left">
|
||||
<view class="menu-icon-wrapper">
|
||||
<uni-icons type="info" size="20" color="#667eea"></uni-icons>
|
||||
@@ -115,7 +113,7 @@
|
||||
</view>
|
||||
<uni-icons type="right" size="16" color="#ccc"></uni-icons>
|
||||
</view>
|
||||
<view class="menu-item" @tap="handleClearCache">
|
||||
<view class="menu-item" @tap="handleClearCache" v-if="false">
|
||||
<view class="menu-left">
|
||||
<view class="menu-icon-wrapper">
|
||||
<uni-icons type="trash" size="20" color="#667eea"></uni-icons>
|
||||
@@ -168,46 +166,48 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
// 检查登录状态
|
||||
checkLoginStatus() {
|
||||
async checkLoginStatus() {
|
||||
this.isLogin = isLogin()
|
||||
this.userInfo = uni.getStorageSync('userInfo') || {}
|
||||
|
||||
if (this.isLogin) {
|
||||
await this.loadUserInfo()
|
||||
this.loadUserStats()
|
||||
} else {
|
||||
this.userInfo = {}
|
||||
}
|
||||
},
|
||||
|
||||
// 加载用户信息
|
||||
async loadUserInfo() {
|
||||
try {
|
||||
const result = await this.$api.auth.info.get()
|
||||
if (result && result.code === 1) {
|
||||
this.userInfo = result.data || {}
|
||||
// 更新本地存储
|
||||
uni.setStorageSync('userInfo', this.userInfo)
|
||||
// 更新 Vuex store
|
||||
this.$store.commit('setUserInfo', this.userInfo)
|
||||
} else {
|
||||
// 如果接口失败,使用本地存储的数据
|
||||
this.userInfo = uni.getStorageSync('userInfo') || {}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载用户信息失败:', error)
|
||||
// 如果接口失败,使用本地存储的数据
|
||||
this.userInfo = uni.getStorageSync('userInfo') || {}
|
||||
}
|
||||
},
|
||||
|
||||
// 加载用户统计数据
|
||||
async loadUserStats() {
|
||||
try {
|
||||
// 获取账单总数
|
||||
const billRes = await this.$api.bill.list.get({
|
||||
page: 1,
|
||||
limit: 1
|
||||
const result = await this.$api.statistics.dashboard.get({
|
||||
data_type: 'family'
|
||||
})
|
||||
if (billRes && billRes.code === 1) {
|
||||
this.stats.billCount = billRes.data?.total || 0
|
||||
}
|
||||
|
||||
// 获取家庭成员数
|
||||
const membersRes = await this.$api.family.members.get()
|
||||
if (membersRes && membersRes.code === 1) {
|
||||
this.stats.familyMembers = membersRes.data?.length || 0
|
||||
}
|
||||
|
||||
// 获取记账天数(计算从第一个账单到现在的天数)
|
||||
const firstBillRes = await this.$api.bill.list.get({
|
||||
page: 1,
|
||||
limit: 1,
|
||||
order: 'asc'
|
||||
})
|
||||
if (firstBillRes && firstBillRes.code === 1 && firstBillRes.data?.list?.length > 0) {
|
||||
const firstBill = firstBillRes.data.list[0]
|
||||
const firstDate = new Date(firstBill.date)
|
||||
const now = new Date()
|
||||
const diffTime = Math.abs(now - firstDate)
|
||||
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24))
|
||||
this.stats.days = diffDays
|
||||
if (result && result.code === 1) {
|
||||
this.stats.billCount = result.data?.bill_count || 0
|
||||
this.stats.days = result.data?.days || 0
|
||||
this.stats.familyMembers = result.data?.family_members || 0
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载统计数据失败', error)
|
||||
@@ -243,10 +243,8 @@ export default {
|
||||
|
||||
// 编辑个人资料
|
||||
handleEditProfile() {
|
||||
uni.showToast({
|
||||
title: '功能开发中',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
uni.navigateTo({
|
||||
url: '/pages/ucenter/profile/edit'
|
||||
})
|
||||
},
|
||||
|
||||
@@ -381,21 +379,11 @@ export default {
|
||||
border: 3rpx solid rgba(255, 255, 255, 0.3);
|
||||
box-shadow: 0 8rpx 20rpx rgba(0, 0, 0, 0.15);
|
||||
|
||||
.vip-badge {
|
||||
position: absolute;
|
||||
bottom: -6rpx;
|
||||
right: -6rpx;
|
||||
background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
|
||||
border-radius: 12rpx;
|
||||
padding: 4rpx 12rpx;
|
||||
border: 2rpx solid #fff;
|
||||
box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.2);
|
||||
|
||||
text {
|
||||
font-size: 18rpx;
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
}
|
||||
.avatar-image {
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
border-radius: 60rpx;
|
||||
object-fit: cover;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -414,6 +402,13 @@ export default {
|
||||
text-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.user-nickname {
|
||||
font-size: 26rpx;
|
||||
color: rgba(255, 255, 255, 0.85);
|
||||
font-weight: 500;
|
||||
margin-top: 8rpx;
|
||||
}
|
||||
|
||||
.user-desc {
|
||||
font-size: 26rpx;
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
|
||||
Reference in New Issue
Block a user