rhb-server/mes-ui/rhb-app/pages/profile/profile.vue
2025-10-20 11:14:41 +08:00

287 lines
5.0 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="container" :style="containerStyle">
<view class="content">
<!-- 顶部区域 -->
<view class="header">
<view class="welcome">
<text class="welcome-text">欢迎{{ userInfo.realName || userInfo.username }}</text>
<text class="logout" @click="handleLogout">退出登录</text>
</view>
</view>
<!-- 页面内容 -->
<view class="user-card">
<view class="avatar-section">
<view class="avatar">
<u-icon name="account" size="80" color="#2979ff"></u-icon>
</view>
<view class="user-info">
<text class="user-name">{{ userInfo.realName || userInfo.username }}</text>
<text class="user-role">管理员</text>
</view>
</view>
</view>
</view>
</view>
</template>
<script>
import {
householdApi
} from '../../utils/api'
import userUtil from '../../utils/UserUtil';
export default {
data() {
return {
userInfo: {},
stats: {
total: 0,
submitted: 0,
draft: 0
},
containerStyle: {
height: '100vh'
}
}
},
onLoad() {
this.calculateHeight()
this.loadUserInfo()
this.loadStats()
},
onShow() {
// 每次显示页面时刷新统计数据
this.loadStats()
},
onReady() {
this.calculateHeight()
// 监听子页面的刷新通知
uni.$on('refreshStats', () => {
this.loadStats()
})
},
onUnload() {
// 移除事件监听
uni.$off('refreshStats')
},
methods: {
calculateHeight() {
// 获取系统信息
const systemInfo = uni.getSystemInfoSync()
const statusBarHeight = systemInfo.statusBarHeight || 0
const windowHeight = systemInfo.windowHeight
// 计算内容区域高度(屏幕高度 - 顶部高度 - 底部tabbar高度
// 微信小程序tabbar高度约为50px
const tabbarHeight = 50
const contentHeight = windowHeight - statusBarHeight - tabbarHeight
// 设置容器样式
this.containerStyle = {
height: contentHeight + 'px'
}
},
loadUserInfo() {
const userInfo = uni.getStorageSync('userInfo')
if (userInfo) {
this.userInfo = userInfo
}
},
async loadStats() {
try {
const response = await householdApi.getUserStats();
if (response) {
this.stats = response
}
} catch (error) {
uni.showToast({
title: error.data.msg,
icon: 'none'
})
}
},
goToForm() {
uni.navigateTo({
url: '/packageForm/pages/householdForm'
})
},
goToQuery() {
uni.navigateTo({
url: '/packageQuery/pages/query'
})
},
handleLogout() {
uni.showModal({
title: '确认退出',
content: '确定要退出登录吗?',
success: (res) => {
if (res.confirm) {
// 清除本地存储
uni.removeStorageSync('userInfo')
uni.removeStorageSync('token')
userUtil.clearAll()
// 跳转到登录页
uni.reLaunch({
url: '/packageUser/pages/login'
})
}
}
})
}
}
}
</script>
<style scoped>
.container {
display: flex;
flex-direction: column;
}
.content {
flex: 1;
overflow-y: auto;
}
.header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 40rpx 32rpx 60rpx;
color: #fff;
}
.welcome {
display: flex;
justify-content: space-between;
align-items: center;
}
.welcome-text {
font-size: 32rpx;
font-weight: bold;
}
.logout {
font-size: 28rpx;
padding: 12rpx 24rpx;
background: rgba(255, 255, 255, 0.2);
border-radius: 20rpx;
}
.user-card {
background: #fff;
border-radius: 24rpx;
padding: 40rpx;
margin-bottom: 32rpx;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.1);
}
.avatar-section {
display: flex;
align-items: center;
}
.avatar {
margin-right: 32rpx;
}
.user-info {
flex: 1;
}
.user-name {
display: block;
font-size: 36rpx;
font-weight: bold;
color: #333;
margin-bottom: 8rpx;
}
.user-role {
display: block;
font-size: 24rpx;
color: #666;
}
.menu-list {
background: #fff;
border-radius: 24rpx;
margin-bottom: 32rpx;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.1);
}
.menu-item {
display: flex;
align-items: center;
padding: 32rpx;
border-bottom: 1rpx solid #f0f0f0;
}
.menu-item:last-child {
border-bottom: none;
}
.menu-icon {
margin-right: 24rpx;
}
.menu-content {
flex: 1;
}
.menu-title {
display: block;
font-size: 32rpx;
font-weight: bold;
color: #333;
margin-bottom: 8rpx;
}
.menu-desc {
display: block;
font-size: 24rpx;
color: #666;
}
.stats-card {
background: #fff;
border-radius: 24rpx;
padding: 32rpx;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.1);
}
.stats-title {
font-size: 32rpx;
font-weight: bold;
color: #333;
margin-bottom: 32rpx;
text-align: center;
}
.stats-content {
display: flex;
justify-content: space-around;
}
.stats-item {
text-align: center;
}
.stats-number {
display: block;
font-size: 48rpx;
font-weight: bold;
color: #2979ff;
margin-bottom: 8rpx;
}
.stats-label {
display: block;
font-size: 24rpx;
color: #666;
}
</style>