按官方通知调整微信登录
This commit is contained in:
parent
441c1eaa68
commit
1929fc9c7d
|
|
@ -4,10 +4,17 @@ var user = require('../../../utils/user.js');
|
|||
|
||||
var app = getApp();
|
||||
Page({
|
||||
data: {
|
||||
canIUseGetUserProfile: false, // 用于向前兼容
|
||||
},
|
||||
onLoad: function(options) {
|
||||
// 页面初始化 options为页面跳转所带来的参数
|
||||
// 页面渲染完成
|
||||
|
||||
if (wx.getUserProfile) {
|
||||
this.setData({
|
||||
canIUseGetUserProfile: true
|
||||
})
|
||||
}
|
||||
},
|
||||
onReady: function() {
|
||||
|
||||
|
|
@ -23,6 +30,30 @@ Page({
|
|||
// 页面关闭
|
||||
|
||||
},
|
||||
getUserProfile(e) {
|
||||
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
|
||||
// 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
|
||||
wx.getUserProfile({
|
||||
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
|
||||
success: (res) => {
|
||||
user.checkLogin().catch(() => {
|
||||
user.loginByWeixin(res.userInfo).then(res => {
|
||||
app.globalData.hasLogin = true;
|
||||
wx.navigateBack({
|
||||
delta: 1
|
||||
})
|
||||
}).catch((err) => {
|
||||
app.globalData.hasLogin = false;
|
||||
util.showErrorToast('微信登录失败');
|
||||
});
|
||||
});
|
||||
},
|
||||
fail: (res) => {
|
||||
app.globalData.hasLogin = false;
|
||||
util.showErrorToast('微信登录失败');
|
||||
}
|
||||
});
|
||||
},
|
||||
wxLogin: function(e) {
|
||||
if (e.detail.userInfo == undefined) {
|
||||
app.globalData.hasLogin = false;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<view class="container">
|
||||
<view class="login-box">
|
||||
<button type="primary" open-type="getUserInfo" class="wx-login-btn" bindgetuserinfo="wxLogin">微信直接登录</button>
|
||||
<button wx:if="{{canIUseGetUserProfile}}" class="wx-login-btn" bindtap="getUserProfile">微信直接登录</button>
|
||||
<button wx:else open-type="getUserInfo" class="wx-login-btn" bindgetuserinfo="wxLogin">微信直接登录</button>
|
||||
<button type="primary" class="account-login-btn" bindtap="accountLogin">账号登录</button>
|
||||
</view>
|
||||
</view>
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
}
|
||||
},
|
||||
"compileType": "miniprogram",
|
||||
"libVersion": "2.9.4",
|
||||
"libVersion": "2.16.0",
|
||||
"appid": "wx4901b319ace4f88a",
|
||||
"projectname": "dts-shop",
|
||||
"simulatorType": "wechat",
|
||||
|
|
|
|||
Loading…
Reference in New Issue