小程序拉取html页面,微信小程序自定义页面手动授权拉取用户信息

WXML代码:立即登录

***申请获取以下权限:

获得你的公开信息(昵称,头像等)

获得你的位置信息(当前位置)

授权登录

暂不授权

请升级微信版本

WXSS代码:.author-modal{

position: fixed;

top: 0rpx;

width: 100%;

height: 100vh;

background-color: rgba(255, 255, 255, 1);

}

.author-header {

margin: 0rpx auto 50rpx auto;

border-bottom: 1px solid #ccc;

text-align: center;

width: 95%;

height: 300rpx;

line-height: 450rpx;

}

.author-header image {

width: 200rpx;

height: 200rpx;

}

.author-content {

width: 80%;

margin: 0rpx auto 30rpx auto;

}

.author-content view{

margin: 0rpx 0rpx 20rpx 0rpx;

}

.author-content text {

display: block;

color: #9d9d9d;

line-height: 56rpx;

}

.author-bottom {

width: 80%;

font-size: 35rpx;

margin: 0rpx auto 20rpx auto;

}

JS代码:Page({

/**

* 页面的初始数据

*/

data: {

//判断小程序的API,回调,参数,组件等是否在当前版本可用。

canIUse: wx.canIUse('button.open-type.getUserInfo'),

authorModal: true

},

/**

* 立即登录

*/

authorLogo: function() {

let that = this;

that.setData({

authorModal: false

});

},

/**

* 授权登录

*/

bindGetUserInfo: function(e) {

if (e.detail.userInfo) {

var that = this;

that.getUserInfo();

} else {

wx.redirectTo({

url: '../pageIndex/index'

});

}

},

/**

* 暂不授权

*/

notAuthorized: function() {

let that = this;

that.setData({

authorModal: true

});

},

/**

* 获取用户信息

*/

getUserInfo: function() {

let that = this;

// 获取用户信息

wx.getUserInfo({

success: function(res) {

wx.login({

success: res => {

let userCode = res.code; // 用户code

// 其他函数

// ..... 根据code获取用户详细信息

that.setData({

authorModal: true

});

}

});

}

});

},

})

效果截图:

ce407d4794d7e8bf4e484b1a89029ad2.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值