微信小程序 用户中心界面
效果图展示
- 用户未授权界面效果图:

- 用户授权后界面展示图:

.wxml 文件
<view wx:if="{{isHide}}">
<view wx:if="{{canIUse}}">
<view class='header'>
<image src='/static/images/weixin_1.png'></image>
</view>
<view class='content'>
<view>申请获取以下权限</view>
<text>获得你的公开信息(昵称,头像等)</text>
</view>
<button class='bottom' type='primary' open-type="getUserInfo" lang="zh_CN" bindgetuserinfo="bindGetUserInfo">
授权登录
</button>
</view>
<view wx:else>请升级微信版本</view>
</view>
<view wx:else>
<view class="userinfo">
<image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" background-size="cover"></image>
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
</view>
<view class="hr"></view>
<view class='item'>
<view class="title">手机绑定</view>
<view class="detail2">
<text>></text>
</view>
</view>
<view class="line"></view>
<view class='item'>
<view class="title">写博客</view>
<view class="detail2">
<text>></text>
</view>
</view>
<view class="hr"></view>
<view class='item'>
<view class="title">我的博客</view>
<view class="detail2">
<text> ></text>
</view>
</view>
<view class="line"></view>
<view class="item">
<view class="title">我的收藏</view>
<view class="detail2">
<text> ></text>
</view>
</view>
<view class="line"></view>
<view class="item">
<view class="title">意见反馈</view>
<view class="detail2">
<text> ></text>
</view>
</view>
<view class="line"></view>
<view class="item">
<view class="title">设置</view>
<view class="detail2">
<text> ></text>
</view>
</view>
<view class="hr"></view>
</view>
.wxss 文件
.userinfo {
display: flex;
flex-direction: column;
align-items: center;
background: #eb6161;
width: 100%;
height: 300rpx;
}
.userinfo-avatar {
width: 128rpx;
height: 128rpx;
margin: 20rpx;
border-radius: 50%;
}
.userinfo-nickname {
color: black;
}
.header {
margin: 90rpx 0 90rpx 50rpx;
border-bottom: 1px solid #ccc;
text-align: center;
width: 650rpx;
height: 300rpx;
line-height: 450rpx;
}
.header image {
width: 200rpx;
height: 200rpx;
}
.content {
margin-left: 50rpx;
margin-bottom: 90rpx;
}
.content text {
display: block;
color: #9d9d9d;
margin-top: 40rpx;
}
.bottom {
border-radius: 80rpx;
margin: 70rpx 50rpx;
font-size: 35rpx;
}
.hr {
width: 100%;
height: 15px;
background-color: #f4f5f6;
}
.item {
display: flex;
flex-direction: row;
}
.title {
padding-top: 15px;
padding-bottom: 15px;
padding-left: 15px;
font-size: 15px;
}
.detail2 {
font-size: 15px;
position: absolute;
right: 10px;
height: 50px;
line-height: 50px;
color: #888;
}
.line {
border: 1px solid #ccc;
opacity: 0.2;
}
.js 文件
const app = getApp()
Page({
data: {
userInfo: {},
canIUse: wx.canIUse('button.open-type.getUserInfo'),
isHide: false,
},
bindViewTap: function() {
wx.navigateTo({
url: '../logs/logs'
})
},
onLoad: function() {
var that = this;
wx.getSetting({
success: function(res) {
if (res.authSetting['scope.userInfo']) {
wx.getUserInfo({
success: function(res) {
app.globalData.userInfo = res.userInfo
that.setData({
userInfo: res.userInfo,
})
wx.login({
success: res => {
}
});
}
});
} else {
that.setData({
isHide: true
});
}
}
});
},
bindGetUserInfo: function(e) {
if (e.detail.userInfo) {
var that = this;
console.log("用户的信息如下:");
console.log(e.detail.userInfo);
that.setData({
isHide: false,
userInfo: e.detail.userInfo
});
} else {
wx.showModal({
title: '警告',
content: '您点击了拒绝授权,将无法进入小程序,请授权之后再进入!!!',
showCancel: false,
confirmText: '返回授权',
success: function(res) {
if (res.confirm) {
console.log('用户点击了“返回授权”');
}
}
});
}
},
onReady: function() {
},
onShow: function() {
},
onHide: function() {
},
onUnload: function() {
},
onPullDownRefresh: function() {
},
onReachBottom: function() {
},
onShareAppMessage: function() {
}
})