Browse Source

feat(用户中心): 添加登录状态判断及登录按钮

在用户中心页面添加了登录状态判断逻辑,未登录时显示登录按钮和提示信息,已登录时显示菜单。同时优化了头像和昵称的默认显示内容,提升用户体验。
master
前端-胡立永 3 weeks ago
parent
commit
ea8f070ff1
2 changed files with 43 additions and 7 deletions
  1. +41
    -5
      pages/index/center.vue
  2. +2
    -2
      pages/index/index.vue

+ 41
- 5
pages/index/center.vue View File

@ -5,11 +5,11 @@
<view class="head">
<view class="headImage">
<image :src="userInfo.headImage" mode="aspectFill"></image>
<image :src="userInfo.headImage || '/static/image/center/default_avatar.png'" mode="aspectFill"></image>
</view>
<view class="info">
<view class="name">
{{ userInfo.nickName || '微信用户'}}
{{ userInfo.nickName || '未登录用户'}}
</view>
<view class="tips"
v-if="userInfo.createTime">
@ -21,7 +21,14 @@
</view>
</view>
<view class="line">
<!-- 未登录状态显示登录按钮 -->
<view v-if="!isLogin" class="login-container">
<button class="login-btn" @click="toLogin">立即登录</button>
<view class="login-tips">登录后查看更多功能</view>
</view>
<!-- 已登录状态显示菜单 -->
<view class="line" v-if="isLogin">
<uv-cell-group>
<!-- 我的收藏 -->
@ -104,6 +111,9 @@
export default {
computed: {
...mapState(['userInfo']),
isLogin() {
return this.userInfo && this.userInfo.id
}
},
data() {
return {
@ -111,10 +121,14 @@
}
},
onShow() {
this.$store.commit('getUserInfo')
if(uni.getStorageSync('token')){
this.$store.commit('getUserInfo')
}
},
methods: {
toLogin() {
this.$utils.navigateTo('/pages_order/auth/wxLogin')
}
}
}
</script>
@ -180,5 +194,27 @@
}
}
.login-container {
display: flex;
flex-direction: column;
align-items: center;
margin: 60rpx 30rpx;
}
.login-btn {
width: 80%;
height: 80rpx;
line-height: 80rpx;
background-color: $uni-color;
color: #fff;
border-radius: 40rpx;
font-size: 32rpx;
margin-bottom: 20rpx;
}
.login-tips {
font-size: 26rpx;
color: #999;
}
</style>

+ 2
- 2
pages/index/index.vue View File

@ -37,9 +37,9 @@
<view class="index_box">
<view class="image-box">
<view class="image-box"
@click="$utils.navigateTo('/pages_order/service/newsList')">
<image :src="config_new_image"
@click="$utils.navigateTo('/pages_order/service/newsList')"
class="image" mode="aspectFill"></image>
<view class="image-text">


Loading…
Cancel
Save