| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- <template>
- <view class="container">
- <!-- 用户资料头部 -->
- <view class="user-header">
- <view class="user-info">
- <image class="avatar" :src="displayAvatar" mode="aspectFill"></image>
- <view class="user-details">
- <text class="username">{{ userInfo ? userInfo.nickname || userInfo.username : '未登录' }}</text>
- <text class="edit-profile" v-if="userInfo" @click="editProfile">编辑个人资料</text>
- <text class="edit-profile" v-else @click="goToLogin">去登录</text>
- </view>
- </view>
- <view class="settings-btn" @click="goToSettings">
- <text class="settings-icon">⚙️</text>
- </view>
- </view>
-
- <!-- VIP会员横幅 -->
- <view class="vip-banner" @click="goToVip">
- <text class="vip-text">开通VIP无限畅读好书</text>
- <button class="vip-btn">去开通</button>
- </view>
-
- <scroll-view class="scroll-content" scroll-y>
- <!-- 菜单列表 -->
- <view class="menu-section" v-if="userInfo">
- <view class="menu-item" v-for="(item, index) in menuItems" :key="index" @click="handleMenuClick(item)">
- <view class="menu-icon-wrapper">
- <text class="menu-icon">{{ item.icon }}</text>
- </view>
- <text class="menu-text">{{ item.name }}</text>
- <text class="menu-arrow">></text>
- </view>
- </view>
- </scroll-view>
- </view>
- </template>
- <script>
- import { getUserProfile } from '../../utils/api.js'
-
- const defaultAvatar = 'https://picsum.photos/seed/avatar/200/200'
-
- export default {
- data() {
- return {
- userInfo: null,
- menuItems: [
- {
- name: '消息',
- icon: '💬',
- action: 'messages'
- },
- {
- name: '笔记',
- icon: '📝',
- action: 'notes'
- },
- {
- name: '阅读排行',
- icon: '🏆',
- action: 'readingRank'
- },
- {
- name: '浏览记录',
- icon: '🕐',
- action: 'browsingHistory'
- },
- {
- name: '开通VIP记录',
- icon: '💰',
- action: 'vipRecords'
- },
- {
- name: '意见反馈',
- icon: '❓',
- action: 'feedback'
- }
- ]
- }
- },
- computed: {
- displayAvatar() {
- if (this.userInfo && this.userInfo.avatar) {
- return this.userInfo.avatar
- }
- return defaultAvatar
- }
- },
- onLoad() {
- this.loadUserInfo()
- },
- onShow() {
- this.loadUserInfo()
- },
- methods: {
- loadUserInfo() {
- try {
- const storedUser = uni.getStorageSync('userInfo')
- const isLogin = uni.getStorageSync('isLogin')
- if (!storedUser || !storedUser.id || !isLogin) {
- this.userInfo = null
- return
- }
- this.userInfo = storedUser
- this.fetchRemoteUser(storedUser.id)
- } catch (e) {
- console.error('读取用户信息失败', e)
- this.userInfo = null
- }
- },
- async fetchRemoteUser(userId) {
- try {
- const res = await getUserProfile(userId)
- if (res && res.code === 200 && res.data) {
- this.userInfo = {
- ...this.userInfo,
- ...res.data
- }
- uni.setStorageSync('userInfo', this.userInfo)
- }
- } catch (e) {
- console.error('刷新用户信息失败', e)
- }
- },
- editProfile() {
- uni.navigateTo({
- url: '/pages/edit-profile/edit-profile'
- })
- },
- goToLogin() {
- uni.navigateTo({
- url: '/pages/login/login'
- })
- },
- goToSettings() {
- uni.navigateTo({
- url: '/pages/settings/settings'
- })
- },
- goToVip() {
- uni.navigateTo({
- url: '/pages/vip/vip'
- })
- },
- handleMenuClick(item) {
- switch(item.action) {
- case 'messages':
- uni.navigateTo({
- url: '/pages/messages/messages'
- })
- break
- case 'notes':
- uni.navigateTo({
- url: '/pages/notes/notes'
- })
- break
- case 'readingRank':
- uni.navigateTo({
- url: '/pages/reading-rank/reading-rank'
- })
- break
- case 'browsingHistory':
- uni.navigateTo({
- url: '/pages/browsing-history/browsing-history'
- })
- break
- case 'vipRecords':
- uni.navigateTo({
- url: '/pages/vip-records/vip-records'
- })
- break
- case 'feedback':
- uni.navigateTo({
- url: '/pages/feedback/feedback'
- })
- break
- }
- }
- }
- }
- </script>
- <style scoped>
- .container {
- width: 100%;
- height: 100vh;
- background-color: #FFFFFF;
- display: flex;
- flex-direction: column;
- padding-top: 80px;
- box-sizing: border-box;
- }
-
- .user-header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 40rpx 30rpx;
- background-color: #FFFFFF;
- border-bottom: 1rpx solid #F0F0F0;
- }
-
- .user-info {
- display: flex;
- align-items: center;
- flex: 1;
- }
-
- .avatar {
- width: 120rpx;
- height: 120rpx;
- border-radius: 50%;
- margin-right: 30rpx;
- background-color: #F5F5F5;
- border: 2rpx solid #E0E0E0;
- }
-
- .user-details {
- display: flex;
- flex-direction: column;
- }
-
- .username {
- font-size: 40rpx;
- font-weight: bold;
- color: #333333;
- margin-bottom: 15rpx;
- }
-
- .edit-profile {
- font-size: 26rpx;
- color: #999999;
- }
-
- .settings-btn {
- width: 60rpx;
- height: 60rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- }
-
- .settings-icon {
- font-size: 40rpx;
- color: #333333;
- }
-
- .vip-banner {
- display: flex;
- align-items: center;
- justify-content: space-between;
- margin: 30rpx;
- padding: 30rpx;
- background: linear-gradient(135deg, #FFE5CC 0%, #FFF0E0 100%);
- border-radius: 16rpx;
- box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.05);
- }
-
- .vip-text {
- font-size: 28rpx;
- color: #666666;
- flex: 1;
- }
-
- .vip-btn {
- width: 140rpx;
- height: 60rpx;
- background-color: #666666;
- color: #FFFFFF;
- font-size: 26rpx;
- border: none;
- border-radius: 30rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- flex-shrink: 0;
- }
-
- .vip-btn::after {
- border: none;
- }
-
- .scroll-content {
- flex: 1;
- width: 100%;
- }
-
- .menu-section {
- background-color: #FFFFFF;
- padding: 0 30rpx;
- }
-
- .menu-item {
- display: flex;
- align-items: center;
- padding: 35rpx 0;
- border-bottom: 1rpx solid #F0F0F0;
- }
-
- .menu-item:last-child {
- border-bottom: none;
- }
-
- .menu-icon-wrapper {
- width: 60rpx;
- height: 60rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- margin-right: 30rpx;
- }
-
- .menu-icon {
- font-size: 40rpx;
- }
-
- .menu-text {
- flex: 1;
- font-size: 32rpx;
- color: #333333;
- }
-
- .menu-arrow {
- font-size: 32rpx;
- color: #CCCCCC;
- }
- </style>
|