/*登入界面 login.js*/
const app = getApp()
Page({
data: {
userIcon: "../../images/default_icon.gif",
userName: "未登录",
settingName: "授权"
},
onShow: function () {
let that = this;
wx.getSetting({
success(res) {
if (!res.authSetting['scope.userInfo']) {
console.info("用户未授权");
wx.openSetting();
} else {
console.info("用户已经授权");
that.setUserInfo();
}
}
})
},
setUserInfo: function () {
let that = this;
wx.getUserInfo({
success: function (userRes) {
that.setData({ //设置数据
userIcon: userRes.userInfo.avatarUrl,
userName: userRes.userInfo.nickName,
settingName: "已授权",
haveLogin: true
})
}
});
},//打开权限设置
openSetting: function () { //打开授权界面
let that = this;
wx.openSetting()
}
})
/*login.wxml*/
<view class="container">
<view class='avatar'><image src="{{userIcon}}"></image></view>
<view class="user-name">{{userName}}</view>
<button bindtap="openSetting" class='btn'>{{settingName}}</button>
</view>
/*login.wxss*/
.avatar{
text-align: center;
}
.avatar image{
margin: 0px auto;
width: 100px;
height: 100px;
border-radius: 50px;
}
.user-name{
text-align: center;
margin-top: 10px;
}
.btn{
margin: 50px 20px 0px 20px;
background:red;
color: #fff;
}